nuxt-ai-ready 2.5.0 → 2.5.2
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/dist/chunks/agent-skills.mjs +1 -1
- package/dist/chunks/prerender.mjs +1 -1
- package/dist/cli.mjs +2 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/server/db/drizzle/queries.js +0 -1
- package/dist/runtime/server/db/queries.d.ts +2 -0
- package/dist/runtime/server/db/queries.js +11 -5
- package/dist/runtime/server/db/seed.d.ts +2 -2
- package/dist/runtime/server/routes/__ai-ready/reindex.post.js +2 -0
- package/dist/runtime/server/utils/batchIndex.js +4 -2
- package/dist/runtime/server/utils/checkStale.d.ts +1 -1
- package/dist/runtime/server/utils/checkStale.js +1 -1
- package/dist/runtime/server/utils/indexPage.d.ts +8 -1
- package/dist/runtime/server/utils/indexPage.js +13 -5
- package/dist/shared/{nuxt-ai-ready.DsokNmXc.mjs → nuxt-ai-ready.CLSWou20.mjs} +2 -0
- package/node_modules/@mdream/js/LICENSE.md +9 -0
- package/node_modules/@mdream/js/README.md +792 -0
- package/node_modules/@mdream/js/bin/mdream.mjs +2 -0
- package/node_modules/@mdream/js/dist/_chunks/const.mjs +134 -0
- package/node_modules/@mdream/js/dist/_chunks/index.d.mts +9 -0
- package/node_modules/@mdream/js/dist/_chunks/markdown-processor.mjs +1968 -0
- package/node_modules/@mdream/js/dist/_chunks/minimal.d.mts +6 -0
- package/node_modules/@mdream/js/dist/_chunks/parse.mjs +2756 -0
- package/node_modules/@mdream/js/dist/_chunks/plugins.mjs +725 -0
- package/node_modules/@mdream/js/dist/_chunks/resolve-plugins.mjs +44 -0
- package/node_modules/@mdream/js/dist/_chunks/stream.mjs +37 -0
- package/node_modules/@mdream/js/dist/_chunks/types.d.mts +473 -0
- package/node_modules/@mdream/js/dist/cli.d.mts +1 -0
- package/node_modules/@mdream/js/dist/cli.mjs +32 -0
- package/node_modules/@mdream/js/dist/core.d.mts +15 -0
- package/node_modules/@mdream/js/dist/core.mjs +28 -0
- package/node_modules/@mdream/js/dist/index.d.mts +4 -0
- package/node_modules/@mdream/js/dist/index.mjs +58 -0
- package/node_modules/@mdream/js/dist/llms-txt.d.mts +86 -0
- package/node_modules/@mdream/js/dist/llms-txt.mjs +308 -0
- package/node_modules/@mdream/js/dist/negotiate.d.mts +35 -0
- package/node_modules/@mdream/js/dist/negotiate.mjs +121 -0
- package/node_modules/@mdream/js/dist/parse.d.mts +90 -0
- package/node_modules/@mdream/js/dist/parse.mjs +2 -0
- package/node_modules/@mdream/js/dist/plugins.d.mts +85 -0
- package/node_modules/@mdream/js/dist/plugins.mjs +2 -0
- package/node_modules/@mdream/js/dist/preset/minimal.d.mts +2 -0
- package/node_modules/@mdream/js/dist/preset/minimal.mjs +33 -0
- package/node_modules/@mdream/js/dist/splitter.d.mts +18 -0
- package/node_modules/@mdream/js/dist/splitter.mjs +194 -0
- package/node_modules/@mdream/js/package.json +103 -0
- package/node_modules/cac/LICENSE +21 -0
- package/node_modules/cac/README.md +492 -0
- package/node_modules/cac/dist/index.d.ts +196 -0
- package/node_modules/cac/dist/index.js +638 -0
- package/node_modules/cac/package.json +72 -0
- package/node_modules/mdream/LICENSE.md +9 -0
- package/node_modules/mdream/README.md +1091 -0
- package/node_modules/mdream/bin/mdream.mjs +46 -0
- package/node_modules/mdream/dist/browser.d.mts +105 -0
- package/node_modules/mdream/dist/browser.mjs +262 -0
- package/node_modules/mdream/dist/edge.d.mts +100 -0
- package/node_modules/mdream/dist/edge.mjs +250 -0
- package/node_modules/mdream/dist/iife.js +605 -0
- package/node_modules/mdream/dist/index.d.mts +89 -0
- package/node_modules/mdream/dist/index.mjs +184 -0
- package/node_modules/mdream/dist/wasm.d.mts +100 -0
- package/node_modules/mdream/dist/wasm.mjs +140 -0
- package/node_modules/mdream/dist/worker.d.mts +101 -0
- package/node_modules/mdream/dist/worker.mjs +217 -0
- package/node_modules/mdream/napi/index.d.mts +127 -0
- package/node_modules/mdream/napi/index.d.ts +127 -0
- package/node_modules/mdream/napi/index.mjs +725 -0
- package/node_modules/mdream/napi/rust.android-arm-eabi.node +0 -0
- package/node_modules/mdream/napi/rust.android-arm64.node +0 -0
- package/node_modules/mdream/napi/rust.darwin-arm64.node +0 -0
- package/node_modules/mdream/napi/rust.darwin-x64.node +0 -0
- package/node_modules/mdream/napi/rust.freebsd-x64.node +0 -0
- package/node_modules/mdream/napi/rust.linux-arm-gnueabihf.node +0 -0
- package/node_modules/mdream/napi/rust.linux-arm64-gnu.node +0 -0
- package/node_modules/mdream/napi/rust.linux-arm64-musl.node +0 -0
- package/node_modules/mdream/napi/rust.linux-x64-gnu.node +0 -0
- package/node_modules/mdream/napi/rust.linux-x64-musl.node +0 -0
- package/node_modules/mdream/napi/rust.wasi.cjs +2144 -0
- package/node_modules/mdream/napi/rust.wasm32-wasi.wasm +0 -0
- package/node_modules/mdream/napi/rust.win32-arm64-msvc.node +0 -0
- package/node_modules/mdream/napi/rust.win32-x64-msvc.node +0 -0
- package/node_modules/mdream/node_modules/@emnapi/core/LICENSE +21 -0
- package/node_modules/mdream/node_modules/@emnapi/core/README.md +1 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.d.ts +392 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.d.ts +392 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.js +8351 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.js +7268 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.d.ts +5 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.js +843 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.d.ts +4 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.js +3 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.d.ts +5 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.js +1010 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.d.ts +5 -0
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.js +1446 -0
- package/node_modules/mdream/node_modules/@emnapi/core/package.json +39 -0
- package/node_modules/mdream/node_modules/@emnapi/core/rollup.config.js +60 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/LICENSE +21 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/README.md +1 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.d.ts +833 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js +2306 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js.map +1 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/index.cjs +63 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/package.json +39 -0
- package/node_modules/mdream/node_modules/@emnapi/runtime/rollup.config.js +25 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/LICENSE +21 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/README.md +203 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +236 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +1086 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/package.json +35 -0
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/rollup.config.js +6 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.cjs +1472 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.js +1470 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs-proxy.cjs +237 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs.js +18260 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +317 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/package.json +67 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.cjs +39 -0
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.js +36 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/LICENSE +21 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/README.md +193 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/tsdoc-metadata.json +11 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.d.ts +423 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js +2932 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +2932 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.min.js +1 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.js +2954 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.min.js +1 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/asyncify.js +158 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/index.js +13 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/jspi.js +46 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/load.js +97 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/memory.js +35 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/error.js +103 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fd.js +268 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fs.js +3 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/index.js +192 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/path.js +316 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +1599 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/rights.js +141 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/types.js +220 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/util.js +128 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/webassembly.js +13 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/asyncify.mjs +153 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/index.mjs +9 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/jspi.mjs +39 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/load.mjs +89 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/memory.mjs +28 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/error.mjs +97 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fd.mjs +256 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fs.mjs +1 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/index.mjs +186 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/path.mjs +310 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +1593 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/rights.mjs +135 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/types.mjs +216 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/util.mjs +113 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/webassembly.mjs +9 -0
- package/node_modules/mdream/node_modules/@tybys/wasm-util/package.json +58 -0
- package/node_modules/mdream/node_modules/tslib/CopyrightNotice.txt +15 -0
- package/node_modules/mdream/node_modules/tslib/LICENSE.txt +12 -0
- package/node_modules/mdream/node_modules/tslib/README.md +164 -0
- package/node_modules/mdream/node_modules/tslib/SECURITY.md +41 -0
- package/node_modules/mdream/node_modules/tslib/modules/index.d.ts +38 -0
- package/node_modules/mdream/node_modules/tslib/modules/index.js +70 -0
- package/node_modules/mdream/node_modules/tslib/modules/package.json +3 -0
- package/node_modules/mdream/node_modules/tslib/package.json +47 -0
- package/node_modules/mdream/node_modules/tslib/tslib.d.ts +460 -0
- package/node_modules/mdream/node_modules/tslib/tslib.es6.html +1 -0
- package/node_modules/mdream/node_modules/tslib/tslib.es6.js +402 -0
- package/node_modules/mdream/node_modules/tslib/tslib.es6.mjs +401 -0
- package/node_modules/mdream/node_modules/tslib/tslib.html +1 -0
- package/node_modules/mdream/node_modules/tslib/tslib.js +484 -0
- package/node_modules/mdream/package.json +110 -0
- package/node_modules/mdream/skills/mdream/SKILL.md +124 -0
- package/node_modules/mdream/skills/mdream/references/runtimes.md +49 -0
- package/node_modules/mdream/wasm/mdream_edge.d.ts +90 -0
- package/node_modules/mdream/wasm/mdream_edge.js +517 -0
- package/node_modules/mdream/wasm/mdream_edge_bg.wasm +0 -0
- package/node_modules/mdream/wasm/mdream_edge_bg.wasm.d.ts +20 -0
- package/node_modules/mdream/wasm/package.json +17 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge.d.ts +45 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge.js +13 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.js +413 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm +0 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm.d.ts +20 -0
- package/node_modules/mdream/wasm-bundler/package.json +19 -0
- package/node_modules/pathe/LICENSE +70 -0
- package/node_modules/pathe/README.md +73 -0
- package/node_modules/pathe/dist/index.cjs +39 -0
- package/node_modules/pathe/dist/index.d.cts +47 -0
- package/node_modules/pathe/dist/index.d.mts +47 -0
- package/node_modules/pathe/dist/index.d.ts +47 -0
- package/node_modules/pathe/dist/index.mjs +19 -0
- package/node_modules/pathe/dist/shared/pathe.BSlhyZSM.cjs +266 -0
- package/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +249 -0
- package/node_modules/pathe/dist/utils.cjs +82 -0
- package/node_modules/pathe/dist/utils.d.cts +32 -0
- package/node_modules/pathe/dist/utils.d.mts +32 -0
- package/node_modules/pathe/dist/utils.d.ts +32 -0
- package/node_modules/pathe/dist/utils.mjs +77 -0
- package/node_modules/pathe/package.json +61 -0
- package/node_modules/pathe/utils.d.ts +1 -0
- package/package.json +8 -64
|
@@ -0,0 +1,638 @@
|
|
|
1
|
+
//#region node_modules/.pnpm/mri@1.2.0/node_modules/mri/lib/index.mjs
|
|
2
|
+
function toArr(any) {
|
|
3
|
+
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
4
|
+
}
|
|
5
|
+
function toVal(out, key, val, opts) {
|
|
6
|
+
var x, old = out[key], nxt = !!~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : !!~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
|
|
7
|
+
out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
|
|
8
|
+
}
|
|
9
|
+
function lib_default(args, opts) {
|
|
10
|
+
args = args || [];
|
|
11
|
+
opts = opts || {};
|
|
12
|
+
var k, arr, arg, name, val, out = { _: [] };
|
|
13
|
+
var i = 0, j = 0, idx = 0, len = args.length;
|
|
14
|
+
const alibi = opts.alias !== void 0;
|
|
15
|
+
const strict = opts.unknown !== void 0;
|
|
16
|
+
const defaults = opts.default !== void 0;
|
|
17
|
+
opts.alias = opts.alias || {};
|
|
18
|
+
opts.string = toArr(opts.string);
|
|
19
|
+
opts.boolean = toArr(opts.boolean);
|
|
20
|
+
if (alibi) for (k in opts.alias) {
|
|
21
|
+
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
22
|
+
for (i = 0; i < arr.length; i++) (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
23
|
+
}
|
|
24
|
+
for (i = opts.boolean.length; i-- > 0;) {
|
|
25
|
+
arr = opts.alias[opts.boolean[i]] || [];
|
|
26
|
+
for (j = arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
|
27
|
+
}
|
|
28
|
+
for (i = opts.string.length; i-- > 0;) {
|
|
29
|
+
arr = opts.alias[opts.string[i]] || [];
|
|
30
|
+
for (j = arr.length; j-- > 0;) opts.string.push(arr[j]);
|
|
31
|
+
}
|
|
32
|
+
if (defaults) for (k in opts.default) {
|
|
33
|
+
name = typeof opts.default[k];
|
|
34
|
+
arr = opts.alias[k] = opts.alias[k] || [];
|
|
35
|
+
if (opts[name] !== void 0) {
|
|
36
|
+
opts[name].push(k);
|
|
37
|
+
for (i = 0; i < arr.length; i++) opts[name].push(arr[i]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const keys = strict ? Object.keys(opts.alias) : [];
|
|
41
|
+
for (i = 0; i < len; i++) {
|
|
42
|
+
arg = args[i];
|
|
43
|
+
if (arg === "--") {
|
|
44
|
+
out._ = out._.concat(args.slice(++i));
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
for (j = 0; j < arg.length; j++) if (arg.charCodeAt(j) !== 45) break;
|
|
48
|
+
if (j === 0) out._.push(arg);
|
|
49
|
+
else if (arg.substring(j, j + 3) === "no-") {
|
|
50
|
+
name = arg.substring(j + 3);
|
|
51
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
|
|
52
|
+
out[name] = false;
|
|
53
|
+
} else {
|
|
54
|
+
for (idx = j + 1; idx < arg.length; idx++) if (arg.charCodeAt(idx) === 61) break;
|
|
55
|
+
name = arg.substring(j, idx);
|
|
56
|
+
val = arg.substring(++idx) || i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i];
|
|
57
|
+
arr = j === 2 ? [name] : name;
|
|
58
|
+
for (idx = 0; idx < arr.length; idx++) {
|
|
59
|
+
name = arr[idx];
|
|
60
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
|
|
61
|
+
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (defaults) {
|
|
66
|
+
for (k in opts.default) if (out[k] === void 0) out[k] = opts.default[k];
|
|
67
|
+
}
|
|
68
|
+
if (alibi) for (k in out) {
|
|
69
|
+
arr = opts.alias[k] || [];
|
|
70
|
+
while (arr.length > 0) out[arr.shift()] = out[k];
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/utils.ts
|
|
77
|
+
function removeBrackets(v) {
|
|
78
|
+
return v.replace(/[<[].+/, "").trim();
|
|
79
|
+
}
|
|
80
|
+
function findAllBrackets(v) {
|
|
81
|
+
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
|
82
|
+
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
|
83
|
+
const res = [];
|
|
84
|
+
const parse = (match) => {
|
|
85
|
+
let variadic = false;
|
|
86
|
+
let value = match[1];
|
|
87
|
+
if (value.startsWith("...")) {
|
|
88
|
+
value = value.slice(3);
|
|
89
|
+
variadic = true;
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
required: match[0].startsWith("<"),
|
|
93
|
+
value,
|
|
94
|
+
variadic
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
let angledMatch;
|
|
98
|
+
while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(angledMatch));
|
|
99
|
+
let squareMatch;
|
|
100
|
+
while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(squareMatch));
|
|
101
|
+
return res;
|
|
102
|
+
}
|
|
103
|
+
function getMriOptions(options) {
|
|
104
|
+
const result = {
|
|
105
|
+
alias: {},
|
|
106
|
+
boolean: []
|
|
107
|
+
};
|
|
108
|
+
for (const [index, option] of options.entries()) {
|
|
109
|
+
if (option.names.length > 1) result.alias[option.names[0]] = option.names.slice(1);
|
|
110
|
+
if (option.isBoolean) if (option.negated) {
|
|
111
|
+
if (!options.some((o, i) => {
|
|
112
|
+
return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
|
|
113
|
+
})) result.boolean.push(option.names[0]);
|
|
114
|
+
} else result.boolean.push(option.names[0]);
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
function findLongest(arr) {
|
|
119
|
+
return arr.sort((a, b) => {
|
|
120
|
+
return a.length > b.length ? -1 : 1;
|
|
121
|
+
})[0];
|
|
122
|
+
}
|
|
123
|
+
function padRight(str, length) {
|
|
124
|
+
return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
|
125
|
+
}
|
|
126
|
+
function camelcase(input) {
|
|
127
|
+
return input.replaceAll(/([a-z])-([a-z])/g, (_, p1, p2) => {
|
|
128
|
+
return p1 + p2.toUpperCase();
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function setDotProp(obj, keys, val) {
|
|
132
|
+
let current = obj;
|
|
133
|
+
for (let i = 0; i < keys.length; i++) {
|
|
134
|
+
const key = keys[i];
|
|
135
|
+
if (i === keys.length - 1) {
|
|
136
|
+
current[key] = val;
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (current[key] == null) {
|
|
140
|
+
const nextKeyIsArrayIndex = +keys[i + 1] > -1;
|
|
141
|
+
current[key] = nextKeyIsArrayIndex ? [] : {};
|
|
142
|
+
}
|
|
143
|
+
current = current[key];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function setByType(obj, transforms) {
|
|
147
|
+
for (const key of Object.keys(transforms)) {
|
|
148
|
+
const transform = transforms[key];
|
|
149
|
+
if (transform.shouldTransform) {
|
|
150
|
+
obj[key] = [obj[key]].flat();
|
|
151
|
+
if (typeof transform.transformFunction === "function") obj[key] = obj[key].map(transform.transformFunction);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function getFileName(input) {
|
|
156
|
+
const m = /([^\\/]+)$/.exec(input);
|
|
157
|
+
return m ? m[1] : "";
|
|
158
|
+
}
|
|
159
|
+
function camelcaseOptionName(name) {
|
|
160
|
+
return name.split(".").map((v, i) => {
|
|
161
|
+
return i === 0 ? camelcase(v) : v;
|
|
162
|
+
}).join(".");
|
|
163
|
+
}
|
|
164
|
+
var CACError = class extends Error {
|
|
165
|
+
constructor(message) {
|
|
166
|
+
super(message);
|
|
167
|
+
this.name = "CACError";
|
|
168
|
+
if (typeof Error.captureStackTrace !== "function") this.stack = new Error(message).stack;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/option.ts
|
|
174
|
+
var Option = class {
|
|
175
|
+
rawName;
|
|
176
|
+
description;
|
|
177
|
+
/** Option name */
|
|
178
|
+
name;
|
|
179
|
+
/** Option name and aliases */
|
|
180
|
+
names;
|
|
181
|
+
isBoolean;
|
|
182
|
+
required;
|
|
183
|
+
config;
|
|
184
|
+
negated;
|
|
185
|
+
constructor(rawName, description, config) {
|
|
186
|
+
this.rawName = rawName;
|
|
187
|
+
this.description = description;
|
|
188
|
+
this.config = Object.assign({}, config);
|
|
189
|
+
rawName = rawName.replaceAll(".*", "");
|
|
190
|
+
this.negated = false;
|
|
191
|
+
this.names = removeBrackets(rawName).split(",").map((v) => {
|
|
192
|
+
let name = v.trim().replace(/^-{1,2}/, "");
|
|
193
|
+
if (name.startsWith("no-")) {
|
|
194
|
+
this.negated = true;
|
|
195
|
+
name = name.replace(/^no-/, "");
|
|
196
|
+
}
|
|
197
|
+
return camelcaseOptionName(name);
|
|
198
|
+
}).sort((a, b) => a.length > b.length ? 1 : -1);
|
|
199
|
+
this.name = this.names.at(-1);
|
|
200
|
+
if (this.negated && this.config.default == null) this.config.default = true;
|
|
201
|
+
if (rawName.includes("<")) this.required = true;
|
|
202
|
+
else if (rawName.includes("[")) this.required = false;
|
|
203
|
+
else this.isBoolean = true;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region src/runtime.ts
|
|
209
|
+
let runtimeProcessArgs;
|
|
210
|
+
let runtimeInfo;
|
|
211
|
+
if (typeof process !== "undefined") {
|
|
212
|
+
let runtimeName;
|
|
213
|
+
if (typeof Deno !== "undefined" && typeof Deno.version?.deno === "string") runtimeName = "deno";
|
|
214
|
+
else if (typeof Bun !== "undefined" && typeof Bun.version === "string") runtimeName = "bun";
|
|
215
|
+
else runtimeName = "node";
|
|
216
|
+
runtimeInfo = `${process.platform}-${process.arch} ${runtimeName}-${process.version}`;
|
|
217
|
+
runtimeProcessArgs = process.argv;
|
|
218
|
+
} else if (typeof navigator === "undefined") runtimeInfo = `unknown`;
|
|
219
|
+
else runtimeInfo = `${navigator.platform} ${navigator.userAgent}`;
|
|
220
|
+
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/command.ts
|
|
223
|
+
var Command = class {
|
|
224
|
+
rawName;
|
|
225
|
+
description;
|
|
226
|
+
config;
|
|
227
|
+
cli;
|
|
228
|
+
options;
|
|
229
|
+
aliasNames;
|
|
230
|
+
name;
|
|
231
|
+
args;
|
|
232
|
+
commandAction;
|
|
233
|
+
usageText;
|
|
234
|
+
versionNumber;
|
|
235
|
+
examples;
|
|
236
|
+
helpCallback;
|
|
237
|
+
globalCommand;
|
|
238
|
+
constructor(rawName, description, config = {}, cli) {
|
|
239
|
+
this.rawName = rawName;
|
|
240
|
+
this.description = description;
|
|
241
|
+
this.config = config;
|
|
242
|
+
this.cli = cli;
|
|
243
|
+
this.options = [];
|
|
244
|
+
this.aliasNames = [];
|
|
245
|
+
this.name = removeBrackets(rawName);
|
|
246
|
+
this.args = findAllBrackets(rawName);
|
|
247
|
+
this.examples = [];
|
|
248
|
+
}
|
|
249
|
+
usage(text) {
|
|
250
|
+
this.usageText = text;
|
|
251
|
+
return this;
|
|
252
|
+
}
|
|
253
|
+
allowUnknownOptions() {
|
|
254
|
+
this.config.allowUnknownOptions = true;
|
|
255
|
+
return this;
|
|
256
|
+
}
|
|
257
|
+
ignoreOptionDefaultValue() {
|
|
258
|
+
this.config.ignoreOptionDefaultValue = true;
|
|
259
|
+
return this;
|
|
260
|
+
}
|
|
261
|
+
version(version, customFlags = "-v, --version") {
|
|
262
|
+
this.versionNumber = version;
|
|
263
|
+
this.option(customFlags, "Display version number");
|
|
264
|
+
return this;
|
|
265
|
+
}
|
|
266
|
+
example(example) {
|
|
267
|
+
this.examples.push(example);
|
|
268
|
+
return this;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Add a option for this command
|
|
272
|
+
* @param rawName Raw option name(s)
|
|
273
|
+
* @param description Option description
|
|
274
|
+
* @param config Option config
|
|
275
|
+
*/
|
|
276
|
+
option(rawName, description, config) {
|
|
277
|
+
const option = new Option(rawName, description, config);
|
|
278
|
+
this.options.push(option);
|
|
279
|
+
return this;
|
|
280
|
+
}
|
|
281
|
+
alias(name) {
|
|
282
|
+
this.aliasNames.push(name);
|
|
283
|
+
return this;
|
|
284
|
+
}
|
|
285
|
+
action(callback) {
|
|
286
|
+
this.commandAction = callback;
|
|
287
|
+
return this;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Check if a command name is matched by this command
|
|
291
|
+
* @param name Command name
|
|
292
|
+
*/
|
|
293
|
+
isMatched(name) {
|
|
294
|
+
return this.name === name || this.aliasNames.includes(name);
|
|
295
|
+
}
|
|
296
|
+
get isDefaultCommand() {
|
|
297
|
+
return this.name === "" || this.aliasNames.includes("!");
|
|
298
|
+
}
|
|
299
|
+
get isGlobalCommand() {
|
|
300
|
+
return this instanceof GlobalCommand;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Check if an option is registered in this command
|
|
304
|
+
* @param name Option name
|
|
305
|
+
*/
|
|
306
|
+
hasOption(name) {
|
|
307
|
+
name = name.split(".")[0];
|
|
308
|
+
return this.options.find((option) => {
|
|
309
|
+
return option.names.includes(name);
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
outputHelp() {
|
|
313
|
+
const { name, commands } = this.cli;
|
|
314
|
+
const { versionNumber, options: globalOptions, helpCallback } = this.cli.globalCommand;
|
|
315
|
+
let sections = [{ body: `${name}${versionNumber ? `/${versionNumber}` : ""}` }];
|
|
316
|
+
sections.push({
|
|
317
|
+
title: "Usage",
|
|
318
|
+
body: ` $ ${name} ${this.usageText || this.rawName}`
|
|
319
|
+
});
|
|
320
|
+
if ((this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0) {
|
|
321
|
+
const longestCommandName = findLongest(commands.map((command) => command.rawName));
|
|
322
|
+
sections.push({
|
|
323
|
+
title: "Commands",
|
|
324
|
+
body: commands.map((command) => {
|
|
325
|
+
return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
|
|
326
|
+
}).join("\n")
|
|
327
|
+
}, {
|
|
328
|
+
title: `For more info, run any command with the \`--help\` flag`,
|
|
329
|
+
body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
|
|
333
|
+
if (!this.isGlobalCommand && !this.isDefaultCommand) options = options.filter((option) => option.name !== "version");
|
|
334
|
+
if (options.length > 0) {
|
|
335
|
+
const longestOptionName = findLongest(options.map((option) => option.rawName));
|
|
336
|
+
sections.push({
|
|
337
|
+
title: "Options",
|
|
338
|
+
body: options.map((option) => {
|
|
339
|
+
return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === void 0 ? "" : `(default: ${option.config.default})`}`;
|
|
340
|
+
}).join("\n")
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
if (this.examples.length > 0) sections.push({
|
|
344
|
+
title: "Examples",
|
|
345
|
+
body: this.examples.map((example) => {
|
|
346
|
+
if (typeof example === "function") return example(name);
|
|
347
|
+
return example;
|
|
348
|
+
}).join("\n")
|
|
349
|
+
});
|
|
350
|
+
if (helpCallback) sections = helpCallback(sections) || sections;
|
|
351
|
+
console.info(sections.map((section) => {
|
|
352
|
+
return section.title ? `${section.title}:\n${section.body}` : section.body;
|
|
353
|
+
}).join("\n\n"));
|
|
354
|
+
}
|
|
355
|
+
outputVersion() {
|
|
356
|
+
const { name } = this.cli;
|
|
357
|
+
const { versionNumber } = this.cli.globalCommand;
|
|
358
|
+
if (versionNumber) console.info(`${name}/${versionNumber} ${runtimeInfo}`);
|
|
359
|
+
}
|
|
360
|
+
checkRequiredArgs() {
|
|
361
|
+
const minimalArgsCount = this.args.filter((arg) => arg.required).length;
|
|
362
|
+
if (this.cli.args.length < minimalArgsCount) throw new CACError(`missing required args for command \`${this.rawName}\``);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Check if the parsed options contain any unknown options
|
|
366
|
+
*
|
|
367
|
+
* Exit and output error when true
|
|
368
|
+
*/
|
|
369
|
+
checkUnknownOptions() {
|
|
370
|
+
const { options, globalCommand } = this.cli;
|
|
371
|
+
if (!this.config.allowUnknownOptions) {
|
|
372
|
+
for (const name of Object.keys(options)) if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Check if the required string-type options exist
|
|
377
|
+
*/
|
|
378
|
+
checkOptionValue() {
|
|
379
|
+
const { options: parsedOptions, globalCommand } = this.cli;
|
|
380
|
+
const options = [...globalCommand.options, ...this.options];
|
|
381
|
+
for (const option of options) {
|
|
382
|
+
const value = parsedOptions[option.name.split(".")[0]];
|
|
383
|
+
if (option.required) {
|
|
384
|
+
const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
|
|
385
|
+
if (value === true || value === false && !hasNegated) throw new CACError(`option \`${option.rawName}\` value is missing`);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Check if the number of args is more than expected
|
|
391
|
+
*/
|
|
392
|
+
checkUnusedArgs() {
|
|
393
|
+
const maximumArgsCount = this.args.some((arg) => arg.variadic) ? Infinity : this.args.length;
|
|
394
|
+
if (maximumArgsCount < this.cli.args.length) throw new CACError(`Unused args: ${this.cli.args.slice(maximumArgsCount).map((arg) => `\`${arg}\``).join(", ")}`);
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
var GlobalCommand = class extends Command {
|
|
398
|
+
constructor(cli) {
|
|
399
|
+
super("@@global@@", "", {}, cli);
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
//#endregion
|
|
404
|
+
//#region src/cac.ts
|
|
405
|
+
var CAC = class extends EventTarget {
|
|
406
|
+
/** The program name to display in help and version message */
|
|
407
|
+
name;
|
|
408
|
+
commands;
|
|
409
|
+
globalCommand;
|
|
410
|
+
matchedCommand;
|
|
411
|
+
matchedCommandName;
|
|
412
|
+
/**
|
|
413
|
+
* Raw CLI arguments
|
|
414
|
+
*/
|
|
415
|
+
rawArgs;
|
|
416
|
+
/**
|
|
417
|
+
* Parsed CLI arguments
|
|
418
|
+
*/
|
|
419
|
+
args;
|
|
420
|
+
/**
|
|
421
|
+
* Parsed CLI options, camelCased
|
|
422
|
+
*/
|
|
423
|
+
options;
|
|
424
|
+
showHelpOnExit;
|
|
425
|
+
showVersionOnExit;
|
|
426
|
+
/**
|
|
427
|
+
* @param name The program name to display in help and version message
|
|
428
|
+
*/
|
|
429
|
+
constructor(name = "") {
|
|
430
|
+
super();
|
|
431
|
+
this.name = name;
|
|
432
|
+
this.commands = [];
|
|
433
|
+
this.rawArgs = [];
|
|
434
|
+
this.args = [];
|
|
435
|
+
this.options = {};
|
|
436
|
+
this.globalCommand = new GlobalCommand(this);
|
|
437
|
+
this.globalCommand.usage("<command> [options]");
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Add a global usage text.
|
|
441
|
+
*
|
|
442
|
+
* This is not used by sub-commands.
|
|
443
|
+
*/
|
|
444
|
+
usage(text) {
|
|
445
|
+
this.globalCommand.usage(text);
|
|
446
|
+
return this;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Add a sub-command
|
|
450
|
+
*/
|
|
451
|
+
command(rawName, description, config) {
|
|
452
|
+
const command = new Command(rawName, description || "", config, this);
|
|
453
|
+
command.globalCommand = this.globalCommand;
|
|
454
|
+
this.commands.push(command);
|
|
455
|
+
return command;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Add a global CLI option.
|
|
459
|
+
*
|
|
460
|
+
* Which is also applied to sub-commands.
|
|
461
|
+
*/
|
|
462
|
+
option(rawName, description, config) {
|
|
463
|
+
this.globalCommand.option(rawName, description, config);
|
|
464
|
+
return this;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Show help message when `-h, --help` flags appear.
|
|
468
|
+
*
|
|
469
|
+
*/
|
|
470
|
+
help(callback) {
|
|
471
|
+
this.globalCommand.option("-h, --help", "Display this message");
|
|
472
|
+
this.globalCommand.helpCallback = callback;
|
|
473
|
+
this.showHelpOnExit = true;
|
|
474
|
+
return this;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Show version number when `-v, --version` flags appear.
|
|
478
|
+
*
|
|
479
|
+
*/
|
|
480
|
+
version(version, customFlags = "-v, --version") {
|
|
481
|
+
this.globalCommand.version(version, customFlags);
|
|
482
|
+
this.showVersionOnExit = true;
|
|
483
|
+
return this;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Add a global example.
|
|
487
|
+
*
|
|
488
|
+
* This example added here will not be used by sub-commands.
|
|
489
|
+
*/
|
|
490
|
+
example(example) {
|
|
491
|
+
this.globalCommand.example(example);
|
|
492
|
+
return this;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Output the corresponding help message
|
|
496
|
+
* When a sub-command is matched, output the help message for the command
|
|
497
|
+
* Otherwise output the global one.
|
|
498
|
+
*
|
|
499
|
+
*/
|
|
500
|
+
outputHelp() {
|
|
501
|
+
if (this.matchedCommand) this.matchedCommand.outputHelp();
|
|
502
|
+
else this.globalCommand.outputHelp();
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Output the version number.
|
|
506
|
+
*
|
|
507
|
+
*/
|
|
508
|
+
outputVersion() {
|
|
509
|
+
this.globalCommand.outputVersion();
|
|
510
|
+
}
|
|
511
|
+
setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
|
|
512
|
+
this.args = args;
|
|
513
|
+
this.options = options;
|
|
514
|
+
if (matchedCommand) this.matchedCommand = matchedCommand;
|
|
515
|
+
if (matchedCommandName) this.matchedCommandName = matchedCommandName;
|
|
516
|
+
return this;
|
|
517
|
+
}
|
|
518
|
+
unsetMatchedCommand() {
|
|
519
|
+
this.matchedCommand = void 0;
|
|
520
|
+
this.matchedCommandName = void 0;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Parse argv
|
|
524
|
+
*/
|
|
525
|
+
parse(argv, { run = true } = {}) {
|
|
526
|
+
if (!argv) {
|
|
527
|
+
if (!runtimeProcessArgs) throw new Error("No argv provided and runtime process argv is not available.");
|
|
528
|
+
argv = runtimeProcessArgs;
|
|
529
|
+
}
|
|
530
|
+
this.rawArgs = argv;
|
|
531
|
+
if (!this.name) this.name = argv[1] ? getFileName(argv[1]) : "cli";
|
|
532
|
+
let shouldParse = true;
|
|
533
|
+
for (const command of this.commands) {
|
|
534
|
+
const parsed = this.mri(argv.slice(2), command);
|
|
535
|
+
const commandName = parsed.args[0];
|
|
536
|
+
if (command.isMatched(commandName)) {
|
|
537
|
+
shouldParse = false;
|
|
538
|
+
const parsedInfo = {
|
|
539
|
+
...parsed,
|
|
540
|
+
args: parsed.args.slice(1)
|
|
541
|
+
};
|
|
542
|
+
this.setParsedInfo(parsedInfo, command, commandName);
|
|
543
|
+
this.dispatchEvent(new CustomEvent(`command:${commandName}`, { detail: command }));
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
if (shouldParse) {
|
|
547
|
+
for (const command of this.commands) if (command.isDefaultCommand) {
|
|
548
|
+
shouldParse = false;
|
|
549
|
+
const parsed = this.mri(argv.slice(2), command);
|
|
550
|
+
this.setParsedInfo(parsed, command);
|
|
551
|
+
this.dispatchEvent(new CustomEvent("command:!", { detail: command }));
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
if (shouldParse) {
|
|
555
|
+
const parsed = this.mri(argv.slice(2));
|
|
556
|
+
this.setParsedInfo(parsed);
|
|
557
|
+
}
|
|
558
|
+
if (this.options.help && this.showHelpOnExit) {
|
|
559
|
+
this.outputHelp();
|
|
560
|
+
run = false;
|
|
561
|
+
this.unsetMatchedCommand();
|
|
562
|
+
}
|
|
563
|
+
if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
|
|
564
|
+
this.outputVersion();
|
|
565
|
+
run = false;
|
|
566
|
+
this.unsetMatchedCommand();
|
|
567
|
+
}
|
|
568
|
+
const parsedArgv = {
|
|
569
|
+
args: this.args,
|
|
570
|
+
options: this.options
|
|
571
|
+
};
|
|
572
|
+
if (run) this.runMatchedCommand();
|
|
573
|
+
if (!this.matchedCommand && this.args[0]) this.dispatchEvent(new CustomEvent("command:*", { detail: this.args[0] }));
|
|
574
|
+
return parsedArgv;
|
|
575
|
+
}
|
|
576
|
+
mri(argv, command) {
|
|
577
|
+
const cliOptions = [...this.globalCommand.options, ...command ? command.options : []];
|
|
578
|
+
const mriOptions = getMriOptions(cliOptions);
|
|
579
|
+
let argsAfterDoubleDashes = [];
|
|
580
|
+
const doubleDashesIndex = argv.indexOf("--");
|
|
581
|
+
if (doubleDashesIndex !== -1) {
|
|
582
|
+
argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
|
|
583
|
+
argv = argv.slice(0, doubleDashesIndex);
|
|
584
|
+
}
|
|
585
|
+
let parsed = lib_default(argv, mriOptions);
|
|
586
|
+
parsed = Object.keys(parsed).reduce((res, name) => {
|
|
587
|
+
return {
|
|
588
|
+
...res,
|
|
589
|
+
[camelcaseOptionName(name)]: parsed[name]
|
|
590
|
+
};
|
|
591
|
+
}, { _: [] });
|
|
592
|
+
const args = parsed._;
|
|
593
|
+
const options = { "--": argsAfterDoubleDashes };
|
|
594
|
+
const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
|
|
595
|
+
const transforms = Object.create(null);
|
|
596
|
+
for (const cliOption of cliOptions) {
|
|
597
|
+
if (!ignoreDefault && cliOption.config.default !== void 0) for (const name of cliOption.names) options[name] = cliOption.config.default;
|
|
598
|
+
if (Array.isArray(cliOption.config.type) && transforms[cliOption.name] === void 0) {
|
|
599
|
+
transforms[cliOption.name] = Object.create(null);
|
|
600
|
+
transforms[cliOption.name].shouldTransform = true;
|
|
601
|
+
transforms[cliOption.name].transformFunction = cliOption.config.type[0];
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
for (const key of Object.keys(parsed)) if (key !== "_") {
|
|
605
|
+
setDotProp(options, key.split("."), parsed[key]);
|
|
606
|
+
setByType(options, transforms);
|
|
607
|
+
}
|
|
608
|
+
return {
|
|
609
|
+
args,
|
|
610
|
+
options
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
runMatchedCommand() {
|
|
614
|
+
const { args, options, matchedCommand: command } = this;
|
|
615
|
+
if (!command || !command.commandAction) return;
|
|
616
|
+
command.checkUnknownOptions();
|
|
617
|
+
command.checkOptionValue();
|
|
618
|
+
command.checkRequiredArgs();
|
|
619
|
+
command.checkUnusedArgs();
|
|
620
|
+
const actionArgs = [];
|
|
621
|
+
command.args.forEach((arg, index) => {
|
|
622
|
+
if (arg.variadic) actionArgs.push(args.slice(index));
|
|
623
|
+
else actionArgs.push(args[index]);
|
|
624
|
+
});
|
|
625
|
+
actionArgs.push(options);
|
|
626
|
+
return command.commandAction.apply(this, actionArgs);
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
//#endregion
|
|
631
|
+
//#region src/index.ts
|
|
632
|
+
/**
|
|
633
|
+
* @param name The program name to display in help and version message
|
|
634
|
+
*/
|
|
635
|
+
const cac = (name = "") => new CAC(name);
|
|
636
|
+
|
|
637
|
+
//#endregion
|
|
638
|
+
export { CAC, Command, cac, cac as default };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cac",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "7.0.0",
|
|
5
|
+
"description": "Simple yet powerful framework for building command-line apps.",
|
|
6
|
+
"author": "egoist <0x142857@gmail.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/cacjs/cac#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/cacjs/cac.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/cacjs/cac/issues"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./dist/index.js",
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=20.19.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@sxzz/eslint-config": "^7.8.2",
|
|
28
|
+
"@sxzz/prettier-config": "^2.3.1",
|
|
29
|
+
"@types/bun": "^1.3.9",
|
|
30
|
+
"@types/deno": "^2.5.0",
|
|
31
|
+
"@types/node": "^25.3.2",
|
|
32
|
+
"@typescript/native-preview": "7.0.0-dev.20260227.1",
|
|
33
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
34
|
+
"bumpp": "^10.4.1",
|
|
35
|
+
"eslint": "^10.0.2",
|
|
36
|
+
"lint-staged": "^16.2.7",
|
|
37
|
+
"mri": "^1.2.0",
|
|
38
|
+
"prettier": "^3.8.1",
|
|
39
|
+
"simple-git-hooks": "^2.13.1",
|
|
40
|
+
"tinyexec": "^1.0.2",
|
|
41
|
+
"tsdown": "^0.21.0-beta.2",
|
|
42
|
+
"tsdown-preset-sxzz": "^0.4.0",
|
|
43
|
+
"typedoc": "^0.28.17",
|
|
44
|
+
"typescript": "^5.9.3",
|
|
45
|
+
"vitest": "^4.0.18"
|
|
46
|
+
},
|
|
47
|
+
"husky": {
|
|
48
|
+
"hooks": {
|
|
49
|
+
"pre-commit": "pnpm test && lint-staged"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"simple-git-hooks": {
|
|
53
|
+
"pre-commit": "pnpm lint-staged && pnpm typecheck"
|
|
54
|
+
},
|
|
55
|
+
"lint-staged": {
|
|
56
|
+
"*.{js,json,ts,md}": [
|
|
57
|
+
"eslint"
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
"prettier": "@sxzz/prettier-config",
|
|
61
|
+
"scripts": {
|
|
62
|
+
"lint": "eslint --cache .",
|
|
63
|
+
"lint:fix": "pnpm run lint --fix",
|
|
64
|
+
"build": "tsdown",
|
|
65
|
+
"dev": "tsdown --watch",
|
|
66
|
+
"test": "vitest",
|
|
67
|
+
"typecheck": "tsgo --noEmit",
|
|
68
|
+
"format": "prettier --cache --write .",
|
|
69
|
+
"release": "bumpp",
|
|
70
|
+
"docs:api": "typedoc"
|
|
71
|
+
}
|
|
72
|
+
}
|