@stacksjs/buddy 0.58.72 → 0.59.1
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-94f0ae38d2d27d78.js → chunk-32440b2561f1e29c.js} +568 -485
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +44 -613
- package/dist/commands/build.d.ts +2 -0
- package/dist/commands/changelog.d.ts +2 -0
- package/dist/commands/clean.d.ts +2 -0
- package/dist/commands/cloud.d.ts +2 -0
- package/dist/commands/commit.d.ts +2 -0
- package/dist/commands/configure.d.ts +2 -0
- package/dist/commands/create.d.ts +2 -0
- package/dist/commands/deploy.d.ts +2 -0
- package/dist/commands/dev.d.ts +3 -0
- package/dist/commands/dns.d.ts +2 -0
- package/dist/commands/domains.d.ts +2 -0
- package/dist/commands/fresh.d.ts +2 -0
- package/dist/commands/generate.d.ts +2 -0
- package/dist/commands/http.d.ts +2 -0
- package/dist/commands/index.d.ts +31 -0
- package/dist/commands/install.d.ts +2 -0
- package/dist/commands/key.d.ts +2 -0
- package/dist/commands/lint.d.ts +2 -0
- package/dist/commands/list.d.ts +2 -0
- package/dist/commands/make.d.ts +2 -0
- package/dist/commands/migrate.d.ts +2 -0
- package/dist/commands/ports.d.ts +2 -0
- package/dist/commands/prepublish.d.ts +2 -0
- package/dist/commands/projects.d.ts +2 -0
- package/dist/commands/release.d.ts +2 -0
- package/dist/commands/seed.d.ts +2 -0
- package/dist/commands/setup.d.ts +4 -0
- package/dist/commands/test.d.ts +2 -0
- package/dist/commands/tinker.d.ts +2 -0
- package/dist/commands/types.d.ts +2 -0
- package/dist/commands/upgrade.d.ts +2 -0
- package/dist/commands/version.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -3
- package/dist/stacks +0 -0
- package/package.json +3 -5
- package/src/cli.ts +36 -31
- package/src/commands/add.ts +1 -1
- package/src/commands/commit.ts +1 -1
- package/src/commands/create.ts +6 -0
- package/src/commands/deploy.ts +1 -1
- package/src/commands/dev.ts +1 -3
- package/src/commands/generate.ts +10 -0
- package/src/commands/index.ts +2 -0
- package/src/commands/key.ts +1 -1
- package/src/commands/list.ts +1 -1
- package/src/commands/make.ts +28 -2
- package/src/commands/ports.ts +180 -0
- package/src/commands/prepublish.ts +1 -1
- package/src/commands/projects.ts +58 -0
- package/src/commands/setup.ts +8 -54
- package/src/commands/types.ts +1 -1
- package/src/commands/upgrade.ts +51 -4
- package/dist/chunk-59a9de11428ba763.js +0 -993
- /package/dist/{chunk-0455e53fab4244b1.js → chunk-970e033f764e29fc.js} +0 -0
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli.js
CHANGED
|
@@ -4,6 +4,7 @@ build,
|
|
|
4
4
|
changelog,
|
|
5
5
|
clean,
|
|
6
6
|
cloud,
|
|
7
|
+
commit,
|
|
7
8
|
configure,
|
|
8
9
|
deploy,
|
|
9
10
|
dev,
|
|
@@ -16,638 +17,69 @@ install,
|
|
|
16
17
|
key,
|
|
17
18
|
lint,
|
|
18
19
|
list,
|
|
20
|
+
make,
|
|
21
|
+
migrate,
|
|
22
|
+
ports,
|
|
23
|
+
prepublish,
|
|
24
|
+
projects,
|
|
19
25
|
release,
|
|
26
|
+
seed,
|
|
20
27
|
setup,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
}
|
|
28
|
+
test,
|
|
29
|
+
upgrade,
|
|
30
|
+
version
|
|
31
|
+
} from "./chunk-32440b2561f1e29c.js";
|
|
32
|
+
import"./chunk-970e033f764e29fc.js";
|
|
623
33
|
|
|
624
34
|
// src/cli.ts
|
|
35
|
+
import process from "process";
|
|
36
|
+
import {cli as cli2, log} from "@stacksjs/cli";
|
|
625
37
|
import {ensureProjectIsInitialized} from "@stacksjs/utils";
|
|
626
38
|
import {path as p} from "@stacksjs/path";
|
|
627
39
|
import {fs} from "@stacksjs/storage";
|
|
628
40
|
async function main() {
|
|
629
|
-
const buddy =
|
|
41
|
+
const buddy = cli2("buddy");
|
|
630
42
|
setup(buddy);
|
|
631
43
|
key(buddy);
|
|
632
|
-
await ensureProjectIsInitialized();
|
|
44
|
+
const isAppKeySet = await ensureProjectIsInitialized();
|
|
45
|
+
if (isAppKeySet) {
|
|
46
|
+
log.info("Project is initialized");
|
|
47
|
+
} else {
|
|
48
|
+
log.warn("Your `APP_KEY` is not yet");
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
633
51
|
build(buddy);
|
|
634
52
|
changelog(buddy);
|
|
635
53
|
clean(buddy);
|
|
636
54
|
cloud(buddy);
|
|
55
|
+
commit(buddy);
|
|
637
56
|
configure(buddy);
|
|
638
57
|
dev(buddy);
|
|
639
58
|
domains(buddy);
|
|
640
59
|
deploy(buddy);
|
|
641
60
|
dns(buddy);
|
|
61
|
+
ports(buddy);
|
|
62
|
+
projects(buddy);
|
|
642
63
|
fresh(buddy);
|
|
643
64
|
generate(buddy);
|
|
644
65
|
http(buddy);
|
|
645
66
|
install(buddy);
|
|
646
67
|
lint(buddy);
|
|
647
68
|
list(buddy);
|
|
69
|
+
make(buddy);
|
|
70
|
+
migrate(buddy);
|
|
648
71
|
release(buddy);
|
|
72
|
+
seed(buddy);
|
|
649
73
|
setup(buddy);
|
|
74
|
+
test(buddy);
|
|
75
|
+
version(buddy);
|
|
76
|
+
prepublish(buddy);
|
|
650
77
|
upgrade(buddy);
|
|
78
|
+
await dynamicImports(buddy);
|
|
79
|
+
buddy.help();
|
|
80
|
+
buddy.parse();
|
|
81
|
+
}
|
|
82
|
+
async function dynamicImports(buddy) {
|
|
651
83
|
const commandsDir = p.appPath("Commands");
|
|
652
84
|
const commandFiles = fs.readdirSync(commandsDir).filter((file) => file.endsWith(".ts"));
|
|
653
85
|
for (const file of commandFiles) {
|
|
@@ -661,16 +93,15 @@ async function main() {
|
|
|
661
93
|
const listenerImport = await import(p.listenersPath("Console.ts"));
|
|
662
94
|
if (typeof listenerImport.default === "function")
|
|
663
95
|
listenerImport.default(buddy);
|
|
664
|
-
buddy.help();
|
|
665
|
-
buddy.parse();
|
|
666
96
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
97
|
+
process.on("uncaughtException", (error) => {
|
|
98
|
+
log.debug("uncaughtException");
|
|
99
|
+
log.error(error);
|
|
100
|
+
process.exit(1);
|
|
670
101
|
});
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
102
|
+
process.on("unhandledRejection", (error) => {
|
|
103
|
+
log.debug("unhandledRejection");
|
|
104
|
+
log.error(error);
|
|
105
|
+
process.exit(1);
|
|
675
106
|
});
|
|
676
107
|
await main();
|