-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·95 lines (93 loc) · 2.34 KB
/
index.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env node
const open = require("open");
const { config } = require("./lib/config");
const postie = require("./commands/postie");
const newTemplate = require("./commands/newTemplate");
const { importTemplate } = require("./lib/templateUtil");
const argv = require("yargs")
.command(
"$0",
"Create file with default template",
yargs => {
return yargs
.option("template", {
type: "string",
alias: "t",
describe: "Create file with a specific template",
nargs: 1
})
.option("path", {
type: "string",
alias: "p",
describe: "Output directory for markdown files",
nargs: 1
});
},
({ t, p }) => postie(t, p)
)
.command(
"config",
"Open the configuration file",
yargs =>
yargs
.option("path", {
alias: "p",
type: "string",
nargs: 1,
describe: "Default output path for markdown files created"
})
.option("list", {
alias: "l",
type: "array",
describe: "List all configs"
})
.option("clear", {
alias: "c",
describe: "Clear all configs"
}),
({ p, l, c }) => {
if (c) config.clear();
else if (l) console.log(config.all);
else if (p) {
config.set("outputPath", p);
console.log("Default path modified");
} else {
open(config.path);
}
}
)
.command(
"template",
"Create a new template",
yargs =>
yargs
.option("list", {
alias: "l",
type: "list",
describe: "List all templates"
})
.option("import", {
alias: "i",
nargs: 1,
describe: "Create template from a javascript file"
}),
({ l, i }) => {
if (i) {
importTemplate(i);
} else if (l) {
console.log(Object.keys(config.get("templates")));
} else {
newTemplate();
}
}
)
.help("h")
.alias("help", "h")
.example("$0 -t mytemplate")
.example("$0 -p ..")
.example("$0 -p /path/to/your/directory")
.example("$0 config -p /default/output/directory")
.example("$0 template -i mytemplate.js")
.usage(
"Usage: $0 <command> [options]\n Use $0 <command> -h to see available options for each command"
).argv;