@jordond/kit 0.0.0-stage → 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/bin/kit +39 -0
- package/dist/_verb-espppzez.js +115 -0
- package/dist/android-g73naxgg.js +31 -0
- package/dist/build-88hxf0kc.js +42 -0
- package/dist/check-7mndz8g8.js +54 -0
- package/dist/check-ngc4kzmj.js +33 -0
- package/dist/cleanup-hrcvxmh2.js +18 -0
- package/dist/cli/builtins.d.ts +13 -0
- package/dist/cli/command.d.ts +86 -0
- package/dist/cli/discover.d.ts +10 -0
- package/dist/cli/main.d.ts +1 -0
- package/dist/cli/plugin.d.ts +7 -0
- package/dist/cli/usage.d.ts +3 -0
- package/dist/cli-07t28k94.js +30 -0
- package/dist/cli-12dww95e.js +195 -0
- package/dist/cli-5d61x8vg.js +675 -0
- package/dist/cli-5wasc5mr.js +76 -0
- package/dist/cli-6dxp4v3m.js +73 -0
- package/dist/cli-7wvrehng.js +23 -0
- package/dist/cli-bam7dqfd.js +33 -0
- package/dist/cli-fqfan92n.js +135 -0
- package/dist/cli-fqxtcj42.js +75 -0
- package/dist/cli-h974q2wr.js +2019 -0
- package/dist/cli-m53122z6.js +221 -0
- package/dist/cli-qhs8ww91.js +51 -0
- package/dist/cli-qq1ktr8q.js +234 -0
- package/dist/cli-rds33bnp.js +101 -0
- package/dist/cli-re3ntm60.js +48 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +35 -0
- package/dist/cloudflare-n5c46k6x.js +43 -0
- package/dist/command-gazq4bmt.js +19 -0
- package/dist/commands/_verb.d.ts +15 -0
- package/dist/commands/build.d.ts +11 -0
- package/dist/commands/check.d.ts +8 -0
- package/dist/commands/config.d.ts +2 -0
- package/dist/commands/db/create.d.ts +7 -0
- package/dist/commands/db/exec.d.ts +16 -0
- package/dist/commands/db/list.d.ts +11 -0
- package/dist/commands/db/migrate.d.ts +11 -0
- package/dist/commands/deploy.d.ts +13 -0
- package/dist/commands/deps.d.ts +72 -0
- package/dist/commands/dev.d.ts +8 -0
- package/dist/commands/doctor.d.ts +56 -0
- package/dist/commands/env/check.d.ts +7 -0
- package/dist/commands/env/init.d.ts +2 -0
- package/dist/commands/env/push.d.ts +12 -0
- package/dist/commands/env/sync.d.ts +2 -0
- package/dist/commands/format.d.ts +11 -0
- package/dist/commands/gradle.d.ts +2 -0
- package/dist/commands/init.d.ts +53 -0
- package/dist/commands/lint.d.ts +12 -0
- package/dist/commands/release/android.d.ts +13 -0
- package/dist/commands/release/ios.d.ts +13 -0
- package/dist/commands/test.d.ts +2 -0
- package/dist/commands/typecheck.d.ts +2 -0
- package/dist/commands/wrangler.d.ts +4 -0
- package/dist/commands/xcode.d.ts +8 -0
- package/dist/config/load.d.ts +6 -0
- package/dist/config/schema.d.ts +135 -0
- package/dist/config-ey5yrrfn.js +22 -0
- package/dist/create-7s8h3dja.js +38 -0
- package/dist/deploy-8mg1zhpb.js +102 -0
- package/dist/deps-97dq4mg8.js +334 -0
- package/dist/dev-yc9xmntj.js +62 -0
- package/dist/doctor-0wzmfyyh.js +324 -0
- package/dist/errors-1fjbr7ee.js +10 -0
- package/dist/exec-1k3sqwxz.js +53 -0
- package/dist/format-mnqfak22.js +39 -0
- package/dist/git-52v5rk51.js +80 -0
- package/dist/gradle-gtkf3geq.js +39 -0
- package/dist/index-cx34x4np.js +874 -0
- package/dist/index-erv82p4z.js +1528 -0
- package/dist/index-jqfz6hfy.js +2659 -0
- package/dist/index-mm4ht8yh.js +9 -0
- package/dist/index-s3ehw02w.js +1610 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +50 -0
- package/dist/init-0402av4m.js +78 -0
- package/dist/init-dk5sym9w.js +76 -0
- package/dist/init-qr7y55ea.js +185 -0
- package/dist/ios-msg4bk15.js +31 -0
- package/dist/lib/cleanup.d.ts +21 -0
- package/dist/lib/cloudflare.d.ts +96 -0
- package/dist/lib/env/init.d.ts +22 -0
- package/dist/lib/env/load.d.ts +12 -0
- package/dist/lib/env/push.d.ts +54 -0
- package/dist/lib/env/render.d.ts +49 -0
- package/dist/lib/env/schema.d.ts +49 -0
- package/dist/lib/errors.d.ts +14 -0
- package/dist/lib/git.d.ts +36 -0
- package/dist/lib/log.d.ts +11 -0
- package/dist/lib/pm.d.ts +8 -0
- package/dist/lib/proc.d.ts +73 -0
- package/dist/lib/prompt.d.ts +32 -0
- package/dist/lib/secrets.d.ts +32 -0
- package/dist/lib/steps.d.ts +38 -0
- package/dist/lib/targets.d.ts +46 -0
- package/dist/lib/toml.d.ts +15 -0
- package/dist/lint-280dpn4y.js +39 -0
- package/dist/list-jdc3dqk0.js +34 -0
- package/dist/load-5qzs1c6b.js +137 -0
- package/dist/log-hhspqwjw.js +11 -0
- package/dist/main-ywtsjxev.js +2052 -0
- package/dist/migrate-emk758k1.js +35 -0
- package/dist/picocolors-0dxagz5d.js +6 -0
- package/dist/pm-5q5vz6w3.js +14 -0
- package/dist/proc-jv4bcyyx.js +33 -0
- package/dist/prompt-v510j04z.js +93 -0
- package/dist/push-4z70h3d8.js +117 -0
- package/dist/push-xzqw218t.js +117 -0
- package/dist/render-488tjnsq.js +22 -0
- package/dist/sync-wc4jpmkj.js +53 -0
- package/dist/targets-hbwxv97d.js +22 -0
- package/dist/test-198w46m4.js +26 -0
- package/dist/toml-zbhtxjh1.js +1062 -0
- package/dist/typecheck-e86e6yg1.js +24 -0
- package/dist/wrangler-0ctx1p3w.js +66 -0
- package/dist/xcode-g44qh2rc.js +60 -0
- package/fastlane/Fastfile +413 -0
- package/fastlane/Gemfile +21 -0
- package/fastlane/Gemfile.lock +275 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.jar +0 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.jar.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.jar.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.jar.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.jar.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.module +64 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.module.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.module.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.module.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.module.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.pom +12 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.pom.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.pom.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.pom.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.pom.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/maven-metadata.xml +13 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/maven-metadata.xml.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/maven-metadata.xml.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/maven-metadata.xml.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/maven-metadata.xml.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.jar +0 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.jar.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.jar.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.jar.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.jar.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.module +64 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.module.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.module.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.module.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.module.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.pom +12 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.pom.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.pom.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.pom.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.pom.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/maven-metadata.xml +13 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/maven-metadata.xml.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/maven-metadata.xml.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/maven-metadata.xml.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/maven-metadata.xml.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/0.1.0/io.github.jordond.kit.release.gradle.plugin-0.1.0.pom +15 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/0.1.0/io.github.jordond.kit.release.gradle.plugin-0.1.0.pom.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/0.1.0/io.github.jordond.kit.release.gradle.plugin-0.1.0.pom.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/0.1.0/io.github.jordond.kit.release.gradle.plugin-0.1.0.pom.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/0.1.0/io.github.jordond.kit.release.gradle.plugin-0.1.0.pom.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/maven-metadata.xml +13 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/maven-metadata.xml.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/maven-metadata.xml.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/maven-metadata.xml.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/maven-metadata.xml.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/0.1.0/io.github.jordond.kit.settings.gradle.plugin-0.1.0.pom +15 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/0.1.0/io.github.jordond.kit.settings.gradle.plugin-0.1.0.pom.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/0.1.0/io.github.jordond.kit.settings.gradle.plugin-0.1.0.pom.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/0.1.0/io.github.jordond.kit.settings.gradle.plugin-0.1.0.pom.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/0.1.0/io.github.jordond.kit.settings.gradle.plugin-0.1.0.pom.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/maven-metadata.xml +13 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/maven-metadata.xml.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/maven-metadata.xml.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/maven-metadata.xml.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/maven-metadata.xml.sha512 +1 -0
- package/package.json +58 -4
- package/templates/lefthook.yml +6 -0
- package/templates/mise.toml +6 -0
- package/README.md +0 -3
|
@@ -0,0 +1,2052 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
installSignalHandlers,
|
|
4
|
+
interrupted,
|
|
5
|
+
runCleanup
|
|
6
|
+
} from "./cli-fqxtcj42.js";
|
|
7
|
+
import {
|
|
8
|
+
computeFlags,
|
|
9
|
+
toGunshi
|
|
10
|
+
} from "./cli-6dxp4v3m.js";
|
|
11
|
+
import {
|
|
12
|
+
log
|
|
13
|
+
} from "./cli-07t28k94.js";
|
|
14
|
+
import {
|
|
15
|
+
require_picocolors
|
|
16
|
+
} from "./cli-5wasc5mr.js";
|
|
17
|
+
import {
|
|
18
|
+
ExitCode,
|
|
19
|
+
KitError
|
|
20
|
+
} from "./cli-7wvrehng.js";
|
|
21
|
+
import {
|
|
22
|
+
__require,
|
|
23
|
+
__toESM
|
|
24
|
+
} from "./cli-re3ntm60.js";
|
|
25
|
+
|
|
26
|
+
// node_modules/gunshi/lib/utils-DbRhwNIU.js
|
|
27
|
+
function kebabnize(str) {
|
|
28
|
+
return str.replace(/[A-Z]/g, (match, offset) => (offset > 0 ? "-" : "") + match.toLowerCase());
|
|
29
|
+
}
|
|
30
|
+
function formatChoices(choices) {
|
|
31
|
+
return choices.map((value) => JSON.stringify(value)).join(", ");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// node_modules/gunshi/lib/utils.js
|
|
35
|
+
function isLazyCommand(cmd) {
|
|
36
|
+
return typeof cmd === "function" && "commandName" in cmd && !!cmd.commandName;
|
|
37
|
+
}
|
|
38
|
+
async function resolveLazyCommand(cmd, name, needRunResolving = false) {
|
|
39
|
+
let command;
|
|
40
|
+
if (isLazyCommand(cmd)) {
|
|
41
|
+
const baseCommand = {
|
|
42
|
+
name: cmd.commandName,
|
|
43
|
+
description: cmd.description,
|
|
44
|
+
args: cmd.args,
|
|
45
|
+
examples: cmd.examples,
|
|
46
|
+
internal: cmd.internal,
|
|
47
|
+
entry: cmd.entry,
|
|
48
|
+
subCommands: cmd.subCommands
|
|
49
|
+
};
|
|
50
|
+
if ("resource" in cmd && cmd.resource)
|
|
51
|
+
baseCommand.resource = cmd.resource;
|
|
52
|
+
command = Object.assign(create(), baseCommand);
|
|
53
|
+
if (needRunResolving) {
|
|
54
|
+
const loaded = await cmd();
|
|
55
|
+
if (typeof loaded === "function")
|
|
56
|
+
command.run = loaded;
|
|
57
|
+
else if (typeof loaded === "object") {
|
|
58
|
+
if (loaded.run == null)
|
|
59
|
+
throw new TypeError(`'run' is required in command: ${cmd.name || name}`);
|
|
60
|
+
command.run = loaded.run;
|
|
61
|
+
command.name = loaded.name;
|
|
62
|
+
command.description = loaded.description;
|
|
63
|
+
command.args = loaded.args;
|
|
64
|
+
command.examples = loaded.examples;
|
|
65
|
+
command.internal = loaded.internal;
|
|
66
|
+
command.entry = loaded.entry;
|
|
67
|
+
command.subCommands = loaded.subCommands || cmd.subCommands;
|
|
68
|
+
if ("resource" in loaded && loaded.resource)
|
|
69
|
+
command.resource = loaded.resource;
|
|
70
|
+
} else
|
|
71
|
+
throw new TypeError(`Cannot resolve command: ${cmd.name || name}`);
|
|
72
|
+
}
|
|
73
|
+
} else
|
|
74
|
+
command = Object.assign(create(), cmd);
|
|
75
|
+
if (command.name == null && name)
|
|
76
|
+
command.name = name;
|
|
77
|
+
return deepFreeze(command);
|
|
78
|
+
}
|
|
79
|
+
function create(obj = null) {
|
|
80
|
+
return Object.create(obj);
|
|
81
|
+
}
|
|
82
|
+
function log2(...args) {
|
|
83
|
+
console.log(...args);
|
|
84
|
+
}
|
|
85
|
+
function getCommandSubCommands(cmd) {
|
|
86
|
+
const subCommands = isLazyCommand(cmd) ? cmd.subCommands : typeof cmd === "object" ? cmd.subCommands : undefined;
|
|
87
|
+
if (!subCommands)
|
|
88
|
+
return;
|
|
89
|
+
if (subCommands instanceof Map)
|
|
90
|
+
return subCommands.size > 0 ? subCommands : undefined;
|
|
91
|
+
if (typeof subCommands === "object") {
|
|
92
|
+
const entries = Object.entries(subCommands);
|
|
93
|
+
if (entries.length === 0)
|
|
94
|
+
return;
|
|
95
|
+
const map = /* @__PURE__ */ new Map;
|
|
96
|
+
for (const [name, cmd2] of entries)
|
|
97
|
+
map.set(name, cmd2);
|
|
98
|
+
return map;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function deepFreeze(obj, ignores = []) {
|
|
102
|
+
if (obj === null || typeof obj !== "object")
|
|
103
|
+
return obj;
|
|
104
|
+
for (const key of Object.keys(obj)) {
|
|
105
|
+
const value = obj[key];
|
|
106
|
+
if (ignores.includes(key))
|
|
107
|
+
continue;
|
|
108
|
+
if (typeof value === "object" && value !== null)
|
|
109
|
+
deepFreeze(value, ignores);
|
|
110
|
+
}
|
|
111
|
+
return Object.freeze(obj);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// node_modules/gunshi/lib/context-CAPhwgJJ.js
|
|
115
|
+
var ANONYMOUS_COMMAND_NAME = "(anonymous)";
|
|
116
|
+
var NOOP = () => {};
|
|
117
|
+
var CLI_OPTIONS_DEFAULT = {
|
|
118
|
+
name: undefined,
|
|
119
|
+
description: undefined,
|
|
120
|
+
version: undefined,
|
|
121
|
+
cwd: undefined,
|
|
122
|
+
usageSilent: false,
|
|
123
|
+
subCommands: undefined,
|
|
124
|
+
leftMargin: 2,
|
|
125
|
+
middleMargin: 10,
|
|
126
|
+
usageOptionType: false,
|
|
127
|
+
usageOptionValue: true,
|
|
128
|
+
strict: false,
|
|
129
|
+
renderHeader: undefined,
|
|
130
|
+
renderUsage: undefined,
|
|
131
|
+
renderValidationErrors: undefined,
|
|
132
|
+
plugins: undefined,
|
|
133
|
+
fallbackToEntry: false
|
|
134
|
+
};
|
|
135
|
+
async function createCommandContext({ args = {}, explicit = {}, values = {}, positionals = [], rest = [], argv = [], tokens = [], command = {}, extensions = {}, cliOptions = {}, callMode = "entry", commandPath = [], omitted = false, validationError }) {
|
|
136
|
+
const _args = Object.entries(args).reduce((acc, [key, value]) => {
|
|
137
|
+
acc[key] = Object.assign(create(), value);
|
|
138
|
+
return acc;
|
|
139
|
+
}, create());
|
|
140
|
+
const env = Object.assign(create(), CLI_OPTIONS_DEFAULT, cliOptions);
|
|
141
|
+
if (command.rendering) {
|
|
142
|
+
const { header, usage, validationErrors } = command.rendering;
|
|
143
|
+
if (header !== undefined)
|
|
144
|
+
env.renderHeader = header;
|
|
145
|
+
if (usage !== undefined)
|
|
146
|
+
env.renderUsage = usage;
|
|
147
|
+
if (validationErrors !== undefined)
|
|
148
|
+
env.renderValidationErrors = validationErrors;
|
|
149
|
+
}
|
|
150
|
+
const core = Object.assign(create(), {
|
|
151
|
+
name: getCommandName(command),
|
|
152
|
+
description: command.description,
|
|
153
|
+
omitted,
|
|
154
|
+
callMode,
|
|
155
|
+
commandPath,
|
|
156
|
+
env,
|
|
157
|
+
args: _args,
|
|
158
|
+
explicit,
|
|
159
|
+
values,
|
|
160
|
+
positionals,
|
|
161
|
+
rest,
|
|
162
|
+
_: argv,
|
|
163
|
+
tokens,
|
|
164
|
+
toKebab: command.toKebab,
|
|
165
|
+
log: cliOptions.usageSilent ? NOOP : log2,
|
|
166
|
+
validationError
|
|
167
|
+
});
|
|
168
|
+
if (Object.keys(extensions).length > 0) {
|
|
169
|
+
const ext = create(null);
|
|
170
|
+
Object.defineProperty(core, "extensions", {
|
|
171
|
+
value: ext,
|
|
172
|
+
writable: false,
|
|
173
|
+
enumerable: true,
|
|
174
|
+
configurable: true
|
|
175
|
+
});
|
|
176
|
+
for (const [key, extension] of Object.entries(extensions)) {
|
|
177
|
+
ext[key] = await extension.factory(core, command);
|
|
178
|
+
if (extension.onFactory)
|
|
179
|
+
await extension.onFactory(core, command);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return deepFreeze(core, ["extensions"]);
|
|
183
|
+
}
|
|
184
|
+
function getCommandName(cmd) {
|
|
185
|
+
if (isLazyCommand(cmd))
|
|
186
|
+
return cmd.commandName || cmd.name || "(anonymous)";
|
|
187
|
+
else if (typeof cmd === "object")
|
|
188
|
+
return cmd.name || "(anonymous)";
|
|
189
|
+
else
|
|
190
|
+
return ANONYMOUS_COMMAND_NAME;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// node_modules/gunshi/lib/resolver-D5skgYcF.js
|
|
194
|
+
var HYPHEN_CHAR = "-";
|
|
195
|
+
var HYPHEN_CODE = HYPHEN_CHAR.codePointAt(0);
|
|
196
|
+
var EQUAL_CHAR = "=";
|
|
197
|
+
var EQUAL_CODE = EQUAL_CHAR.codePointAt(0);
|
|
198
|
+
var TERMINATOR = "--";
|
|
199
|
+
var SHORT_OPTION_PREFIX = HYPHEN_CHAR;
|
|
200
|
+
var LONG_OPTION_PREFIX = "--";
|
|
201
|
+
function parseArgs(args, options = {}) {
|
|
202
|
+
const { allowCompatible = false } = options;
|
|
203
|
+
const tokens = [];
|
|
204
|
+
const remainings = [...args];
|
|
205
|
+
let index = -1;
|
|
206
|
+
let groupCount = 0;
|
|
207
|
+
let hasShortValueSeparator = false;
|
|
208
|
+
while (remainings.length > 0) {
|
|
209
|
+
const arg = remainings.shift();
|
|
210
|
+
if (arg == undefined)
|
|
211
|
+
break;
|
|
212
|
+
const nextArg = remainings[0];
|
|
213
|
+
if (groupCount > 0)
|
|
214
|
+
groupCount--;
|
|
215
|
+
else
|
|
216
|
+
index++;
|
|
217
|
+
if (arg === TERMINATOR) {
|
|
218
|
+
tokens.push({
|
|
219
|
+
kind: "option-terminator",
|
|
220
|
+
index
|
|
221
|
+
});
|
|
222
|
+
const mapped = remainings.map((arg2) => {
|
|
223
|
+
return {
|
|
224
|
+
kind: "positional",
|
|
225
|
+
index: ++index,
|
|
226
|
+
value: arg2
|
|
227
|
+
};
|
|
228
|
+
});
|
|
229
|
+
tokens.push(...mapped);
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
if (isShortOption(arg)) {
|
|
233
|
+
const shortOption = arg.charAt(1);
|
|
234
|
+
let value;
|
|
235
|
+
let inlineValue;
|
|
236
|
+
if (groupCount) {
|
|
237
|
+
tokens.push({
|
|
238
|
+
kind: "option",
|
|
239
|
+
name: shortOption,
|
|
240
|
+
rawName: arg,
|
|
241
|
+
index,
|
|
242
|
+
value,
|
|
243
|
+
inlineValue
|
|
244
|
+
});
|
|
245
|
+
if (groupCount === 1 && hasOptionValue(nextArg)) {
|
|
246
|
+
value = remainings.shift();
|
|
247
|
+
if (hasShortValueSeparator) {
|
|
248
|
+
inlineValue = true;
|
|
249
|
+
hasShortValueSeparator = false;
|
|
250
|
+
}
|
|
251
|
+
tokens.push({
|
|
252
|
+
kind: "option",
|
|
253
|
+
index,
|
|
254
|
+
value,
|
|
255
|
+
inlineValue
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
} else
|
|
259
|
+
tokens.push({
|
|
260
|
+
kind: "option",
|
|
261
|
+
name: shortOption,
|
|
262
|
+
rawName: arg,
|
|
263
|
+
index,
|
|
264
|
+
value,
|
|
265
|
+
inlineValue
|
|
266
|
+
});
|
|
267
|
+
if (value != null)
|
|
268
|
+
++index;
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
if (isShortOptionGroup(arg)) {
|
|
272
|
+
const expanded = [];
|
|
273
|
+
let shortValue = "";
|
|
274
|
+
for (let i = 1;i < arg.length; i++) {
|
|
275
|
+
const shortableOption = arg.charAt(i);
|
|
276
|
+
if (hasShortValueSeparator)
|
|
277
|
+
shortValue += shortableOption;
|
|
278
|
+
else if (!allowCompatible && shortableOption.codePointAt(0) === EQUAL_CODE)
|
|
279
|
+
hasShortValueSeparator = true;
|
|
280
|
+
else
|
|
281
|
+
expanded.push(`${SHORT_OPTION_PREFIX}${shortableOption}`);
|
|
282
|
+
}
|
|
283
|
+
if (shortValue)
|
|
284
|
+
expanded.push(shortValue);
|
|
285
|
+
remainings.unshift(...expanded);
|
|
286
|
+
groupCount = expanded.length;
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
if (isLongOption(arg)) {
|
|
290
|
+
const longOption = arg.slice(2);
|
|
291
|
+
tokens.push({
|
|
292
|
+
kind: "option",
|
|
293
|
+
name: longOption,
|
|
294
|
+
rawName: arg,
|
|
295
|
+
index,
|
|
296
|
+
value: undefined,
|
|
297
|
+
inlineValue: undefined
|
|
298
|
+
});
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (isLongOptionAndValue(arg)) {
|
|
302
|
+
const equalIndex = arg.indexOf(EQUAL_CHAR);
|
|
303
|
+
const longOption = arg.slice(2, equalIndex);
|
|
304
|
+
const value = arg.slice(equalIndex + 1);
|
|
305
|
+
tokens.push({
|
|
306
|
+
kind: "option",
|
|
307
|
+
name: longOption,
|
|
308
|
+
rawName: `${LONG_OPTION_PREFIX}${longOption}`,
|
|
309
|
+
index,
|
|
310
|
+
value,
|
|
311
|
+
inlineValue: true
|
|
312
|
+
});
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
tokens.push({
|
|
316
|
+
kind: "positional",
|
|
317
|
+
index,
|
|
318
|
+
value: arg
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
return tokens;
|
|
322
|
+
}
|
|
323
|
+
function isShortOption(arg) {
|
|
324
|
+
return arg.length === 2 && arg.codePointAt(0) === HYPHEN_CODE && arg.codePointAt(1) !== HYPHEN_CODE;
|
|
325
|
+
}
|
|
326
|
+
function isShortOptionGroup(arg) {
|
|
327
|
+
if (arg.length <= 2)
|
|
328
|
+
return false;
|
|
329
|
+
if (arg.codePointAt(0) !== HYPHEN_CODE)
|
|
330
|
+
return false;
|
|
331
|
+
if (arg.codePointAt(1) === HYPHEN_CODE)
|
|
332
|
+
return false;
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
function isLongOption(arg) {
|
|
336
|
+
return hasLongOptionPrefix(arg) && !arg.includes(EQUAL_CHAR, 3);
|
|
337
|
+
}
|
|
338
|
+
function isLongOptionAndValue(arg) {
|
|
339
|
+
return hasLongOptionPrefix(arg) && arg.includes(EQUAL_CHAR, 3);
|
|
340
|
+
}
|
|
341
|
+
function hasLongOptionPrefix(arg) {
|
|
342
|
+
return arg.startsWith(LONG_OPTION_PREFIX) && arg.length > 2;
|
|
343
|
+
}
|
|
344
|
+
function hasOptionValue(value) {
|
|
345
|
+
return !(value == null) && value.codePointAt(0) !== HYPHEN_CODE;
|
|
346
|
+
}
|
|
347
|
+
var ArgsValidationErrorKeys = {
|
|
348
|
+
requiredOption: "err:arg:required-option",
|
|
349
|
+
requiredPositional: "err:arg:required-positional",
|
|
350
|
+
invalidType: "err:arg:invalid-type",
|
|
351
|
+
invalidChoice: "err:arg:invalid-choice",
|
|
352
|
+
customParse: "err:arg:custom-parse",
|
|
353
|
+
unknownOption: "err:arg:unknown-option"
|
|
354
|
+
};
|
|
355
|
+
var ARGS_VALIDATION_ERROR_BRAND = Symbol.for("args-tokens.ArgsValidationError");
|
|
356
|
+
var ArgsValidationError = class extends Error {
|
|
357
|
+
code;
|
|
358
|
+
values;
|
|
359
|
+
constructor(message, options = {}) {
|
|
360
|
+
super(message, { cause: options.cause });
|
|
361
|
+
this.name = "ArgsValidationError";
|
|
362
|
+
this.code = options.code;
|
|
363
|
+
this.values = options.values ?? {};
|
|
364
|
+
Object.defineProperty(this, ARGS_VALIDATION_ERROR_BRAND, {
|
|
365
|
+
value: true,
|
|
366
|
+
enumerable: false,
|
|
367
|
+
writable: false,
|
|
368
|
+
configurable: false
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
function isArgsValidationError(error) {
|
|
373
|
+
if (error instanceof ArgsValidationError)
|
|
374
|
+
return true;
|
|
375
|
+
if (typeof error !== "object" || error === null)
|
|
376
|
+
return false;
|
|
377
|
+
if (!Object.hasOwn(error, ARGS_VALIDATION_ERROR_BRAND) || error[ARGS_VALIDATION_ERROR_BRAND] !== true)
|
|
378
|
+
return false;
|
|
379
|
+
const values = error.values;
|
|
380
|
+
return typeof values === "object" && values !== null;
|
|
381
|
+
}
|
|
382
|
+
var SKIP_POSITIONAL_DEFAULT = -1;
|
|
383
|
+
function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKIP_POSITIONAL_DEFAULT, toKebab = false } = {}) {
|
|
384
|
+
const skipPositionalIndex = typeof skipPositional === "number" ? Math.max(skipPositional, SKIP_POSITIONAL_DEFAULT) : SKIP_POSITIONAL_DEFAULT;
|
|
385
|
+
const rest = [];
|
|
386
|
+
const optionTokens = [];
|
|
387
|
+
const positionalTokens = [];
|
|
388
|
+
const argEntries = Object.entries(args);
|
|
389
|
+
let currentLongOption;
|
|
390
|
+
let currentShortOption;
|
|
391
|
+
const expandableShortOptions = [];
|
|
392
|
+
function getOptionName(rawArg, schema) {
|
|
393
|
+
return toKebab || schema.toKebab ? kebabnize(rawArg) : rawArg;
|
|
394
|
+
}
|
|
395
|
+
function checkLongTokenName(option, schema, token) {
|
|
396
|
+
if (token.rawName == undefined || !hasLongOptionPrefix(token.rawName))
|
|
397
|
+
return false;
|
|
398
|
+
return token.name === option || schema.type === "boolean" && schema.negatable === true && token.name === `no-${option}`;
|
|
399
|
+
}
|
|
400
|
+
function toShortValue() {
|
|
401
|
+
if (expandableShortOptions.length === 0)
|
|
402
|
+
return;
|
|
403
|
+
else {
|
|
404
|
+
const value = expandableShortOptions.map((token) => token.name).join("");
|
|
405
|
+
expandableShortOptions.length = 0;
|
|
406
|
+
return value;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function applyLongOptionValue(value) {
|
|
410
|
+
if (currentLongOption) {
|
|
411
|
+
currentLongOption.value = value;
|
|
412
|
+
optionTokens.push({ ...currentLongOption });
|
|
413
|
+
currentLongOption = undefined;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
function applyShortOptionValue(value) {
|
|
417
|
+
if (currentShortOption) {
|
|
418
|
+
currentShortOption.value = value || toShortValue();
|
|
419
|
+
optionTokens.push({ ...currentShortOption });
|
|
420
|
+
currentShortOption = undefined;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
const schemas = Object.values(args);
|
|
424
|
+
const booleanLongOptionNames = /* @__PURE__ */ new Set;
|
|
425
|
+
for (const [rawArg, schema] of Object.entries(args)) {
|
|
426
|
+
if (schema.type !== "boolean")
|
|
427
|
+
continue;
|
|
428
|
+
const arg = toKebab || schema.toKebab ? kebabnize(rawArg) : rawArg;
|
|
429
|
+
booleanLongOptionNames.add(arg);
|
|
430
|
+
if (schema.negatable === true)
|
|
431
|
+
booleanLongOptionNames.add(`no-${arg}`);
|
|
432
|
+
}
|
|
433
|
+
let terminated = false;
|
|
434
|
+
for (let i = 0;i < tokens.length; i++) {
|
|
435
|
+
const token = tokens[i];
|
|
436
|
+
if (token.kind === "positional") {
|
|
437
|
+
if (terminated && token.value) {
|
|
438
|
+
rest.push(token.value);
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
if (currentShortOption) {
|
|
442
|
+
if (schemas.find((schema) => schema.short === currentShortOption.name && schema.type === "boolean")) {
|
|
443
|
+
positionalTokens.push({ ...token });
|
|
444
|
+
applyShortOptionValue();
|
|
445
|
+
} else
|
|
446
|
+
applyShortOptionValue(token.value);
|
|
447
|
+
} else if (currentLongOption) {
|
|
448
|
+
if (booleanLongOptionNames.has(currentLongOption.name)) {
|
|
449
|
+
positionalTokens.push({ ...token });
|
|
450
|
+
applyLongOptionValue();
|
|
451
|
+
} else
|
|
452
|
+
applyLongOptionValue(token.value);
|
|
453
|
+
} else
|
|
454
|
+
positionalTokens.push({ ...token });
|
|
455
|
+
} else if (token.kind === "option") {
|
|
456
|
+
if (token.rawName) {
|
|
457
|
+
if (hasLongOptionPrefix(token.rawName)) {
|
|
458
|
+
applyLongOptionValue();
|
|
459
|
+
if (token.inlineValue)
|
|
460
|
+
optionTokens.push({ ...token });
|
|
461
|
+
else
|
|
462
|
+
currentLongOption = { ...token };
|
|
463
|
+
applyShortOptionValue();
|
|
464
|
+
} else if (isShortOption(token.rawName)) {
|
|
465
|
+
if (currentShortOption) {
|
|
466
|
+
if (currentShortOption.index === token.index) {
|
|
467
|
+
if (shortGrouping) {
|
|
468
|
+
currentShortOption.value = token.value;
|
|
469
|
+
optionTokens.push({ ...currentShortOption });
|
|
470
|
+
currentShortOption = { ...token };
|
|
471
|
+
} else
|
|
472
|
+
expandableShortOptions.push({ ...token });
|
|
473
|
+
} else {
|
|
474
|
+
currentShortOption.value = toShortValue();
|
|
475
|
+
optionTokens.push({ ...currentShortOption });
|
|
476
|
+
currentShortOption = { ...token };
|
|
477
|
+
}
|
|
478
|
+
applyLongOptionValue();
|
|
479
|
+
} else {
|
|
480
|
+
currentShortOption = { ...token };
|
|
481
|
+
applyLongOptionValue();
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
} else {
|
|
485
|
+
if (currentShortOption && currentShortOption.index == token.index && token.inlineValue) {
|
|
486
|
+
currentShortOption.value = token.value;
|
|
487
|
+
optionTokens.push({ ...currentShortOption });
|
|
488
|
+
currentShortOption = undefined;
|
|
489
|
+
}
|
|
490
|
+
applyLongOptionValue();
|
|
491
|
+
}
|
|
492
|
+
} else {
|
|
493
|
+
if (token.kind === "option-terminator")
|
|
494
|
+
terminated = true;
|
|
495
|
+
applyLongOptionValue();
|
|
496
|
+
applyShortOptionValue();
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
applyLongOptionValue();
|
|
500
|
+
applyShortOptionValue();
|
|
501
|
+
const values = Object.create(null);
|
|
502
|
+
const errors = [];
|
|
503
|
+
const explicit = Object.create(null);
|
|
504
|
+
const actualInputNames = /* @__PURE__ */ new Map;
|
|
505
|
+
let requiredPositionalsAfter;
|
|
506
|
+
const positionalItemCount = tokens.filter((token) => token.kind === "positional").length;
|
|
507
|
+
function getPositionalSkipIndex() {
|
|
508
|
+
return Math.min(skipPositionalIndex, positionalItemCount);
|
|
509
|
+
}
|
|
510
|
+
function getRequiredPositionalsAfter(rawArg) {
|
|
511
|
+
requiredPositionalsAfter ??= createRequiredPositionalsAfter(argEntries);
|
|
512
|
+
return requiredPositionalsAfter[rawArg] ?? 0;
|
|
513
|
+
}
|
|
514
|
+
let positionalsCount = 0;
|
|
515
|
+
for (const [rawArg, schema] of argEntries) {
|
|
516
|
+
const arg = getOptionName(rawArg, schema);
|
|
517
|
+
explicit[rawArg] = false;
|
|
518
|
+
if (schema.type === "positional") {
|
|
519
|
+
if (skipPositionalIndex > SKIP_POSITIONAL_DEFAULT)
|
|
520
|
+
while (positionalsCount <= getPositionalSkipIndex())
|
|
521
|
+
positionalsCount++;
|
|
522
|
+
if (schema.multiple) {
|
|
523
|
+
const availablePositionals = Math.max(positionalTokens.length - positionalsCount, 0);
|
|
524
|
+
if (availablePositionals > 0) {
|
|
525
|
+
const requiredPositionals = getRequiredPositionalsAfter(rawArg);
|
|
526
|
+
const positionalsToConsume = Math.max(availablePositionals - requiredPositionals, 0);
|
|
527
|
+
if (positionalsToConsume > 0) {
|
|
528
|
+
const endPositionals = positionalsCount + positionalsToConsume;
|
|
529
|
+
if (typeof schema.parse === "function") {
|
|
530
|
+
const parsed = [];
|
|
531
|
+
for (let i = positionalsCount;i < endPositionals; i++) {
|
|
532
|
+
const p = positionalTokens[i];
|
|
533
|
+
const [parsedValue, error] = parseSchemaValue(p.value, rawArg, arg, schema);
|
|
534
|
+
if (error)
|
|
535
|
+
errors.push(error);
|
|
536
|
+
else
|
|
537
|
+
parsed.push(parsedValue);
|
|
538
|
+
}
|
|
539
|
+
values[rawArg] = parsed;
|
|
540
|
+
} else {
|
|
541
|
+
const valuesArray = [];
|
|
542
|
+
for (let i = positionalsCount;i < endPositionals; i++)
|
|
543
|
+
valuesArray.push(positionalTokens[i].value);
|
|
544
|
+
values[rawArg] = valuesArray;
|
|
545
|
+
}
|
|
546
|
+
positionalsCount = endPositionals;
|
|
547
|
+
explicit[rawArg] = true;
|
|
548
|
+
} else if (schema.required)
|
|
549
|
+
errors.push(createRequireError(rawArg, arg, schema));
|
|
550
|
+
} else if (schema.required)
|
|
551
|
+
errors.push(createRequireError(rawArg, arg, schema));
|
|
552
|
+
} else {
|
|
553
|
+
const positional = positionalTokens[positionalsCount];
|
|
554
|
+
if (shouldRequireMissingSinglePositional(schema)) {
|
|
555
|
+
if (positional != null) {
|
|
556
|
+
resolveSinglePositionalValue(values, errors, rawArg, arg, schema, positional);
|
|
557
|
+
explicit[rawArg] = true;
|
|
558
|
+
positionalsCount++;
|
|
559
|
+
} else
|
|
560
|
+
errors.push(createRequireError(rawArg, arg, schema));
|
|
561
|
+
continue;
|
|
562
|
+
}
|
|
563
|
+
if (positional != null) {
|
|
564
|
+
const requiredPositionals = getRequiredPositionalsAfter(rawArg);
|
|
565
|
+
if (Math.max(positionalTokens.length - positionalsCount, 0) > requiredPositionals) {
|
|
566
|
+
resolveSinglePositionalValue(values, errors, rawArg, arg, schema, positional);
|
|
567
|
+
explicit[rawArg] = true;
|
|
568
|
+
positionalsCount++;
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
if (hasDefault(schema))
|
|
573
|
+
values[rawArg] = schema.default;
|
|
574
|
+
}
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
if (schema.required) {
|
|
578
|
+
if (!optionTokens.find((token) => {
|
|
579
|
+
return schema.short && token.name === schema.short && token.rawName != null && isShortOption(token.rawName) || checkLongTokenName(arg, schema, token);
|
|
580
|
+
})) {
|
|
581
|
+
errors.push(createRequireError(rawArg, arg, schema));
|
|
582
|
+
continue;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
for (let i = 0;i < optionTokens.length; i++) {
|
|
586
|
+
const token = optionTokens[i];
|
|
587
|
+
if (checkLongTokenName(arg, schema, token) || schema.short === token.name && token.rawName != null && isShortOption(token.rawName)) {
|
|
588
|
+
const invalid = validateRequire(token, rawArg, arg, schema);
|
|
589
|
+
if (invalid) {
|
|
590
|
+
errors.push(invalid);
|
|
591
|
+
continue;
|
|
592
|
+
}
|
|
593
|
+
explicit[rawArg] = true;
|
|
594
|
+
const rawName = token.rawName;
|
|
595
|
+
const actualInputName = isShortOption(rawName) ? `-${token.name}` : rawName;
|
|
596
|
+
actualInputNames.set(rawArg, actualInputName);
|
|
597
|
+
const [parsedValue, error] = parse(token, rawArg, arg, schema);
|
|
598
|
+
if (error)
|
|
599
|
+
errors.push(error);
|
|
600
|
+
else if (schema.multiple) {
|
|
601
|
+
values[rawArg] ||= [];
|
|
602
|
+
values[rawArg].push(parsedValue);
|
|
603
|
+
} else
|
|
604
|
+
values[rawArg] = parsedValue;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
if (values[rawArg] == null && schema.default != null)
|
|
608
|
+
values[rawArg] = schema.default;
|
|
609
|
+
}
|
|
610
|
+
const conflictErrors = checkConflicts(args, explicit, toKebab, actualInputNames);
|
|
611
|
+
errors.push(...conflictErrors);
|
|
612
|
+
return {
|
|
613
|
+
values,
|
|
614
|
+
positionals: positionalTokens.map((token) => token.value),
|
|
615
|
+
rest,
|
|
616
|
+
error: errors.length > 0 ? new AggregateError(errors) : undefined,
|
|
617
|
+
explicit
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
function parse(token, rawArg, option, schema) {
|
|
621
|
+
if (typeof schema.parse === "function") {
|
|
622
|
+
if (schema.type === "boolean") {
|
|
623
|
+
const boolValue = !(schema.negatable && token.name.startsWith("no-"));
|
|
624
|
+
return parseSchemaValue(String(boolValue), rawArg, option, schema);
|
|
625
|
+
}
|
|
626
|
+
return parseSchemaValue(token.value ?? String(schema.default ?? ""), rawArg, option, schema);
|
|
627
|
+
}
|
|
628
|
+
switch (schema.type) {
|
|
629
|
+
case "string":
|
|
630
|
+
return typeof token.value === "string" ? [token.value || schema.default, undefined] : [undefined, createTypeError(rawArg, option, schema, token.value)];
|
|
631
|
+
case "boolean":
|
|
632
|
+
return [!(schema.negatable && token.name.startsWith("no-")), undefined];
|
|
633
|
+
case "number":
|
|
634
|
+
if (!isNumeric(token.value))
|
|
635
|
+
return [undefined, createTypeError(rawArg, option, schema, token.value)];
|
|
636
|
+
return token.value ? [+token.value, undefined] : [+(schema.default || ""), undefined];
|
|
637
|
+
case "enum":
|
|
638
|
+
if (schema.choices && !schema.choices.includes(token.value))
|
|
639
|
+
return [undefined, createChoiceError(rawArg, option, schema, token.value)];
|
|
640
|
+
return [token.value || schema.default, undefined];
|
|
641
|
+
case "custom":
|
|
642
|
+
throw new TypeError(`argument '${option}' should have a 'parse' function`);
|
|
643
|
+
default:
|
|
644
|
+
throw new Error(`Unsupported argument type '${schema.type}' for option '${option}'`);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
function parseSchemaValue(value, rawArg, option, schema) {
|
|
648
|
+
try {
|
|
649
|
+
return [schema.parse(value), undefined];
|
|
650
|
+
} catch (error) {
|
|
651
|
+
return [undefined, createCustomParseError(error, rawArg, option, schema, value)];
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
function createRequireError(rawArg, option, schema) {
|
|
655
|
+
return new ArgResolveError(schema.type === "positional" ? `Positional argument '${option}' is required` : `Optional argument ${createOptionDisplayName(option, schema)} is required`, option, "required", schema, {
|
|
656
|
+
code: schema.type === "positional" ? ArgsValidationErrorKeys.requiredPositional : ArgsValidationErrorKeys.requiredOption,
|
|
657
|
+
values: schema.type === "positional" ? { name: rawArg } : {
|
|
658
|
+
displayName: createOptionDisplayName(option, schema),
|
|
659
|
+
name: rawArg
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
function resolveSinglePositionalValue(values, errors, rawArg, option, schema, positional) {
|
|
664
|
+
if (typeof schema.parse === "function") {
|
|
665
|
+
const [parsedValue, error] = parseSchemaValue(positional.value, rawArg, option, schema);
|
|
666
|
+
if (error)
|
|
667
|
+
errors.push(error);
|
|
668
|
+
else
|
|
669
|
+
values[rawArg] = parsedValue;
|
|
670
|
+
} else
|
|
671
|
+
values[rawArg] = positional.value;
|
|
672
|
+
}
|
|
673
|
+
function hasDefault(schema) {
|
|
674
|
+
return schema.default != null;
|
|
675
|
+
}
|
|
676
|
+
function shouldRequireMissingSinglePositional(schema) {
|
|
677
|
+
if (schema.required === true)
|
|
678
|
+
return true;
|
|
679
|
+
if (schema.required === false)
|
|
680
|
+
return false;
|
|
681
|
+
return !hasDefault(schema);
|
|
682
|
+
}
|
|
683
|
+
function getRequiredPositionalInputCount(schema) {
|
|
684
|
+
if (schema.type !== "positional")
|
|
685
|
+
return 0;
|
|
686
|
+
if (schema.multiple)
|
|
687
|
+
return schema.required === true ? 1 : 0;
|
|
688
|
+
return shouldRequireMissingSinglePositional(schema) ? 1 : 0;
|
|
689
|
+
}
|
|
690
|
+
function createRequiredPositionalsAfter(argEntries) {
|
|
691
|
+
const requiredPositionalsAfter = Object.create(null);
|
|
692
|
+
let minimumRequiredPositionals = 0;
|
|
693
|
+
for (let i = argEntries.length - 1;i >= 0; i--) {
|
|
694
|
+
const [rawArg, schema] = argEntries[i];
|
|
695
|
+
if (schema.type !== "positional")
|
|
696
|
+
continue;
|
|
697
|
+
requiredPositionalsAfter[rawArg] = minimumRequiredPositionals;
|
|
698
|
+
minimumRequiredPositionals += getRequiredPositionalInputCount(schema);
|
|
699
|
+
}
|
|
700
|
+
return requiredPositionalsAfter;
|
|
701
|
+
}
|
|
702
|
+
var ArgResolveError = class extends ArgsValidationError {
|
|
703
|
+
name;
|
|
704
|
+
schema;
|
|
705
|
+
type;
|
|
706
|
+
constructor(message, name, type, schema, options = {}) {
|
|
707
|
+
super(message, options);
|
|
708
|
+
this.name = name;
|
|
709
|
+
this.type = type;
|
|
710
|
+
this.schema = schema;
|
|
711
|
+
}
|
|
712
|
+
};
|
|
713
|
+
function validateRequire(token, rawArg, option, schema) {
|
|
714
|
+
if (schema.required && schema.type !== "boolean" && !token.value)
|
|
715
|
+
return createRequireError(rawArg, option, schema);
|
|
716
|
+
}
|
|
717
|
+
function isNumeric(str) {
|
|
718
|
+
return str.trim() !== "" && !isNaN(str);
|
|
719
|
+
}
|
|
720
|
+
function createTypeError(rawArg, option, schema, actual) {
|
|
721
|
+
return new ArgResolveError(`Optional argument ${createOptionDisplayName(option, schema)} should be '${schema.type}'`, option, "type", schema, {
|
|
722
|
+
code: ArgsValidationErrorKeys.invalidType,
|
|
723
|
+
values: {
|
|
724
|
+
displayName: createOptionDisplayName(option, schema),
|
|
725
|
+
name: rawArg,
|
|
726
|
+
expected: schema.type,
|
|
727
|
+
...actual != null ? { actual } : {}
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
function createChoiceError(rawArg, option, schema, actual) {
|
|
732
|
+
const choices = schema.choices ?? [];
|
|
733
|
+
return new ArgResolveError(`Optional argument ${createOptionDisplayName(option, schema)} should be chosen from '${schema.type}' [${formatChoices(choices)}] values`, option, "type", schema, {
|
|
734
|
+
code: ArgsValidationErrorKeys.invalidChoice,
|
|
735
|
+
values: {
|
|
736
|
+
displayName: createOptionDisplayName(option, schema),
|
|
737
|
+
name: rawArg,
|
|
738
|
+
expected: schema.type,
|
|
739
|
+
choices: formatChoices(choices),
|
|
740
|
+
choiceValues: [...choices],
|
|
741
|
+
...actual != null ? { actual } : {}
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
function createCustomParseError(error, rawArg, option, schema, value) {
|
|
746
|
+
const reused = reuseValidationError(error, rawArg, option, schema, value);
|
|
747
|
+
if (reused)
|
|
748
|
+
return reused;
|
|
749
|
+
const reason = getErrorReason(error);
|
|
750
|
+
return new ArgsValidationError(reason, {
|
|
751
|
+
code: ArgsValidationErrorKeys.customParse,
|
|
752
|
+
values: {
|
|
753
|
+
displayName: createArgumentDisplayName(option, schema),
|
|
754
|
+
name: rawArg,
|
|
755
|
+
reason
|
|
756
|
+
},
|
|
757
|
+
cause: error
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
function reuseValidationError(error, rawArg, option, schema, value) {
|
|
761
|
+
try {
|
|
762
|
+
if (isArgsValidationError(error)) {
|
|
763
|
+
augmentValidationError(error, rawArg, option, schema, value);
|
|
764
|
+
return error;
|
|
765
|
+
}
|
|
766
|
+
} catch {}
|
|
767
|
+
}
|
|
768
|
+
function augmentValidationError(error, rawArg, option, schema, value) {
|
|
769
|
+
const values = error.values;
|
|
770
|
+
values.name ??= rawArg;
|
|
771
|
+
values.displayName ??= createArgumentDisplayName(option, schema);
|
|
772
|
+
if ((error.code === ArgsValidationErrorKeys.invalidType || error.code === ArgsValidationErrorKeys.invalidChoice) && values.actual == null)
|
|
773
|
+
values.actual = value;
|
|
774
|
+
}
|
|
775
|
+
function getErrorReason(error) {
|
|
776
|
+
return error instanceof Error ? error.message : String(error);
|
|
777
|
+
}
|
|
778
|
+
function createArgumentDisplayName(option, schema) {
|
|
779
|
+
return schema.type === "positional" ? `'${option}'` : createOptionDisplayName(option, schema);
|
|
780
|
+
}
|
|
781
|
+
function createOptionDisplayName(option, schema) {
|
|
782
|
+
return `'--${option}'${schema.short ? ` or '-${schema.short}'` : ""}`;
|
|
783
|
+
}
|
|
784
|
+
function checkConflicts(args, explicit, toKebab, actualInputNames) {
|
|
785
|
+
for (const rawArg in args) {
|
|
786
|
+
const schema = args[rawArg];
|
|
787
|
+
if (!explicit[rawArg])
|
|
788
|
+
continue;
|
|
789
|
+
if (!schema.conflicts)
|
|
790
|
+
continue;
|
|
791
|
+
const conflicts = Array.isArray(schema.conflicts) ? schema.conflicts : [schema.conflicts];
|
|
792
|
+
for (let i = 0;i < conflicts.length; i++) {
|
|
793
|
+
const conflictingArg = conflicts[i];
|
|
794
|
+
if (!explicit[conflictingArg])
|
|
795
|
+
continue;
|
|
796
|
+
const arg = toKebab || schema.toKebab ? kebabnize(rawArg) : rawArg;
|
|
797
|
+
const conflictingArgKebab = toKebab || args[conflictingArg]?.toKebab ? kebabnize(conflictingArg) : conflictingArg;
|
|
798
|
+
return [new ArgResolveError(`Optional argument '${actualInputNames.get(rawArg) || `--${arg}`}' conflicts with '${actualInputNames.get(conflictingArg) || `--${conflictingArgKebab}`}'`, rawArg, "conflict", schema)];
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
return [];
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
// node_modules/gunshi/lib/error-B5QxSzk9.js
|
|
805
|
+
var CommandNotFoundErrorKeys = { notFound: "err:cmd:not-found" };
|
|
806
|
+
var COMMAND_NOT_FOUND_ERROR_BRAND = Symbol.for("gunshi.CommandNotFoundError");
|
|
807
|
+
var CommandNotFoundError = class extends Error {
|
|
808
|
+
code;
|
|
809
|
+
values;
|
|
810
|
+
commandName;
|
|
811
|
+
candidates;
|
|
812
|
+
commandPath;
|
|
813
|
+
constructor(message, options) {
|
|
814
|
+
super(message, { cause: options.cause });
|
|
815
|
+
this.name = "CommandNotFoundError";
|
|
816
|
+
this.code = options.code;
|
|
817
|
+
this.values = options.values || {};
|
|
818
|
+
this.commandName = options.commandName;
|
|
819
|
+
this.candidates = options.candidates || [];
|
|
820
|
+
this.commandPath = options.commandPath || [];
|
|
821
|
+
Object.defineProperty(this, COMMAND_NOT_FOUND_ERROR_BRAND, {
|
|
822
|
+
value: true,
|
|
823
|
+
enumerable: false,
|
|
824
|
+
writable: false,
|
|
825
|
+
configurable: false
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
function isCommandNotFoundError(error) {
|
|
830
|
+
if (error instanceof CommandNotFoundError)
|
|
831
|
+
return true;
|
|
832
|
+
if (!isRecord(error) || !hasCommandNotFoundErrorShape(error))
|
|
833
|
+
return false;
|
|
834
|
+
if (Object.hasOwn(error, COMMAND_NOT_FOUND_ERROR_BRAND) && error[COMMAND_NOT_FOUND_ERROR_BRAND] === true)
|
|
835
|
+
return true;
|
|
836
|
+
return error instanceof Error && error.name === "CommandNotFoundError";
|
|
837
|
+
}
|
|
838
|
+
function isArgsValidationError2(error) {
|
|
839
|
+
if (error instanceof ArgsValidationError)
|
|
840
|
+
return true;
|
|
841
|
+
if (!isRecord(error) || !hasArgsValidationErrorShape(error))
|
|
842
|
+
return false;
|
|
843
|
+
if (isArgsValidationError(error))
|
|
844
|
+
return true;
|
|
845
|
+
return error instanceof Error && error.name === "ArgsValidationError";
|
|
846
|
+
}
|
|
847
|
+
function isRecord(value) {
|
|
848
|
+
return typeof value === "object" && value !== null;
|
|
849
|
+
}
|
|
850
|
+
function isStringArray(value) {
|
|
851
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
852
|
+
}
|
|
853
|
+
function hasOptionalStringCode(error) {
|
|
854
|
+
return "code" in error && (error.code === undefined || typeof error.code === "string");
|
|
855
|
+
}
|
|
856
|
+
function hasCommandNotFoundErrorShape(error) {
|
|
857
|
+
return hasOptionalStringCode(error) && isRecord(error.values) && typeof error.commandName === "string" && isStringArray(error.candidates) && isStringArray(error.commandPath);
|
|
858
|
+
}
|
|
859
|
+
function hasArgsValidationErrorShape(error) {
|
|
860
|
+
return hasOptionalStringCode(error) && isRecord(error.values);
|
|
861
|
+
}
|
|
862
|
+
function hasPriorityValidationError(error) {
|
|
863
|
+
return error?.errors.some((error2) => isCommandNotFoundError(error2) || isArgsValidationError2(error2) && error2.code === ArgsValidationErrorKeys.unknownOption) ?? false;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
// node_modules/gunshi/lib/core-CLzX86kY.js
|
|
867
|
+
var EMPTY_RENDERER = () => Promise.resolve("");
|
|
868
|
+
function createDecorators() {
|
|
869
|
+
const headerDecorators = [];
|
|
870
|
+
const usageDecorators = [];
|
|
871
|
+
const validationDecorators = [];
|
|
872
|
+
const commandDecorators = [];
|
|
873
|
+
function buildRenderer(decorators, defaultRenderer) {
|
|
874
|
+
if (decorators.length === 0)
|
|
875
|
+
return defaultRenderer;
|
|
876
|
+
let renderer = defaultRenderer;
|
|
877
|
+
for (const decorator of decorators) {
|
|
878
|
+
const previousRenderer = renderer;
|
|
879
|
+
renderer = (ctx) => decorator(previousRenderer, ctx);
|
|
880
|
+
}
|
|
881
|
+
return renderer;
|
|
882
|
+
}
|
|
883
|
+
return Object.freeze({
|
|
884
|
+
addHeaderDecorator(decorator) {
|
|
885
|
+
headerDecorators.push(decorator);
|
|
886
|
+
},
|
|
887
|
+
addUsageDecorator(decorator) {
|
|
888
|
+
usageDecorators.push(decorator);
|
|
889
|
+
},
|
|
890
|
+
addValidationErrorsDecorator(decorator) {
|
|
891
|
+
validationDecorators.push(decorator);
|
|
892
|
+
},
|
|
893
|
+
addCommandDecorator(decorator) {
|
|
894
|
+
commandDecorators.push(decorator);
|
|
895
|
+
},
|
|
896
|
+
get commandDecorators() {
|
|
897
|
+
return [...commandDecorators];
|
|
898
|
+
},
|
|
899
|
+
getHeaderRenderer() {
|
|
900
|
+
return buildRenderer(headerDecorators, EMPTY_RENDERER);
|
|
901
|
+
},
|
|
902
|
+
getUsageRenderer() {
|
|
903
|
+
return buildRenderer(usageDecorators, EMPTY_RENDERER);
|
|
904
|
+
},
|
|
905
|
+
getValidationErrorsRenderer() {
|
|
906
|
+
if (validationDecorators.length === 0)
|
|
907
|
+
return EMPTY_RENDERER;
|
|
908
|
+
let renderer = EMPTY_RENDERER;
|
|
909
|
+
for (const decorator of validationDecorators) {
|
|
910
|
+
const previousRenderer = renderer;
|
|
911
|
+
renderer = (ctx, error) => decorator(previousRenderer, ctx, error);
|
|
912
|
+
}
|
|
913
|
+
return renderer;
|
|
914
|
+
}
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
function createPluginContext(decorators, initialSubCommands) {
|
|
918
|
+
const globalOptions = /* @__PURE__ */ new Map;
|
|
919
|
+
const subCommands = new Map(initialSubCommands || []);
|
|
920
|
+
return Object.freeze({
|
|
921
|
+
get globalOptions() {
|
|
922
|
+
return new Map(globalOptions);
|
|
923
|
+
},
|
|
924
|
+
addGlobalOption(name, schema) {
|
|
925
|
+
if (!name)
|
|
926
|
+
throw new Error("Option name must be a non-empty string");
|
|
927
|
+
if (globalOptions.has(name))
|
|
928
|
+
throw new Error(`Global option '${name}' is already registered`);
|
|
929
|
+
globalOptions.set(name, schema);
|
|
930
|
+
},
|
|
931
|
+
get subCommands() {
|
|
932
|
+
return new Map(subCommands);
|
|
933
|
+
},
|
|
934
|
+
addCommand(name, command) {
|
|
935
|
+
if (!name)
|
|
936
|
+
throw new Error("Command name must be a non-empty string");
|
|
937
|
+
if (subCommands.has(name))
|
|
938
|
+
throw new Error(`Command '${name}' is already registered`);
|
|
939
|
+
subCommands.set(name, command);
|
|
940
|
+
},
|
|
941
|
+
hasCommand(name) {
|
|
942
|
+
return subCommands.has(name);
|
|
943
|
+
},
|
|
944
|
+
decorateHeaderRenderer(decorator) {
|
|
945
|
+
decorators.addHeaderDecorator(decorator);
|
|
946
|
+
},
|
|
947
|
+
decorateUsageRenderer(decorator) {
|
|
948
|
+
decorators.addUsageDecorator(decorator);
|
|
949
|
+
},
|
|
950
|
+
decorateValidationErrorsRenderer(decorator) {
|
|
951
|
+
decorators.addValidationErrorsDecorator(decorator);
|
|
952
|
+
},
|
|
953
|
+
decorateCommand(decorator) {
|
|
954
|
+
decorators.addCommandDecorator(decorator);
|
|
955
|
+
}
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
function resolveDependencies(plugins) {
|
|
959
|
+
const sorted = [];
|
|
960
|
+
const visited = /* @__PURE__ */ new Set;
|
|
961
|
+
const visiting = /* @__PURE__ */ new Set;
|
|
962
|
+
const pluginMap = /* @__PURE__ */ new Map;
|
|
963
|
+
for (const plugin of plugins)
|
|
964
|
+
if (plugin.id) {
|
|
965
|
+
if (pluginMap.has(plugin.id))
|
|
966
|
+
console.warn(`Duplicate plugin id detected: \`${plugin.id}\``);
|
|
967
|
+
pluginMap.set(plugin.id, plugin);
|
|
968
|
+
}
|
|
969
|
+
function visit(plugin) {
|
|
970
|
+
if (!plugin.id)
|
|
971
|
+
return;
|
|
972
|
+
if (visited.has(plugin.id))
|
|
973
|
+
return;
|
|
974
|
+
if (visiting.has(plugin.id))
|
|
975
|
+
throw new Error(`Circular dependency detected: \`${[...visiting].join(` -> `) + " -> " + plugin.id}\``);
|
|
976
|
+
visiting.add(plugin.id);
|
|
977
|
+
const deps = plugin.dependencies || [];
|
|
978
|
+
for (const dep of deps) {
|
|
979
|
+
const depId = typeof dep === "string" ? dep : dep.id;
|
|
980
|
+
const isOptional = typeof dep === "string" ? false : dep.optional || false;
|
|
981
|
+
const depPlugin = pluginMap.get(depId);
|
|
982
|
+
if (!depPlugin && !isOptional)
|
|
983
|
+
throw new Error(`Missing required dependency: \`${depId}\` on \`${plugin.id}\``);
|
|
984
|
+
if (depPlugin)
|
|
985
|
+
visit(depPlugin);
|
|
986
|
+
}
|
|
987
|
+
visiting.delete(plugin.id);
|
|
988
|
+
visited.add(plugin.id);
|
|
989
|
+
sorted.push(plugin);
|
|
990
|
+
}
|
|
991
|
+
for (const plugin of plugins)
|
|
992
|
+
visit(plugin);
|
|
993
|
+
return sorted;
|
|
994
|
+
}
|
|
995
|
+
async function cliCore(argv, entry, options, plugins) {
|
|
996
|
+
const decorators = createDecorators();
|
|
997
|
+
const pluginContext = createPluginContext(decorators, createInitialSubCommands(options, entry));
|
|
998
|
+
const resolvedPlugins = await applyPlugins(pluginContext, [...plugins, ...options.plugins || []]);
|
|
999
|
+
const cliOptions = normalizeCliOptions(options, decorators, pluginContext);
|
|
1000
|
+
const tokens = parseArgs(argv);
|
|
1001
|
+
const resolved = resolveCommandTree(tokens, entry, cliOptions);
|
|
1002
|
+
const { commandName: name, command, callMode, commandPath, depth, levelSubCommands } = resolved;
|
|
1003
|
+
let targetCommand = command;
|
|
1004
|
+
let targetCommandName = name;
|
|
1005
|
+
let targetCallMode = callMode;
|
|
1006
|
+
let targetCommandPath = commandPath;
|
|
1007
|
+
let targetDepth = depth;
|
|
1008
|
+
let targetOmitted = resolved.omitted;
|
|
1009
|
+
let targetLevelSubCommands = levelSubCommands;
|
|
1010
|
+
const additionalValidationErrors = [];
|
|
1011
|
+
if (!targetCommand) {
|
|
1012
|
+
if (!resolved.parentCommand || !resolved.unresolvedCommandName)
|
|
1013
|
+
throw new Error(`Command not found: ${name || ""}`);
|
|
1014
|
+
targetCommand = resolved.parentCommand;
|
|
1015
|
+
targetCommandName = resolved.parentCommandName;
|
|
1016
|
+
targetCommandPath = resolved.parentCommandPath || [];
|
|
1017
|
+
targetDepth = targetCommandPath.length;
|
|
1018
|
+
targetCallMode = targetDepth > 0 ? "subCommand" : "entry";
|
|
1019
|
+
targetOmitted = false;
|
|
1020
|
+
targetLevelSubCommands = resolved.parentSubCommands;
|
|
1021
|
+
additionalValidationErrors.push(createCommandNotFoundError(resolved));
|
|
1022
|
+
}
|
|
1023
|
+
if (targetLevelSubCommands)
|
|
1024
|
+
cliOptions.subCommands = targetLevelSubCommands;
|
|
1025
|
+
const resolvedCommand = isLazyCommand(targetCommand) ? await resolveLazyCommand(targetCommand, targetCommandName, true) : targetCommand;
|
|
1026
|
+
const args = resolveArguments(pluginContext, getCommandArgs(resolvedCommand));
|
|
1027
|
+
const skipPositional = targetDepth > 0 ? targetDepth - 1 : -1;
|
|
1028
|
+
const { explicit, values, positionals, rest, error } = resolveArgs(args, tokens, {
|
|
1029
|
+
shortGrouping: true,
|
|
1030
|
+
toKebab: resolvedCommand.toKebab,
|
|
1031
|
+
skipPositional
|
|
1032
|
+
});
|
|
1033
|
+
const validationError = mergeValidationErrors(error, [...additionalValidationErrors, ...cliOptions.strict ? createUnknownOptionErrors(findUnknownOptions(args, tokens, { toKebab: resolvedCommand.toKebab })) : []]);
|
|
1034
|
+
return await executeCommand(resolvedCommand, await createCommandContext({
|
|
1035
|
+
args,
|
|
1036
|
+
explicit,
|
|
1037
|
+
values,
|
|
1038
|
+
positionals,
|
|
1039
|
+
rest,
|
|
1040
|
+
argv,
|
|
1041
|
+
tokens,
|
|
1042
|
+
omitted: targetOmitted,
|
|
1043
|
+
callMode: targetCallMode,
|
|
1044
|
+
commandPath: targetCommandPath,
|
|
1045
|
+
command: resolvedCommand,
|
|
1046
|
+
extensions: getPluginExtensions(resolvedPlugins),
|
|
1047
|
+
validationError,
|
|
1048
|
+
cliOptions
|
|
1049
|
+
}), decorators.commandDecorators);
|
|
1050
|
+
}
|
|
1051
|
+
async function applyPlugins(pluginContext, plugins) {
|
|
1052
|
+
const sortedPlugins = resolveDependencies(plugins);
|
|
1053
|
+
try {
|
|
1054
|
+
for (const plugin of sortedPlugins)
|
|
1055
|
+
await plugin(pluginContext);
|
|
1056
|
+
} catch (error) {
|
|
1057
|
+
console.error("Error loading plugin:", error.message);
|
|
1058
|
+
}
|
|
1059
|
+
return sortedPlugins;
|
|
1060
|
+
}
|
|
1061
|
+
function getCommandArgs(cmd) {
|
|
1062
|
+
if (isLazyCommand(cmd))
|
|
1063
|
+
return cmd.args || create();
|
|
1064
|
+
else if (typeof cmd === "object")
|
|
1065
|
+
return cmd.args || create();
|
|
1066
|
+
else
|
|
1067
|
+
return create();
|
|
1068
|
+
}
|
|
1069
|
+
function resolveArguments(pluginContext, args) {
|
|
1070
|
+
return Object.assign(create(), Object.fromEntries(pluginContext.globalOptions), args);
|
|
1071
|
+
}
|
|
1072
|
+
var NEGATABLE_OPTION_PREFIX = "no-";
|
|
1073
|
+
function findUnknownOptions(args, tokens, options) {
|
|
1074
|
+
const knownLongOptions = /* @__PURE__ */ new Set;
|
|
1075
|
+
const knownShortOptions = /* @__PURE__ */ new Set;
|
|
1076
|
+
const knownNegatableOptions = /* @__PURE__ */ new Set;
|
|
1077
|
+
const knownLongOptionCandidates = /* @__PURE__ */ new Set;
|
|
1078
|
+
const longOptionCandidates = [];
|
|
1079
|
+
function addLongOptionCandidate(name) {
|
|
1080
|
+
const candidate = `--${name}`;
|
|
1081
|
+
if (knownLongOptionCandidates.has(candidate))
|
|
1082
|
+
return;
|
|
1083
|
+
knownLongOptionCandidates.add(candidate);
|
|
1084
|
+
longOptionCandidates.push(candidate);
|
|
1085
|
+
}
|
|
1086
|
+
for (const [name, schema] of Object.entries(args)) {
|
|
1087
|
+
if (schema.type === "positional")
|
|
1088
|
+
continue;
|
|
1089
|
+
const optionName = resolveOptionName(name, schema, options);
|
|
1090
|
+
knownLongOptions.add(optionName);
|
|
1091
|
+
addLongOptionCandidate(optionName);
|
|
1092
|
+
if (schema.short)
|
|
1093
|
+
knownShortOptions.add(schema.short);
|
|
1094
|
+
if (schema.type === "boolean" && schema.negatable) {
|
|
1095
|
+
const negatableOptionName = `${NEGATABLE_OPTION_PREFIX}${optionName}`;
|
|
1096
|
+
knownNegatableOptions.add(negatableOptionName);
|
|
1097
|
+
addLongOptionCandidate(negatableOptionName);
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
const unknownOptions = [];
|
|
1101
|
+
for (const token of tokens) {
|
|
1102
|
+
if (token.kind === "option-terminator")
|
|
1103
|
+
break;
|
|
1104
|
+
if (token.kind !== "option" || !token.name || !token.rawName)
|
|
1105
|
+
continue;
|
|
1106
|
+
const isLongOption2 = token.rawName.startsWith("--");
|
|
1107
|
+
if (isLongOption2) {
|
|
1108
|
+
if (knownLongOptions.has(token.name) || knownNegatableOptions.has(token.name))
|
|
1109
|
+
continue;
|
|
1110
|
+
} else if (knownShortOptions.has(token.name))
|
|
1111
|
+
continue;
|
|
1112
|
+
unknownOptions.push({
|
|
1113
|
+
rawName: token.rawName,
|
|
1114
|
+
name: token.name,
|
|
1115
|
+
candidates: isLongOption2 ? longOptionCandidates : []
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
return unknownOptions;
|
|
1119
|
+
}
|
|
1120
|
+
function resolveOptionName(name, schema, options) {
|
|
1121
|
+
return options.toKebab || schema.toKebab ? kebabnize(name) : name;
|
|
1122
|
+
}
|
|
1123
|
+
function createUnknownOptionErrors(unknownOptions) {
|
|
1124
|
+
return unknownOptions.map(({ rawName, name, candidates }) => {
|
|
1125
|
+
return new ArgsValidationError(`Unknown option: ${rawName}`, {
|
|
1126
|
+
code: ArgsValidationErrorKeys.unknownOption,
|
|
1127
|
+
values: {
|
|
1128
|
+
rawName,
|
|
1129
|
+
name,
|
|
1130
|
+
candidates
|
|
1131
|
+
}
|
|
1132
|
+
});
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
function mergeValidationErrors(error, additionalErrors) {
|
|
1136
|
+
if (additionalErrors.length === 0)
|
|
1137
|
+
return error;
|
|
1138
|
+
return new AggregateError(error ? [...error.errors, ...additionalErrors] : additionalErrors, error?.message || additionalErrors[0]?.message);
|
|
1139
|
+
}
|
|
1140
|
+
var isObject = (val) => val !== null && typeof val === "object";
|
|
1141
|
+
function createInitialSubCommands(options, entryCmd) {
|
|
1142
|
+
const hasSubCommands = options.subCommands ? options.subCommands instanceof Map ? options.subCommands.size > 0 : isObject(options.subCommands) && Object.keys(options.subCommands).length > 0 : false;
|
|
1143
|
+
const subCommands = new Map(options.subCommands instanceof Map ? options.subCommands : []);
|
|
1144
|
+
if (!(options.subCommands instanceof Map) && isObject(options.subCommands))
|
|
1145
|
+
for (const [name, cmd] of Object.entries(options.subCommands))
|
|
1146
|
+
subCommands.set(name, cmd);
|
|
1147
|
+
if (hasSubCommands) {
|
|
1148
|
+
if (isLazyCommand(entryCmd)) {
|
|
1149
|
+
const entryCopy = Object.assign((...args) => entryCmd(...args), entryCmd, { entry: true });
|
|
1150
|
+
subCommands.set(resolveEntryName(entryCopy), entryCopy);
|
|
1151
|
+
} else if (typeof entryCmd === "object") {
|
|
1152
|
+
const entryCopy = Object.assign(create(), entryCmd, { entry: true });
|
|
1153
|
+
subCommands.set(resolveEntryName(entryCopy), entryCopy);
|
|
1154
|
+
} else if (typeof entryCmd === "function") {
|
|
1155
|
+
const name = entryCmd.name || "(anonymous)";
|
|
1156
|
+
subCommands.set(name, {
|
|
1157
|
+
run: entryCmd,
|
|
1158
|
+
name,
|
|
1159
|
+
entry: true
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
return subCommands;
|
|
1164
|
+
}
|
|
1165
|
+
function normalizeCliOptions(options, decorators, pluginContext) {
|
|
1166
|
+
const subCommands = new Map(pluginContext.subCommands);
|
|
1167
|
+
const resolvedOptions = Object.assign(create(), CLI_OPTIONS_DEFAULT, options, { subCommands });
|
|
1168
|
+
if (resolvedOptions.renderHeader === undefined)
|
|
1169
|
+
resolvedOptions.renderHeader = decorators.getHeaderRenderer();
|
|
1170
|
+
if (resolvedOptions.renderUsage === undefined)
|
|
1171
|
+
resolvedOptions.renderUsage = decorators.getUsageRenderer();
|
|
1172
|
+
if (resolvedOptions.renderValidationErrors === undefined)
|
|
1173
|
+
resolvedOptions.renderValidationErrors = decorators.getValidationErrorsRenderer();
|
|
1174
|
+
return resolvedOptions;
|
|
1175
|
+
}
|
|
1176
|
+
function getPositionalTokens(tokens) {
|
|
1177
|
+
return tokens.filter((t) => t.kind === "positional").map((t) => t.value).filter((v) => !!v);
|
|
1178
|
+
}
|
|
1179
|
+
function resolveCommandTree(tokens, entry, options) {
|
|
1180
|
+
const positionals = getPositionalTokens(tokens);
|
|
1181
|
+
function resolveAsEntry() {
|
|
1182
|
+
if (typeof entry === "function") {
|
|
1183
|
+
if ("commandName" in entry && entry.commandName)
|
|
1184
|
+
return {
|
|
1185
|
+
commandName: entry.commandName,
|
|
1186
|
+
command: entry,
|
|
1187
|
+
callMode: "entry",
|
|
1188
|
+
commandPath: [],
|
|
1189
|
+
depth: 0,
|
|
1190
|
+
omitted: options.subCommands.size > 0 && !positionals[0],
|
|
1191
|
+
levelSubCommands: options.subCommands.size > 0 ? options.subCommands : undefined
|
|
1192
|
+
};
|
|
1193
|
+
else
|
|
1194
|
+
return {
|
|
1195
|
+
command: {
|
|
1196
|
+
run: entry,
|
|
1197
|
+
entry: true
|
|
1198
|
+
},
|
|
1199
|
+
callMode: "entry",
|
|
1200
|
+
commandPath: [],
|
|
1201
|
+
depth: 0,
|
|
1202
|
+
omitted: options.subCommands.size > 0 && !positionals[0],
|
|
1203
|
+
levelSubCommands: options.subCommands.size > 0 ? options.subCommands : undefined
|
|
1204
|
+
};
|
|
1205
|
+
} else if (typeof entry === "object")
|
|
1206
|
+
return {
|
|
1207
|
+
commandName: resolveEntryName(entry),
|
|
1208
|
+
command: entry,
|
|
1209
|
+
callMode: "entry",
|
|
1210
|
+
commandPath: [],
|
|
1211
|
+
depth: 0,
|
|
1212
|
+
omitted: options.subCommands.size > 0 && !positionals[0],
|
|
1213
|
+
levelSubCommands: options.subCommands.size > 0 ? options.subCommands : undefined
|
|
1214
|
+
};
|
|
1215
|
+
else
|
|
1216
|
+
return {
|
|
1217
|
+
callMode: "unexpected",
|
|
1218
|
+
commandPath: [],
|
|
1219
|
+
depth: 0,
|
|
1220
|
+
omitted: false,
|
|
1221
|
+
levelSubCommands: undefined
|
|
1222
|
+
};
|
|
1223
|
+
}
|
|
1224
|
+
if (positionals.length === 0 || options.subCommands.size === 0)
|
|
1225
|
+
return resolveAsEntry();
|
|
1226
|
+
let currentSubCommands = options.subCommands;
|
|
1227
|
+
let resolvedCommand;
|
|
1228
|
+
let resolvedName;
|
|
1229
|
+
const commandPath = [];
|
|
1230
|
+
let depth = 0;
|
|
1231
|
+
for (let i = 0;i < positionals.length; i++) {
|
|
1232
|
+
const token = positionals[i];
|
|
1233
|
+
const cmd = currentSubCommands.get(token);
|
|
1234
|
+
if (cmd == null) {
|
|
1235
|
+
if (depth === 0) {
|
|
1236
|
+
if (options.fallbackToEntry)
|
|
1237
|
+
return resolveAsEntry();
|
|
1238
|
+
const parent = resolveAsEntry();
|
|
1239
|
+
return {
|
|
1240
|
+
commandName: token,
|
|
1241
|
+
callMode: "unexpected",
|
|
1242
|
+
commandPath: [],
|
|
1243
|
+
depth: 0,
|
|
1244
|
+
omitted: false,
|
|
1245
|
+
levelSubCommands: undefined,
|
|
1246
|
+
unresolvedCommandName: token,
|
|
1247
|
+
parentCommand: parent.command,
|
|
1248
|
+
parentCommandName: parent.commandName,
|
|
1249
|
+
parentCommandPath: [],
|
|
1250
|
+
parentSubCommands: options.subCommands
|
|
1251
|
+
};
|
|
1252
|
+
}
|
|
1253
|
+
return {
|
|
1254
|
+
commandName: token,
|
|
1255
|
+
callMode: "unexpected",
|
|
1256
|
+
commandPath: [...commandPath],
|
|
1257
|
+
depth,
|
|
1258
|
+
omitted: false,
|
|
1259
|
+
levelSubCommands: undefined,
|
|
1260
|
+
unresolvedCommandName: token,
|
|
1261
|
+
parentCommand: resolvedCommand,
|
|
1262
|
+
parentCommandName: resolvedName,
|
|
1263
|
+
parentCommandPath: [...commandPath],
|
|
1264
|
+
parentSubCommands: currentSubCommands
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
let resolved = cmd;
|
|
1268
|
+
if (typeof cmd === "function" && cmd.commandName == null)
|
|
1269
|
+
resolved = Object.assign((...args) => cmd(...args), cmd, { commandName: token });
|
|
1270
|
+
else if (typeof cmd === "object" && cmd.name == null)
|
|
1271
|
+
resolved = Object.assign(create(), cmd, { name: token });
|
|
1272
|
+
resolvedCommand = resolved;
|
|
1273
|
+
resolvedName = token;
|
|
1274
|
+
commandPath.push(token);
|
|
1275
|
+
depth++;
|
|
1276
|
+
const nestedSubCommands = getCommandSubCommands(cmd);
|
|
1277
|
+
if (nestedSubCommands && nestedSubCommands.size > 0)
|
|
1278
|
+
currentSubCommands = nestedSubCommands;
|
|
1279
|
+
else
|
|
1280
|
+
break;
|
|
1281
|
+
}
|
|
1282
|
+
if (!resolvedCommand)
|
|
1283
|
+
return resolveAsEntry();
|
|
1284
|
+
const resolvedSubCommands = getCommandSubCommands(resolvedCommand);
|
|
1285
|
+
const omitted = resolvedSubCommands != null && resolvedSubCommands.size > 0;
|
|
1286
|
+
let levelSubCommands;
|
|
1287
|
+
if (omitted && resolvedSubCommands) {
|
|
1288
|
+
levelSubCommands = new Map(resolvedSubCommands);
|
|
1289
|
+
let entryCopy;
|
|
1290
|
+
if (typeof resolvedCommand === "function")
|
|
1291
|
+
entryCopy = Object.assign((...args) => resolvedCommand(...args), resolvedCommand, { entry: true });
|
|
1292
|
+
else
|
|
1293
|
+
entryCopy = Object.assign(create(), resolvedCommand, { entry: true });
|
|
1294
|
+
levelSubCommands.set(resolvedName || resolveEntryName(entryCopy), entryCopy);
|
|
1295
|
+
}
|
|
1296
|
+
return {
|
|
1297
|
+
commandName: resolvedName,
|
|
1298
|
+
command: resolvedCommand,
|
|
1299
|
+
callMode: depth > 0 ? "subCommand" : "entry",
|
|
1300
|
+
commandPath,
|
|
1301
|
+
depth,
|
|
1302
|
+
omitted,
|
|
1303
|
+
levelSubCommands
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
function createCommandNotFoundError(resolved) {
|
|
1307
|
+
const commandName = resolved.unresolvedCommandName || resolved.commandName || "";
|
|
1308
|
+
return new CommandNotFoundError(`Command not found: ${commandName}`, {
|
|
1309
|
+
code: CommandNotFoundErrorKeys.notFound,
|
|
1310
|
+
values: { commandName },
|
|
1311
|
+
commandName,
|
|
1312
|
+
candidates: [...resolved.parentSubCommands?.keys() || []],
|
|
1313
|
+
commandPath: resolved.parentCommandPath || []
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
function resolveEntryName(entry) {
|
|
1317
|
+
return isLazyCommand(entry) ? entry.commandName || "(anonymous)" : entry.name || "(anonymous)";
|
|
1318
|
+
}
|
|
1319
|
+
function getPluginExtensions(plugins) {
|
|
1320
|
+
const extensions = create();
|
|
1321
|
+
for (const plugin of plugins)
|
|
1322
|
+
if (plugin.extension) {
|
|
1323
|
+
const key = plugin.id;
|
|
1324
|
+
if (extensions[key])
|
|
1325
|
+
console.warn(`Plugin "${key}" is already installed. Ignore it for command context extending.`);
|
|
1326
|
+
else
|
|
1327
|
+
extensions[key] = plugin.extension;
|
|
1328
|
+
}
|
|
1329
|
+
return extensions;
|
|
1330
|
+
}
|
|
1331
|
+
async function executeCommand(cmd, ctx, decorators) {
|
|
1332
|
+
const commandRunner = cmd.run || NOOP;
|
|
1333
|
+
const baseRunner = (ctx2) => {
|
|
1334
|
+
if (hasPriorityValidationError(ctx2.validationError))
|
|
1335
|
+
throw ctx2.validationError;
|
|
1336
|
+
return commandRunner(ctx2);
|
|
1337
|
+
};
|
|
1338
|
+
const decoratedRunner = decorators.reduceRight((runner, decorator) => decorator(runner), baseRunner);
|
|
1339
|
+
try {
|
|
1340
|
+
if (ctx.env.onBeforeCommand)
|
|
1341
|
+
await ctx.env.onBeforeCommand(ctx);
|
|
1342
|
+
const result = await decoratedRunner(ctx);
|
|
1343
|
+
if (ctx.env.onAfterCommand)
|
|
1344
|
+
await ctx.env.onAfterCommand(ctx, result);
|
|
1345
|
+
return typeof result === "string" ? result : undefined;
|
|
1346
|
+
} catch (error) {
|
|
1347
|
+
if (ctx.env.onErrorCommand)
|
|
1348
|
+
try {
|
|
1349
|
+
await ctx.env.onErrorCommand(ctx, error);
|
|
1350
|
+
} catch (hookError) {
|
|
1351
|
+
console.error("Error in onErrorCommand hook:", hookError);
|
|
1352
|
+
}
|
|
1353
|
+
throw error;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
// node_modules/gunshi/lib/bone.js
|
|
1358
|
+
async function cli(args, entry, options = {}) {
|
|
1359
|
+
return cliCore(args, entry, options, []);
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
// src/cli/main.ts
|
|
1363
|
+
var import_picocolors2 = __toESM(require_picocolors(), 1);
|
|
1364
|
+
// package.json
|
|
1365
|
+
var package_default = {
|
|
1366
|
+
name: "@jordond/kit",
|
|
1367
|
+
version: "0.1.0",
|
|
1368
|
+
description: "One dev toolkit for every app: CLI, shared fastlane, Gradle conventions",
|
|
1369
|
+
license: "MIT",
|
|
1370
|
+
type: "module",
|
|
1371
|
+
repository: {
|
|
1372
|
+
type: "git",
|
|
1373
|
+
url: "git+https://github.com/jordond/kit.git"
|
|
1374
|
+
},
|
|
1375
|
+
bin: {
|
|
1376
|
+
kit: "bin/kit"
|
|
1377
|
+
},
|
|
1378
|
+
exports: {
|
|
1379
|
+
".": {
|
|
1380
|
+
types: "./dist/index.d.ts",
|
|
1381
|
+
default: "./dist/index.js"
|
|
1382
|
+
}
|
|
1383
|
+
},
|
|
1384
|
+
files: [
|
|
1385
|
+
"bin",
|
|
1386
|
+
"dist",
|
|
1387
|
+
"fastlane",
|
|
1388
|
+
"gradle/maven",
|
|
1389
|
+
"templates"
|
|
1390
|
+
],
|
|
1391
|
+
engines: {
|
|
1392
|
+
bun: ">=1.3"
|
|
1393
|
+
},
|
|
1394
|
+
scripts: {
|
|
1395
|
+
build: "rm -rf dist && bun build src/cli.ts src/index.ts --outdir dist --target bun --splitting --external zod && tsc -p tsconfig.build.json",
|
|
1396
|
+
"build:gradle": "gradle/gradlew -p gradle publishKit",
|
|
1397
|
+
dev: "bun src/cli.ts",
|
|
1398
|
+
test: "bun test",
|
|
1399
|
+
"test:pack": "KIT_PACK_TEST=1 bun test test/pack",
|
|
1400
|
+
typecheck: "tsc --noEmit",
|
|
1401
|
+
lint: "biome check .",
|
|
1402
|
+
format: "biome format --write ."
|
|
1403
|
+
},
|
|
1404
|
+
publishConfig: {
|
|
1405
|
+
access: "public"
|
|
1406
|
+
},
|
|
1407
|
+
peerDependencies: {
|
|
1408
|
+
zod: "^4.0.0"
|
|
1409
|
+
},
|
|
1410
|
+
dependencies: {
|
|
1411
|
+
"@clack/prompts": "^1.9.0",
|
|
1412
|
+
gunshi: "0.37.3",
|
|
1413
|
+
"@gunshi/plugin-completion": "0.37.3",
|
|
1414
|
+
listr2: "^11.4.1",
|
|
1415
|
+
picocolors: "^1.1.1",
|
|
1416
|
+
"smol-toml": "^1.9.1"
|
|
1417
|
+
},
|
|
1418
|
+
devDependencies: {
|
|
1419
|
+
"@biomejs/biome": "^2.6.6",
|
|
1420
|
+
"@types/bun": "^1.4.4",
|
|
1421
|
+
typescript: "^7.0.2",
|
|
1422
|
+
zod: "^4.6.7"
|
|
1423
|
+
}
|
|
1424
|
+
};
|
|
1425
|
+
|
|
1426
|
+
// src/config/load.ts
|
|
1427
|
+
import { existsSync } from "fs";
|
|
1428
|
+
import { dirname, join } from "path";
|
|
1429
|
+
import { pathToFileURL } from "url";
|
|
1430
|
+
|
|
1431
|
+
// src/config/schema.ts
|
|
1432
|
+
import { z } from "zod";
|
|
1433
|
+
var verbs = ["lint", "format", "typecheck", "test", "build", "dev", "deploy"];
|
|
1434
|
+
var kinds = ["gradle", "worker", "vite", "astro", "docker", "custom"];
|
|
1435
|
+
var tracks = ["internal", "alpha", "beta", "prod"];
|
|
1436
|
+
var command = z.union([z.string(), z.array(z.string()), z.literal(false)]);
|
|
1437
|
+
var verbOverrides = Object.fromEntries(verbs.map((v) => [v, command.optional()]));
|
|
1438
|
+
var deploy = z.union([
|
|
1439
|
+
command,
|
|
1440
|
+
z.object({
|
|
1441
|
+
run: command.optional(),
|
|
1442
|
+
before: z.array(z.string()).optional()
|
|
1443
|
+
}).strict()
|
|
1444
|
+
]);
|
|
1445
|
+
var target = z.object({
|
|
1446
|
+
kind: z.enum(kinds),
|
|
1447
|
+
dir: z.string(),
|
|
1448
|
+
envs: z.array(z.string()).optional(),
|
|
1449
|
+
...verbOverrides,
|
|
1450
|
+
deploy: deploy.optional()
|
|
1451
|
+
}).strict();
|
|
1452
|
+
var workspace = z.object({
|
|
1453
|
+
...verbOverrides,
|
|
1454
|
+
prepare: command.optional()
|
|
1455
|
+
}).strict();
|
|
1456
|
+
var configSchema = z.object({
|
|
1457
|
+
name: z.string().min(1),
|
|
1458
|
+
gradle: z.object({ root: z.string() }).strict().optional(),
|
|
1459
|
+
versions: z.object({
|
|
1460
|
+
file: z.string(),
|
|
1461
|
+
keys: z.record(z.string(), z.string())
|
|
1462
|
+
}).strict().optional(),
|
|
1463
|
+
env: z.object({
|
|
1464
|
+
schema: z.string().optional(),
|
|
1465
|
+
outputs: z.record(z.string(), z.object({
|
|
1466
|
+
pick: z.array(z.string()).optional(),
|
|
1467
|
+
rename: z.record(z.string(), z.string()).optional()
|
|
1468
|
+
}).strict()).optional(),
|
|
1469
|
+
workerSecrets: z.record(z.string(), z.array(z.string())).optional(),
|
|
1470
|
+
githubSecrets: z.array(z.string()).optional()
|
|
1471
|
+
}).strict().optional(),
|
|
1472
|
+
workspace: workspace.optional(),
|
|
1473
|
+
targets: z.record(z.string(), target).default({}),
|
|
1474
|
+
cloudflare: z.object({
|
|
1475
|
+
accountId: z.string().optional(),
|
|
1476
|
+
d1: z.record(z.string(), z.object({ name: z.string(), target: z.string() }).strict()).optional()
|
|
1477
|
+
}).strict().optional(),
|
|
1478
|
+
release: z.object({
|
|
1479
|
+
branches: z.array(z.string()).optional(),
|
|
1480
|
+
notes: z.object({ maxLength: z.number().int().positive().optional() }).strict().optional(),
|
|
1481
|
+
preflight: z.array(z.string()).optional(),
|
|
1482
|
+
ios: z.object({
|
|
1483
|
+
bundleIds: z.array(z.string()).min(1),
|
|
1484
|
+
project: z.string(),
|
|
1485
|
+
scheme: z.string(),
|
|
1486
|
+
output: z.string(),
|
|
1487
|
+
teamId: z.string().optional(),
|
|
1488
|
+
testflightGroups: z.object({ alpha: z.string(), beta: z.string() }).partial().optional(),
|
|
1489
|
+
sentry: z.object({ org: z.string(), project: z.string() }).strict().optional()
|
|
1490
|
+
}).strict().optional(),
|
|
1491
|
+
android: z.object({
|
|
1492
|
+
packageName: z.string(),
|
|
1493
|
+
module: z.string(),
|
|
1494
|
+
prodRollout: z.number().gt(0).lte(1).optional(),
|
|
1495
|
+
gates: z.array(z.object({
|
|
1496
|
+
task: z.string(),
|
|
1497
|
+
tracks: z.array(z.enum(tracks))
|
|
1498
|
+
})).optional()
|
|
1499
|
+
}).strict().optional(),
|
|
1500
|
+
services: z.record(z.string(), z.object({ versionKey: z.string(), build: z.string().optional(), deploy: z.string() }).strict()).optional()
|
|
1501
|
+
}).strict().optional()
|
|
1502
|
+
}).strict().superRefine((c, ctx) => {
|
|
1503
|
+
for (const [name, d] of Object.entries(c.cloudflare?.d1 ?? {})) {
|
|
1504
|
+
if (!c.targets[d.target]) {
|
|
1505
|
+
ctx.addIssue({
|
|
1506
|
+
code: "custom",
|
|
1507
|
+
path: ["cloudflare", "d1", name, "target"],
|
|
1508
|
+
message: `Unknown target "${d.target}"`
|
|
1509
|
+
});
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
if (c.targets.workspace) {
|
|
1513
|
+
ctx.addIssue({ code: "custom", path: ["targets", "workspace"], message: '"workspace" is reserved' });
|
|
1514
|
+
}
|
|
1515
|
+
});
|
|
1516
|
+
|
|
1517
|
+
// src/config/load.ts
|
|
1518
|
+
var CONFIG_FILE = "kit.config.ts";
|
|
1519
|
+
function findRoot(from = process.cwd()) {
|
|
1520
|
+
if (process.env.KIT_ROOT && existsSync(join(process.env.KIT_ROOT, CONFIG_FILE)))
|
|
1521
|
+
return process.env.KIT_ROOT;
|
|
1522
|
+
let dir = from;
|
|
1523
|
+
while (true) {
|
|
1524
|
+
if (existsSync(join(dir, CONFIG_FILE)))
|
|
1525
|
+
return dir;
|
|
1526
|
+
const parent = dirname(dir);
|
|
1527
|
+
if (parent === dir)
|
|
1528
|
+
return;
|
|
1529
|
+
dir = parent;
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
async function loadDotEnv(root) {
|
|
1533
|
+
const file = Bun.file(join(root, ".env"));
|
|
1534
|
+
if (!await file.exists())
|
|
1535
|
+
return;
|
|
1536
|
+
for (const line of (await file.text()).split(`
|
|
1537
|
+
`)) {
|
|
1538
|
+
const m = line.match(/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$/);
|
|
1539
|
+
if (!m)
|
|
1540
|
+
continue;
|
|
1541
|
+
const [, key, raw] = m;
|
|
1542
|
+
if (process.env[key] !== undefined)
|
|
1543
|
+
continue;
|
|
1544
|
+
process.env[key] = raw.replace(/^(['"])(.*)\1$/, "$2");
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
async function loadConfig(root) {
|
|
1548
|
+
const mod = await import(pathToFileURL(join(root, CONFIG_FILE)).href);
|
|
1549
|
+
const result = configSchema.safeParse(mod.default);
|
|
1550
|
+
if (!result.success) {
|
|
1551
|
+
const issues = result.error.issues.map((i) => ` ${i.path.join(".") || "(root)"}: ${i.message}`).join(`
|
|
1552
|
+
`);
|
|
1553
|
+
throw new KitError(`Invalid ${CONFIG_FILE}:
|
|
1554
|
+
${issues}`, "Fix the fields above", ExitCode.config);
|
|
1555
|
+
}
|
|
1556
|
+
return result.data;
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
// src/cli/builtins.ts
|
|
1560
|
+
var builtins = [
|
|
1561
|
+
{ path: ["dev"], description: "Run a dev server", group: "Develop", load: () => import("./dev-yc9xmntj.js") },
|
|
1562
|
+
{
|
|
1563
|
+
path: ["build"],
|
|
1564
|
+
description: "Build every target",
|
|
1565
|
+
group: "Develop",
|
|
1566
|
+
load: () => import("./build-88hxf0kc.js")
|
|
1567
|
+
},
|
|
1568
|
+
{
|
|
1569
|
+
path: ["deploy"],
|
|
1570
|
+
description: "Deploy a target",
|
|
1571
|
+
group: "Develop",
|
|
1572
|
+
load: () => import("./deploy-8mg1zhpb.js")
|
|
1573
|
+
},
|
|
1574
|
+
{
|
|
1575
|
+
path: ["lint"],
|
|
1576
|
+
description: "Lint every target",
|
|
1577
|
+
group: "Quality",
|
|
1578
|
+
load: () => import("./lint-280dpn4y.js")
|
|
1579
|
+
},
|
|
1580
|
+
{
|
|
1581
|
+
path: ["format"],
|
|
1582
|
+
description: "Format every target",
|
|
1583
|
+
group: "Quality",
|
|
1584
|
+
load: () => import("./format-mnqfak22.js")
|
|
1585
|
+
},
|
|
1586
|
+
{
|
|
1587
|
+
path: ["typecheck"],
|
|
1588
|
+
description: "Typecheck every target",
|
|
1589
|
+
group: "Quality",
|
|
1590
|
+
load: () => import("./typecheck-e86e6yg1.js")
|
|
1591
|
+
},
|
|
1592
|
+
{
|
|
1593
|
+
path: ["check"],
|
|
1594
|
+
description: "Lint and typecheck every target",
|
|
1595
|
+
group: "Quality",
|
|
1596
|
+
load: () => import("./check-ngc4kzmj.js")
|
|
1597
|
+
},
|
|
1598
|
+
{
|
|
1599
|
+
path: ["test"],
|
|
1600
|
+
description: "Run the test suites",
|
|
1601
|
+
group: "Quality",
|
|
1602
|
+
load: () => import("./test-198w46m4.js")
|
|
1603
|
+
},
|
|
1604
|
+
{
|
|
1605
|
+
path: ["release", "ios"],
|
|
1606
|
+
description: "Build and upload iOS to a track",
|
|
1607
|
+
group: "Release",
|
|
1608
|
+
load: () => import("./ios-msg4bk15.js")
|
|
1609
|
+
},
|
|
1610
|
+
{
|
|
1611
|
+
path: ["release", "android"],
|
|
1612
|
+
description: "Build and upload Android to a track",
|
|
1613
|
+
group: "Release",
|
|
1614
|
+
load: () => import("./android-g73naxgg.js")
|
|
1615
|
+
},
|
|
1616
|
+
{
|
|
1617
|
+
path: ["env", "sync"],
|
|
1618
|
+
description: "Render env outputs (.dev.vars) from .env",
|
|
1619
|
+
group: "Infra",
|
|
1620
|
+
load: () => import("./sync-wc4jpmkj.js")
|
|
1621
|
+
},
|
|
1622
|
+
{
|
|
1623
|
+
path: ["env", "check"],
|
|
1624
|
+
description: "Validate .env and check outputs for drift",
|
|
1625
|
+
group: "Infra",
|
|
1626
|
+
load: () => import("./check-7mndz8g8.js")
|
|
1627
|
+
},
|
|
1628
|
+
{
|
|
1629
|
+
path: ["env", "push"],
|
|
1630
|
+
description: "Push secrets with wrangler and gh",
|
|
1631
|
+
group: "Infra",
|
|
1632
|
+
load: () => import("./push-xzqw218t.js")
|
|
1633
|
+
},
|
|
1634
|
+
{
|
|
1635
|
+
path: ["env", "init"],
|
|
1636
|
+
description: "Create .env and ask for missing keys",
|
|
1637
|
+
group: "Infra",
|
|
1638
|
+
load: () => import("./init-0402av4m.js")
|
|
1639
|
+
},
|
|
1640
|
+
{
|
|
1641
|
+
path: ["db", "migrate"],
|
|
1642
|
+
description: "Apply pending D1 migrations",
|
|
1643
|
+
group: "Infra",
|
|
1644
|
+
load: () => import("./migrate-emk758k1.js")
|
|
1645
|
+
},
|
|
1646
|
+
{
|
|
1647
|
+
path: ["db", "list"],
|
|
1648
|
+
description: "List D1 migrations",
|
|
1649
|
+
group: "Infra",
|
|
1650
|
+
load: () => import("./list-jdc3dqk0.js")
|
|
1651
|
+
},
|
|
1652
|
+
{
|
|
1653
|
+
path: ["db", "create"],
|
|
1654
|
+
description: "Create a D1 migration",
|
|
1655
|
+
group: "Infra",
|
|
1656
|
+
load: () => import("./create-7s8h3dja.js")
|
|
1657
|
+
},
|
|
1658
|
+
{
|
|
1659
|
+
path: ["db", "exec"],
|
|
1660
|
+
description: "Run SQL against D1",
|
|
1661
|
+
group: "Infra",
|
|
1662
|
+
load: () => import("./exec-1k3sqwxz.js")
|
|
1663
|
+
},
|
|
1664
|
+
{
|
|
1665
|
+
path: ["gradle"],
|
|
1666
|
+
description: "Run ./gradlew in the Gradle root",
|
|
1667
|
+
group: "Develop",
|
|
1668
|
+
load: () => import("./gradle-gtkf3geq.js")
|
|
1669
|
+
},
|
|
1670
|
+
{
|
|
1671
|
+
path: ["wrangler"],
|
|
1672
|
+
description: "Run wrangler in a worker target's directory",
|
|
1673
|
+
group: "Develop",
|
|
1674
|
+
load: () => import("./wrangler-0ctx1p3w.js")
|
|
1675
|
+
},
|
|
1676
|
+
{
|
|
1677
|
+
path: ["xcode"],
|
|
1678
|
+
description: "Open the iOS project in Xcode",
|
|
1679
|
+
group: "Develop",
|
|
1680
|
+
load: () => import("./xcode-g44qh2rc.js")
|
|
1681
|
+
},
|
|
1682
|
+
{
|
|
1683
|
+
path: ["doctor"],
|
|
1684
|
+
description: "Check tools, versions and .env",
|
|
1685
|
+
group: "Setup",
|
|
1686
|
+
load: () => import("./doctor-0wzmfyyh.js")
|
|
1687
|
+
},
|
|
1688
|
+
{
|
|
1689
|
+
path: ["init"],
|
|
1690
|
+
description: "Set up a fresh clone",
|
|
1691
|
+
group: "Setup",
|
|
1692
|
+
load: () => import("./init-qr7y55ea.js")
|
|
1693
|
+
},
|
|
1694
|
+
{
|
|
1695
|
+
path: ["deps"],
|
|
1696
|
+
description: "List or update npm dependencies (catalog-aware)",
|
|
1697
|
+
group: "Setup",
|
|
1698
|
+
load: () => import("./deps-97dq4mg8.js")
|
|
1699
|
+
},
|
|
1700
|
+
{
|
|
1701
|
+
path: ["config"],
|
|
1702
|
+
description: "Print the resolved kit.config.ts",
|
|
1703
|
+
group: "Setup",
|
|
1704
|
+
load: () => import("./config-ey5yrrfn.js")
|
|
1705
|
+
}
|
|
1706
|
+
];
|
|
1707
|
+
var groupDescriptions = {
|
|
1708
|
+
release: "Ship to the stores",
|
|
1709
|
+
env: "Render, check and push env from .env",
|
|
1710
|
+
db: "Cloudflare D1 migrations and queries"
|
|
1711
|
+
};
|
|
1712
|
+
|
|
1713
|
+
// src/cli/discover.ts
|
|
1714
|
+
import { join as join2 } from "path";
|
|
1715
|
+
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
1716
|
+
function listRepoCommands(root) {
|
|
1717
|
+
const dir = join2(root, ".kit", "commands");
|
|
1718
|
+
const glob = new Bun.Glob("**/*.ts");
|
|
1719
|
+
const out = [];
|
|
1720
|
+
try {
|
|
1721
|
+
for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
|
|
1722
|
+
if (rel.endsWith(".d.ts") || rel.split("/").some((s) => s.startsWith("_")))
|
|
1723
|
+
continue;
|
|
1724
|
+
out.push({ path: rel.replace(/\.ts$/, "").split("/"), file: join2(dir, rel) });
|
|
1725
|
+
}
|
|
1726
|
+
} catch {
|
|
1727
|
+
return [];
|
|
1728
|
+
}
|
|
1729
|
+
return out.sort((a, b) => a.path.join(" ").localeCompare(b.path.join(" ")));
|
|
1730
|
+
}
|
|
1731
|
+
async function importRepoCommand(f) {
|
|
1732
|
+
const mod = await import(pathToFileURL2(f.file).href);
|
|
1733
|
+
const cmd = mod.default;
|
|
1734
|
+
if (!cmd || typeof cmd.run !== "function") {
|
|
1735
|
+
throw new KitError(`${f.file} does not default-export a command`, "export default defineCommand({ description, run })");
|
|
1736
|
+
}
|
|
1737
|
+
return cmd;
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
// node_modules/gunshi/lib/plugin-DneW3Toi.js
|
|
1741
|
+
var NOOP_EXTENSION = () => {
|
|
1742
|
+
return Object.create(null);
|
|
1743
|
+
};
|
|
1744
|
+
function plugin(options = {}) {
|
|
1745
|
+
const { id, name, setup, onExtension, dependencies } = options;
|
|
1746
|
+
const extension = options.extension || NOOP_EXTENSION;
|
|
1747
|
+
const pluginFn = async (ctx) => {
|
|
1748
|
+
if (setup)
|
|
1749
|
+
await setup(ctx);
|
|
1750
|
+
};
|
|
1751
|
+
const props = {
|
|
1752
|
+
writable: false,
|
|
1753
|
+
enumerable: true,
|
|
1754
|
+
configurable: true
|
|
1755
|
+
};
|
|
1756
|
+
return Object.defineProperties(pluginFn, {
|
|
1757
|
+
id: {
|
|
1758
|
+
value: id,
|
|
1759
|
+
...props
|
|
1760
|
+
},
|
|
1761
|
+
...name && { name: {
|
|
1762
|
+
value: name,
|
|
1763
|
+
...props
|
|
1764
|
+
} },
|
|
1765
|
+
...dependencies && { dependencies: {
|
|
1766
|
+
value: dependencies,
|
|
1767
|
+
...props
|
|
1768
|
+
} },
|
|
1769
|
+
...extension && { extension: {
|
|
1770
|
+
value: {
|
|
1771
|
+
key: Symbol(id),
|
|
1772
|
+
factory: extension,
|
|
1773
|
+
onFactory: onExtension
|
|
1774
|
+
},
|
|
1775
|
+
...props
|
|
1776
|
+
} }
|
|
1777
|
+
});
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
// src/cli/plugin.ts
|
|
1781
|
+
var SHOW_USAGE = Symbol("kit.showUsage");
|
|
1782
|
+
function kitGlobals(version, renderUsage) {
|
|
1783
|
+
return plugin({
|
|
1784
|
+
id: "kit:globals",
|
|
1785
|
+
name: "kit global options",
|
|
1786
|
+
setup(ctx) {
|
|
1787
|
+
ctx.addGlobalOption("help", { type: "boolean", short: "h", description: "Show help" });
|
|
1788
|
+
ctx.addGlobalOption("version", { type: "boolean", short: "V", description: "Show kit version" });
|
|
1789
|
+
ctx.decorateCommand((run) => async (c) => {
|
|
1790
|
+
if (c.values.version) {
|
|
1791
|
+
process.stdout.write(`${version}
|
|
1792
|
+
`);
|
|
1793
|
+
return;
|
|
1794
|
+
}
|
|
1795
|
+
if (c.values.help || c.callMode === "entry") {
|
|
1796
|
+
process.stdout.write(`${await renderUsage(c)}
|
|
1797
|
+
`);
|
|
1798
|
+
return;
|
|
1799
|
+
}
|
|
1800
|
+
if (c.validationError) {
|
|
1801
|
+
const msgs = c.validationError.errors.map((e) => e.message).join(`
|
|
1802
|
+
`);
|
|
1803
|
+
throw new KitError(msgs, `Run \`kit ${c.commandPath.join(" ")} --help\``, ExitCode.usage);
|
|
1804
|
+
}
|
|
1805
|
+
try {
|
|
1806
|
+
return await run(c);
|
|
1807
|
+
} catch (e) {
|
|
1808
|
+
if (e !== SHOW_USAGE)
|
|
1809
|
+
throw e;
|
|
1810
|
+
process.stdout.write(`${await renderUsage(c)}
|
|
1811
|
+
`);
|
|
1812
|
+
}
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
});
|
|
1816
|
+
}
|
|
1817
|
+
|
|
1818
|
+
// src/cli/usage.ts
|
|
1819
|
+
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
1820
|
+
var GROUP_ORDER = ["Develop", "Quality", "Release", "Infra", "Setup"];
|
|
1821
|
+
function childrenOf(ctx) {
|
|
1822
|
+
let level = ctx.env.subCommands;
|
|
1823
|
+
for (const seg of ctx.commandPath ?? []) {
|
|
1824
|
+
const next = level?.get(seg)?.subCommands;
|
|
1825
|
+
level = next ? new Map(Object.entries(next)) : undefined;
|
|
1826
|
+
}
|
|
1827
|
+
return level ?? new Map;
|
|
1828
|
+
}
|
|
1829
|
+
async function renderUsage(ctx) {
|
|
1830
|
+
const path = ["kit", ...ctx.commandPath ?? []].join(" ");
|
|
1831
|
+
const lines = [];
|
|
1832
|
+
if (ctx.description)
|
|
1833
|
+
lines.push(ctx.description, "");
|
|
1834
|
+
const children = childrenOf(ctx);
|
|
1835
|
+
const hasRun = typeof ctx === "object" && ctx.commandPath.length > 0;
|
|
1836
|
+
lines.push(import_picocolors.default.bold("Usage"), ` ${import_picocolors.default.cyan(path)}${children.size ? " <command>" : ""} [options]`, "");
|
|
1837
|
+
if (children.size) {
|
|
1838
|
+
const groups = new Map;
|
|
1839
|
+
for (const [name, cmd] of children) {
|
|
1840
|
+
if (cmd.internal || cmd.entry || name === ctx.env.name)
|
|
1841
|
+
continue;
|
|
1842
|
+
const g = ctx.commandPath.length ? "Commands" : cmd.group ?? "Other";
|
|
1843
|
+
groups.set(g, [...groups.get(g) ?? [], [name, cmd]]);
|
|
1844
|
+
}
|
|
1845
|
+
const order = [...groups.keys()].sort((a, b) => {
|
|
1846
|
+
const ia = GROUP_ORDER.indexOf(a);
|
|
1847
|
+
const ib = GROUP_ORDER.indexOf(b);
|
|
1848
|
+
return (ia < 0 ? 99 : ia) - (ib < 0 ? 99 : ib) || a.localeCompare(b);
|
|
1849
|
+
});
|
|
1850
|
+
const width = Math.max(...[...children.keys()].map((n) => n.length)) + 2;
|
|
1851
|
+
for (const g of order) {
|
|
1852
|
+
lines.push(import_picocolors.default.bold(g));
|
|
1853
|
+
for (const [name, cmd] of groups.get(g) ?? []) {
|
|
1854
|
+
const more = cmd.subCommands ? import_picocolors.default.dim(" \u2026") : "";
|
|
1855
|
+
lines.push(` ${import_picocolors.default.cyan(name.padEnd(width))}${cmd.description ?? ""}${more}`);
|
|
1856
|
+
}
|
|
1857
|
+
lines.push("");
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
const args = Object.entries(ctx.args ?? {});
|
|
1861
|
+
if (args.length && (hasRun || !children.size)) {
|
|
1862
|
+
lines.push(import_picocolors.default.bold("Options"));
|
|
1863
|
+
const rows = args.map(([name, a]) => {
|
|
1864
|
+
const flag = a.type === "positional" ? `<${name}>` : `${a.short ? `-${a.short}, ` : " "}--${name}`;
|
|
1865
|
+
const value = a.type === "string" || a.type === "number" || a.type === "enum" ? ` <${a.type}>` : "";
|
|
1866
|
+
return [`${flag}${value}`, a.description ?? ""];
|
|
1867
|
+
});
|
|
1868
|
+
const w = Math.max(...rows.map(([f]) => f.length)) + 2;
|
|
1869
|
+
for (const [f, d] of rows)
|
|
1870
|
+
lines.push(` ${f.padEnd(w)}${import_picocolors.default.dim(d)}`);
|
|
1871
|
+
lines.push("");
|
|
1872
|
+
}
|
|
1873
|
+
return lines.join(`
|
|
1874
|
+
`);
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
// src/cli/main.ts
|
|
1878
|
+
function commandTokens(argv) {
|
|
1879
|
+
const out = [];
|
|
1880
|
+
for (const a of argv) {
|
|
1881
|
+
if (a === "--" || a.startsWith("-"))
|
|
1882
|
+
break;
|
|
1883
|
+
out.push(a);
|
|
1884
|
+
}
|
|
1885
|
+
return out;
|
|
1886
|
+
}
|
|
1887
|
+
var same = (a, b) => a.length === b.length && a.every((s, i) => s === b[i]);
|
|
1888
|
+
var startsWith = (a, prefix) => prefix.every((s, i) => a[i] === s);
|
|
1889
|
+
async function collectLeaves(root, appName) {
|
|
1890
|
+
const leaves = builtins.map((b) => ({
|
|
1891
|
+
path: b.path,
|
|
1892
|
+
description: b.description,
|
|
1893
|
+
group: b.group,
|
|
1894
|
+
source: "builtin",
|
|
1895
|
+
load: async () => (await b.load()).default
|
|
1896
|
+
}));
|
|
1897
|
+
if (!root)
|
|
1898
|
+
return leaves;
|
|
1899
|
+
for (const f of listRepoCommands(root)) {
|
|
1900
|
+
leaves.push({
|
|
1901
|
+
path: f.path,
|
|
1902
|
+
description: "",
|
|
1903
|
+
group: appName ?? "Repo",
|
|
1904
|
+
source: "repo",
|
|
1905
|
+
load: () => importRepoCommand(f)
|
|
1906
|
+
});
|
|
1907
|
+
}
|
|
1908
|
+
return leaves;
|
|
1909
|
+
}
|
|
1910
|
+
function buildTree(leaves, loaded, rt, depth = 0) {
|
|
1911
|
+
const tree = {};
|
|
1912
|
+
const names = [...new Set(leaves.map((l) => l.path[depth]))];
|
|
1913
|
+
for (const name of names) {
|
|
1914
|
+
const here = leaves.filter((l) => l.path[depth] === name);
|
|
1915
|
+
const atDepth = here.filter((l) => l.path.length === depth + 1);
|
|
1916
|
+
const leaf = atDepth.find((l) => l.source === "repo" && (l.override || loaded.get(l)?.override)) ?? atDepth[0];
|
|
1917
|
+
const children = here.filter((l) => l.path.length > depth + 1);
|
|
1918
|
+
const loadedCmd = leaf ? loaded.get(leaf) : undefined;
|
|
1919
|
+
const base = loadedCmd ? toGunshi(name, loadedCmd, rt) : {
|
|
1920
|
+
name,
|
|
1921
|
+
description: leaf ? leaf.description || loaded.get(leaf)?.description : groupDescriptions[name] ?? "",
|
|
1922
|
+
group: leaf?.group ?? here[0]?.group,
|
|
1923
|
+
run: () => {
|
|
1924
|
+
throw SHOW_USAGE;
|
|
1925
|
+
}
|
|
1926
|
+
};
|
|
1927
|
+
if (children.length)
|
|
1928
|
+
base.subCommands = buildTree(children, loaded, rt, depth + 1);
|
|
1929
|
+
tree[name] = base;
|
|
1930
|
+
}
|
|
1931
|
+
return tree;
|
|
1932
|
+
}
|
|
1933
|
+
function suggest(token, candidates) {
|
|
1934
|
+
const dist = (a, b) => {
|
|
1935
|
+
const d = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)]);
|
|
1936
|
+
for (let j = 1;j <= b.length; j++)
|
|
1937
|
+
d[0][j] = j;
|
|
1938
|
+
for (let i = 1;i <= a.length; i++)
|
|
1939
|
+
for (let j = 1;j <= b.length; j++)
|
|
1940
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
1941
|
+
return d[a.length][b.length];
|
|
1942
|
+
};
|
|
1943
|
+
const best = candidates.map((c) => [c, dist(token, c)]).sort((x, y) => x[1] - y[1])[0];
|
|
1944
|
+
return best && best[1] <= 2 ? best[0] : undefined;
|
|
1945
|
+
}
|
|
1946
|
+
async function main(argv) {
|
|
1947
|
+
const root = findRoot();
|
|
1948
|
+
let config;
|
|
1949
|
+
if (root) {
|
|
1950
|
+
await loadDotEnv(root);
|
|
1951
|
+
config = await loadConfig(root);
|
|
1952
|
+
}
|
|
1953
|
+
const rt = { root, config };
|
|
1954
|
+
const leaves = await collectLeaves(root, config?.name);
|
|
1955
|
+
const tokens = commandTokens(argv);
|
|
1956
|
+
if (tokens[0] === "complete") {
|
|
1957
|
+
const { default: completion } = await import("./index-erv82p4z.js");
|
|
1958
|
+
const all = new Map;
|
|
1959
|
+
await Promise.all(leaves.map(async (l) => all.set(l, await l.load())));
|
|
1960
|
+
await cli(argv, { name: "kit", run: () => {} }, {
|
|
1961
|
+
name: "kit",
|
|
1962
|
+
version: package_default.version,
|
|
1963
|
+
subCommands: buildTree(leaves, all, rt),
|
|
1964
|
+
renderUsage: null,
|
|
1965
|
+
renderHeader: null,
|
|
1966
|
+
plugins: [completion()]
|
|
1967
|
+
});
|
|
1968
|
+
return 0;
|
|
1969
|
+
}
|
|
1970
|
+
const matches = leaves.filter((l) => startsWith(tokens, l.path)).sort((a, b) => b.path.length - a.path.length);
|
|
1971
|
+
const loaded = new Map;
|
|
1972
|
+
let target2;
|
|
1973
|
+
const longest = matches[0]?.path.length;
|
|
1974
|
+
for (const m of matches.filter((x) => x.path.length === longest)) {
|
|
1975
|
+
const cmd = await m.load();
|
|
1976
|
+
if (target2 && target2.source === "builtin" && m.source === "repo" && !cmd.override) {
|
|
1977
|
+
throw new KitError(`.kit/commands/${m.path.join("/")}.ts conflicts with built-in \`kit ${m.path.join(" ")}\``, "Rename it, or set `override: true` to replace the built-in", ExitCode.usage);
|
|
1978
|
+
}
|
|
1979
|
+
if (!target2 || m.source === "repo" && cmd.override) {
|
|
1980
|
+
if (target2)
|
|
1981
|
+
loaded.delete(target2);
|
|
1982
|
+
target2 = m;
|
|
1983
|
+
loaded.set(m, cmd);
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
const picked = target2 && loaded.get(target2);
|
|
1987
|
+
if (target2 && picked?.passthrough) {
|
|
1988
|
+
const rest = argv.slice(target2.path.length);
|
|
1989
|
+
await picked.run({ root, config, args: {}, positionals: [], rest, flags: computeFlags({}), log });
|
|
1990
|
+
return process.exitCode === undefined ? 0 : Number(process.exitCode);
|
|
1991
|
+
}
|
|
1992
|
+
const wantsHelp = argv.includes("--help") || argv.includes("-h");
|
|
1993
|
+
if (!target2 || wantsHelp) {
|
|
1994
|
+
const level = leaves.filter((l) => l.source === "repo" && startsWith(l.path, tokens.slice(0, l.path.length - 1)));
|
|
1995
|
+
await Promise.all(level.map(async (l) => loaded.set(l, await l.load())));
|
|
1996
|
+
for (const l of level) {
|
|
1997
|
+
l.description = loaded.get(l)?.description ?? "";
|
|
1998
|
+
l.override = loaded.get(l)?.override;
|
|
1999
|
+
}
|
|
2000
|
+
if (!target2)
|
|
2001
|
+
for (const l of level)
|
|
2002
|
+
loaded.delete(l);
|
|
2003
|
+
}
|
|
2004
|
+
if (!target2 && tokens.length) {
|
|
2005
|
+
let i = 0;
|
|
2006
|
+
while (i < tokens.length && leaves.some((l) => same(l.path.slice(0, i + 1), tokens.slice(0, i + 1))))
|
|
2007
|
+
i++;
|
|
2008
|
+
const isGroup = i === tokens.length;
|
|
2009
|
+
if (!isGroup) {
|
|
2010
|
+
const prefix = tokens.slice(0, i);
|
|
2011
|
+
const options = [...new Set(leaves.filter((l) => startsWith(l.path, prefix)).map((l) => l.path[i]))];
|
|
2012
|
+
const guess = suggest(tokens[i], options);
|
|
2013
|
+
throw new KitError(`Unknown command "${tokens.slice(0, i + 1).join(" ")}".${guess ? ` Did you mean "${[...prefix, guess].join(" ")}"?` : ""}`, `Run \`kit ${prefix.length ? `${prefix.join(" ")} ` : ""}--help\` to list commands`, ExitCode.usage);
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
const subCommands = buildTree(leaves, loaded, rt);
|
|
2017
|
+
const entry = {
|
|
2018
|
+
name: "kit",
|
|
2019
|
+
description: config ? `kit \xB7 ${config.name}` : "kit",
|
|
2020
|
+
run: () => {}
|
|
2021
|
+
};
|
|
2022
|
+
await cli(argv, entry, {
|
|
2023
|
+
name: "kit",
|
|
2024
|
+
version: package_default.version,
|
|
2025
|
+
description: "One dev toolkit for every app",
|
|
2026
|
+
subCommands,
|
|
2027
|
+
renderUsage: null,
|
|
2028
|
+
renderHeader: null,
|
|
2029
|
+
renderValidationErrors: null,
|
|
2030
|
+
plugins: [kitGlobals(package_default.version, renderUsage)]
|
|
2031
|
+
});
|
|
2032
|
+
return process.exitCode === undefined ? 0 : Number(process.exitCode);
|
|
2033
|
+
}
|
|
2034
|
+
installSignalHandlers();
|
|
2035
|
+
try {
|
|
2036
|
+
process.exitCode = await main(process.argv.slice(2));
|
|
2037
|
+
} catch (e) {
|
|
2038
|
+
if (e instanceof KitError) {
|
|
2039
|
+
log.error(e.message, e.hint);
|
|
2040
|
+
process.exitCode = e.exitCode;
|
|
2041
|
+
} else {
|
|
2042
|
+
log.error(e instanceof Error ? e.message : String(e));
|
|
2043
|
+
if (process.env.DEBUG?.includes("kit") && e instanceof Error)
|
|
2044
|
+
log.dim(e.stack ?? "");
|
|
2045
|
+
else
|
|
2046
|
+
log.dim(` ${import_picocolors2.default.dim("re-run with DEBUG=kit for a stack trace")}`);
|
|
2047
|
+
process.exitCode = ExitCode.failed;
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
if (interrupted())
|
|
2051
|
+
process.exitCode = ExitCode.interrupted;
|
|
2052
|
+
await runCleanup();
|