-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewmd.js
More file actions
executable file
·51 lines (42 loc) · 1.47 KB
/
viewmd.js
File metadata and controls
executable file
·51 lines (42 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env node
const { program } = require('commander');
const { viewMarkdown } = require('./index.js');
const fs = require('fs');
const path = require('path');
program
.name('viewmd')
.description('View markdown files with GitHub-flavored markdown and Mermaid support')
.version('1.0.0')
.argument('<files...>', 'markdown files to view')
.option('-p, --port <number>', 'specific port to use', parseInt)
.option('--no-open', 'don\'t automatically open browser')
.option('-k, --keep-alive', 'keep server running after browser closes')
.option('-s, --snapshot', 'render once without watching for changes')
.action(async (files, options) => {
try {
const filePaths = [];
for (const file of files) {
const filePath = path.resolve(file);
if (!fs.existsSync(filePath)) {
console.error(`Error: File not found: ${file}`);
process.exit(1);
}
const stats = fs.statSync(filePath);
if (!stats.isFile()) {
console.error(`Error: Not a file: ${file}`);
process.exit(1);
}
filePaths.push(filePath);
}
// Set watch to true by default unless snapshot mode is requested
const viewOptions = {
...options,
watch: !options.snapshot
};
await viewMarkdown(filePaths, viewOptions);
} catch (error) {
console.error('Error:', error.message);
process.exit(1);
}
});
program.parse();