@rzl-zone/build-tools 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/.references/index.d.cts +18 -0
- package/dist/.references/index.d.ts +18 -0
- package/dist/bundler/rolldown.cjs +32 -0
- package/dist/bundler/rolldown.cjs.map +1 -0
- package/dist/bundler/rolldown.d.cts +162 -0
- package/dist/bundler/rolldown.d.ts +162 -0
- package/dist/bundler/rolldown.js +25 -0
- package/dist/bundler/rolldown.js.map +1 -0
- package/dist/bundler/tsdown.cjs +132 -0
- package/dist/bundler/tsdown.cjs.map +1 -0
- package/dist/bundler/tsdown.d.cts +1165 -0
- package/dist/bundler/tsdown.d.ts +1165 -0
- package/dist/bundler/tsdown.js +124 -0
- package/dist/bundler/tsdown.js.map +1 -0
- package/dist/bundler/utils.cjs +24 -0
- package/dist/bundler/utils.cjs.map +1 -0
- package/dist/bundler/utils.d.cts +40 -0
- package/dist/bundler/utils.d.ts +40 -0
- package/dist/bundler/utils.js +21 -0
- package/dist/bundler/utils.js.map +1 -0
- package/dist/client-XhkdKJ4d.js +160 -0
- package/dist/client-XhkdKJ4d.js.map +1 -0
- package/dist/client-u8yLSxEI.cjs +221 -0
- package/dist/client-u8yLSxEI.cjs.map +1 -0
- package/dist/commander-kit/index.cjs +569 -0
- package/dist/commander-kit/index.cjs.map +1 -0
- package/dist/commander-kit/index.d.cts +1383 -0
- package/dist/commander-kit/index.d.ts +1383 -0
- package/dist/commander-kit/index.js +550 -0
- package/dist/commander-kit/index.js.map +1 -0
- package/dist/extra-CVuXMpEw.d.ts +994 -0
- package/dist/extra-CxDwtQEy.d.cts +994 -0
- package/dist/fast-globe-options-6r2aj6UC.d.ts +126 -0
- package/dist/fast-globe-options-BFt__e__.d.cts +126 -0
- package/dist/helper-BdjaR8Yv.js +215 -0
- package/dist/helper-BdjaR8Yv.js.map +1 -0
- package/dist/helper-DorgNsB9.cjs +377 -0
- package/dist/helper-DorgNsB9.cjs.map +1 -0
- package/dist/identity-BJ0QX7AJ.js +88 -0
- package/dist/identity-BJ0QX7AJ.js.map +1 -0
- package/dist/identity-CxR9DRMh.cjs +100 -0
- package/dist/identity-CxR9DRMh.cjs.map +1 -0
- package/dist/index-B-NeF7PU.d.cts +670 -0
- package/dist/index-CzxZta4Z.d.ts +356 -0
- package/dist/index-Idak1iwg.d.cts +356 -0
- package/dist/index-PXsb85LI.d.ts +670 -0
- package/dist/index.cjs +1689 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2193 -0
- package/dist/index.d.ts +2193 -0
- package/dist/index.js +1641 -0
- package/dist/index.js.map +1 -0
- package/dist/package-banner-6RzEf-mV.cjs +54 -0
- package/dist/package-banner-6RzEf-mV.cjs.map +1 -0
- package/dist/package-banner-BzheZbxy.js +41 -0
- package/dist/package-banner-BzheZbxy.js.map +1 -0
- package/dist/server-B2hBoGDR.cjs +181 -0
- package/dist/server-B2hBoGDR.cjs.map +1 -0
- package/dist/server-CWrDd29Y.js +142 -0
- package/dist/server-CWrDd29Y.js.map +1 -0
- package/dist/utils/client.cjs +23 -0
- package/dist/utils/client.d.cts +887 -0
- package/dist/utils/client.d.ts +887 -0
- package/dist/utils/client.js +12 -0
- package/dist/utils/server.cjs +17 -0
- package/dist/utils/server.d.cts +124 -0
- package/dist/utils/server.d.ts +124 -0
- package/dist/utils/server.js +12 -0
- package/package.json +151 -0
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ========================================================================
|
|
3
|
+
* @rzl-zone/build-tools
|
|
4
|
+
* ------------------------------------------------------------------------
|
|
5
|
+
* Version: `0.0.5`
|
|
6
|
+
* Author: `Rizalvin Dwiky <rizalvindwiky1998@gmail.com>`
|
|
7
|
+
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/build-tools`
|
|
8
|
+
* ========================================================================
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { _ as isUndefined, c as isNil, i as isBoolean, l as isNonEmptyString, t as deepFreeze, u as isNull } from "../helper-BdjaR8Yv.js";
|
|
12
|
+
import { r as ICONS } from "../server-CWrDd29Y.js";
|
|
13
|
+
import { n as PACKAGE_META, t as CommandIdentity } from "../identity-BJ0QX7AJ.js";
|
|
14
|
+
import { a as joinInline, i as formatOptionValue, l as picocolors, n as EOL, s as joinLinesLoose, t as ConfigurationError } from "../client-XhkdKJ4d.js";
|
|
15
|
+
import "@rzl-zone/node-only";
|
|
16
|
+
import { parse } from "node:path";
|
|
17
|
+
import { Argument, Command, CommanderError, Help, InvalidArgumentError, InvalidOptionArgumentError, Option } from "commander";
|
|
18
|
+
function isCommanderError(err) {
|
|
19
|
+
return err instanceof CommanderError;
|
|
20
|
+
}
|
|
21
|
+
function formatCommanderError(err) {
|
|
22
|
+
if (err instanceof CommanderError) return err.message;
|
|
23
|
+
return String(err);
|
|
24
|
+
}
|
|
25
|
+
function getCommanderErrorCode(err) {
|
|
26
|
+
if (err instanceof CommanderError) return err.code;
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
var CliCommand = class extends Command {
|
|
30
|
+
constructor(name) {
|
|
31
|
+
name = isNonEmptyString(name) ? name : void 0;
|
|
32
|
+
super(name);
|
|
33
|
+
}
|
|
34
|
+
usage(str) {
|
|
35
|
+
if (str === false) {
|
|
36
|
+
super.usage("");
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
if (!isNonEmptyString(str)) return super.usage();
|
|
40
|
+
return super.usage(str);
|
|
41
|
+
}
|
|
42
|
+
version(str, flags, description) {
|
|
43
|
+
if (str === false) {
|
|
44
|
+
super.version("");
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
if (!isNonEmptyString(str)) return super.version();
|
|
48
|
+
return super.version(str, flags, description);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
function handleCommanderExit(err) {
|
|
52
|
+
if (isCommanderError(err)) {
|
|
53
|
+
const code = err.code;
|
|
54
|
+
if (code === "commander.helpDisplayed" || code === "commander.version") process.exit(0);
|
|
55
|
+
process.exit(err.exitCode ?? 1);
|
|
56
|
+
}
|
|
57
|
+
console.error(err);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
function isExactInstanceOf(value, ctor) {
|
|
61
|
+
//! Constraint: Immediately reject primitives
|
|
62
|
+
if (value === null || typeof value !== "object" && typeof value !== "function") return false;
|
|
63
|
+
return Object.getPrototypeOf(value) === ctor.prototype;
|
|
64
|
+
}
|
|
65
|
+
var CliHelp = class extends Help {
|
|
66
|
+
constructor() {
|
|
67
|
+
super();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var CliOption = class extends Option {
|
|
71
|
+
constructor(arg, description) {
|
|
72
|
+
super(arg, description);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const hasSymbolConstructor = typeof Symbol === "function" && typeof Symbol("x") === "symbol" && typeof Symbol.for === "function" && typeof Symbol.keyFor === "function";
|
|
76
|
+
const REGISTRY_KEY = "__rzl_global_symbol_registry__";
|
|
77
|
+
function getGlobal() {
|
|
78
|
+
if (typeof globalThis !== "undefined") return globalThis;
|
|
79
|
+
if (typeof self !== "undefined") return self;
|
|
80
|
+
if (typeof window !== "undefined") return window;
|
|
81
|
+
if (typeof global !== "undefined") return global;
|
|
82
|
+
return {};
|
|
83
|
+
}
|
|
84
|
+
function createUID() {
|
|
85
|
+
return Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2) + Date.now().toString(36);
|
|
86
|
+
}
|
|
87
|
+
function createLocalSymbol(desc) {
|
|
88
|
+
if (hasSymbolConstructor) return Symbol(desc);
|
|
89
|
+
return "@@rzl/local/" + (desc ?? "") + "/" + createUID();
|
|
90
|
+
}
|
|
91
|
+
function createGlobalSymbol(key) {
|
|
92
|
+
if (hasSymbolConstructor) return Symbol.for(key);
|
|
93
|
+
const registry = getRegistry();
|
|
94
|
+
if (registry.byKey[key]) return registry.byKey[key];
|
|
95
|
+
const value = "@@rzl/global/" + key + "/" + createUID();
|
|
96
|
+
registry.byKey[key] = value;
|
|
97
|
+
registry.byValue.set(value, key);
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
function getRegistry() {
|
|
101
|
+
const g = getGlobal();
|
|
102
|
+
if (!g[REGISTRY_KEY]) g[REGISTRY_KEY] = {
|
|
103
|
+
byKey: Object.create(null),
|
|
104
|
+
byValue: /* @__PURE__ */ new Map()
|
|
105
|
+
};
|
|
106
|
+
return g[REGISTRY_KEY];
|
|
107
|
+
}
|
|
108
|
+
const SymbolSafe = Object.assign(function SymbolSafe(description) {
|
|
109
|
+
return createLocalSymbol(description);
|
|
110
|
+
}, {
|
|
111
|
+
for(key) {
|
|
112
|
+
return createGlobalSymbol(key);
|
|
113
|
+
},
|
|
114
|
+
keyFor(sym) {
|
|
115
|
+
if (hasSymbolConstructor && typeof sym === "symbol") return Symbol.keyFor(sym);
|
|
116
|
+
return getRegistry().byValue.get(sym);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
const COMMANDER_INTERNAL_SYMBOL = SymbolSafe("rzl-built-tools:commander.internal");
|
|
120
|
+
function createDefaultInternalState() {
|
|
121
|
+
return {
|
|
122
|
+
ui: void 0,
|
|
123
|
+
help: void 0,
|
|
124
|
+
packageName: void 0,
|
|
125
|
+
manualUsage: void 0,
|
|
126
|
+
disableUsage: false,
|
|
127
|
+
versionMeta: void 0,
|
|
128
|
+
versionInjected: false,
|
|
129
|
+
versionDisable: false,
|
|
130
|
+
versionOriginal: void 0,
|
|
131
|
+
versionSetByUser: false
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const resetAllCommandInternal = (cmd) => {
|
|
135
|
+
const fresh = createDefaultInternalState();
|
|
136
|
+
if ("_internalState" in cmd && "_setInternalState" in cmd) {
|
|
137
|
+
cmd._setInternalState(fresh);
|
|
138
|
+
return fresh;
|
|
139
|
+
}
|
|
140
|
+
cmd[COMMANDER_INTERNAL_SYMBOL] = fresh;
|
|
141
|
+
return fresh;
|
|
142
|
+
};
|
|
143
|
+
function getInternalState(cmd) {
|
|
144
|
+
if ("_internalState" in cmd && "_setInternalState" in cmd) {
|
|
145
|
+
let state = cmd._internalState;
|
|
146
|
+
if (!state) {
|
|
147
|
+
state = resetAllCommandInternal(cmd);
|
|
148
|
+
cmd._setInternalState(state);
|
|
149
|
+
}
|
|
150
|
+
return state;
|
|
151
|
+
}
|
|
152
|
+
if (!cmd[COMMANDER_INTERNAL_SYMBOL]) cmd[COMMANDER_INTERNAL_SYMBOL] = resetAllCommandInternal(cmd);
|
|
153
|
+
return cmd[COMMANDER_INTERNAL_SYMBOL];
|
|
154
|
+
}
|
|
155
|
+
function setInternalUiState(cmd, input) {
|
|
156
|
+
const internal = getInternalState(cmd);
|
|
157
|
+
const sanitized = createUIState(input);
|
|
158
|
+
if (!internal.ui) {
|
|
159
|
+
internal.ui = sanitized;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
Object.assign(internal.ui, sanitized);
|
|
163
|
+
}
|
|
164
|
+
function createUIState(input) {
|
|
165
|
+
const result = {};
|
|
166
|
+
if (isNonEmptyString(input.title)) result.title = input.title;
|
|
167
|
+
if (isNonEmptyString(input.usage)) result.usage = input.usage;
|
|
168
|
+
if (isNonEmptyString(input.packageName)) result.packageName = input.packageName;
|
|
169
|
+
if (isNonEmptyString(input.version)) result.version = input.version;
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
function styleUsage(raw, { fromHelpCommandUsage, errorConfig: { field = "raw", expected = "a non-empty string", context = "styleUsage" } = {} } = {}) {
|
|
173
|
+
if (!isNonEmptyString(raw)) throw ConfigurationError.type(field, expected, raw, context);
|
|
174
|
+
return raw.split(/\s+/).map((token, index) => {
|
|
175
|
+
if (!!fromHelpCommandUsage && index === 0) return picocolors.cyanBright(token);
|
|
176
|
+
if (token === "[options]") return picocolors.blueBright(token);
|
|
177
|
+
if (token === "[command]") return picocolors.magentaBright(token);
|
|
178
|
+
if (token.startsWith("<") && token.endsWith(">")) return picocolors.gray(token);
|
|
179
|
+
if (token.startsWith("[") && token.endsWith("]")) return picocolors.gray(token);
|
|
180
|
+
return token;
|
|
181
|
+
}).join(" ");
|
|
182
|
+
}
|
|
183
|
+
function reorderUsage(raw, { errorConfig: { field = "raw", expected = "a non-empty string", context = "reorderUsage" } = {} } = {}) {
|
|
184
|
+
if (!isNonEmptyString(raw)) throw ConfigurationError.type(field, expected, raw, context);
|
|
185
|
+
const tokens = raw.match(/\S+/g) ?? [];
|
|
186
|
+
const optionTokens = tokens.filter((t) => t === "[options]");
|
|
187
|
+
return [...tokens.filter((t) => t !== "[options]"), ...optionTokens].join(" ");
|
|
188
|
+
}
|
|
189
|
+
var StyledHelp = class extends CliHelp {
|
|
190
|
+
constructor() {
|
|
191
|
+
super();
|
|
192
|
+
}
|
|
193
|
+
commandUsage(cmd) {
|
|
194
|
+
const { manualUsage, ui, disableUsage } = getInternalState(cmd);
|
|
195
|
+
if (disableUsage) return "";
|
|
196
|
+
if (isNonEmptyString(manualUsage)) return manualUsage;
|
|
197
|
+
if (isNonEmptyString(ui?.usage)) return ui.usage;
|
|
198
|
+
return styleUsage(reorderUsage(super.commandUsage(cmd), { errorConfig: {
|
|
199
|
+
field: "`super.commandUsage(cmd)`",
|
|
200
|
+
context: "StyledHelp.commandUsage"
|
|
201
|
+
} }), {
|
|
202
|
+
fromHelpCommandUsage: true,
|
|
203
|
+
errorConfig: {
|
|
204
|
+
field: "`reorderUsage(super.commandUsage(cmd))`",
|
|
205
|
+
context: "StyledHelp.commandUsage (by `reorderUsage(super.commandUsage(cmd))`)"
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
formatHelp(cmd, helper) {
|
|
210
|
+
const usage = this.commandUsage(cmd);
|
|
211
|
+
const usageBlock = joinLinesLoose(picocolors.reset("Usage:"), ` ${usage}`);
|
|
212
|
+
const rest = super.formatHelp(cmd, helper);
|
|
213
|
+
if (!usage) return rest.replace(/^Usage:[\s\S]*?\n(?=\S)/, "");
|
|
214
|
+
return rest.replace(/^Usage:[\s\S]*?\n(?=\S)/, usageBlock + EOL + EOL);
|
|
215
|
+
}
|
|
216
|
+
optionDescription(option) {
|
|
217
|
+
let desc = option.description || "";
|
|
218
|
+
const hasDefault = option.defaultValue !== void 0;
|
|
219
|
+
if (isNonEmptyString(desc)) {
|
|
220
|
+
desc = desc.trim();
|
|
221
|
+
if (hasDefault) {
|
|
222
|
+
if (desc.endsWith(".")) desc = desc.slice(0, -1) + "";
|
|
223
|
+
else if (!desc.endsWith(",")) desc += "";
|
|
224
|
+
desc += ` ${picocolors.italic(`(default: ${formatOptionValue(option.defaultValue)})`)}.`;
|
|
225
|
+
} else if (!desc.trim().endsWith(".")) desc += ".";
|
|
226
|
+
}
|
|
227
|
+
return desc;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
function resolveFactoryOriginErrorSuffix(programCommand) {
|
|
231
|
+
return isExactInstanceOf(programCommand, CommandBaseProgram) ? " by 'createBaseProgram' factory function" : "";
|
|
232
|
+
}
|
|
233
|
+
function resolveInstanceOriginErrorSuffix(programCommand) {
|
|
234
|
+
return isExactInstanceOf(programCommand, Command) ? "Command" : isExactInstanceOf(programCommand, CliCommand) ? "CliCommand" : "";
|
|
235
|
+
}
|
|
236
|
+
function interceptUsage(cmd) {
|
|
237
|
+
const originalUsage = cmd.usage.bind(cmd);
|
|
238
|
+
function usage(str) {
|
|
239
|
+
if (!isNil(str)) {
|
|
240
|
+
if (str === false) {
|
|
241
|
+
getInternalState(cmd).manualUsage = void 0;
|
|
242
|
+
getInternalState(cmd).disableUsage = true;
|
|
243
|
+
return cmd;
|
|
244
|
+
}
|
|
245
|
+
if (!isNonEmptyString(str)) {
|
|
246
|
+
const errorMessageByFactory = resolveFactoryOriginErrorSuffix(cmd);
|
|
247
|
+
const errorMessageInstance = resolveInstanceOriginErrorSuffix(cmd);
|
|
248
|
+
throw ConfigurationError.type("usage", "a non-empty string or `false` only", str, `'${errorMessageInstance}.usage'${errorMessageByFactory}`);
|
|
249
|
+
}
|
|
250
|
+
getInternalState(cmd).manualUsage = str;
|
|
251
|
+
return originalUsage(str);
|
|
252
|
+
}
|
|
253
|
+
return originalUsage();
|
|
254
|
+
}
|
|
255
|
+
cmd.usage = usage;
|
|
256
|
+
}
|
|
257
|
+
const COMMANDER_UI_DEFAULTS = deepFreeze({
|
|
258
|
+
FLAGS: {
|
|
259
|
+
VERSION: "-v, --version",
|
|
260
|
+
HELP: "-h, --help"
|
|
261
|
+
},
|
|
262
|
+
DESCRIPTIONS: {
|
|
263
|
+
HELP: "To display help for this command.",
|
|
264
|
+
VERSION: "The version package of this command."
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
const { DESCRIPTIONS: DESCRIPTIONS$2, FLAGS: FLAGS$3 } = COMMANDER_UI_DEFAULTS;
|
|
268
|
+
function interceptHelp(cmd) {
|
|
269
|
+
function resetInternalHelpState(cmd) {
|
|
270
|
+
getInternalState(cmd).help = void 0;
|
|
271
|
+
}
|
|
272
|
+
const original = cmd.helpOption.bind(cmd);
|
|
273
|
+
cmd.helpOption = function(flags, description) {
|
|
274
|
+
const errorMessageByFactory = resolveFactoryOriginErrorSuffix(cmd);
|
|
275
|
+
const errorMessageInstance = resolveInstanceOriginErrorSuffix(cmd);
|
|
276
|
+
if (!isNil(flags) && !isNonEmptyString(flags) && !isBoolean(flags)) {
|
|
277
|
+
resetInternalHelpState(cmd);
|
|
278
|
+
throw ConfigurationError.type("flags", "a non-empty string or a boolean", flags, `'${errorMessageInstance}.helpOption'${errorMessageByFactory}`);
|
|
279
|
+
}
|
|
280
|
+
if (!isNil(description) && !isNonEmptyString(description)) {
|
|
281
|
+
resetInternalHelpState(cmd);
|
|
282
|
+
throw ConfigurationError.type("description", "a non-empty string if provided", description, `'${errorMessageInstance}.helpOption'${errorMessageByFactory}`);
|
|
283
|
+
}
|
|
284
|
+
const _decs = isNonEmptyString(description) ? description : DESCRIPTIONS$2.HELP;
|
|
285
|
+
if (flags === false) {
|
|
286
|
+
getInternalState(cmd).help = { disabled: true };
|
|
287
|
+
return original(flags);
|
|
288
|
+
}
|
|
289
|
+
if (flags === true) {
|
|
290
|
+
getInternalState(cmd).help = {
|
|
291
|
+
flags: FLAGS$3.HELP,
|
|
292
|
+
description: _decs,
|
|
293
|
+
disabled: false
|
|
294
|
+
};
|
|
295
|
+
return original(flags, _decs);
|
|
296
|
+
}
|
|
297
|
+
if (isNonEmptyString(flags)) {
|
|
298
|
+
getInternalState(cmd).help = {
|
|
299
|
+
flags,
|
|
300
|
+
description: _decs,
|
|
301
|
+
disabled: false
|
|
302
|
+
};
|
|
303
|
+
return original(flags, _decs);
|
|
304
|
+
}
|
|
305
|
+
return original(flags, _decs);
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
const { FLAGS: FLAGS$2 } = COMMANDER_UI_DEFAULTS;
|
|
309
|
+
function interceptVersion(cmd, versionDescription) {
|
|
310
|
+
const originalVersion = cmd.version.bind(cmd);
|
|
311
|
+
getInternalState(cmd).versionOriginal = originalVersion;
|
|
312
|
+
function version(value, flags, description) {
|
|
313
|
+
if (arguments.length === 0) return originalVersion();
|
|
314
|
+
if (value === false) {
|
|
315
|
+
getInternalState(cmd).versionDisable = true;
|
|
316
|
+
getInternalState(cmd).versionOriginal = void 0;
|
|
317
|
+
return cmd;
|
|
318
|
+
}
|
|
319
|
+
const errorMessageByFactory = resolveFactoryOriginErrorSuffix(cmd);
|
|
320
|
+
const errorMessageInstance = resolveInstanceOriginErrorSuffix(cmd);
|
|
321
|
+
if (!isNonEmptyString(value)) throw ConfigurationError.type("str", "a non-empty string", value, `'${errorMessageInstance}.version'${errorMessageByFactory}`);
|
|
322
|
+
if (!isNil(flags) && !isNonEmptyString(flags)) throw ConfigurationError.type("flags", "a non-empty string if provided", flags, `'${errorMessageInstance}.version'${errorMessageByFactory}`);
|
|
323
|
+
if (!isNil(description) && !isNonEmptyString(description)) throw ConfigurationError.type("description", "a non-empty string if provided", description, `'${errorMessageInstance}.version'${errorMessageByFactory}`);
|
|
324
|
+
const _flag = isNonEmptyString(flags) ? flags : FLAGS$2.VERSION;
|
|
325
|
+
const _decs = isNonEmptyString(description) ? description : versionDescription;
|
|
326
|
+
getInternalState(cmd).versionMeta = {
|
|
327
|
+
value,
|
|
328
|
+
flags: _flag,
|
|
329
|
+
description: _decs
|
|
330
|
+
};
|
|
331
|
+
getInternalState(cmd).versionSetByUser = true;
|
|
332
|
+
return originalVersion(value, _flag, _decs);
|
|
333
|
+
}
|
|
334
|
+
cmd.version = version;
|
|
335
|
+
}
|
|
336
|
+
var CliArgument = class extends Argument {
|
|
337
|
+
constructor(arg, description) {
|
|
338
|
+
super(arg, description);
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
const { DESCRIPTIONS: DESCRIPTIONS$1, FLAGS: FLAGS$1 } = COMMANDER_UI_DEFAULTS;
|
|
342
|
+
const composeVersionDescription = (packageName) => {
|
|
343
|
+
const isPkgNameEmptyString = !isNonEmptyString(packageName);
|
|
344
|
+
if (!isUndefined(packageName) && isPkgNameEmptyString) throw ConfigurationError.type("packageName", "a non-empty string", packageName, "composeVersionDescription");
|
|
345
|
+
return (!isPkgNameEmptyString ? `The version package of ${packageName}.` : DESCRIPTIONS$1.VERSION).trim().replace(/\.*$/, "") + ".";
|
|
346
|
+
};
|
|
347
|
+
function normalizeVersionPrefix(version) {
|
|
348
|
+
if (!isNil(version) && !isNonEmptyString(version)) throw ConfigurationError.type("version", "a non-empty string, null or undefined", version, "composeVersionDescription");
|
|
349
|
+
if (isNull(version)) return null;
|
|
350
|
+
return version?.replace(/^v(?=\d)/, "");
|
|
351
|
+
}
|
|
352
|
+
function ensureVersionInjected(cmd, options) {
|
|
353
|
+
const { pkgNameFormatted, normalizedVersion } = options;
|
|
354
|
+
const _internal = getInternalState(cmd);
|
|
355
|
+
if (!_internal.versionSetByUser && !_internal.versionInjected) {
|
|
356
|
+
const _isNonEmptyString = isNonEmptyString(pkgNameFormatted);
|
|
357
|
+
const _pkgName = _isNonEmptyString ? pkgNameFormatted : void 0;
|
|
358
|
+
const _subTitle = _isNonEmptyString ? `${pkgNameFormatted} ${picocolors.reset("version")}:` : `${picocolors.blueBright("Version")}:`;
|
|
359
|
+
_internal.versionOriginal?.(joinLinesLoose(_subTitle, joinInline(`${picocolors.magentaBright(ICONS.arrowRight)}`, `${picocolors.gray(`v${normalizedVersion}`)}`)), FLAGS$1.VERSION, composeVersionDescription(_pkgName));
|
|
360
|
+
_internal.versionInjected = true;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
function resolveBaseProgramPresentationMeta(params) {
|
|
364
|
+
const { cliName, packageName, packageVersion, commandIdentity, ui } = params;
|
|
365
|
+
const resolvedCliName = isNonEmptyString(cliName) ? cliName : isNonEmptyString(commandIdentity?.commandName) ? commandIdentity.commandName : isNonEmptyString(process.argv[1]) ? parse(process.argv[1]).name : void 0;
|
|
366
|
+
const identityTitle = commandIdentity?.cli?.();
|
|
367
|
+
const commandTitle = isNonEmptyString(identityTitle) ? identityTitle : isNonEmptyString(ui?.title) ? ui.title : void 0;
|
|
368
|
+
const resolvedPackageName = isNonEmptyString(packageName) ? packageName : isNonEmptyString(commandIdentity?.packageName) ? commandIdentity.packageName : PACKAGE_META.name;
|
|
369
|
+
const resolvedPackageVersion = isNonEmptyString(packageVersion) ? packageVersion : isNonEmptyString(commandIdentity?.version) ? commandIdentity.version : PACKAGE_META.version;
|
|
370
|
+
const normalizedVersion = normalizeVersionPrefix(resolvedPackageVersion);
|
|
371
|
+
const isDiffCommandName = !!resolvedCliName && resolvedCliName !== PACKAGE_META.name;
|
|
372
|
+
const pkgNameFormatted = `${picocolors.blueBright(resolvedPackageName)}${isDiffCommandName ? ` ${picocolors.cyanBright(`(${resolvedCliName})`)}` : ""}`;
|
|
373
|
+
const defaultTitleFormatted = joinInline(picocolors.blueBright(PACKAGE_META.name + "@" + normalizedVersion), isDiffCommandName ? `${picocolors.magentaBright(ICONS.arrowRight)} ${picocolors.yellowBright(resolvedCliName)}` : false);
|
|
374
|
+
return Object.freeze({
|
|
375
|
+
resolvedCliName,
|
|
376
|
+
commandTitle,
|
|
377
|
+
resolvedPackageName,
|
|
378
|
+
resolvedPackageVersion,
|
|
379
|
+
normalizedVersion,
|
|
380
|
+
isDiffCommandName,
|
|
381
|
+
pkgNameFormatted,
|
|
382
|
+
defaultTitleFormatted
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
function installParseVersionInterceptor(program, options) {
|
|
386
|
+
const { versionInjection } = options;
|
|
387
|
+
const originalParse = program.parse.bind(program);
|
|
388
|
+
const originalParseAsync = program.parseAsync.bind(program);
|
|
389
|
+
program.parse = function(...args) {
|
|
390
|
+
ensureVersionInjected(program, versionInjection);
|
|
391
|
+
return originalParse(...args);
|
|
392
|
+
};
|
|
393
|
+
program.parseAsync = async function(...args) {
|
|
394
|
+
ensureVersionInjected(program, versionInjection);
|
|
395
|
+
return originalParseAsync(...args);
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
var CommandBaseProgram = class CommandBaseProgram extends CliCommand {
|
|
399
|
+
_internalStateData;
|
|
400
|
+
constructor(name) {
|
|
401
|
+
super(name);
|
|
402
|
+
this._internalStateData = createDefaultInternalState();
|
|
403
|
+
}
|
|
404
|
+
get _internalState() {
|
|
405
|
+
return this._internalStateData;
|
|
406
|
+
}
|
|
407
|
+
_setInternalState(state) {
|
|
408
|
+
this._internalStateData = state;
|
|
409
|
+
}
|
|
410
|
+
createCommand(name) {
|
|
411
|
+
const sub = new CommandBaseProgram(name);
|
|
412
|
+
sub._setInternalState({ ...this._internalState });
|
|
413
|
+
return sub;
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
function createBaseProgram(options = {}) {
|
|
417
|
+
if (options.commandIdentity && !isExactInstanceOf(options.commandIdentity, CommandIdentity)) throw ConfigurationError.type("options.commandIdentity", "instanceof CommandIdentity", options.commandIdentity, "createBaseProgram");
|
|
418
|
+
const { commandTitle, defaultTitleFormatted, normalizedVersion, pkgNameFormatted, resolvedCliName, resolvedPackageName } = resolveBaseProgramPresentationMeta(options);
|
|
419
|
+
const cmd = new CommandBaseProgram(resolvedCliName);
|
|
420
|
+
cmd._setInternalState({
|
|
421
|
+
...createDefaultInternalState(),
|
|
422
|
+
ui: createUIState(options.ui || {}),
|
|
423
|
+
packageName: resolvedPackageName
|
|
424
|
+
});
|
|
425
|
+
interceptUsage(cmd);
|
|
426
|
+
interceptHelp(cmd);
|
|
427
|
+
interceptVersion(cmd, composeVersionDescription(pkgNameFormatted));
|
|
428
|
+
cmd.createHelp = () => new StyledHelp();
|
|
429
|
+
cmd.addHelpText("before", joinLinesLoose("", commandTitle ?? defaultTitleFormatted, ""));
|
|
430
|
+
cmd.exitOverride(handleCommanderExit);
|
|
431
|
+
const cmdApplyUi = applyCommanderUi(cmd, {
|
|
432
|
+
title: commandTitle,
|
|
433
|
+
usage: options.ui?.usage,
|
|
434
|
+
__commandName: resolvedCliName
|
|
435
|
+
});
|
|
436
|
+
installParseVersionInterceptor(cmdApplyUi, { versionInjection: {
|
|
437
|
+
normalizedVersion,
|
|
438
|
+
pkgNameFormatted
|
|
439
|
+
} });
|
|
440
|
+
return cmdApplyUi;
|
|
441
|
+
}
|
|
442
|
+
const { DESCRIPTIONS, FLAGS } = COMMANDER_UI_DEFAULTS;
|
|
443
|
+
function resolveCliPresentationMeta(params) {
|
|
444
|
+
const { program, commandName, title, version, packageName } = params;
|
|
445
|
+
const _internal = getInternalState(program);
|
|
446
|
+
const isCommandBaseProgram = isExactInstanceOf(program, CommandBaseProgram);
|
|
447
|
+
const resolvedCliName = isNonEmptyString(commandName) ? commandName : isNonEmptyString(process.argv[1]) ? parse(process.argv[1]).name : void 0;
|
|
448
|
+
const isDiffCommandName = !!resolvedCliName && resolvedCliName !== PACKAGE_META.name;
|
|
449
|
+
const commandTitle = isNonEmptyString(commandName) ? commandName : isNonEmptyString(title) ? title : void 0;
|
|
450
|
+
let normalizedVersion = normalizeVersionPrefix(!isCommandBaseProgram && isNonEmptyString(version) ? version : isNonEmptyString(_internal.versionMeta?.value) ? _internal.versionMeta.value : void 0);
|
|
451
|
+
normalizedVersion = isNonEmptyString(normalizedVersion) ? normalizedVersion : normalizeVersionPrefix(PACKAGE_META.version);
|
|
452
|
+
const defaultTitleFormatted = joinInline(picocolors.blueBright((isNonEmptyString(_internal.packageName) ? _internal.packageName : PACKAGE_META.name) + "@" + normalizedVersion), isDiffCommandName ? `${picocolors.magentaBright(ICONS.arrowRight)} ${picocolors.yellowBright(resolvedCliName)}` : false);
|
|
453
|
+
const dynamicUsage = isNonEmptyString(_internal.manualUsage) ? _internal.manualUsage : isNonEmptyString(_internal.ui?.usage) ? _internal.ui.usage : (isDiffCommandName ? `${picocolors.cyanBright(resolvedCliName)} ` : "") + (isNonEmptyString(program.usage()) ? styleUsage(reorderUsage(program.usage(), { errorConfig: {
|
|
454
|
+
field: "`program.usage()`",
|
|
455
|
+
context: "resolveCliPresentationMeta (by `program.usage()` at const variable 'dynamicUsage')"
|
|
456
|
+
} }), { errorConfig: {
|
|
457
|
+
field: "`reorderUsage(program.usage())`",
|
|
458
|
+
context: "resolveCliPresentationMeta (by `reorderUsage(program.usage())` at const variable 'dynamicUsage')"
|
|
459
|
+
} }) : "");
|
|
460
|
+
const resolvedPackageName = isNonEmptyString(packageName) ? packageName : PACKAGE_META.name;
|
|
461
|
+
const resolvedPackageNameFormatted = `${picocolors.blueBright(resolvedPackageName)}${isDiffCommandName ? ` ${picocolors.cyanBright(`(${resolvedCliName})`)}` : ""}`;
|
|
462
|
+
const helpMeta = _internal.help;
|
|
463
|
+
const isHelpDisabled = helpMeta?.disabled === true;
|
|
464
|
+
const helpFlags = helpMeta?.flags ?? FLAGS.HELP;
|
|
465
|
+
const helpDesc = helpMeta?.description ?? DESCRIPTIONS.HELP;
|
|
466
|
+
return Object.freeze({
|
|
467
|
+
resolvedCliName,
|
|
468
|
+
resolvedPackageName,
|
|
469
|
+
resolvedPackageNameFormatted,
|
|
470
|
+
isDiffCommandName,
|
|
471
|
+
commandTitle,
|
|
472
|
+
normalizedVersion,
|
|
473
|
+
defaultTitleFormatted,
|
|
474
|
+
dynamicUsage,
|
|
475
|
+
help: {
|
|
476
|
+
meta: helpMeta,
|
|
477
|
+
disabled: isHelpDisabled,
|
|
478
|
+
flags: helpFlags,
|
|
479
|
+
description: helpDesc
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
function applyCommanderUi(program, options) {
|
|
484
|
+
const { title, usage, version, packageName, __commandName } = options;
|
|
485
|
+
if (!isExactInstanceOf(program, Command) && !isExactInstanceOf(program, CliCommand) && !isExactInstanceOf(program, CommandBaseProgram)) throw ConfigurationError.type("program", "instanceof Command, CliCommand or create by factory function 'createBaseProgram'", program, "applyCommanderUi");
|
|
486
|
+
setInternalUiState(program, {
|
|
487
|
+
title,
|
|
488
|
+
usage
|
|
489
|
+
});
|
|
490
|
+
if (!isExactInstanceOf(program, CommandBaseProgram)) {
|
|
491
|
+
const { commandTitle, defaultTitleFormatted, normalizedVersion, resolvedPackageNameFormatted } = resolveCliPresentationMeta({
|
|
492
|
+
program,
|
|
493
|
+
commandName: __commandName,
|
|
494
|
+
version,
|
|
495
|
+
packageName,
|
|
496
|
+
title
|
|
497
|
+
});
|
|
498
|
+
interceptUsage(program);
|
|
499
|
+
interceptHelp(program);
|
|
500
|
+
interceptVersion(program, composeVersionDescription(resolvedPackageNameFormatted));
|
|
501
|
+
program.createHelp = () => new StyledHelp();
|
|
502
|
+
program.addHelpText("before", joinLinesLoose("", commandTitle ?? defaultTitleFormatted, ""));
|
|
503
|
+
program.exitOverride(handleCommanderExit);
|
|
504
|
+
installParseVersionInterceptor(program, { versionInjection: {
|
|
505
|
+
normalizedVersion,
|
|
506
|
+
pkgNameFormatted: resolvedPackageNameFormatted
|
|
507
|
+
} });
|
|
508
|
+
}
|
|
509
|
+
program.error = function(message) {
|
|
510
|
+
let errMsg = message.replace(/^error:\s*/i, "");
|
|
511
|
+
errMsg = errMsg.trim().replace(/\.*$/, "") + ".";
|
|
512
|
+
const { disableUsage } = getInternalState(program);
|
|
513
|
+
const { defaultTitleFormatted, dynamicUsage, help } = resolveCliPresentationMeta({
|
|
514
|
+
program,
|
|
515
|
+
title,
|
|
516
|
+
commandName: __commandName
|
|
517
|
+
});
|
|
518
|
+
const printOut = [
|
|
519
|
+
isNonEmptyString(title) ? title : defaultTitleFormatted,
|
|
520
|
+
"",
|
|
521
|
+
`${picocolors.bold(`${picocolors.red(`${ICONS.error} Error`)}`)} ${picocolors.redBright(errMsg)}`
|
|
522
|
+
];
|
|
523
|
+
if (!disableUsage && isNonEmptyString(dynamicUsage)) printOut.push("", picocolors.bold("Usage:"), ` ${picocolors.reset(picocolors.gray(dynamicUsage))}`);
|
|
524
|
+
if (!help.disabled) printOut.push("", `${picocolors.dim("Run")} ${picocolors.cyanBright(help.flags)} ${picocolors.dim(help.description)}`);
|
|
525
|
+
console.error(joinLinesLoose(...printOut));
|
|
526
|
+
process.exit(1);
|
|
527
|
+
};
|
|
528
|
+
return program;
|
|
529
|
+
}
|
|
530
|
+
const cliProgram = new CliCommand();
|
|
531
|
+
var CliCommanderError = class extends CommanderError {
|
|
532
|
+
constructor(exitCode, code, message) {
|
|
533
|
+
super(exitCode, code, message);
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
var CliInvalidArgumentError = class extends InvalidArgumentError {
|
|
537
|
+
constructor(message) {
|
|
538
|
+
super(message);
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
var CliInvalidOptionArgumentError = class extends InvalidOptionArgumentError {
|
|
542
|
+
constructor(message) {
|
|
543
|
+
super(message);
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
const cliCreateArgument = (name, description) => new CliArgument(name, description);
|
|
547
|
+
const cliCreateCommand = (name) => new CliCommand(name);
|
|
548
|
+
const cliCreateOption = (arg, description) => new CliOption(arg, description);
|
|
549
|
+
export { CliArgument, CliCommand, CliCommanderError, CliHelp, CliInvalidArgumentError, CliInvalidOptionArgumentError, CliOption, CommandIdentity, applyCommanderUi, cliCreateArgument, cliCreateCommand, cliCreateOption, cliProgram, createBaseProgram, formatCommanderError, getCommanderErrorCode, handleCommanderExit, isCommanderError };
|
|
550
|
+
//# sourceMappingURL=index.js.map
|