generated from AnandChowdhary/node.ts
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcli.ts
32 lines (28 loc) · 887 Bytes
/
cli.ts
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
#!/usr/bin/env node
import { fetchGoogleDocsFiles, googleDocsToMarkdown } from "./index";
import { readFileSync, writeFileSync } from "fs";
import { join } from "path";
const command = process.argv[2];
if (!command) throw new Error("Command required: 'docs-markdown fetch'");
if (command === "fetch") {
const files: string[] = (process.argv.length > 3
? process.argv[3]
: process.env.FILES || ""
)
.split(",")
.map((i) => i.trim());
fetchGoogleDocsFiles(files);
}
if (command === "convert") {
const files: string[] = (process.argv.length > 3
? process.argv[3]
: process.env.FILES || ""
)
.split(",")
.map((i) => i.trim());
files.forEach((file) => {
const fileContents = JSON.parse(readFileSync(join(".", file)).toString());
const markdown = googleDocsToMarkdown(fileContents);
writeFileSync(join(".", `${file.replace(".json", "")}.md`), markdown);
});
}