@ayushshanker/mdo 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cli.js +30 -2
- package/package.json +1 -1
package/lib/cli.js
CHANGED
|
@@ -12,10 +12,33 @@ const {
|
|
|
12
12
|
validatePort
|
|
13
13
|
} = require("./utils");
|
|
14
14
|
|
|
15
|
+
function themeNames() {
|
|
16
|
+
return Object.keys(THEMES);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function hasBareThemeFlag(argv) {
|
|
20
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
21
|
+
if (argv[index] !== "--theme") {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const next = argv[index + 1];
|
|
26
|
+
if (!next || next.startsWith("-")) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function printThemeList() {
|
|
35
|
+
process.stdout.write(`Available themes:\n${themeNames().map((name) => `- ${name}`).join("\n")}\n`);
|
|
36
|
+
}
|
|
37
|
+
|
|
15
38
|
function resolveThemeOption(options) {
|
|
16
39
|
if (options.theme) {
|
|
17
40
|
if (!Object.hasOwn(THEMES, options.theme)) {
|
|
18
|
-
throw new Error(`Theme must be one of: ${
|
|
41
|
+
throw new Error(`Theme must be one of: ${themeNames().join(", ")}.`);
|
|
19
42
|
}
|
|
20
43
|
return options.theme;
|
|
21
44
|
}
|
|
@@ -34,7 +57,7 @@ function buildProgram() {
|
|
|
34
57
|
.option("--dark", "Use GitHub dark theme.")
|
|
35
58
|
.option(
|
|
36
59
|
"--theme <name>",
|
|
37
|
-
`Use a named theme: ${
|
|
60
|
+
`Use a named theme: ${themeNames().join(", ")}.`
|
|
38
61
|
)
|
|
39
62
|
.option("--output <file>", "Write HTML to a file instead of opening the browser.")
|
|
40
63
|
.option("--port <port>", "Use a fixed port for folder mode.", validatePort)
|
|
@@ -56,6 +79,11 @@ Examples:
|
|
|
56
79
|
}
|
|
57
80
|
|
|
58
81
|
async function runCli(argv = process.argv) {
|
|
82
|
+
if (hasBareThemeFlag(argv.slice(2))) {
|
|
83
|
+
printThemeList();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
59
87
|
const program = buildProgram();
|
|
60
88
|
program.exitOverride();
|
|
61
89
|
|