comarkserv 0.1.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/LICENSE +21 -0
- package/README.md +389 -0
- package/dist/THIRD_PARTY_LICENSES.md +932 -0
- package/dist/build-CsToYJrU.mjs +2 -0
- package/dist/build-Cv5aO0CB.mjs +205 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +894 -0
- package/dist/cloudflared-6f_lzz4F.mjs +181 -0
- package/dist/dist-B-IALNns.mjs +2 -0
- package/dist/dist-BK-bpLWg.mjs +2 -0
- package/dist/dist-BQzCbTko.mjs +1693 -0
- package/dist/dist-BWcWG5YB.mjs +671 -0
- package/dist/dist-BiVw4ojz.mjs +592 -0
- package/dist/dist-BnmL9jeq.mjs +538 -0
- package/dist/dist-BtedNLrc.mjs +276 -0
- package/dist/dist-BvdNTrap.mjs +2710 -0
- package/dist/dist-ByijHttv.mjs +69 -0
- package/dist/dist-C2E4zSX1.mjs +347 -0
- package/dist/dist-CWYRQLUT.mjs +2 -0
- package/dist/dist-CXQ7eTfT.mjs +417 -0
- package/dist/dist-CfsjQ0o8.mjs +905 -0
- package/dist/dist-CsTXDvwi.mjs +300 -0
- package/dist/dist-CtONMLh4.mjs +283 -0
- package/dist/dist-DMftjyxU.mjs +370 -0
- package/dist/dist-Dr9uTCX7.mjs +2 -0
- package/dist/dist-Dxvc11TH.mjs +339 -0
- package/dist/dist-GmbcGEAc.mjs +3 -0
- package/dist/dist-V1rkISnf.mjs +220 -0
- package/dist/dist-ZoN94PJ0.mjs +76 -0
- package/dist/dist-fh99cWMN.mjs +524 -0
- package/dist/editor-CHDyOp-8.mjs +721 -0
- package/dist/index.d.mts +301 -0
- package/dist/index.mjs +6 -0
- package/dist/languages-C0kEygG_.mjs +119 -0
- package/dist/markdown-BqKed1Vq.mjs +710 -0
- package/dist/markdown-DWuqfzps.mjs +2 -0
- package/dist/rolldown-runtime-CMFfr-1z.mjs +26 -0
- package/dist/server-Dkjk_D1Y.mjs +2628 -0
- package/dist/terminal-aKr5Xlp3.mjs +169 -0
- package/dist/themes-mEufQ_3e.mjs +2194 -0
- package/dist/twinkleplop.production-Coccf2Q9.mjs +2 -0
- package/dist/twinkleplop.production-DekYmX6O.mjs +4697 -0
- package/dist/twinkleplop.tokens-CgBUTCSg.mjs +76 -0
- package/package.json +133 -0
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,894 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { O as relative, T as dirname, k as resolve, r as createThemeStore, t as OMARCHY_CURRENT, u as findReadme, w as basename } from "./themes-mEufQ_3e.mjs";
|
|
3
|
+
import { o as CLOUDFLARE_LINKS, r as startServer, s as isCloudflaredInstalled, t as DEFAULT_PORT } from "./server-Dkjk_D1Y.mjs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
6
|
+
import { networkInterfaces } from "node:os";
|
|
7
|
+
import { parseArgs, styleText } from "node:util";
|
|
8
|
+
import { spawn } from "node:child_process";
|
|
9
|
+
import { createInterface } from "node:readline/promises";
|
|
10
|
+
//#region node_modules/.pnpm/citty@0.2.2/node_modules/citty/dist/_chunks/libs/scule.mjs
|
|
11
|
+
const NUMBER_CHAR_RE = /\d/;
|
|
12
|
+
const STR_SPLITTERS = [
|
|
13
|
+
"-",
|
|
14
|
+
"_",
|
|
15
|
+
"/",
|
|
16
|
+
"."
|
|
17
|
+
];
|
|
18
|
+
function isUppercase(char = "") {
|
|
19
|
+
if (NUMBER_CHAR_RE.test(char)) return;
|
|
20
|
+
return char !== char.toLowerCase();
|
|
21
|
+
}
|
|
22
|
+
function splitByCase(str, separators) {
|
|
23
|
+
const splitters = separators ?? STR_SPLITTERS;
|
|
24
|
+
const parts = [];
|
|
25
|
+
if (!str || typeof str !== "string") return parts;
|
|
26
|
+
let buff = "";
|
|
27
|
+
let previousUpper;
|
|
28
|
+
let previousSplitter;
|
|
29
|
+
for (const char of str) {
|
|
30
|
+
const isSplitter = splitters.includes(char);
|
|
31
|
+
if (isSplitter === true) {
|
|
32
|
+
parts.push(buff);
|
|
33
|
+
buff = "";
|
|
34
|
+
previousUpper = void 0;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const isUpper = isUppercase(char);
|
|
38
|
+
if (previousSplitter === false) {
|
|
39
|
+
if (previousUpper === false && isUpper === true) {
|
|
40
|
+
parts.push(buff);
|
|
41
|
+
buff = char;
|
|
42
|
+
previousUpper = isUpper;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (previousUpper === true && isUpper === false && buff.length > 1) {
|
|
46
|
+
const lastChar = buff.at(-1);
|
|
47
|
+
parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
|
|
48
|
+
buff = lastChar + char;
|
|
49
|
+
previousUpper = isUpper;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
buff += char;
|
|
54
|
+
previousUpper = isUpper;
|
|
55
|
+
previousSplitter = isSplitter;
|
|
56
|
+
}
|
|
57
|
+
parts.push(buff);
|
|
58
|
+
return parts;
|
|
59
|
+
}
|
|
60
|
+
function upperFirst(str) {
|
|
61
|
+
return str ? str[0].toUpperCase() + str.slice(1) : "";
|
|
62
|
+
}
|
|
63
|
+
function lowerFirst(str) {
|
|
64
|
+
return str ? str[0].toLowerCase() + str.slice(1) : "";
|
|
65
|
+
}
|
|
66
|
+
function pascalCase(str, opts) {
|
|
67
|
+
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
|
|
68
|
+
}
|
|
69
|
+
function camelCase(str, opts) {
|
|
70
|
+
return lowerFirst(pascalCase(str || "", opts));
|
|
71
|
+
}
|
|
72
|
+
function kebabCase(str, joiner) {
|
|
73
|
+
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
|
|
74
|
+
}
|
|
75
|
+
function snakeCase(str) {
|
|
76
|
+
return kebabCase(str || "", "_");
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region node_modules/.pnpm/citty@0.2.2/node_modules/citty/dist/index.mjs
|
|
80
|
+
function toArray(val) {
|
|
81
|
+
if (Array.isArray(val)) return val;
|
|
82
|
+
return val === void 0 ? [] : [val];
|
|
83
|
+
}
|
|
84
|
+
function formatLineColumns(lines, linePrefix = "") {
|
|
85
|
+
const maxLength = [];
|
|
86
|
+
for (const line of lines) for (const [i, element] of line.entries()) maxLength[i] = Math.max(maxLength[i] || 0, element.length);
|
|
87
|
+
return lines.map((l) => l.map((c, i) => linePrefix + c[i === 0 ? "padStart" : "padEnd"](maxLength[i])).join(" ")).join("\n");
|
|
88
|
+
}
|
|
89
|
+
function resolveValue(input) {
|
|
90
|
+
return typeof input === "function" ? input() : input;
|
|
91
|
+
}
|
|
92
|
+
var CLIError = class extends Error {
|
|
93
|
+
code;
|
|
94
|
+
constructor(message, code) {
|
|
95
|
+
super(message);
|
|
96
|
+
this.name = "CLIError";
|
|
97
|
+
this.code = code;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
function parseRawArgs(args = [], opts = {}) {
|
|
101
|
+
const booleans = new Set(opts.boolean || []);
|
|
102
|
+
const strings = new Set(opts.string || []);
|
|
103
|
+
const aliasMap = opts.alias || {};
|
|
104
|
+
const defaults = opts.default || {};
|
|
105
|
+
const aliasToMain = /* @__PURE__ */ new Map();
|
|
106
|
+
const mainToAliases = /* @__PURE__ */ new Map();
|
|
107
|
+
for (const [key, value] of Object.entries(aliasMap)) {
|
|
108
|
+
const targets = value;
|
|
109
|
+
for (const target of targets) {
|
|
110
|
+
aliasToMain.set(key, target);
|
|
111
|
+
if (!mainToAliases.has(target)) mainToAliases.set(target, []);
|
|
112
|
+
mainToAliases.get(target).push(key);
|
|
113
|
+
aliasToMain.set(target, key);
|
|
114
|
+
if (!mainToAliases.has(key)) mainToAliases.set(key, []);
|
|
115
|
+
mainToAliases.get(key).push(target);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const options = {};
|
|
119
|
+
function getType(name) {
|
|
120
|
+
if (booleans.has(name)) return "boolean";
|
|
121
|
+
const aliases = mainToAliases.get(name) || [];
|
|
122
|
+
for (const alias of aliases) if (booleans.has(alias)) return "boolean";
|
|
123
|
+
return "string";
|
|
124
|
+
}
|
|
125
|
+
function isStringType(name) {
|
|
126
|
+
if (strings.has(name)) return true;
|
|
127
|
+
const aliases = mainToAliases.get(name) || [];
|
|
128
|
+
for (const alias of aliases) if (strings.has(alias)) return true;
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
const allOptions = /* @__PURE__ */ new Set([
|
|
132
|
+
...booleans,
|
|
133
|
+
...strings,
|
|
134
|
+
...Object.keys(aliasMap),
|
|
135
|
+
...Object.values(aliasMap).flat(),
|
|
136
|
+
...Object.keys(defaults)
|
|
137
|
+
]);
|
|
138
|
+
for (const name of allOptions) if (!options[name]) options[name] = {
|
|
139
|
+
type: getType(name),
|
|
140
|
+
default: defaults[name]
|
|
141
|
+
};
|
|
142
|
+
for (const [alias, main] of aliasToMain.entries()) if (alias.length === 1 && options[main] && !options[main].short) options[main].short = alias;
|
|
143
|
+
const processedArgs = [];
|
|
144
|
+
const negatedFlags = {};
|
|
145
|
+
for (let i = 0; i < args.length; i++) {
|
|
146
|
+
const arg = args[i];
|
|
147
|
+
if (arg === "--") {
|
|
148
|
+
processedArgs.push(...args.slice(i));
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
if (arg.startsWith("--no-")) {
|
|
152
|
+
const flagName = arg.slice(5);
|
|
153
|
+
negatedFlags[flagName] = true;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
processedArgs.push(arg);
|
|
157
|
+
}
|
|
158
|
+
let parsed;
|
|
159
|
+
try {
|
|
160
|
+
parsed = parseArgs({
|
|
161
|
+
args: processedArgs,
|
|
162
|
+
options: Object.keys(options).length > 0 ? options : void 0,
|
|
163
|
+
allowPositionals: true,
|
|
164
|
+
strict: false
|
|
165
|
+
});
|
|
166
|
+
} catch {
|
|
167
|
+
parsed = {
|
|
168
|
+
values: {},
|
|
169
|
+
positionals: processedArgs
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const out = { _: [] };
|
|
173
|
+
out._ = parsed.positionals;
|
|
174
|
+
for (const [key, value] of Object.entries(parsed.values)) {
|
|
175
|
+
let coerced = value;
|
|
176
|
+
if (getType(key) === "boolean" && typeof value === "string") coerced = value !== "false";
|
|
177
|
+
else if (isStringType(key) && typeof value === "boolean") coerced = "";
|
|
178
|
+
out[key] = coerced;
|
|
179
|
+
}
|
|
180
|
+
for (const [name] of Object.entries(negatedFlags)) {
|
|
181
|
+
out[name] = false;
|
|
182
|
+
const mainName = aliasToMain.get(name);
|
|
183
|
+
if (mainName) out[mainName] = false;
|
|
184
|
+
const aliases = mainToAliases.get(name);
|
|
185
|
+
if (aliases) for (const alias of aliases) out[alias] = false;
|
|
186
|
+
}
|
|
187
|
+
for (const [alias, main] of aliasToMain.entries()) {
|
|
188
|
+
if (out[alias] !== void 0 && out[main] === void 0) out[main] = out[alias];
|
|
189
|
+
if (out[main] !== void 0 && out[alias] === void 0) out[alias] = out[main];
|
|
190
|
+
if (out[alias] !== out[main] && defaults[main] === out[main]) out[main] = out[alias];
|
|
191
|
+
}
|
|
192
|
+
return out;
|
|
193
|
+
}
|
|
194
|
+
const noColor = /* @__PURE__ */ (() => {
|
|
195
|
+
const env = globalThis.process?.env ?? {};
|
|
196
|
+
return env.NO_COLOR === "1" || env.TERM === "dumb" || env.TEST || env.CI;
|
|
197
|
+
})();
|
|
198
|
+
const _c = (c, r = 39) => (t) => noColor ? t : `\u001B[${c}m${t}\u001B[${r}m`;
|
|
199
|
+
const bold = /* @__PURE__ */ _c(1, 22);
|
|
200
|
+
const cyan = /* @__PURE__ */ _c(36);
|
|
201
|
+
const gray = /* @__PURE__ */ _c(90);
|
|
202
|
+
const underline = /* @__PURE__ */ _c(4, 24);
|
|
203
|
+
function parseArgs$1(rawArgs, argsDef) {
|
|
204
|
+
const parseOptions = {
|
|
205
|
+
boolean: [],
|
|
206
|
+
string: [],
|
|
207
|
+
alias: {},
|
|
208
|
+
default: {}
|
|
209
|
+
};
|
|
210
|
+
const args = resolveArgs(argsDef);
|
|
211
|
+
for (const arg of args) {
|
|
212
|
+
if (arg.type === "positional") continue;
|
|
213
|
+
if (arg.type === "string" || arg.type === "enum") parseOptions.string.push(arg.name);
|
|
214
|
+
else if (arg.type === "boolean") parseOptions.boolean.push(arg.name);
|
|
215
|
+
if (arg.default !== void 0) parseOptions.default[arg.name] = arg.default;
|
|
216
|
+
if (arg.alias) parseOptions.alias[arg.name] = arg.alias;
|
|
217
|
+
const camelName = camelCase(arg.name);
|
|
218
|
+
const kebabName = kebabCase(arg.name);
|
|
219
|
+
if (camelName !== arg.name || kebabName !== arg.name) {
|
|
220
|
+
const existingAliases = toArray(parseOptions.alias[arg.name] || []);
|
|
221
|
+
if (camelName !== arg.name && !existingAliases.includes(camelName)) existingAliases.push(camelName);
|
|
222
|
+
if (kebabName !== arg.name && !existingAliases.includes(kebabName)) existingAliases.push(kebabName);
|
|
223
|
+
if (existingAliases.length > 0) parseOptions.alias[arg.name] = existingAliases;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const parsed = parseRawArgs(rawArgs, parseOptions);
|
|
227
|
+
const [ ...positionalArguments] = parsed._;
|
|
228
|
+
const parsedArgsProxy = new Proxy(parsed, { get(target, prop) {
|
|
229
|
+
return target[prop] ?? target[camelCase(prop)] ?? target[kebabCase(prop)];
|
|
230
|
+
} });
|
|
231
|
+
for (const [, arg] of args.entries()) if (arg.type === "positional") {
|
|
232
|
+
const nextPositionalArgument = positionalArguments.shift();
|
|
233
|
+
if (nextPositionalArgument !== void 0) parsedArgsProxy[arg.name] = nextPositionalArgument;
|
|
234
|
+
else if (arg.default === void 0 && arg.required !== false) throw new CLIError(`Missing required positional argument: ${arg.name.toUpperCase()}`, "EARG");
|
|
235
|
+
else parsedArgsProxy[arg.name] = arg.default;
|
|
236
|
+
} else if (arg.type === "enum") {
|
|
237
|
+
const argument = parsedArgsProxy[arg.name];
|
|
238
|
+
const options = arg.options || [];
|
|
239
|
+
if (argument !== void 0 && options.length > 0 && !options.includes(argument)) throw new CLIError(`Invalid value for argument: ${cyan(`--${arg.name}`)} (${cyan(argument)}). Expected one of: ${options.map((o) => cyan(o)).join(", ")}.`, "EARG");
|
|
240
|
+
} else if (arg.required && parsedArgsProxy[arg.name] === void 0) throw new CLIError(`Missing required argument: --${arg.name}`, "EARG");
|
|
241
|
+
return parsedArgsProxy;
|
|
242
|
+
}
|
|
243
|
+
function resolveArgs(argsDef) {
|
|
244
|
+
const args = [];
|
|
245
|
+
for (const [name, argDef] of Object.entries(argsDef || {})) args.push({
|
|
246
|
+
...argDef,
|
|
247
|
+
name,
|
|
248
|
+
alias: toArray(argDef.alias)
|
|
249
|
+
});
|
|
250
|
+
return args;
|
|
251
|
+
}
|
|
252
|
+
async function resolvePlugins(plugins) {
|
|
253
|
+
return Promise.all(plugins.map((p) => resolveValue(p)));
|
|
254
|
+
}
|
|
255
|
+
function defineCommand(def) {
|
|
256
|
+
return def;
|
|
257
|
+
}
|
|
258
|
+
async function runCommand(cmd, opts) {
|
|
259
|
+
const cmdArgs = await resolveValue(cmd.args || {});
|
|
260
|
+
const parsedArgs = parseArgs$1(opts.rawArgs, cmdArgs);
|
|
261
|
+
const context = {
|
|
262
|
+
rawArgs: opts.rawArgs,
|
|
263
|
+
args: parsedArgs,
|
|
264
|
+
data: opts.data,
|
|
265
|
+
cmd
|
|
266
|
+
};
|
|
267
|
+
const plugins = await resolvePlugins(cmd.plugins ?? []);
|
|
268
|
+
let result;
|
|
269
|
+
let runError;
|
|
270
|
+
try {
|
|
271
|
+
for (const plugin of plugins) await plugin.setup?.(context);
|
|
272
|
+
if (typeof cmd.setup === "function") await cmd.setup(context);
|
|
273
|
+
const subCommands = await resolveValue(cmd.subCommands);
|
|
274
|
+
if (subCommands && Object.keys(subCommands).length > 0) {
|
|
275
|
+
const subCommandArgIndex = findSubCommandIndex(opts.rawArgs, cmdArgs);
|
|
276
|
+
const explicitName = opts.rawArgs[subCommandArgIndex];
|
|
277
|
+
if (explicitName) {
|
|
278
|
+
const subCommand = await _findSubCommand(subCommands, explicitName);
|
|
279
|
+
if (!subCommand) throw new CLIError(`Unknown command ${cyan(explicitName)}`, "E_UNKNOWN_COMMAND");
|
|
280
|
+
await runCommand(subCommand, { rawArgs: opts.rawArgs.slice(subCommandArgIndex + 1) });
|
|
281
|
+
} else {
|
|
282
|
+
const defaultSubCommand = await resolveValue(cmd.default);
|
|
283
|
+
if (defaultSubCommand) {
|
|
284
|
+
if (cmd.run) throw new CLIError(`Cannot specify both 'run' and 'default' on the same command.`, "E_DEFAULT_CONFLICT");
|
|
285
|
+
const subCommand = await _findSubCommand(subCommands, defaultSubCommand);
|
|
286
|
+
if (!subCommand) throw new CLIError(`Default sub command ${cyan(defaultSubCommand)} not found in subCommands.`, "E_UNKNOWN_COMMAND");
|
|
287
|
+
await runCommand(subCommand, { rawArgs: opts.rawArgs });
|
|
288
|
+
} else if (!cmd.run) throw new CLIError(`No command specified.`, "E_NO_COMMAND");
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (typeof cmd.run === "function") result = await cmd.run(context);
|
|
292
|
+
} catch (error) {
|
|
293
|
+
runError = error;
|
|
294
|
+
}
|
|
295
|
+
const cleanupErrors = [];
|
|
296
|
+
if (typeof cmd.cleanup === "function") try {
|
|
297
|
+
await cmd.cleanup(context);
|
|
298
|
+
} catch (error) {
|
|
299
|
+
cleanupErrors.push(error);
|
|
300
|
+
}
|
|
301
|
+
for (const plugin of [...plugins].reverse()) try {
|
|
302
|
+
await plugin.cleanup?.(context);
|
|
303
|
+
} catch (error) {
|
|
304
|
+
cleanupErrors.push(error);
|
|
305
|
+
}
|
|
306
|
+
if (runError) throw runError;
|
|
307
|
+
if (cleanupErrors.length === 1) throw cleanupErrors[0];
|
|
308
|
+
if (cleanupErrors.length > 1) throw new Error("Multiple cleanup errors", { cause: cleanupErrors });
|
|
309
|
+
return { result };
|
|
310
|
+
}
|
|
311
|
+
async function resolveSubCommand(cmd, rawArgs, parent) {
|
|
312
|
+
const subCommands = await resolveValue(cmd.subCommands);
|
|
313
|
+
if (subCommands && Object.keys(subCommands).length > 0) {
|
|
314
|
+
const subCommandArgIndex = findSubCommandIndex(rawArgs, await resolveValue(cmd.args || {}));
|
|
315
|
+
const subCommandName = rawArgs[subCommandArgIndex];
|
|
316
|
+
const subCommand = await _findSubCommand(subCommands, subCommandName);
|
|
317
|
+
if (subCommand) return resolveSubCommand(subCommand, rawArgs.slice(subCommandArgIndex + 1), cmd);
|
|
318
|
+
}
|
|
319
|
+
return [cmd, parent];
|
|
320
|
+
}
|
|
321
|
+
async function _findSubCommand(subCommands, name) {
|
|
322
|
+
if (name in subCommands) return resolveValue(subCommands[name]);
|
|
323
|
+
for (const sub of Object.values(subCommands)) {
|
|
324
|
+
const resolved = await resolveValue(sub);
|
|
325
|
+
const meta = await resolveValue(resolved?.meta);
|
|
326
|
+
if (meta?.alias) {
|
|
327
|
+
if (toArray(meta.alias).includes(name)) return resolved;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function findSubCommandIndex(rawArgs, argsDef) {
|
|
332
|
+
for (let i = 0; i < rawArgs.length; i++) {
|
|
333
|
+
const arg = rawArgs[i];
|
|
334
|
+
if (arg === "--") return -1;
|
|
335
|
+
if (arg.startsWith("-")) {
|
|
336
|
+
if (!arg.includes("=") && _isValueFlag(arg, argsDef)) i++;
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
return i;
|
|
340
|
+
}
|
|
341
|
+
return -1;
|
|
342
|
+
}
|
|
343
|
+
function _isValueFlag(flag, argsDef) {
|
|
344
|
+
const name = flag.replace(/^-{1,2}/, "");
|
|
345
|
+
const normalized = camelCase(name);
|
|
346
|
+
for (const [key, def] of Object.entries(argsDef)) {
|
|
347
|
+
if (def.type !== "string" && def.type !== "enum") continue;
|
|
348
|
+
if (normalized === camelCase(key)) return true;
|
|
349
|
+
if ((Array.isArray(def.alias) ? def.alias : def.alias ? [def.alias] : []).includes(name)) return true;
|
|
350
|
+
}
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
async function showUsage(cmd, parent) {
|
|
354
|
+
try {
|
|
355
|
+
console.log(await renderUsage(cmd, parent) + "\n");
|
|
356
|
+
} catch (error) {
|
|
357
|
+
console.error(error);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
const negativePrefixRe = /^no[-A-Z]/;
|
|
361
|
+
async function renderUsage(cmd, parent) {
|
|
362
|
+
const cmdMeta = await resolveValue(cmd.meta || {});
|
|
363
|
+
const cmdArgs = resolveArgs(await resolveValue(cmd.args || {}));
|
|
364
|
+
const parentMeta = await resolveValue(parent?.meta || {});
|
|
365
|
+
const commandName = `${parentMeta.name ? `${parentMeta.name} ` : ""}` + (cmdMeta.name || process.argv[1]);
|
|
366
|
+
const argLines = [];
|
|
367
|
+
const posLines = [];
|
|
368
|
+
const commandsLines = [];
|
|
369
|
+
const usageLine = [];
|
|
370
|
+
for (const arg of cmdArgs) if (arg.type === "positional") {
|
|
371
|
+
const name = arg.name.toUpperCase();
|
|
372
|
+
const isRequired = arg.required !== false && arg.default === void 0;
|
|
373
|
+
posLines.push([cyan(name + renderValueHint(arg)), renderDescription(arg, isRequired)]);
|
|
374
|
+
usageLine.push(isRequired ? `<${name}>` : `[${name}]`);
|
|
375
|
+
} else {
|
|
376
|
+
const isRequired = arg.required === true && arg.default === void 0;
|
|
377
|
+
const argStr = [...(arg.alias || []).map((a) => `-${a}`), `--${arg.name}`].join(", ") + renderValueHint(arg);
|
|
378
|
+
argLines.push([cyan(argStr), renderDescription(arg, isRequired)]);
|
|
379
|
+
/**
|
|
380
|
+
* print negative boolean arg variant usage when
|
|
381
|
+
* - enabled by default or has `negativeDescription`
|
|
382
|
+
* - not prefixed with `no-` or `no[A-Z]`
|
|
383
|
+
*/
|
|
384
|
+
if (arg.type === "boolean" && (arg.default === true || arg.negativeDescription) && !negativePrefixRe.test(arg.name)) {
|
|
385
|
+
const negativeArgStr = [...(arg.alias || []).map((a) => `--no-${a}`), `--no-${arg.name}`].join(", ");
|
|
386
|
+
argLines.push([cyan(negativeArgStr), [arg.negativeDescription, isRequired ? gray("(Required)") : ""].filter(Boolean).join(" ")]);
|
|
387
|
+
}
|
|
388
|
+
if (isRequired) usageLine.push(`--${arg.name}` + renderValueHint(arg));
|
|
389
|
+
}
|
|
390
|
+
if (cmd.subCommands) {
|
|
391
|
+
const commandNames = [];
|
|
392
|
+
const subCommands = await resolveValue(cmd.subCommands);
|
|
393
|
+
for (const [name, sub] of Object.entries(subCommands)) {
|
|
394
|
+
const meta = await resolveValue((await resolveValue(sub))?.meta);
|
|
395
|
+
if (meta?.hidden) continue;
|
|
396
|
+
const aliases = toArray(meta?.alias);
|
|
397
|
+
const label = [name, ...aliases].join(", ");
|
|
398
|
+
commandsLines.push([cyan(label), meta?.description || ""]);
|
|
399
|
+
commandNames.push(name, ...aliases);
|
|
400
|
+
}
|
|
401
|
+
usageLine.push(commandNames.join("|"));
|
|
402
|
+
}
|
|
403
|
+
const usageLines = [];
|
|
404
|
+
const version = cmdMeta.version || parentMeta.version;
|
|
405
|
+
usageLines.push(gray(`${cmdMeta.description} (${commandName + (version ? ` v${version}` : "")})`), "");
|
|
406
|
+
const hasOptions = argLines.length > 0 || posLines.length > 0;
|
|
407
|
+
usageLines.push(`${underline(bold("USAGE"))} ${cyan(`${commandName}${hasOptions ? " [OPTIONS]" : ""} ${usageLine.join(" ")}`)}`, "");
|
|
408
|
+
if (posLines.length > 0) {
|
|
409
|
+
usageLines.push(underline(bold("ARGUMENTS")), "");
|
|
410
|
+
usageLines.push(formatLineColumns(posLines, " "));
|
|
411
|
+
usageLines.push("");
|
|
412
|
+
}
|
|
413
|
+
if (argLines.length > 0) {
|
|
414
|
+
usageLines.push(underline(bold("OPTIONS")), "");
|
|
415
|
+
usageLines.push(formatLineColumns(argLines, " "));
|
|
416
|
+
usageLines.push("");
|
|
417
|
+
}
|
|
418
|
+
if (commandsLines.length > 0) {
|
|
419
|
+
usageLines.push(underline(bold("COMMANDS")), "");
|
|
420
|
+
usageLines.push(formatLineColumns(commandsLines, " "));
|
|
421
|
+
usageLines.push("", `Use ${cyan(`${commandName} <command> --help`)} for more information about a command.`);
|
|
422
|
+
}
|
|
423
|
+
return usageLines.filter((l) => typeof l === "string").join("\n");
|
|
424
|
+
}
|
|
425
|
+
function renderValueHint(arg) {
|
|
426
|
+
const valueHint = arg.valueHint ? `=<${arg.valueHint}>` : "";
|
|
427
|
+
const fallbackValueHint = valueHint || `=<${snakeCase(arg.name)}>`;
|
|
428
|
+
if (!arg.type || arg.type === "positional" || arg.type === "boolean") return valueHint;
|
|
429
|
+
if (arg.type === "enum" && arg.options?.length) return `=<${arg.options.join("|")}>`;
|
|
430
|
+
return fallbackValueHint;
|
|
431
|
+
}
|
|
432
|
+
function renderDescription(arg, required) {
|
|
433
|
+
const requiredHint = required ? gray("(Required)") : "";
|
|
434
|
+
const defaultHint = arg.default === void 0 ? "" : gray(`(Default: ${arg.default})`);
|
|
435
|
+
return [
|
|
436
|
+
arg.description,
|
|
437
|
+
requiredHint,
|
|
438
|
+
defaultHint
|
|
439
|
+
].filter(Boolean).join(" ");
|
|
440
|
+
}
|
|
441
|
+
async function runMain(cmd, opts = {}) {
|
|
442
|
+
const rawArgs = opts.rawArgs || process.argv.slice(2);
|
|
443
|
+
const showUsage$1 = opts.showUsage || showUsage;
|
|
444
|
+
try {
|
|
445
|
+
const builtinFlags = await _resolveBuiltinFlags(cmd);
|
|
446
|
+
if (builtinFlags.help.length > 0 && rawArgs.some((arg) => builtinFlags.help.includes(arg))) {
|
|
447
|
+
await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
|
|
448
|
+
process.exit(0);
|
|
449
|
+
} else if (rawArgs.length === 1 && builtinFlags.version.includes(rawArgs[0])) {
|
|
450
|
+
const meta = typeof cmd.meta === "function" ? await cmd.meta() : await cmd.meta;
|
|
451
|
+
if (!meta?.version) throw new CLIError("No version specified", "E_NO_VERSION");
|
|
452
|
+
console.log(meta.version);
|
|
453
|
+
} else await runCommand(cmd, { rawArgs });
|
|
454
|
+
} catch (error) {
|
|
455
|
+
if (error instanceof CLIError) {
|
|
456
|
+
await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
|
|
457
|
+
console.error(error.message);
|
|
458
|
+
} else console.error(error, "\n");
|
|
459
|
+
process.exit(1);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
async function _resolveBuiltinFlags(cmd) {
|
|
463
|
+
const argsDef = await resolveValue(cmd.args || {});
|
|
464
|
+
const userNames = /* @__PURE__ */ new Set();
|
|
465
|
+
const userAliases = /* @__PURE__ */ new Set();
|
|
466
|
+
for (const [name, def] of Object.entries(argsDef)) {
|
|
467
|
+
userNames.add(name);
|
|
468
|
+
for (const alias of toArray(def.alias)) userAliases.add(alias);
|
|
469
|
+
}
|
|
470
|
+
return {
|
|
471
|
+
help: _getBuiltinFlags("help", "h", userNames, userAliases),
|
|
472
|
+
version: _getBuiltinFlags("version", "v", userNames, userAliases)
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
function _getBuiltinFlags(long, short, userNames, userAliases) {
|
|
476
|
+
if (userNames.has(long) || userAliases.has(long)) return [];
|
|
477
|
+
if (userNames.has(short) || userAliases.has(short)) return [`--${long}`];
|
|
478
|
+
return [`--${long}`, `-${short}`];
|
|
479
|
+
}
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region src/cli.ts
|
|
482
|
+
const { version } = createRequire(import.meta.url)("../package.json");
|
|
483
|
+
function fail(message) {
|
|
484
|
+
console.error(styleText("red", `✖ ${message}`));
|
|
485
|
+
process.exit(1);
|
|
486
|
+
}
|
|
487
|
+
function plural(count, noun) {
|
|
488
|
+
return `${count} ${noun}${count === 1 ? "" : "s"}`;
|
|
489
|
+
}
|
|
490
|
+
function display(path) {
|
|
491
|
+
const local = relative(process.cwd(), path);
|
|
492
|
+
return local === "" ? "." : local.startsWith("..") ? path : `./${local}`;
|
|
493
|
+
}
|
|
494
|
+
function networkUrls(port) {
|
|
495
|
+
return Object.values(networkInterfaces()).flat().filter((address) => address?.family === "IPv4" && !address.internal).map((address) => `http://${address?.address}:${port}/`);
|
|
496
|
+
}
|
|
497
|
+
function openBrowser(url) {
|
|
498
|
+
const [command, ...args] = process.platform === "darwin" ? ["open", url] : process.platform === "win32" ? [
|
|
499
|
+
"cmd",
|
|
500
|
+
"/c",
|
|
501
|
+
"start",
|
|
502
|
+
"",
|
|
503
|
+
url
|
|
504
|
+
] : ["xdg-open", url];
|
|
505
|
+
spawn(command ?? "open", args, {
|
|
506
|
+
stdio: "ignore",
|
|
507
|
+
detached: true
|
|
508
|
+
}).on("error", () => console.error(styleText("yellow", `Could not open a browser. Open ${url}`))).unref();
|
|
509
|
+
}
|
|
510
|
+
const commonArgs = {
|
|
511
|
+
"line-numbers": {
|
|
512
|
+
type: "boolean",
|
|
513
|
+
description: "Show line numbers on all code blocks"
|
|
514
|
+
},
|
|
515
|
+
dotfiles: {
|
|
516
|
+
type: "boolean",
|
|
517
|
+
description: "Include dotfiles, such as .github/"
|
|
518
|
+
},
|
|
519
|
+
theme: {
|
|
520
|
+
type: "string",
|
|
521
|
+
description: "The default theme: github, base16:<id>, base24:<id>, omarchy:<id>, omarchy (live), a .yaml or .toml file, or a URL. Run `comarkserv themes` for the list",
|
|
522
|
+
default: "github",
|
|
523
|
+
valueHint: "name"
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
const serverArgs = {
|
|
527
|
+
port: {
|
|
528
|
+
type: "string",
|
|
529
|
+
alias: "p",
|
|
530
|
+
description: "The port. When it is in use, comarkserv uses the next free port",
|
|
531
|
+
default: String(DEFAULT_PORT)
|
|
532
|
+
},
|
|
533
|
+
host: {
|
|
534
|
+
type: "string",
|
|
535
|
+
alias: "H",
|
|
536
|
+
description: "The host. Use 0.0.0.0 to accept connections from the network",
|
|
537
|
+
default: "localhost"
|
|
538
|
+
},
|
|
539
|
+
livereload: {
|
|
540
|
+
type: "boolean",
|
|
541
|
+
default: true,
|
|
542
|
+
description: "Update open pages when files change",
|
|
543
|
+
negativeDescription: "Do not watch the files"
|
|
544
|
+
},
|
|
545
|
+
"strict-port": {
|
|
546
|
+
type: "boolean",
|
|
547
|
+
description: "Stop when the port is in use"
|
|
548
|
+
},
|
|
549
|
+
share: {
|
|
550
|
+
type: "boolean",
|
|
551
|
+
description: "Share the pages at a public URL, through a Cloudflare tunnel. Anyone with the URL can read the files"
|
|
552
|
+
},
|
|
553
|
+
silent: {
|
|
554
|
+
type: "boolean",
|
|
555
|
+
alias: "s",
|
|
556
|
+
description: "Do not print the requests"
|
|
557
|
+
},
|
|
558
|
+
...commonArgs
|
|
559
|
+
};
|
|
560
|
+
const LOCAL_HOSTS = /* @__PURE__ */ new Set([
|
|
561
|
+
"localhost",
|
|
562
|
+
"127.0.0.1",
|
|
563
|
+
"::1"
|
|
564
|
+
]);
|
|
565
|
+
async function qrCode(url) {
|
|
566
|
+
const { renderUnicodeCompact } = await import("./dist-CfsjQ0o8.mjs");
|
|
567
|
+
return renderUnicodeCompact(url).split("\n").map((line) => ` ${line}`).join("\n");
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Gets the consent for the Cloudflare license before cloudflared is installed, and
|
|
571
|
+
* returns it for the tunnel. untun answers its own prompt with yes when there is no
|
|
572
|
+
* terminal, so comarkserv asks the question itself, or stops.
|
|
573
|
+
*/
|
|
574
|
+
async function tunnelConsent() {
|
|
575
|
+
if (isCloudflaredInstalled()) return false;
|
|
576
|
+
if (process.env.UNTUN_ACCEPT_CLOUDFLARE_NOTICE) return true;
|
|
577
|
+
if (!process.stdin.isTTY) fail("The first --share installs cloudflared, and you must accept the Cloudflare license first. Run the command in a terminal, or set UNTUN_ACCEPT_CLOUDFLARE_NOTICE=1 to accept the license.");
|
|
578
|
+
console.log([
|
|
579
|
+
"",
|
|
580
|
+
" --share installs cloudflared from GitHub. Before that, accept the Cloudflare documents:",
|
|
581
|
+
` License ${CLOUDFLARE_LINKS.license}`,
|
|
582
|
+
` Terms ${CLOUDFLARE_LINKS.terms}`,
|
|
583
|
+
` Privacy ${CLOUDFLARE_LINKS.privacy}`,
|
|
584
|
+
""
|
|
585
|
+
].join("\n"));
|
|
586
|
+
const prompt = createInterface({
|
|
587
|
+
input: process.stdin,
|
|
588
|
+
output: process.stdout
|
|
589
|
+
});
|
|
590
|
+
const answer = await prompt.question(" Do you accept them and install cloudflared? (y/N) ");
|
|
591
|
+
prompt.close();
|
|
592
|
+
if (!/^y(es)?$/i.test(answer.trim())) fail("comarkserv did not share the pages.");
|
|
593
|
+
return true;
|
|
594
|
+
}
|
|
595
|
+
/** Starts the tunnel of the server and prints its public URL. */
|
|
596
|
+
async function share(server, accept, open) {
|
|
597
|
+
const service = server.handler.share;
|
|
598
|
+
if (!service) fail("Sharing is off for this server.");
|
|
599
|
+
console.log(styleText("dim", " Starting a public tunnel. This can take some seconds..."));
|
|
600
|
+
const url = await service.start({
|
|
601
|
+
origin: `http://127.0.0.1:${server.port}`,
|
|
602
|
+
accept
|
|
603
|
+
}).catch((error) => fail(`The tunnel did not start: ${error instanceof Error ? error.message : String(error)}`));
|
|
604
|
+
console.log([
|
|
605
|
+
"",
|
|
606
|
+
` ${styleText("dim", "Public".padEnd(9))}${styleText("cyan", url)}`,
|
|
607
|
+
"",
|
|
608
|
+
await qrCode(url),
|
|
609
|
+
"",
|
|
610
|
+
styleText("yellow", ` Anyone with this URL can read the files in ${display(server.handler.root)}. Visitors cannot edit.`),
|
|
611
|
+
styleText("dim", " Press Ctrl+C to stop the server and the tunnel."),
|
|
612
|
+
""
|
|
613
|
+
].join("\n"));
|
|
614
|
+
if (open) openBrowser(url);
|
|
615
|
+
}
|
|
616
|
+
/** Serves a directory, or the directory of a markdown file, and prints the banner. */
|
|
617
|
+
async function serve(target, args, open) {
|
|
618
|
+
if (!existsSync(target)) fail(`There is no file or directory at ${target}.`);
|
|
619
|
+
const accept = args.share ? await tunnelConsent() : false;
|
|
620
|
+
const isFile = statSync(target).isFile();
|
|
621
|
+
const port = Number(args.port);
|
|
622
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) fail("--port must be a number from 0 to 65535.");
|
|
623
|
+
const theme = await createThemeStore().load(args.theme).catch((error) => fail(error instanceof Error ? error.message : String(error)));
|
|
624
|
+
const host = args.share && args.host === "localhost" ? "127.0.0.1" : args.host;
|
|
625
|
+
const server = await startServer({
|
|
626
|
+
root: isFile ? dirname(target) : target,
|
|
627
|
+
theme: args.theme,
|
|
628
|
+
port,
|
|
629
|
+
host,
|
|
630
|
+
editor: LOCAL_HOSTS.has(host),
|
|
631
|
+
share: LOCAL_HOSTS.has(host),
|
|
632
|
+
strictPort: args["strict-port"],
|
|
633
|
+
livereload: args.livereload,
|
|
634
|
+
lineNumbers: args["line-numbers"],
|
|
635
|
+
dotfiles: args.dotfiles,
|
|
636
|
+
log: !args.silent
|
|
637
|
+
}).catch((error) => fail(error instanceof Error ? error.message : String(error)));
|
|
638
|
+
const url = isFile ? new URL(encodeURIComponent(basename(target)), server.url).href : server.url;
|
|
639
|
+
const label = (name) => styleText("dim", name.padEnd(9));
|
|
640
|
+
const lines = [
|
|
641
|
+
"",
|
|
642
|
+
` ${styleText("bold", styleText("magenta", "comarkserv"))} ${styleText("dim", `v${version}`)} ` + styleText("dim", `ready in ${Math.round(performance.now())} ms`),
|
|
643
|
+
"",
|
|
644
|
+
` ${label("Local")}${styleText("cyan", url)}`,
|
|
645
|
+
...args.host === "0.0.0.0" || args.host === "::" ? networkUrls(server.port).map((address) => ` ${label("Network")}${styleText("cyan", address)}`) : [],
|
|
646
|
+
` ${label("Root")}${display(server.handler.root)}`,
|
|
647
|
+
` ${label("Reload")}${args.livereload ? "on" : "off"}`,
|
|
648
|
+
` ${label("Theme")}${theme ? `${theme.name} ${styleText("dim", `(${args.theme})`)}` : "GitHub"}`,
|
|
649
|
+
"",
|
|
650
|
+
styleText("dim", " Press Ctrl+C to stop."),
|
|
651
|
+
""
|
|
652
|
+
];
|
|
653
|
+
console.log(lines.join("\n"));
|
|
654
|
+
if (server.port !== port && port !== 0) console.log(styleText("yellow", ` Port ${port} is in use, so comarkserv uses port ${server.port}.\n`));
|
|
655
|
+
if (args.host === "0.0.0.0" || args.host === "::") {
|
|
656
|
+
const [address] = networkUrls(server.port);
|
|
657
|
+
if (address) console.log(`${await qrCode(address)}\n`);
|
|
658
|
+
}
|
|
659
|
+
if (args.share) await share(server, accept, open);
|
|
660
|
+
else if (open) openBrowser(url);
|
|
661
|
+
const stop = () => {
|
|
662
|
+
server.close().finally(() => process.exit(0));
|
|
663
|
+
};
|
|
664
|
+
process.once("SIGINT", stop);
|
|
665
|
+
process.once("SIGTERM", stop);
|
|
666
|
+
}
|
|
667
|
+
const serveCommand = defineCommand({
|
|
668
|
+
meta: {
|
|
669
|
+
name: "comarkserv",
|
|
670
|
+
version,
|
|
671
|
+
description: "Serve markdown as HTML, with live reload. Other commands: `comarkserv readme`, `comarkserv cat`, `comarkserv build`, `comarkserv themes`."
|
|
672
|
+
},
|
|
673
|
+
args: {
|
|
674
|
+
path: {
|
|
675
|
+
type: "positional",
|
|
676
|
+
description: "The directory or markdown file to serve",
|
|
677
|
+
default: "."
|
|
678
|
+
},
|
|
679
|
+
open: {
|
|
680
|
+
type: "boolean",
|
|
681
|
+
alias: "o",
|
|
682
|
+
description: "Open the page in the browser"
|
|
683
|
+
},
|
|
684
|
+
...serverArgs
|
|
685
|
+
},
|
|
686
|
+
run: ({ args }) => serve(resolve(args.path), args, args.open === true)
|
|
687
|
+
});
|
|
688
|
+
const readmeCommand = defineCommand({
|
|
689
|
+
meta: {
|
|
690
|
+
name: "comarkserv readme",
|
|
691
|
+
version,
|
|
692
|
+
description: "Serve the closest README: in the directory, or in the first parent directory that has one"
|
|
693
|
+
},
|
|
694
|
+
args: {
|
|
695
|
+
from: {
|
|
696
|
+
type: "positional",
|
|
697
|
+
description: "The directory to search from",
|
|
698
|
+
default: "."
|
|
699
|
+
},
|
|
700
|
+
open: {
|
|
701
|
+
type: "boolean",
|
|
702
|
+
alias: "o",
|
|
703
|
+
default: true,
|
|
704
|
+
description: "Open the README in the browser",
|
|
705
|
+
negativeDescription: "Do not open the browser"
|
|
706
|
+
},
|
|
707
|
+
...serverArgs
|
|
708
|
+
},
|
|
709
|
+
async run({ args }) {
|
|
710
|
+
const start = resolve(args.from);
|
|
711
|
+
const readme = await findReadme(start);
|
|
712
|
+
if (!readme) fail(`There is no README in ${start} or in a parent directory.`);
|
|
713
|
+
await serve(readme, args, args.open);
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
const buildCommand = defineCommand({
|
|
717
|
+
meta: {
|
|
718
|
+
name: "comarkserv build",
|
|
719
|
+
version,
|
|
720
|
+
description: "Build a static HTML site from a directory of markdown"
|
|
721
|
+
},
|
|
722
|
+
args: {
|
|
723
|
+
path: {
|
|
724
|
+
type: "positional",
|
|
725
|
+
description: "The directory to build",
|
|
726
|
+
default: "."
|
|
727
|
+
},
|
|
728
|
+
out: {
|
|
729
|
+
type: "string",
|
|
730
|
+
alias: "o",
|
|
731
|
+
description: "The output directory. comarkserv deletes an earlier build in it",
|
|
732
|
+
default: "dist"
|
|
733
|
+
},
|
|
734
|
+
...commonArgs
|
|
735
|
+
},
|
|
736
|
+
async run({ args }) {
|
|
737
|
+
const root = resolve(args.path);
|
|
738
|
+
if (!existsSync(root) || !statSync(root).isDirectory()) fail(`There is no directory at ${root}.`);
|
|
739
|
+
const { build } = await import("./build-CsToYJrU.mjs");
|
|
740
|
+
const result = await build({
|
|
741
|
+
root,
|
|
742
|
+
outDir: resolve(args.out),
|
|
743
|
+
lineNumbers: args["line-numbers"],
|
|
744
|
+
dotfiles: args.dotfiles,
|
|
745
|
+
theme: args.theme
|
|
746
|
+
}).catch((error) => fail(error instanceof Error ? error.message : String(error)));
|
|
747
|
+
for (const warning of result.warnings) console.warn(styleText("yellow", `! ${warning}`));
|
|
748
|
+
console.log(`${styleText("green", "✓")} Built ${plural(result.pages, "page")} and copied ${plural(result.files, "file")} to ${display(result.outDir)} in ${Math.round(result.ms)} ms`);
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
function page(text, pager) {
|
|
752
|
+
if (!pager || !process.stdout.isTTY) {
|
|
753
|
+
process.stdout.write(text);
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
const less = spawn("less", [
|
|
757
|
+
"-R",
|
|
758
|
+
"-F",
|
|
759
|
+
"-X"
|
|
760
|
+
], { stdio: [
|
|
761
|
+
"pipe",
|
|
762
|
+
"inherit",
|
|
763
|
+
"inherit"
|
|
764
|
+
] });
|
|
765
|
+
less.on("error", () => process.stdout.write(text));
|
|
766
|
+
less.stdin.on("error", () => {});
|
|
767
|
+
less.stdin.end(text);
|
|
768
|
+
}
|
|
769
|
+
const catCommand = defineCommand({
|
|
770
|
+
meta: {
|
|
771
|
+
name: "comarkserv cat",
|
|
772
|
+
version,
|
|
773
|
+
description: "Show a markdown file in the terminal"
|
|
774
|
+
},
|
|
775
|
+
args: {
|
|
776
|
+
file: {
|
|
777
|
+
type: "positional",
|
|
778
|
+
description: "The markdown file",
|
|
779
|
+
required: true
|
|
780
|
+
},
|
|
781
|
+
color: {
|
|
782
|
+
type: "boolean",
|
|
783
|
+
description: "Use colors. The default is on in a terminal, unless NO_COLOR is set",
|
|
784
|
+
negativeDescription: "Do not use colors"
|
|
785
|
+
},
|
|
786
|
+
pager: {
|
|
787
|
+
type: "boolean",
|
|
788
|
+
default: true,
|
|
789
|
+
description: "Show a long file in less",
|
|
790
|
+
negativeDescription: "Print the whole file"
|
|
791
|
+
}
|
|
792
|
+
},
|
|
793
|
+
async run({ args }) {
|
|
794
|
+
const path = resolve(args.file);
|
|
795
|
+
if (!existsSync(path) || !statSync(path).isFile()) fail(`There is no file at ${path}.`);
|
|
796
|
+
const source = readFileSync(path, "utf8");
|
|
797
|
+
const colors = args.color ?? (process.stdout.isTTY === true && !process.env.NO_COLOR);
|
|
798
|
+
const { createTerminalRenderer } = await import("./terminal-aKr5Xlp3.mjs");
|
|
799
|
+
page(await createTerminalRenderer({
|
|
800
|
+
colors,
|
|
801
|
+
width: Math.min(process.stdout.columns || 80, 100)
|
|
802
|
+
})(source), args.pager);
|
|
803
|
+
}
|
|
804
|
+
});
|
|
805
|
+
const themesCommand = defineCommand({
|
|
806
|
+
meta: {
|
|
807
|
+
name: "comarkserv themes",
|
|
808
|
+
version,
|
|
809
|
+
description: "List the themes for --theme"
|
|
810
|
+
},
|
|
811
|
+
args: {
|
|
812
|
+
filter: {
|
|
813
|
+
type: "positional",
|
|
814
|
+
description: "Show only the themes with this text",
|
|
815
|
+
default: ""
|
|
816
|
+
},
|
|
817
|
+
json: {
|
|
818
|
+
type: "boolean",
|
|
819
|
+
description: "Print the list as JSON, for other tools"
|
|
820
|
+
}
|
|
821
|
+
},
|
|
822
|
+
async run({ args }) {
|
|
823
|
+
const entries = await createThemeStore().catalog().catch((error) => fail(`The theme list is not available: ${error instanceof Error ? error.message : String(error)}`));
|
|
824
|
+
const rows = [
|
|
825
|
+
{
|
|
826
|
+
id: "github",
|
|
827
|
+
name: "GitHub, built in (the default)"
|
|
828
|
+
},
|
|
829
|
+
...existsSync(OMARCHY_CURRENT) ? [{
|
|
830
|
+
id: "omarchy",
|
|
831
|
+
name: "The current Omarchy theme, live"
|
|
832
|
+
}] : [],
|
|
833
|
+
...entries
|
|
834
|
+
];
|
|
835
|
+
const filter = args.filter.toLowerCase();
|
|
836
|
+
const shown = rows.filter((row) => `${row.id} ${row.name}`.toLowerCase().includes(filter));
|
|
837
|
+
if (args.json) {
|
|
838
|
+
console.log(JSON.stringify(shown.map(({ id, name }) => ({
|
|
839
|
+
id,
|
|
840
|
+
name
|
|
841
|
+
}))));
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
const width = Math.max(0, ...shown.map((row) => row.id.length));
|
|
845
|
+
for (const row of shown) console.log(`${row.id.padEnd(width)} ${styleText("dim", row.name)}`);
|
|
846
|
+
console.log(styleText("dim", `\n${plural(shown.length, "theme")}. Use one with --theme <id>, or give a .yaml or .toml file.`));
|
|
847
|
+
}
|
|
848
|
+
});
|
|
849
|
+
const themeCommand = defineCommand({
|
|
850
|
+
meta: {
|
|
851
|
+
name: "comarkserv theme",
|
|
852
|
+
version,
|
|
853
|
+
description: "Show the name, the variant and the 16 colors of a theme"
|
|
854
|
+
},
|
|
855
|
+
args: {
|
|
856
|
+
id: {
|
|
857
|
+
type: "positional",
|
|
858
|
+
description: "The theme, as for --theme",
|
|
859
|
+
required: true
|
|
860
|
+
},
|
|
861
|
+
json: {
|
|
862
|
+
type: "boolean",
|
|
863
|
+
description: "Print the theme as JSON, for other tools"
|
|
864
|
+
}
|
|
865
|
+
},
|
|
866
|
+
async run({ args }) {
|
|
867
|
+
const theme = await createThemeStore().load(args.id).catch((error) => fail(error instanceof Error ? error.message : String(error)));
|
|
868
|
+
if (!theme) fail("github is the built-in theme. It has no base16 colors.");
|
|
869
|
+
if (args.json) {
|
|
870
|
+
console.log(JSON.stringify(theme));
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
console.log(`${styleText("bold", theme.name)} ${styleText("dim", `(${theme.variant})`)}`);
|
|
874
|
+
theme.colors.forEach((color, index) => {
|
|
875
|
+
const slot = `base0${index.toString(16).toUpperCase()}`;
|
|
876
|
+
const [r, g, b] = [
|
|
877
|
+
1,
|
|
878
|
+
3,
|
|
879
|
+
5
|
|
880
|
+
].map((start) => Number.parseInt(color.slice(start, start + 2), 16));
|
|
881
|
+
const swatch = process.stdout.isTTY ? `\x1b[48;2;${r};${g};${b}m \x1b[0m ` : "";
|
|
882
|
+
console.log(`${swatch}${slot} ${color}`);
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
});
|
|
886
|
+
const argv = process.argv.slice(2);
|
|
887
|
+
if (argv[0] === "build") await runMain(buildCommand, { rawArgs: argv.slice(1) });
|
|
888
|
+
else if (argv[0] === "themes") await runMain(themesCommand, { rawArgs: argv.slice(1) });
|
|
889
|
+
else if (argv[0] === "readme") await runMain(readmeCommand, { rawArgs: argv.slice(1) });
|
|
890
|
+
else if (argv[0] === "cat") await runMain(catCommand, { rawArgs: argv.slice(1) });
|
|
891
|
+
else if (argv[0] === "theme") await runMain(themeCommand, { rawArgs: argv.slice(1) });
|
|
892
|
+
else await runMain(serveCommand, { rawArgs: argv });
|
|
893
|
+
//#endregion
|
|
894
|
+
export {};
|