@stacksjs/buddy 0.58.72 → 0.58.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-1a569f35f66ae151.js +10945 -0
- package/dist/{chunk-59a9de11428ba763.js → chunk-bf054cfbc9cf2201.js} +4 -4
- package/dist/cli.js +27 -610
- package/dist/index.js +8 -2
- package/dist/stacks +0 -0
- package/package.json +3 -3
- package/src/cli.ts +20 -20
- package/src/commands/check.ts +45 -0
- package/src/commands/create.ts +6 -0
- package/src/commands/generate.ts +10 -0
- package/src/commands/index.ts +3 -0
- package/src/commands/ports.ts +73 -0
- package/src/commands/projects.ts +59 -0
- package/src/commands/setup.ts +8 -54
- package/src/commands/upgrade.ts +51 -4
- package/dist/chunk-94f0ae38d2d27d78.js +0 -1932
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// ../../../../node_modules/consola/dist/core.mjs
|
|
2
2
|
var isObject = function(value) {
|
|
3
3
|
return value !== null && typeof value === "object";
|
|
4
4
|
};
|
|
@@ -377,7 +377,7 @@ Consola.prototype.mock = Consola.prototype.mockTypes;
|
|
|
377
377
|
Consola.prototype.pause = Consola.prototype.pauseLogs;
|
|
378
378
|
Consola.prototype.resume = Consola.prototype.resumeLogs;
|
|
379
379
|
|
|
380
|
-
//
|
|
380
|
+
// ../../../../node_modules/consola/dist/shared/consola.06ad8a64.mjs
|
|
381
381
|
import {formatWithOptions} from "util";
|
|
382
382
|
import {sep} from "path";
|
|
383
383
|
var parseStack = function(stack) {
|
|
@@ -434,7 +434,7 @@ class BasicReporter {
|
|
|
434
434
|
}
|
|
435
435
|
}
|
|
436
436
|
|
|
437
|
-
//
|
|
437
|
+
// ../../../../node_modules/consola/dist/utils.mjs
|
|
438
438
|
import * as tty from "tty";
|
|
439
439
|
var replaceClose = function(index, string, close, replace, head = string.slice(0, Math.max(0, index)) + replace, tail = string.slice(Math.max(0, index + close.length)), next = tail.indexOf(close)) {
|
|
440
440
|
return head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
|
|
@@ -644,7 +644,7 @@ var defaultStyle = {
|
|
|
644
644
|
marginBottom: 1
|
|
645
645
|
};
|
|
646
646
|
|
|
647
|
-
//
|
|
647
|
+
// ../../../../node_modules/consola/dist/shared/consola.36c0034f.mjs
|
|
648
648
|
import process$1 from "process";
|
|
649
649
|
var detectProvider = function(env2) {
|
|
650
650
|
for (const provider of providers) {
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
|
+
CAC,
|
|
3
4
|
build,
|
|
4
5
|
changelog,
|
|
6
|
+
check,
|
|
5
7
|
clean,
|
|
6
8
|
cloud,
|
|
7
9
|
configure,
|
|
@@ -16,612 +18,19 @@ install,
|
|
|
16
18
|
key,
|
|
17
19
|
lint,
|
|
18
20
|
list,
|
|
21
|
+
ports,
|
|
22
|
+
projects,
|
|
19
23
|
release,
|
|
20
24
|
setup,
|
|
21
|
-
upgrade
|
|
22
|
-
|
|
25
|
+
upgrade,
|
|
26
|
+
version
|
|
27
|
+
} from "./chunk-1a569f35f66ae151.js";
|
|
23
28
|
import"./chunk-0455e53fab4244b1.js";
|
|
24
|
-
import"./chunk-
|
|
25
|
-
|
|
26
|
-
// src/cli.ts
|
|
27
|
-
import process2 from "process";
|
|
28
|
-
import {handleError} from "@stacksjs/error-handling";
|
|
29
|
-
|
|
30
|
-
// /home/runner/work/stacks/stacks/node_modules/cac/dist/index.mjs
|
|
31
|
-
import {EventEmitter} from "events";
|
|
32
|
-
var toArr = function(any) {
|
|
33
|
-
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
34
|
-
};
|
|
35
|
-
var toVal = function(out, key2, val, opts) {
|
|
36
|
-
var x, old = out[key2], nxt = ~opts.string.indexOf(key2) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : ~opts.boolean.indexOf(key2) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
|
|
37
|
-
out[key2] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
|
|
38
|
-
};
|
|
39
|
-
var mri2 = function(args, opts) {
|
|
40
|
-
args = args || [];
|
|
41
|
-
opts = opts || {};
|
|
42
|
-
var k, arr, arg, name, val, out = { _: [] };
|
|
43
|
-
var i = 0, j = 0, idx = 0, len = args.length;
|
|
44
|
-
const alibi = opts.alias !== undefined;
|
|
45
|
-
const strict = opts.unknown !== undefined;
|
|
46
|
-
const defaults = opts.default !== undefined;
|
|
47
|
-
opts.alias = opts.alias || {};
|
|
48
|
-
opts.string = toArr(opts.string);
|
|
49
|
-
opts.boolean = toArr(opts.boolean);
|
|
50
|
-
if (alibi) {
|
|
51
|
-
for (k in opts.alias) {
|
|
52
|
-
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
53
|
-
for (i = 0;i < arr.length; i++) {
|
|
54
|
-
(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
for (i = opts.boolean.length;i-- > 0; ) {
|
|
59
|
-
arr = opts.alias[opts.boolean[i]] || [];
|
|
60
|
-
for (j = arr.length;j-- > 0; )
|
|
61
|
-
opts.boolean.push(arr[j]);
|
|
62
|
-
}
|
|
63
|
-
for (i = opts.string.length;i-- > 0; ) {
|
|
64
|
-
arr = opts.alias[opts.string[i]] || [];
|
|
65
|
-
for (j = arr.length;j-- > 0; )
|
|
66
|
-
opts.string.push(arr[j]);
|
|
67
|
-
}
|
|
68
|
-
if (defaults) {
|
|
69
|
-
for (k in opts.default) {
|
|
70
|
-
name = typeof opts.default[k];
|
|
71
|
-
arr = opts.alias[k] = opts.alias[k] || [];
|
|
72
|
-
if (opts[name] !== undefined) {
|
|
73
|
-
opts[name].push(k);
|
|
74
|
-
for (i = 0;i < arr.length; i++) {
|
|
75
|
-
opts[name].push(arr[i]);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
const keys = strict ? Object.keys(opts.alias) : [];
|
|
81
|
-
for (i = 0;i < len; i++) {
|
|
82
|
-
arg = args[i];
|
|
83
|
-
if (arg === "--") {
|
|
84
|
-
out._ = out._.concat(args.slice(++i));
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
for (j = 0;j < arg.length; j++) {
|
|
88
|
-
if (arg.charCodeAt(j) !== 45)
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
if (j === 0) {
|
|
92
|
-
out._.push(arg);
|
|
93
|
-
} else if (arg.substring(j, j + 3) === "no-") {
|
|
94
|
-
name = arg.substring(j + 3);
|
|
95
|
-
if (strict && !~keys.indexOf(name)) {
|
|
96
|
-
return opts.unknown(arg);
|
|
97
|
-
}
|
|
98
|
-
out[name] = false;
|
|
99
|
-
} else {
|
|
100
|
-
for (idx = j + 1;idx < arg.length; idx++) {
|
|
101
|
-
if (arg.charCodeAt(idx) === 61)
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
name = arg.substring(j, idx);
|
|
105
|
-
val = arg.substring(++idx) || (i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i]);
|
|
106
|
-
arr = j === 2 ? [name] : name;
|
|
107
|
-
for (idx = 0;idx < arr.length; idx++) {
|
|
108
|
-
name = arr[idx];
|
|
109
|
-
if (strict && !~keys.indexOf(name))
|
|
110
|
-
return opts.unknown("-".repeat(j) + name);
|
|
111
|
-
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (defaults) {
|
|
116
|
-
for (k in opts.default) {
|
|
117
|
-
if (out[k] === undefined) {
|
|
118
|
-
out[k] = opts.default[k];
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (alibi) {
|
|
123
|
-
for (k in out) {
|
|
124
|
-
arr = opts.alias[k] || [];
|
|
125
|
-
while (arr.length > 0) {
|
|
126
|
-
out[arr.shift()] = out[k];
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return out;
|
|
131
|
-
};
|
|
132
|
-
var removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
|
|
133
|
-
var findAllBrackets = (v) => {
|
|
134
|
-
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
|
135
|
-
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
|
136
|
-
const res = [];
|
|
137
|
-
const parse = (match) => {
|
|
138
|
-
let variadic = false;
|
|
139
|
-
let value = match[1];
|
|
140
|
-
if (value.startsWith("...")) {
|
|
141
|
-
value = value.slice(3);
|
|
142
|
-
variadic = true;
|
|
143
|
-
}
|
|
144
|
-
return {
|
|
145
|
-
required: match[0].startsWith("<"),
|
|
146
|
-
value,
|
|
147
|
-
variadic
|
|
148
|
-
};
|
|
149
|
-
};
|
|
150
|
-
let angledMatch;
|
|
151
|
-
while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) {
|
|
152
|
-
res.push(parse(angledMatch));
|
|
153
|
-
}
|
|
154
|
-
let squareMatch;
|
|
155
|
-
while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) {
|
|
156
|
-
res.push(parse(squareMatch));
|
|
157
|
-
}
|
|
158
|
-
return res;
|
|
159
|
-
};
|
|
160
|
-
var getMriOptions = (options) => {
|
|
161
|
-
const result = { alias: {}, boolean: [] };
|
|
162
|
-
for (const [index, option] of options.entries()) {
|
|
163
|
-
if (option.names.length > 1) {
|
|
164
|
-
result.alias[option.names[0]] = option.names.slice(1);
|
|
165
|
-
}
|
|
166
|
-
if (option.isBoolean) {
|
|
167
|
-
if (option.negated) {
|
|
168
|
-
const hasStringTypeOption = options.some((o, i) => {
|
|
169
|
-
return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
|
|
170
|
-
});
|
|
171
|
-
if (!hasStringTypeOption) {
|
|
172
|
-
result.boolean.push(option.names[0]);
|
|
173
|
-
}
|
|
174
|
-
} else {
|
|
175
|
-
result.boolean.push(option.names[0]);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return result;
|
|
180
|
-
};
|
|
181
|
-
var findLongest = (arr) => {
|
|
182
|
-
return arr.sort((a, b) => {
|
|
183
|
-
return a.length > b.length ? -1 : 1;
|
|
184
|
-
})[0];
|
|
185
|
-
};
|
|
186
|
-
var padRight = (str, length) => {
|
|
187
|
-
return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
|
188
|
-
};
|
|
189
|
-
var camelcase = (input) => {
|
|
190
|
-
return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
|
|
191
|
-
return p1 + p2.toUpperCase();
|
|
192
|
-
});
|
|
193
|
-
};
|
|
194
|
-
var setDotProp = (obj, keys, val) => {
|
|
195
|
-
let i = 0;
|
|
196
|
-
let length = keys.length;
|
|
197
|
-
let t = obj;
|
|
198
|
-
let x;
|
|
199
|
-
for (;i < length; ++i) {
|
|
200
|
-
x = t[keys[i]];
|
|
201
|
-
t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
var setByType = (obj, transforms) => {
|
|
205
|
-
for (const key2 of Object.keys(transforms)) {
|
|
206
|
-
const transform = transforms[key2];
|
|
207
|
-
if (transform.shouldTransform) {
|
|
208
|
-
obj[key2] = Array.prototype.concat.call([], obj[key2]);
|
|
209
|
-
if (typeof transform.transformFunction === "function") {
|
|
210
|
-
obj[key2] = obj[key2].map(transform.transformFunction);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
var getFileName = (input) => {
|
|
216
|
-
const m = /([^\\\/]+)$/.exec(input);
|
|
217
|
-
return m ? m[1] : "";
|
|
218
|
-
};
|
|
219
|
-
var camelcaseOptionName = (name) => {
|
|
220
|
-
return name.split(".").map((v, i) => {
|
|
221
|
-
return i === 0 ? camelcase(v) : v;
|
|
222
|
-
}).join(".");
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
class CACError extends Error {
|
|
226
|
-
constructor(message) {
|
|
227
|
-
super(message);
|
|
228
|
-
this.name = this.constructor.name;
|
|
229
|
-
if (typeof Error.captureStackTrace === "function") {
|
|
230
|
-
Error.captureStackTrace(this, this.constructor);
|
|
231
|
-
} else {
|
|
232
|
-
this.stack = new Error(message).stack;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
class Option {
|
|
238
|
-
constructor(rawName, description, config) {
|
|
239
|
-
this.rawName = rawName;
|
|
240
|
-
this.description = description;
|
|
241
|
-
this.config = Object.assign({}, config);
|
|
242
|
-
rawName = rawName.replace(/\.\*/g, "");
|
|
243
|
-
this.negated = false;
|
|
244
|
-
this.names = removeBrackets(rawName).split(",").map((v) => {
|
|
245
|
-
let name = v.trim().replace(/^-{1,2}/, "");
|
|
246
|
-
if (name.startsWith("no-")) {
|
|
247
|
-
this.negated = true;
|
|
248
|
-
name = name.replace(/^no-/, "");
|
|
249
|
-
}
|
|
250
|
-
return camelcaseOptionName(name);
|
|
251
|
-
}).sort((a, b) => a.length > b.length ? 1 : -1);
|
|
252
|
-
this.name = this.names[this.names.length - 1];
|
|
253
|
-
if (this.negated && this.config.default == null) {
|
|
254
|
-
this.config.default = true;
|
|
255
|
-
}
|
|
256
|
-
if (rawName.includes("<")) {
|
|
257
|
-
this.required = true;
|
|
258
|
-
} else if (rawName.includes("[")) {
|
|
259
|
-
this.required = false;
|
|
260
|
-
} else {
|
|
261
|
-
this.isBoolean = true;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
var processArgs = process.argv;
|
|
266
|
-
var platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
|
|
267
|
-
|
|
268
|
-
class Command {
|
|
269
|
-
constructor(rawName, description, config = {}, cli) {
|
|
270
|
-
this.rawName = rawName;
|
|
271
|
-
this.description = description;
|
|
272
|
-
this.config = config;
|
|
273
|
-
this.cli = cli;
|
|
274
|
-
this.options = [];
|
|
275
|
-
this.aliasNames = [];
|
|
276
|
-
this.name = removeBrackets(rawName);
|
|
277
|
-
this.args = findAllBrackets(rawName);
|
|
278
|
-
this.examples = [];
|
|
279
|
-
}
|
|
280
|
-
usage(text) {
|
|
281
|
-
this.usageText = text;
|
|
282
|
-
return this;
|
|
283
|
-
}
|
|
284
|
-
allowUnknownOptions() {
|
|
285
|
-
this.config.allowUnknownOptions = true;
|
|
286
|
-
return this;
|
|
287
|
-
}
|
|
288
|
-
ignoreOptionDefaultValue() {
|
|
289
|
-
this.config.ignoreOptionDefaultValue = true;
|
|
290
|
-
return this;
|
|
291
|
-
}
|
|
292
|
-
version(version, customFlags = "-v, --version") {
|
|
293
|
-
this.versionNumber = version;
|
|
294
|
-
this.option(customFlags, "Display version number");
|
|
295
|
-
return this;
|
|
296
|
-
}
|
|
297
|
-
example(example) {
|
|
298
|
-
this.examples.push(example);
|
|
299
|
-
return this;
|
|
300
|
-
}
|
|
301
|
-
option(rawName, description, config) {
|
|
302
|
-
const option = new Option(rawName, description, config);
|
|
303
|
-
this.options.push(option);
|
|
304
|
-
return this;
|
|
305
|
-
}
|
|
306
|
-
alias(name) {
|
|
307
|
-
this.aliasNames.push(name);
|
|
308
|
-
return this;
|
|
309
|
-
}
|
|
310
|
-
action(callback) {
|
|
311
|
-
this.commandAction = callback;
|
|
312
|
-
return this;
|
|
313
|
-
}
|
|
314
|
-
isMatched(name) {
|
|
315
|
-
return this.name === name || this.aliasNames.includes(name);
|
|
316
|
-
}
|
|
317
|
-
get isDefaultCommand() {
|
|
318
|
-
return this.name === "" || this.aliasNames.includes("!");
|
|
319
|
-
}
|
|
320
|
-
get isGlobalCommand() {
|
|
321
|
-
return this instanceof GlobalCommand;
|
|
322
|
-
}
|
|
323
|
-
hasOption(name) {
|
|
324
|
-
name = name.split(".")[0];
|
|
325
|
-
return this.options.find((option) => {
|
|
326
|
-
return option.names.includes(name);
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
outputHelp() {
|
|
330
|
-
const { name, commands } = this.cli;
|
|
331
|
-
const {
|
|
332
|
-
versionNumber,
|
|
333
|
-
options: globalOptions,
|
|
334
|
-
helpCallback
|
|
335
|
-
} = this.cli.globalCommand;
|
|
336
|
-
let sections = [
|
|
337
|
-
{
|
|
338
|
-
body: `${name}${versionNumber ? `/${versionNumber}` : ""}`
|
|
339
|
-
}
|
|
340
|
-
];
|
|
341
|
-
sections.push({
|
|
342
|
-
title: "Usage",
|
|
343
|
-
body: ` \$ ${name} ${this.usageText || this.rawName}`
|
|
344
|
-
});
|
|
345
|
-
const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
|
|
346
|
-
if (showCommands) {
|
|
347
|
-
const longestCommandName = findLongest(commands.map((command) => command.rawName));
|
|
348
|
-
sections.push({
|
|
349
|
-
title: "Commands",
|
|
350
|
-
body: commands.map((command) => {
|
|
351
|
-
return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
|
|
352
|
-
}).join("\n")
|
|
353
|
-
});
|
|
354
|
-
sections.push({
|
|
355
|
-
title: `For more info, run any command with the \`--help\` flag`,
|
|
356
|
-
body: commands.map((command) => ` \$ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
|
|
360
|
-
if (!this.isGlobalCommand && !this.isDefaultCommand) {
|
|
361
|
-
options = options.filter((option) => option.name !== "version");
|
|
362
|
-
}
|
|
363
|
-
if (options.length > 0) {
|
|
364
|
-
const longestOptionName = findLongest(options.map((option) => option.rawName));
|
|
365
|
-
sections.push({
|
|
366
|
-
title: "Options",
|
|
367
|
-
body: options.map((option) => {
|
|
368
|
-
return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === undefined ? "" : `(default: ${option.config.default})`}`;
|
|
369
|
-
}).join("\n")
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
if (this.examples.length > 0) {
|
|
373
|
-
sections.push({
|
|
374
|
-
title: "Examples",
|
|
375
|
-
body: this.examples.map((example) => {
|
|
376
|
-
if (typeof example === "function") {
|
|
377
|
-
return example(name);
|
|
378
|
-
}
|
|
379
|
-
return example;
|
|
380
|
-
}).join("\n")
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
if (helpCallback) {
|
|
384
|
-
sections = helpCallback(sections) || sections;
|
|
385
|
-
}
|
|
386
|
-
console.log(sections.map((section) => {
|
|
387
|
-
return section.title ? `${section.title}:
|
|
388
|
-
${section.body}` : section.body;
|
|
389
|
-
}).join("\n\n"));
|
|
390
|
-
}
|
|
391
|
-
outputVersion() {
|
|
392
|
-
const { name } = this.cli;
|
|
393
|
-
const { versionNumber } = this.cli.globalCommand;
|
|
394
|
-
if (versionNumber) {
|
|
395
|
-
console.log(`${name}/${versionNumber} ${platformInfo}`);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
checkRequiredArgs() {
|
|
399
|
-
const minimalArgsCount = this.args.filter((arg) => arg.required).length;
|
|
400
|
-
if (this.cli.args.length < minimalArgsCount) {
|
|
401
|
-
throw new CACError(`missing required args for command \`${this.rawName}\``);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
checkUnknownOptions() {
|
|
405
|
-
const { options, globalCommand } = this.cli;
|
|
406
|
-
if (!this.config.allowUnknownOptions) {
|
|
407
|
-
for (const name of Object.keys(options)) {
|
|
408
|
-
if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) {
|
|
409
|
-
throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
checkOptionValue() {
|
|
415
|
-
const { options: parsedOptions, globalCommand } = this.cli;
|
|
416
|
-
const options = [...globalCommand.options, ...this.options];
|
|
417
|
-
for (const option of options) {
|
|
418
|
-
const value = parsedOptions[option.name.split(".")[0]];
|
|
419
|
-
if (option.required) {
|
|
420
|
-
const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
|
|
421
|
-
if (value === true || value === false && !hasNegated) {
|
|
422
|
-
throw new CACError(`option \`${option.rawName}\` value is missing`);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
class GlobalCommand extends Command {
|
|
430
|
-
constructor(cli) {
|
|
431
|
-
super("@@global@@", "", {}, cli);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
var __assign = Object.assign;
|
|
435
|
-
|
|
436
|
-
class CAC extends EventEmitter {
|
|
437
|
-
constructor(name = "") {
|
|
438
|
-
super();
|
|
439
|
-
this.name = name;
|
|
440
|
-
this.commands = [];
|
|
441
|
-
this.rawArgs = [];
|
|
442
|
-
this.args = [];
|
|
443
|
-
this.options = {};
|
|
444
|
-
this.globalCommand = new GlobalCommand(this);
|
|
445
|
-
this.globalCommand.usage("<command> [options]");
|
|
446
|
-
}
|
|
447
|
-
usage(text) {
|
|
448
|
-
this.globalCommand.usage(text);
|
|
449
|
-
return this;
|
|
450
|
-
}
|
|
451
|
-
command(rawName, description, config) {
|
|
452
|
-
const command = new Command(rawName, description || "", config, this);
|
|
453
|
-
command.globalCommand = this.globalCommand;
|
|
454
|
-
this.commands.push(command);
|
|
455
|
-
return command;
|
|
456
|
-
}
|
|
457
|
-
option(rawName, description, config) {
|
|
458
|
-
this.globalCommand.option(rawName, description, config);
|
|
459
|
-
return this;
|
|
460
|
-
}
|
|
461
|
-
help(callback) {
|
|
462
|
-
this.globalCommand.option("-h, --help", "Display this message");
|
|
463
|
-
this.globalCommand.helpCallback = callback;
|
|
464
|
-
this.showHelpOnExit = true;
|
|
465
|
-
return this;
|
|
466
|
-
}
|
|
467
|
-
version(version, customFlags = "-v, --version") {
|
|
468
|
-
this.globalCommand.version(version, customFlags);
|
|
469
|
-
this.showVersionOnExit = true;
|
|
470
|
-
return this;
|
|
471
|
-
}
|
|
472
|
-
example(example) {
|
|
473
|
-
this.globalCommand.example(example);
|
|
474
|
-
return this;
|
|
475
|
-
}
|
|
476
|
-
outputHelp() {
|
|
477
|
-
if (this.matchedCommand) {
|
|
478
|
-
this.matchedCommand.outputHelp();
|
|
479
|
-
} else {
|
|
480
|
-
this.globalCommand.outputHelp();
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
outputVersion() {
|
|
484
|
-
this.globalCommand.outputVersion();
|
|
485
|
-
}
|
|
486
|
-
setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
|
|
487
|
-
this.args = args;
|
|
488
|
-
this.options = options;
|
|
489
|
-
if (matchedCommand) {
|
|
490
|
-
this.matchedCommand = matchedCommand;
|
|
491
|
-
}
|
|
492
|
-
if (matchedCommandName) {
|
|
493
|
-
this.matchedCommandName = matchedCommandName;
|
|
494
|
-
}
|
|
495
|
-
return this;
|
|
496
|
-
}
|
|
497
|
-
unsetMatchedCommand() {
|
|
498
|
-
this.matchedCommand = undefined;
|
|
499
|
-
this.matchedCommandName = undefined;
|
|
500
|
-
}
|
|
501
|
-
parse(argv = processArgs, {
|
|
502
|
-
run = true
|
|
503
|
-
} = {}) {
|
|
504
|
-
this.rawArgs = argv;
|
|
505
|
-
if (!this.name) {
|
|
506
|
-
this.name = argv[1] ? getFileName(argv[1]) : "cli";
|
|
507
|
-
}
|
|
508
|
-
let shouldParse = true;
|
|
509
|
-
for (const command of this.commands) {
|
|
510
|
-
const parsed = this.mri(argv.slice(2), command);
|
|
511
|
-
const commandName = parsed.args[0];
|
|
512
|
-
if (command.isMatched(commandName)) {
|
|
513
|
-
shouldParse = false;
|
|
514
|
-
const parsedInfo = __assign(__assign({}, parsed), {
|
|
515
|
-
args: parsed.args.slice(1)
|
|
516
|
-
});
|
|
517
|
-
this.setParsedInfo(parsedInfo, command, commandName);
|
|
518
|
-
this.emit(`command:${commandName}`, command);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
if (shouldParse) {
|
|
522
|
-
for (const command of this.commands) {
|
|
523
|
-
if (command.name === "") {
|
|
524
|
-
shouldParse = false;
|
|
525
|
-
const parsed = this.mri(argv.slice(2), command);
|
|
526
|
-
this.setParsedInfo(parsed, command);
|
|
527
|
-
this.emit(`command:!`, command);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
if (shouldParse) {
|
|
532
|
-
const parsed = this.mri(argv.slice(2));
|
|
533
|
-
this.setParsedInfo(parsed);
|
|
534
|
-
}
|
|
535
|
-
if (this.options.help && this.showHelpOnExit) {
|
|
536
|
-
this.outputHelp();
|
|
537
|
-
run = false;
|
|
538
|
-
this.unsetMatchedCommand();
|
|
539
|
-
}
|
|
540
|
-
if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
|
|
541
|
-
this.outputVersion();
|
|
542
|
-
run = false;
|
|
543
|
-
this.unsetMatchedCommand();
|
|
544
|
-
}
|
|
545
|
-
const parsedArgv = { args: this.args, options: this.options };
|
|
546
|
-
if (run) {
|
|
547
|
-
this.runMatchedCommand();
|
|
548
|
-
}
|
|
549
|
-
if (!this.matchedCommand && this.args[0]) {
|
|
550
|
-
this.emit("command:*");
|
|
551
|
-
}
|
|
552
|
-
return parsedArgv;
|
|
553
|
-
}
|
|
554
|
-
mri(argv, command) {
|
|
555
|
-
const cliOptions = [
|
|
556
|
-
...this.globalCommand.options,
|
|
557
|
-
...command ? command.options : []
|
|
558
|
-
];
|
|
559
|
-
const mriOptions = getMriOptions(cliOptions);
|
|
560
|
-
let argsAfterDoubleDashes = [];
|
|
561
|
-
const doubleDashesIndex = argv.indexOf("--");
|
|
562
|
-
if (doubleDashesIndex > -1) {
|
|
563
|
-
argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
|
|
564
|
-
argv = argv.slice(0, doubleDashesIndex);
|
|
565
|
-
}
|
|
566
|
-
let parsed = mri2(argv, mriOptions);
|
|
567
|
-
parsed = Object.keys(parsed).reduce((res, name) => {
|
|
568
|
-
return __assign(__assign({}, res), {
|
|
569
|
-
[camelcaseOptionName(name)]: parsed[name]
|
|
570
|
-
});
|
|
571
|
-
}, { _: [] });
|
|
572
|
-
const args = parsed._;
|
|
573
|
-
const options = {
|
|
574
|
-
"--": argsAfterDoubleDashes
|
|
575
|
-
};
|
|
576
|
-
const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
|
|
577
|
-
let transforms = Object.create(null);
|
|
578
|
-
for (const cliOption of cliOptions) {
|
|
579
|
-
if (!ignoreDefault && cliOption.config.default !== undefined) {
|
|
580
|
-
for (const name of cliOption.names) {
|
|
581
|
-
options[name] = cliOption.config.default;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
if (Array.isArray(cliOption.config.type)) {
|
|
585
|
-
if (transforms[cliOption.name] === undefined) {
|
|
586
|
-
transforms[cliOption.name] = Object.create(null);
|
|
587
|
-
transforms[cliOption.name]["shouldTransform"] = true;
|
|
588
|
-
transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
for (const key2 of Object.keys(parsed)) {
|
|
593
|
-
if (key2 !== "_") {
|
|
594
|
-
const keys = key2.split(".");
|
|
595
|
-
setDotProp(options, keys, parsed[key2]);
|
|
596
|
-
setByType(options, transforms);
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
return {
|
|
600
|
-
args,
|
|
601
|
-
options
|
|
602
|
-
};
|
|
603
|
-
}
|
|
604
|
-
runMatchedCommand() {
|
|
605
|
-
const { args, options, matchedCommand: command } = this;
|
|
606
|
-
if (!command || !command.commandAction)
|
|
607
|
-
return;
|
|
608
|
-
command.checkUnknownOptions();
|
|
609
|
-
command.checkOptionValue();
|
|
610
|
-
command.checkRequiredArgs();
|
|
611
|
-
const actionArgs = [];
|
|
612
|
-
command.args.forEach((arg, index) => {
|
|
613
|
-
if (arg.variadic) {
|
|
614
|
-
actionArgs.push(args.slice(index));
|
|
615
|
-
} else {
|
|
616
|
-
actionArgs.push(args[index]);
|
|
617
|
-
}
|
|
618
|
-
});
|
|
619
|
-
actionArgs.push(options);
|
|
620
|
-
return command.commandAction.apply(this, actionArgs);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
29
|
+
import"./chunk-bf054cfbc9cf2201.js";
|
|
623
30
|
|
|
624
31
|
// src/cli.ts
|
|
32
|
+
import process from "process";
|
|
33
|
+
import {log} from "@stacksjs/logging";
|
|
625
34
|
import {ensureProjectIsInitialized} from "@stacksjs/utils";
|
|
626
35
|
import {path as p} from "@stacksjs/path";
|
|
627
36
|
import {fs} from "@stacksjs/storage";
|
|
@@ -632,6 +41,7 @@ async function main() {
|
|
|
632
41
|
await ensureProjectIsInitialized();
|
|
633
42
|
build(buddy);
|
|
634
43
|
changelog(buddy);
|
|
44
|
+
check(buddy);
|
|
635
45
|
clean(buddy);
|
|
636
46
|
cloud(buddy);
|
|
637
47
|
configure(buddy);
|
|
@@ -639,6 +49,8 @@ async function main() {
|
|
|
639
49
|
domains(buddy);
|
|
640
50
|
deploy(buddy);
|
|
641
51
|
dns(buddy);
|
|
52
|
+
ports(buddy);
|
|
53
|
+
projects(buddy);
|
|
642
54
|
fresh(buddy);
|
|
643
55
|
generate(buddy);
|
|
644
56
|
http(buddy);
|
|
@@ -647,7 +59,13 @@ async function main() {
|
|
|
647
59
|
list(buddy);
|
|
648
60
|
release(buddy);
|
|
649
61
|
setup(buddy);
|
|
62
|
+
version(buddy);
|
|
650
63
|
upgrade(buddy);
|
|
64
|
+
await dynamicImports(buddy);
|
|
65
|
+
buddy.help();
|
|
66
|
+
buddy.parse();
|
|
67
|
+
}
|
|
68
|
+
async function dynamicImports(buddy) {
|
|
651
69
|
const commandsDir = p.appPath("Commands");
|
|
652
70
|
const commandFiles = fs.readdirSync(commandsDir).filter((file) => file.endsWith(".ts"));
|
|
653
71
|
for (const file of commandFiles) {
|
|
@@ -661,16 +79,15 @@ async function main() {
|
|
|
661
79
|
const listenerImport = await import(p.listenersPath("Console.ts"));
|
|
662
80
|
if (typeof listenerImport.default === "function")
|
|
663
81
|
listenerImport.default(buddy);
|
|
664
|
-
buddy.help();
|
|
665
|
-
buddy.parse();
|
|
666
82
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
83
|
+
process.on("uncaughtException", (error) => {
|
|
84
|
+
log.debug("uncaughtException");
|
|
85
|
+
log.error(error);
|
|
86
|
+
process.exit(1);
|
|
670
87
|
});
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
88
|
+
process.on("unhandledRejection", (error) => {
|
|
89
|
+
log.debug("unhandledRejection");
|
|
90
|
+
log.error(error);
|
|
91
|
+
process.exit(1);
|
|
675
92
|
});
|
|
676
93
|
await main();
|