nuxt-ai-ready 2.5.2 → 3.0.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/README.md +13 -12
- package/dist/chunks/agent-skills.mjs +35 -12
- package/dist/chunks/prerender.mjs +35 -24
- package/dist/cli.mjs +5 -2
- package/dist/module.d.mts +4 -0
- package/dist/module.json +2 -2
- package/dist/module.mjs +8 -4
- package/dist/runtime/app/index.d.ts +3 -0
- package/dist/runtime/app/index.js +2 -0
- package/dist/runtime/cache-control.d.ts +2 -0
- package/dist/runtime/cache-control.js +11 -0
- package/dist/runtime/llms-txt-utils.js +1 -1
- package/dist/runtime/server/db/context.d.ts +13 -0
- package/dist/runtime/server/db/drizzle/client.d.ts +6 -7
- package/dist/runtime/server/db/drizzle/client.js +13 -2
- package/dist/runtime/server/db/drizzle/providers/bun.d.ts +2 -2
- package/dist/runtime/server/db/drizzle/providers/bun.js +2 -2
- package/dist/runtime/server/db/drizzle/providers/d1.d.ts +2 -2
- package/dist/runtime/server/db/drizzle/providers/d1.js +3 -2
- package/dist/runtime/server/db/drizzle/providers/libsql.d.ts +2 -2
- package/dist/runtime/server/db/drizzle/providers/libsql.js +2 -2
- package/dist/runtime/server/db/drizzle/providers/neon.d.ts +2 -2
- package/dist/runtime/server/db/drizzle/providers/neon.js +2 -2
- package/dist/runtime/server/db/drizzle/providers/node-sqlite.d.ts +2 -2
- package/dist/runtime/server/db/drizzle/providers/node-sqlite.js +2 -2
- package/dist/runtime/server/db/drizzle/providers/postgres.d.ts +2 -2
- package/dist/runtime/server/db/drizzle/providers/postgres.js +2 -2
- package/dist/runtime/server/db/drizzle/queries.d.ts +27 -27
- package/dist/runtime/server/db/drizzle/queries.js +6 -5
- package/dist/runtime/server/db/drizzle/raw.d.ts +2 -6
- package/dist/runtime/server/db/index.d.ts +1 -1
- package/dist/runtime/server/db/index.js +1 -1
- package/dist/runtime/server/db/queries.d.ts +36 -36
- package/dist/runtime/server/db/queries.js +8 -9
- package/dist/runtime/server/db/seed.d.ts +2 -2
- package/dist/runtime/server/db/seed.js +4 -3
- package/dist/runtime/server/db/shared.d.ts +8 -0
- package/dist/runtime/server/db/shared.js +8 -2
- package/dist/runtime/server/index.d.ts +2 -0
- package/dist/runtime/server/index.js +17 -0
- package/dist/runtime/server/mcp/tools/get-page-markdown.js +1 -1
- package/dist/runtime/server/mcp/tools/list-pages.js +1 -1
- package/dist/runtime/server/mcp/tools/search-pages.js +1 -1
- package/dist/runtime/server/middleware/markdown.js +3 -3
- package/dist/runtime/server/middleware/markdown.prerender.js +1 -1
- package/dist/runtime/server/plugins/db-lifecycle-nitro3.d.ts +2 -0
- package/dist/runtime/server/plugins/db-lifecycle-nitro3.js +16 -0
- package/dist/runtime/server/plugins/html-capture.prerender.js +6 -4
- package/dist/runtime/server/plugins/link-header-nitro3.d.ts +2 -0
- package/dist/runtime/server/plugins/link-header-nitro3.js +20 -0
- package/dist/runtime/server/plugins/link-header.d.ts +6 -0
- package/dist/runtime/server/plugins/link-header.js +7 -11
- package/dist/runtime/server/plugins/markdown-negotiation.js +8 -1
- package/dist/runtime/server/plugins/sitemap-seeder.js +3 -3
- package/dist/runtime/server/routes/agent-skills-artifact.d.ts +1 -1
- package/dist/runtime/server/routes/agent-skills-artifact.js +10 -10
- package/dist/runtime/server/routes/agent-skills-index.d.ts +1 -1
- package/dist/runtime/server/routes/agent-skills-index.js +7 -6
- package/dist/runtime/server/routes/ai-catalog.d.ts +2 -1
- package/dist/runtime/server/routes/ai-catalog.js +7 -8
- package/dist/runtime/server/routes/api-catalog.d.ts +3 -1
- package/dist/runtime/server/routes/api-catalog.js +12 -12
- package/dist/runtime/server/routes/llms-full.txt.get.js +1 -1
- package/dist/runtime/server/routes/mcp-server-card.d.ts +1 -1
- package/dist/runtime/server/routes/mcp-server-card.js +7 -8
- package/dist/runtime/server/utils/checkStale.d.ts +2 -2
- package/dist/runtime/server/utils/cloudflare-prerendered.d.ts +3 -0
- package/dist/runtime/server/utils/cloudflare-prerendered.js +23 -0
- package/dist/runtime/server/utils/cloudflare.d.ts +5 -5
- package/dist/runtime/server/utils/cloudflare.js +31 -7
- package/dist/runtime/server/utils/content-negotiation.d.ts +5 -3
- package/dist/runtime/server/utils/content-negotiation.js +8 -7
- package/dist/runtime/server/utils/context.d.ts +3 -3
- package/dist/runtime/server/utils/context.js +1 -1
- package/dist/runtime/server/utils/discovery-response.d.ts +2 -0
- package/dist/runtime/server/utils/link-header.d.ts +5 -3
- package/dist/runtime/server/utils/link-header.js +26 -2
- package/dist/runtime/server/utils/markdown-request.d.ts +4 -3
- package/dist/runtime/server/utils/markdown-request.js +15 -13
- package/dist/runtime/server/utils/negotiation-decision.d.ts +4 -0
- package/dist/runtime/server/utils/negotiation-decision.js +6 -5
- package/dist/runtime/server/utils/negotiation-response.d.ts +1 -1
- package/dist/runtime/server/utils/negotiation-response.js +63 -23
- package/dist/runtime/server/utils/prerender-html.d.ts +2 -1
- package/dist/runtime/server/utils/prerender-html.js +3 -1
- package/dist/runtime/types.d.ts +15 -7
- package/dist/shared/nuxt-ai-ready.B3hAuOLQ.mjs +29 -0
- package/dist/shared/{nuxt-ai-ready.CLSWou20.mjs → nuxt-ai-ready.C34F0LJo.mjs} +560 -219
- package/package.json +85 -20
- package/skills/nuxt-ai-ready/SKILL.md +26 -12
- package/skills/nuxt-ai-ready/references/runtime-indexing.md +7 -6
- package/dist/runtime/server/db/drizzle/providers/sqlite.d.ts +0 -8
- package/dist/runtime/server/db/drizzle/providers/sqlite.js +0 -15
- package/node_modules/@mdream/js/LICENSE.md +0 -9
- package/node_modules/@mdream/js/README.md +0 -792
- package/node_modules/@mdream/js/bin/mdream.mjs +0 -2
- package/node_modules/@mdream/js/dist/_chunks/const.mjs +0 -134
- package/node_modules/@mdream/js/dist/_chunks/index.d.mts +0 -9
- package/node_modules/@mdream/js/dist/_chunks/markdown-processor.mjs +0 -1968
- package/node_modules/@mdream/js/dist/_chunks/minimal.d.mts +0 -6
- package/node_modules/@mdream/js/dist/_chunks/parse.mjs +0 -2756
- package/node_modules/@mdream/js/dist/_chunks/plugins.mjs +0 -725
- package/node_modules/@mdream/js/dist/_chunks/resolve-plugins.mjs +0 -44
- package/node_modules/@mdream/js/dist/_chunks/stream.mjs +0 -37
- package/node_modules/@mdream/js/dist/_chunks/types.d.mts +0 -473
- package/node_modules/@mdream/js/dist/cli.d.mts +0 -1
- package/node_modules/@mdream/js/dist/cli.mjs +0 -32
- package/node_modules/@mdream/js/dist/core.d.mts +0 -15
- package/node_modules/@mdream/js/dist/core.mjs +0 -28
- package/node_modules/@mdream/js/dist/index.d.mts +0 -4
- package/node_modules/@mdream/js/dist/index.mjs +0 -58
- package/node_modules/@mdream/js/dist/llms-txt.d.mts +0 -86
- package/node_modules/@mdream/js/dist/llms-txt.mjs +0 -308
- package/node_modules/@mdream/js/dist/negotiate.d.mts +0 -35
- package/node_modules/@mdream/js/dist/negotiate.mjs +0 -121
- package/node_modules/@mdream/js/dist/parse.d.mts +0 -90
- package/node_modules/@mdream/js/dist/parse.mjs +0 -2
- package/node_modules/@mdream/js/dist/plugins.d.mts +0 -85
- package/node_modules/@mdream/js/dist/plugins.mjs +0 -2
- package/node_modules/@mdream/js/dist/preset/minimal.d.mts +0 -2
- package/node_modules/@mdream/js/dist/preset/minimal.mjs +0 -33
- package/node_modules/@mdream/js/dist/splitter.d.mts +0 -18
- package/node_modules/@mdream/js/dist/splitter.mjs +0 -194
- package/node_modules/@mdream/js/package.json +0 -103
- package/node_modules/cac/LICENSE +0 -21
- package/node_modules/cac/README.md +0 -492
- package/node_modules/cac/dist/index.d.ts +0 -196
- package/node_modules/cac/dist/index.js +0 -638
- package/node_modules/cac/package.json +0 -72
- package/node_modules/mdream/LICENSE.md +0 -9
- package/node_modules/mdream/README.md +0 -1091
- package/node_modules/mdream/bin/mdream.mjs +0 -46
- package/node_modules/mdream/dist/browser.d.mts +0 -105
- package/node_modules/mdream/dist/browser.mjs +0 -262
- package/node_modules/mdream/dist/edge.d.mts +0 -100
- package/node_modules/mdream/dist/edge.mjs +0 -250
- package/node_modules/mdream/dist/iife.js +0 -605
- package/node_modules/mdream/dist/index.d.mts +0 -89
- package/node_modules/mdream/dist/index.mjs +0 -184
- package/node_modules/mdream/dist/wasm.d.mts +0 -100
- package/node_modules/mdream/dist/wasm.mjs +0 -140
- package/node_modules/mdream/dist/worker.d.mts +0 -101
- package/node_modules/mdream/dist/worker.mjs +0 -217
- package/node_modules/mdream/napi/index.d.mts +0 -127
- package/node_modules/mdream/napi/index.d.ts +0 -127
- package/node_modules/mdream/napi/index.mjs +0 -725
- 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 +0 -2144
- 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 +0 -21
- package/node_modules/mdream/node_modules/@emnapi/core/README.md +0 -1
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.d.ts +0 -392
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.d.ts +0 -392
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.js +0 -8351
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.js +0 -7268
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.d.ts +0 -5
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.js +0 -843
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.d.ts +0 -4
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.js +0 -3
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.d.ts +0 -5
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.js +0 -1010
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.d.ts +0 -5
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.js +0 -1446
- package/node_modules/mdream/node_modules/@emnapi/core/package.json +0 -39
- package/node_modules/mdream/node_modules/@emnapi/core/rollup.config.js +0 -60
- package/node_modules/mdream/node_modules/@emnapi/runtime/LICENSE +0 -21
- package/node_modules/mdream/node_modules/@emnapi/runtime/README.md +0 -1
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.d.ts +0 -833
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js +0 -2306
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js.map +0 -1
- package/node_modules/mdream/node_modules/@emnapi/runtime/index.cjs +0 -63
- package/node_modules/mdream/node_modules/@emnapi/runtime/package.json +0 -39
- package/node_modules/mdream/node_modules/@emnapi/runtime/rollup.config.js +0 -25
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/LICENSE +0 -21
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/README.md +0 -203
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +0 -236
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +0 -1086
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/package.json +0 -35
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/rollup.config.js +0 -6
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.cjs +0 -1472
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.js +0 -1470
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs-proxy.cjs +0 -237
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs.js +0 -18260
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +0 -317
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/package.json +0 -67
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.cjs +0 -39
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.js +0 -36
- package/node_modules/mdream/node_modules/@tybys/wasm-util/LICENSE +0 -21
- package/node_modules/mdream/node_modules/@tybys/wasm-util/README.md +0 -193
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/tsdoc-metadata.json +0 -11
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.d.ts +0 -423
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js +0 -2932
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +0 -2932
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.min.js +0 -1
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.js +0 -2954
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.min.js +0 -1
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/asyncify.js +0 -158
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/index.js +0 -13
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/jspi.js +0 -46
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/load.js +0 -97
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/memory.js +0 -35
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/error.js +0 -103
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fd.js +0 -268
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fs.js +0 -3
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/index.js +0 -192
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/path.js +0 -316
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +0 -1599
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/rights.js +0 -141
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/types.js +0 -220
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/util.js +0 -128
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/webassembly.js +0 -13
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/asyncify.mjs +0 -153
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/index.mjs +0 -9
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/jspi.mjs +0 -39
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/load.mjs +0 -89
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/memory.mjs +0 -28
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/error.mjs +0 -97
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fd.mjs +0 -256
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fs.mjs +0 -1
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/index.mjs +0 -186
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/path.mjs +0 -310
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +0 -1593
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/rights.mjs +0 -135
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/types.mjs +0 -216
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/util.mjs +0 -113
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/webassembly.mjs +0 -9
- package/node_modules/mdream/node_modules/@tybys/wasm-util/package.json +0 -58
- package/node_modules/mdream/node_modules/tslib/CopyrightNotice.txt +0 -15
- package/node_modules/mdream/node_modules/tslib/LICENSE.txt +0 -12
- package/node_modules/mdream/node_modules/tslib/README.md +0 -164
- package/node_modules/mdream/node_modules/tslib/SECURITY.md +0 -41
- package/node_modules/mdream/node_modules/tslib/modules/index.d.ts +0 -38
- package/node_modules/mdream/node_modules/tslib/modules/index.js +0 -70
- package/node_modules/mdream/node_modules/tslib/modules/package.json +0 -3
- package/node_modules/mdream/node_modules/tslib/package.json +0 -47
- package/node_modules/mdream/node_modules/tslib/tslib.d.ts +0 -460
- package/node_modules/mdream/node_modules/tslib/tslib.es6.html +0 -1
- package/node_modules/mdream/node_modules/tslib/tslib.es6.js +0 -402
- package/node_modules/mdream/node_modules/tslib/tslib.es6.mjs +0 -401
- package/node_modules/mdream/node_modules/tslib/tslib.html +0 -1
- package/node_modules/mdream/node_modules/tslib/tslib.js +0 -484
- package/node_modules/mdream/package.json +0 -110
- package/node_modules/mdream/skills/mdream/SKILL.md +0 -124
- package/node_modules/mdream/skills/mdream/references/runtimes.md +0 -49
- package/node_modules/mdream/wasm/mdream_edge.d.ts +0 -90
- package/node_modules/mdream/wasm/mdream_edge.js +0 -517
- package/node_modules/mdream/wasm/mdream_edge_bg.wasm +0 -0
- package/node_modules/mdream/wasm/mdream_edge_bg.wasm.d.ts +0 -20
- package/node_modules/mdream/wasm/package.json +0 -17
- package/node_modules/mdream/wasm-bundler/mdream_edge.d.ts +0 -45
- package/node_modules/mdream/wasm-bundler/mdream_edge.js +0 -13
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.js +0 -413
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm +0 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm.d.ts +0 -20
- package/node_modules/mdream/wasm-bundler/package.json +0 -19
- package/node_modules/pathe/LICENSE +0 -70
- package/node_modules/pathe/README.md +0 -73
- package/node_modules/pathe/dist/index.cjs +0 -39
- package/node_modules/pathe/dist/index.d.cts +0 -47
- package/node_modules/pathe/dist/index.d.mts +0 -47
- package/node_modules/pathe/dist/index.d.ts +0 -47
- package/node_modules/pathe/dist/index.mjs +0 -19
- package/node_modules/pathe/dist/shared/pathe.BSlhyZSM.cjs +0 -266
- package/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +0 -249
- package/node_modules/pathe/dist/utils.cjs +0 -82
- package/node_modules/pathe/dist/utils.d.cts +0 -32
- package/node_modules/pathe/dist/utils.d.mts +0 -32
- package/node_modules/pathe/dist/utils.d.ts +0 -32
- package/node_modules/pathe/dist/utils.mjs +0 -77
- package/node_modules/pathe/package.json +0 -61
- package/node_modules/pathe/utils.d.ts +0 -1
|
@@ -1,638 +0,0 @@
|
|
|
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 };
|
|
@@ -1,72 +0,0 @@
|
|
|
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
|
-
}
|