-
-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathmain.js
More file actions
27 lines (23 loc) · 806 Bytes
/
main.js
File metadata and controls
27 lines (23 loc) · 806 Bytes
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
import { program } from "commander";
import * as fs from "node:fs/promises";
import { marked } from "marked";
// gfmオプションを定義する
program.option("--gfm", "GFMを有効にする");
program.parse(process.argv);
const filePath = program.args[0];
// コマンドライン引数のオプションを取得する
const options = program.opts();
// コマンドライン引数で指定されなかったオプションにデフォルト値を上書きする
const cliOptions = {
gfm: options.gfm ?? false,
};
fs.readFile(filePath, { encoding: "utf8" }).then(file => {
const html = marked.parse(file, {
// オプションの値を使用する
gfm: cliOptions.gfm,
});
console.log(html);
}).catch(err => {
console.error(err.message);
process.exit(1);
});