@h3ravel/console 11.9.0 → 11.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/fire.cjs +3 -37
- package/bin/fire.js +3 -37
- package/dist/index.cjs +64 -600
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -151
- package/dist/index.d.ts +4 -151
- package/dist/index.js +53 -585
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
1
|
import { FileSystem, Logger, TaskManager } from "@h3ravel/shared";
|
|
3
|
-
import {
|
|
2
|
+
import { Command, Kernel } from "@h3ravel/musket";
|
|
4
3
|
import { execa } from "execa";
|
|
5
4
|
import preferredPM from "preferred-pm";
|
|
6
|
-
import {
|
|
5
|
+
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
7
6
|
import { Str } from "@h3ravel/support";
|
|
8
7
|
import nodepath from "node:path";
|
|
9
|
-
import {
|
|
8
|
+
import { ContainerResolver, ServiceProvider } from "@h3ravel/core";
|
|
10
9
|
import { existsSync } from "node:fs";
|
|
11
10
|
import { fork } from "child_process";
|
|
12
11
|
import { dirname, join, resolve } from "path";
|
|
13
|
-
import { build } from "tsdown";
|
|
14
12
|
|
|
15
|
-
//#region rolldown:runtime
|
|
16
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
13
|
//#region src/Commands/BuildCommand.ts
|
|
20
|
-
var BuildCommand = class BuildCommand extends
|
|
14
|
+
var BuildCommand = class BuildCommand extends Command {
|
|
21
15
|
/**
|
|
22
16
|
* The name and signature of the console command.
|
|
23
17
|
*
|
|
@@ -112,146 +106,6 @@ var BuildCommand = class BuildCommand extends ConsoleCommand {
|
|
|
112
106
|
}
|
|
113
107
|
};
|
|
114
108
|
|
|
115
|
-
//#endregion
|
|
116
|
-
//#region src/Commands/Command.ts
|
|
117
|
-
var Command = class extends ConsoleCommand {};
|
|
118
|
-
|
|
119
|
-
//#endregion
|
|
120
|
-
//#region src/Commands/HelpCommand.ts
|
|
121
|
-
var HelpCommand = class extends Command {
|
|
122
|
-
/**
|
|
123
|
-
* The name and signature of the console command.
|
|
124
|
-
*
|
|
125
|
-
* @var string
|
|
126
|
-
*/
|
|
127
|
-
signature = `help
|
|
128
|
-
{command_name=help : The command name}
|
|
129
|
-
{--format=txt : The output format}
|
|
130
|
-
`;
|
|
131
|
-
/**
|
|
132
|
-
* The console command description.
|
|
133
|
-
*
|
|
134
|
-
* @var string
|
|
135
|
-
*/
|
|
136
|
-
description = "Display help for a command";
|
|
137
|
-
async handle() {
|
|
138
|
-
const cmd = this.argument("command_name");
|
|
139
|
-
if (!cmd) {
|
|
140
|
-
this.program.outputHelp();
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
const target = this.program.commands.find((c) => c.name() === cmd);
|
|
144
|
-
if (!target) {
|
|
145
|
-
this.error(`ERROR: Unknown command: ${Logger.log(cmd, ["italic", "grey"], false)}.`);
|
|
146
|
-
process.exit(1);
|
|
147
|
-
}
|
|
148
|
-
target.outputHelp();
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
//#endregion
|
|
153
|
-
//#region src/logo.ts
|
|
154
|
-
const logo = String.raw`
|
|
155
|
-
111
|
|
156
|
-
111111111
|
|
157
|
-
1111111111 111111
|
|
158
|
-
111111 111 111111
|
|
159
|
-
111111 111 111111
|
|
160
|
-
11111 111 11111
|
|
161
|
-
1111111 111 1111111
|
|
162
|
-
111 11111 111 111111 111 1111 1111 11111111 1111
|
|
163
|
-
111 11111 1111 111111 111 1111 1111 1111 11111 1111
|
|
164
|
-
111 11111 11111 111 1111 1111 111111111111 111111111111 1111 1111111 1111
|
|
165
|
-
111 111111 1111 111 111111111111 111111 11111 1111 111 1111 11111111 1111 1111
|
|
166
|
-
111 111 11111111 111 1101 1101 111111111 11111111 1111 1111111111111111101
|
|
167
|
-
111 1111111111111111 1111 111 1111 1111 111 11111011 1111 111 1111111 1101 1111
|
|
168
|
-
111 11111 1110111111111111 111 1111 1111 1111111101 1111 111111111 1111011 111111111 1111
|
|
169
|
-
1111111 111110111110 111 1111 1111 111111 1111 11011101 10111 11111 1111
|
|
170
|
-
11011 111111 11 11111
|
|
171
|
-
111111 11101 111111
|
|
172
|
-
111111 111 111111
|
|
173
|
-
111111 111 111111
|
|
174
|
-
111111111
|
|
175
|
-
110
|
|
176
|
-
`;
|
|
177
|
-
const altLogo = String.raw`
|
|
178
|
-
_ _ _____ _
|
|
179
|
-
| | | |___ / _ __ __ ___ _____| |
|
|
180
|
-
| |_| | |_ \| '__/ _ \ \ / / _ \ |
|
|
181
|
-
| _ |___) | | | (_| |\ V / __/ |
|
|
182
|
-
|_| |_|____/|_| \__,_| \_/ \___|_|
|
|
183
|
-
|
|
184
|
-
`;
|
|
185
|
-
|
|
186
|
-
//#endregion
|
|
187
|
-
//#region src/Commands/ListCommand.ts
|
|
188
|
-
var ListCommand = class ListCommand extends Command {
|
|
189
|
-
/**
|
|
190
|
-
* The name and signature of the console command.
|
|
191
|
-
*
|
|
192
|
-
* @var string
|
|
193
|
-
*/
|
|
194
|
-
signature = "list";
|
|
195
|
-
/**
|
|
196
|
-
* The console command description.
|
|
197
|
-
*
|
|
198
|
-
* @var string
|
|
199
|
-
*/
|
|
200
|
-
description = "List all available commands";
|
|
201
|
-
async handle() {
|
|
202
|
-
const options = [{
|
|
203
|
-
short: "-h",
|
|
204
|
-
long: "--help",
|
|
205
|
-
description: "Display help for the given command. When no command is given display help for the list command"
|
|
206
|
-
}].concat(this.program.options).map((e) => {
|
|
207
|
-
return Logger.describe(Logger.log(" " + [e.short, e.long].filter((e$1) => !!e$1).join(", "), "green", false), e.description, 25, false).join("");
|
|
208
|
-
});
|
|
209
|
-
/** Get the program commands */
|
|
210
|
-
const commands = this.program.commands.map((e) => {
|
|
211
|
-
return Logger.describe(Logger.log(" " + e.name(), "green", false), e.description(), 25, false).join("");
|
|
212
|
-
});
|
|
213
|
-
const list = ListCommand.groupItems(commands);
|
|
214
|
-
/** Ootput the app version */
|
|
215
|
-
Logger.log([["H3ravel Framework", "white"], [this.kernel.modulePackage.version, "green"]], " ");
|
|
216
|
-
console.log("");
|
|
217
|
-
console.log(altLogo);
|
|
218
|
-
console.log("");
|
|
219
|
-
Logger.log("Usage:", "yellow");
|
|
220
|
-
Logger.log(" command [options] [arguments]", "white");
|
|
221
|
-
console.log("");
|
|
222
|
-
/** Ootput the options */
|
|
223
|
-
Logger.log("Options:", "yellow");
|
|
224
|
-
console.log(options.join("\n").trim());
|
|
225
|
-
console.log("");
|
|
226
|
-
/** Ootput the commands */
|
|
227
|
-
Logger.log("Available Commands:", "yellow");
|
|
228
|
-
console.log(list.join("\n\n").trim());
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Group Commands based on thier names
|
|
232
|
-
*
|
|
233
|
-
* @param commands
|
|
234
|
-
* @returns
|
|
235
|
-
*/
|
|
236
|
-
static groupItems(commands, fmtd = false) {
|
|
237
|
-
const grouped = commands.reduce((acc, cmd) => {
|
|
238
|
-
/** strip colors before checking prefix */
|
|
239
|
-
const clean = cmd.replace(/\x1b\[\d+m/g, "");
|
|
240
|
-
const prefix = clean.includes(":") ? clean.split(":")[0].trim() : "__root__";
|
|
241
|
-
acc[prefix] ??= [];
|
|
242
|
-
/** keep original with colors */
|
|
243
|
-
acc[prefix].push(cmd);
|
|
244
|
-
return acc;
|
|
245
|
-
}, {});
|
|
246
|
-
return Object.entries(grouped).map(([group, cmds]) => {
|
|
247
|
-
const label = group === "__root__" ? "" : group;
|
|
248
|
-
let out = [Logger.log(label, "yellow", false), cmds.join("\n")].join("\n");
|
|
249
|
-
if (fmtd) out += "\n";
|
|
250
|
-
return out;
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
|
|
255
109
|
//#endregion
|
|
256
110
|
//#region src/Commands/MakeCommand.ts
|
|
257
111
|
var MakeCommand = class extends Command {
|
|
@@ -371,190 +225,38 @@ var PostinstallCommand = class extends Command {
|
|
|
371
225
|
};
|
|
372
226
|
|
|
373
227
|
//#endregion
|
|
374
|
-
//#region src/
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
/**
|
|
407
|
-
* Check for nested options after '|'
|
|
408
|
-
*/
|
|
409
|
-
let description = rest;
|
|
410
|
-
let nestedOptions;
|
|
411
|
-
const pipeIndex = rest.indexOf("|");
|
|
412
|
-
if (pipeIndex !== -1) {
|
|
413
|
-
description = rest.substring(0, pipeIndex).trim();
|
|
414
|
-
/**
|
|
415
|
-
* nestedText should start with '{' and end with ')', clean it
|
|
416
|
-
* Also Remove trailing ')' if present
|
|
417
|
-
*/
|
|
418
|
-
const cleanedNestedText = rest.substring(pipeIndex + 1).trim().replace(/^\{/, "").trim();
|
|
419
|
-
/**
|
|
420
|
-
* Parse nested options recursively
|
|
421
|
-
*/
|
|
422
|
-
nestedOptions = Signature.parseOptions("{" + cleanedNestedText + "}");
|
|
423
|
-
} else
|
|
424
|
-
/**
|
|
425
|
-
* Trim the string
|
|
426
|
-
*/
|
|
427
|
-
description = description.trim();
|
|
428
|
-
let name = namePart;
|
|
429
|
-
let flags;
|
|
430
|
-
let choices = [];
|
|
431
|
-
let required = /[^a-zA-Z0-9_|-]/.test(name);
|
|
432
|
-
let multiple = false;
|
|
433
|
-
let placeholder;
|
|
434
|
-
let defaultValue;
|
|
435
|
-
/**
|
|
436
|
-
* Parse the command name
|
|
437
|
-
*/
|
|
438
|
-
if (name.includes("=")) {
|
|
439
|
-
const [rawName, rawDefault] = name.split("=");
|
|
440
|
-
name = rawName.trim();
|
|
441
|
-
const hold = rawName.trim().split("|");
|
|
442
|
-
const holder = (hold.at(1) ?? hold.at(0)).replace("--", "");
|
|
443
|
-
defaultValue = rawDefault.trim();
|
|
444
|
-
placeholder = defaultValue ? `[${holder}]` : `<${holder}>`;
|
|
445
|
-
required = false;
|
|
446
|
-
}
|
|
447
|
-
/**
|
|
448
|
-
* Parse name modifiers (?, *, ?*)
|
|
449
|
-
*/
|
|
450
|
-
if (name.endsWith("?*")) {
|
|
451
|
-
required = false;
|
|
452
|
-
multiple = true;
|
|
453
|
-
name = name.slice(0, -2);
|
|
454
|
-
} else if (name.endsWith("*")) {
|
|
455
|
-
multiple = true;
|
|
456
|
-
name = name.slice(0, -1);
|
|
457
|
-
} else if (name.endsWith("?")) {
|
|
458
|
-
required = false;
|
|
459
|
-
name = name.slice(0, -1);
|
|
460
|
-
placeholder = `[${name.split("--").at(1)?.split("|").at(1) ?? name}]`;
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Check if it's a flag option (starts with --)
|
|
464
|
-
*/
|
|
465
|
-
const isFlag = name.startsWith("--");
|
|
466
|
-
if (isFlag) {
|
|
467
|
-
/**
|
|
468
|
-
* Parse flags and default values
|
|
469
|
-
*/
|
|
470
|
-
const flagParts = name.split("|").map((s) => s.trim());
|
|
471
|
-
flags = [];
|
|
472
|
-
for (let part of flagParts) {
|
|
473
|
-
if (part.startsWith("--") && part.slice(2).length === 1) part = "-" + part.slice(2);
|
|
474
|
-
else if (part.startsWith("-") && !part.startsWith("--") && part.slice(1).length > 1) part = "--" + part.slice(1);
|
|
475
|
-
else if (!part.startsWith("-") && part.slice(1).length > 1) part = "--" + part;
|
|
476
|
-
const eqIndex = part.indexOf("=");
|
|
477
|
-
if (eqIndex !== -1) {
|
|
478
|
-
flags.push(part.substring(0, eqIndex));
|
|
479
|
-
const val = part.substring(eqIndex + 1);
|
|
480
|
-
if (val === "*") defaultValue = [];
|
|
481
|
-
else if (val === "true" || val === "false" || !val && !required) defaultValue = val === "true";
|
|
482
|
-
else if (!isNaN(Number(val))) defaultValue = Number(val);
|
|
483
|
-
else defaultValue = val;
|
|
484
|
-
} else flags.push(part);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
const desc = description.match(/^([^:]+?)\s*:\s*\[?([\w\s,]+)\]?$/);
|
|
488
|
-
if (match) {
|
|
489
|
-
description = desc?.[1].trim() ?? description;
|
|
490
|
-
choices = desc?.[2].split(",").map((s) => s.trim()).filter(Boolean) ?? choices;
|
|
491
|
-
}
|
|
492
|
-
options.push({
|
|
493
|
-
name: isFlag ? flags[flags.length - 1] : name,
|
|
494
|
-
choices,
|
|
495
|
-
required,
|
|
496
|
-
multiple,
|
|
497
|
-
description,
|
|
498
|
-
flags,
|
|
499
|
-
shared,
|
|
500
|
-
isFlag,
|
|
501
|
-
isHidden,
|
|
502
|
-
placeholder,
|
|
503
|
-
defaultValue,
|
|
504
|
-
nestedOptions
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
return options;
|
|
508
|
-
}
|
|
509
|
-
/**
|
|
510
|
-
* Helper to parse a command's signature
|
|
511
|
-
*
|
|
512
|
-
* @param signature
|
|
513
|
-
* @param commandClass
|
|
514
|
-
* @returns
|
|
515
|
-
*/
|
|
516
|
-
static parseSignature(signature, commandClass) {
|
|
517
|
-
const lines = signature.split("\n").map((l) => l.trim()).filter((l) => l.length > 0);
|
|
518
|
-
const isHidden = ["#", "^"].includes(lines[0][0]) || /:[#^]/.test(lines[0]);
|
|
519
|
-
const baseCommand = lines[0].split("{")[0].trim().replace(/[^\w:-]/g, "");
|
|
520
|
-
const description = commandClass.getDescription();
|
|
521
|
-
const isNamespaceCommand = baseCommand.endsWith(":");
|
|
522
|
-
/**
|
|
523
|
-
* Join the rest lines to a single string for parsing
|
|
524
|
-
*/
|
|
525
|
-
const rest = lines.slice(1).join(" ");
|
|
526
|
-
/**
|
|
527
|
-
* Parse all top-level options/subcommands
|
|
528
|
-
*/
|
|
529
|
-
const allOptions = Signature.parseOptions(rest);
|
|
530
|
-
if (isNamespaceCommand)
|
|
531
|
-
/**
|
|
532
|
-
* Separate subcommands (those without flags) and base options (flags)
|
|
533
|
-
* Here we assume subcommands are those without flags (isFlag false)
|
|
534
|
-
* and base options are flags or options after subcommands
|
|
535
|
-
|
|
536
|
-
* For simplicity, treat all top-level options as subcommands
|
|
537
|
-
* and assume base command options come after subcommands in signature (not shown in example)
|
|
538
|
-
*/
|
|
539
|
-
return {
|
|
540
|
-
baseCommand: baseCommand.slice(0, -1),
|
|
541
|
-
isNamespaceCommand,
|
|
542
|
-
subCommands: allOptions.filter((e) => !e.flags && !e.isHidden),
|
|
543
|
-
description,
|
|
544
|
-
commandClass,
|
|
545
|
-
options: allOptions.filter((e) => !!e.flags),
|
|
546
|
-
isHidden
|
|
547
|
-
};
|
|
548
|
-
else return {
|
|
549
|
-
baseCommand,
|
|
550
|
-
isNamespaceCommand,
|
|
551
|
-
options: allOptions,
|
|
552
|
-
description,
|
|
553
|
-
commandClass,
|
|
554
|
-
isHidden
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
};
|
|
228
|
+
//#region src/logo.ts
|
|
229
|
+
const logo = String.raw`
|
|
230
|
+
111
|
|
231
|
+
111111111
|
|
232
|
+
1111111111 111111
|
|
233
|
+
111111 111 111111
|
|
234
|
+
111111 111 111111
|
|
235
|
+
11111 111 11111
|
|
236
|
+
1111111 111 1111111
|
|
237
|
+
111 11111 111 111111 111 1111 1111 11111111 1111
|
|
238
|
+
111 11111 1111 111111 111 1111 1111 1111 11111 1111
|
|
239
|
+
111 11111 11111 111 1111 1111 111111111111 111111111111 1111 1111111 1111
|
|
240
|
+
111 111111 1111 111 111111111111 111111 11111 1111 111 1111 11111111 1111 1111
|
|
241
|
+
111 111 11111111 111 1101 1101 111111111 11111111 1111 1111111111111111101
|
|
242
|
+
111 1111111111111111 1111 111 1111 1111 111 11111011 1111 111 1111111 1101 1111
|
|
243
|
+
111 11111 1110111111111111 111 1111 1111 1111111101 1111 111111111 1111011 111111111 1111
|
|
244
|
+
1111111 111110111110 111 1111 1111 111111 1111 11011101 10111 11111 1111
|
|
245
|
+
11011 111111 11 11111
|
|
246
|
+
111111 11101 111111
|
|
247
|
+
111111 111 111111
|
|
248
|
+
111111 111 111111
|
|
249
|
+
111111111
|
|
250
|
+
110
|
|
251
|
+
`;
|
|
252
|
+
const altLogo = String.raw`
|
|
253
|
+
_ _ _____ _
|
|
254
|
+
| | | |___ / _ __ __ ___ _____| |
|
|
255
|
+
| |_| | |_ \| '__/ _ \ \ / / _ \ |
|
|
256
|
+
| _ |___) | | | (_| |\ V / __/ |
|
|
257
|
+
|_| |_|____/|_| \__,_| \_/ \___|_|
|
|
258
|
+
|
|
259
|
+
`;
|
|
558
260
|
|
|
559
261
|
//#endregion
|
|
560
262
|
//#region ../../node_modules/.pnpm/@rollup+plugin-run@3.1.0_rollup@4.52.3/node_modules/@rollup/plugin-run/dist/es/index.js
|
|
@@ -667,260 +369,11 @@ const TsDownConfig = {
|
|
|
667
369
|
};
|
|
668
370
|
var TsdownConfig_default = TsDownConfig;
|
|
669
371
|
|
|
670
|
-
//#endregion
|
|
671
|
-
//#region src/Musket.ts
|
|
672
|
-
var Musket = class Musket {
|
|
673
|
-
commands = [];
|
|
674
|
-
constructor(app, kernel) {
|
|
675
|
-
this.app = app;
|
|
676
|
-
this.kernel = kernel;
|
|
677
|
-
}
|
|
678
|
-
async build() {
|
|
679
|
-
this.loadBaseCommands();
|
|
680
|
-
await this.loadDiscoveredCommands();
|
|
681
|
-
return await this.initialize();
|
|
682
|
-
}
|
|
683
|
-
loadBaseCommands() {
|
|
684
|
-
[
|
|
685
|
-
new HelpCommand(this.app, this.kernel),
|
|
686
|
-
new MakeCommand(this.app, this.kernel),
|
|
687
|
-
new ListCommand(this.app, this.kernel),
|
|
688
|
-
new PostinstallCommand(this.app, this.kernel),
|
|
689
|
-
new BuildCommand(this.app, this.kernel)
|
|
690
|
-
].forEach((e) => this.addCommand(e));
|
|
691
|
-
}
|
|
692
|
-
async loadDiscoveredCommands() {
|
|
693
|
-
const DIST_DIR = `/${env("DIST_DIR", ".h3ravel/serve")}/`.replaceAll("//", "");
|
|
694
|
-
const commands = [...this.app.registeredCommands.map((cmd) => new cmd(this.app, this.kernel))];
|
|
695
|
-
/**
|
|
696
|
-
* Musket Commands auto registration
|
|
697
|
-
*/
|
|
698
|
-
const providers_path = app_path("Console/Commands/*.js").replace("/src/", DIST_DIR);
|
|
699
|
-
/** Add the App Commands */
|
|
700
|
-
for await (const cmd of glob(providers_path)) {
|
|
701
|
-
const name = nodepath.basename(cmd).replace(".js", "");
|
|
702
|
-
try {
|
|
703
|
-
const cmdClass = (await import(cmd))[name];
|
|
704
|
-
commands.push(new cmdClass(this.app, this.kernel));
|
|
705
|
-
} catch {}
|
|
706
|
-
}
|
|
707
|
-
commands.forEach((e) => this.addCommand(e));
|
|
708
|
-
}
|
|
709
|
-
addCommand(command) {
|
|
710
|
-
this.commands.push(Signature.parseSignature(command.getSignature(), command));
|
|
711
|
-
}
|
|
712
|
-
async initialize() {
|
|
713
|
-
if (process.argv.includes("--help") || process.argv.includes("-h")) {
|
|
714
|
-
await this.rebuild("help");
|
|
715
|
-
Object.keys(__require.cache).forEach((key) => delete __require.cache[key]);
|
|
716
|
-
}
|
|
717
|
-
/** Init the Musket Version */
|
|
718
|
-
const cliVersion = Logger.parse([["Musket CLI:", "white"], [this.kernel.consolePackage.version, "green"]], " ", false);
|
|
719
|
-
/** Init the App Version */
|
|
720
|
-
const localVersion = Logger.parse([["H3ravel Framework:", "white"], [this.kernel.modulePackage.version, "green"]], " ", false);
|
|
721
|
-
const additional = {
|
|
722
|
-
quiet: ["-q, --quiet", "Do not output any message except errors and warnings"],
|
|
723
|
-
silent: ["--silent", "Do not output any message"],
|
|
724
|
-
verbose: ["-v, --verbose <number>", "Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug"],
|
|
725
|
-
noInteraction: ["-n, --no-interaction", "Do not ask any interactive question"]
|
|
726
|
-
};
|
|
727
|
-
/**
|
|
728
|
-
* Init Commander
|
|
729
|
-
*/
|
|
730
|
-
program.name("musket").version(`${cliVersion}\n${localVersion}`).description(altLogo).configureHelp({ showGlobalOptions: true }).addOption(new Option(additional.quiet[0], additional.quiet[1])).addOption(new Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).addOption(new Option(additional.verbose[0], additional.verbose[1]).choices([
|
|
731
|
-
"1",
|
|
732
|
-
"2",
|
|
733
|
-
"3"
|
|
734
|
-
])).addOption(new Option(additional.noInteraction[0], additional.noInteraction[1])).action(async () => {
|
|
735
|
-
const instance = new ListCommand(this.app, this.kernel);
|
|
736
|
-
instance.setInput(program.opts(), program.args, program.registeredArguments, {}, program);
|
|
737
|
-
await this.handle(instance);
|
|
738
|
-
});
|
|
739
|
-
/**
|
|
740
|
-
* Format the help command display
|
|
741
|
-
*/
|
|
742
|
-
program.configureHelp({
|
|
743
|
-
styleTitle: (str) => Logger.log(str, "yellow", false),
|
|
744
|
-
styleOptionTerm: (str) => Logger.log(str, "green", false),
|
|
745
|
-
styleArgumentTerm: (str) => Logger.log(str, "green", false),
|
|
746
|
-
styleSubcommandTerm: (str) => Logger.log(str, "green", false),
|
|
747
|
-
formatItemList(heading, items) {
|
|
748
|
-
if (items.length < 1) return [];
|
|
749
|
-
if (!heading.includes("Commands:")) return items;
|
|
750
|
-
const c = (str) => str.replace(/[^A-Za-z0-9-,]/g, "").replace("32m", "");
|
|
751
|
-
let flags = items.filter((e) => c(e).startsWith("--") || c(e).includes(",--"));
|
|
752
|
-
if (flags.length > 0) flags = [Logger.log("\n" + heading + "\n", "yellow", false)].concat(flags);
|
|
753
|
-
const list = items.filter((e) => !c(e).startsWith("--") && !c(e).includes(",--"));
|
|
754
|
-
if (list.length < 1) return flags;
|
|
755
|
-
const _heading = c(heading).includes("Arguments") ? heading : "Available Commands:";
|
|
756
|
-
return flags.concat(Logger.log(`\n${_heading}`, "yellow", false), ListCommand.groupItems(list, true));
|
|
757
|
-
},
|
|
758
|
-
showGlobalOptions: true
|
|
759
|
-
});
|
|
760
|
-
/**
|
|
761
|
-
* Create the init Command
|
|
762
|
-
*/
|
|
763
|
-
program.command("init").description("Initialize H3ravel.").action(async () => {
|
|
764
|
-
Logger.success("Initialized: H3ravel has been initialized!");
|
|
765
|
-
});
|
|
766
|
-
/**
|
|
767
|
-
* Loop through all the available commands
|
|
768
|
-
*/
|
|
769
|
-
for (let i = 0; i < this.commands.length; i++) {
|
|
770
|
-
const command = this.commands[i];
|
|
771
|
-
const instance = command.commandClass;
|
|
772
|
-
if (command.isNamespaceCommand && command.subCommands) {
|
|
773
|
-
/**
|
|
774
|
-
* Initialize the base command
|
|
775
|
-
*/
|
|
776
|
-
const cmd = command.isHidden ? program : program.command(command.baseCommand).description(command.description ?? "").action(async () => {
|
|
777
|
-
instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command, program);
|
|
778
|
-
await this.handle(instance);
|
|
779
|
-
});
|
|
780
|
-
/**
|
|
781
|
-
* Add options to the base command if it has any
|
|
782
|
-
*/
|
|
783
|
-
if ((command.options?.length ?? 0) > 0) command.options?.filter((v, i$1, a) => a.findIndex((t) => t.name === v.name) === i$1).forEach((opt) => {
|
|
784
|
-
this.makeOption(opt, cmd);
|
|
785
|
-
});
|
|
786
|
-
/**
|
|
787
|
-
* Initialize the sub commands
|
|
788
|
-
*/
|
|
789
|
-
command.subCommands.filter((v, i$1, a) => !v.shared && a.findIndex((t) => t.name === v.name) === i$1).forEach((sub) => {
|
|
790
|
-
const cmd$1 = program.command(`${command.baseCommand}:${sub.name}`).description(sub.description || "").action(async () => {
|
|
791
|
-
instance.setInput(cmd$1.opts(), cmd$1.args, cmd$1.registeredArguments, sub, program);
|
|
792
|
-
await this.handle(instance);
|
|
793
|
-
});
|
|
794
|
-
/**
|
|
795
|
-
* Add the shared arguments here
|
|
796
|
-
*/
|
|
797
|
-
command.subCommands?.filter((e) => e.shared).forEach((opt) => {
|
|
798
|
-
this.makeOption(opt, cmd$1, false, sub);
|
|
799
|
-
});
|
|
800
|
-
/**
|
|
801
|
-
* Add the shared options here
|
|
802
|
-
*/
|
|
803
|
-
command.options?.filter((e) => e.shared).forEach((opt) => {
|
|
804
|
-
this.makeOption(opt, cmd$1, false, sub);
|
|
805
|
-
});
|
|
806
|
-
/**
|
|
807
|
-
* Add options to the sub command if it has any
|
|
808
|
-
*/
|
|
809
|
-
if (sub.nestedOptions) sub.nestedOptions.filter((v, i$1, a) => a.findIndex((t) => t.name === v.name) === i$1).forEach((opt) => {
|
|
810
|
-
this.makeOption(opt, cmd$1);
|
|
811
|
-
});
|
|
812
|
-
});
|
|
813
|
-
} else {
|
|
814
|
-
/**
|
|
815
|
-
* Initialize command with options
|
|
816
|
-
*/
|
|
817
|
-
const cmd = program.command(command.baseCommand).description(command.description ?? "");
|
|
818
|
-
command?.options?.filter((v, i$1, a) => a.findIndex((t) => t.name === v.name) === i$1).forEach((opt) => {
|
|
819
|
-
this.makeOption(opt, cmd, true);
|
|
820
|
-
});
|
|
821
|
-
cmd.action(async () => {
|
|
822
|
-
instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command, program);
|
|
823
|
-
await this.handle(instance);
|
|
824
|
-
});
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
/** Rebuild the app on every command except fire so we wont need TS */
|
|
828
|
-
program.hook("preAction", async (_, cmd) => {
|
|
829
|
-
this.rebuild(cmd.name());
|
|
830
|
-
});
|
|
831
|
-
return program;
|
|
832
|
-
}
|
|
833
|
-
async rebuild(name) {
|
|
834
|
-
if (name !== "fire" && name !== "build") await build({
|
|
835
|
-
...TsdownConfig_default,
|
|
836
|
-
watch: false,
|
|
837
|
-
plugins: []
|
|
838
|
-
});
|
|
839
|
-
}
|
|
840
|
-
makeOption(opt, cmd, parse, parent) {
|
|
841
|
-
const description = opt.description?.replace(/\[(\w+)\]/g, (_, k) => parent?.[k] ?? `[${k}]`) ?? "";
|
|
842
|
-
const type = opt.name.replaceAll("-", "");
|
|
843
|
-
if (opt.isFlag) if (parse) {
|
|
844
|
-
let flags = opt.flags?.map((f) => f.length === 1 ? `-${f}` : `--${f.replace(/^-+/, "")}`).join(", ") ?? void 0;
|
|
845
|
-
if (opt.required && !opt.placeholder) flags += ` <${type}>`;
|
|
846
|
-
else if (opt.placeholder) flags += " " + opt.placeholder;
|
|
847
|
-
let optn = new Option(flags || "", description).default(opt.defaultValue);
|
|
848
|
-
if (opt.choices && opt.choices.length) optn = optn.choices(opt.choices ?? []);
|
|
849
|
-
cmd.addOption(optn);
|
|
850
|
-
} else {
|
|
851
|
-
let flags = opt.flags?.join(", ") ?? "";
|
|
852
|
-
if (opt.required && !opt.placeholder) flags += ` <${type}>`;
|
|
853
|
-
else if (opt.placeholder) flags += " " + opt.placeholder;
|
|
854
|
-
let optn = new Option(flags, description).default(opt.defaultValue);
|
|
855
|
-
if (opt.choices && opt.choices.length) optn = optn.choices(opt.choices ?? []);
|
|
856
|
-
cmd.addOption(optn);
|
|
857
|
-
}
|
|
858
|
-
else {
|
|
859
|
-
let name = opt.placeholder;
|
|
860
|
-
if (!name) name = opt.required ? `<${opt.name}>` : `[${opt.name}]`;
|
|
861
|
-
let arg = new Argument(name, description);
|
|
862
|
-
if (opt.choices && opt.choices.length) arg = arg.choices(opt.choices ?? []);
|
|
863
|
-
if (opt.defaultValue) arg.default(opt.defaultValue);
|
|
864
|
-
cmd.addArgument(arg);
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
async handle(cmd) {
|
|
868
|
-
await new ContainerResolver(this.app).resolveMethodParams(cmd, "handle");
|
|
869
|
-
}
|
|
870
|
-
static async parse(kernel) {
|
|
871
|
-
return (await new Musket(kernel.app, kernel).build()).exitOverride(() => {
|
|
872
|
-
Logger.log("Unknown command or argument.", "white");
|
|
873
|
-
Logger.log([
|
|
874
|
-
["Run", "white"],
|
|
875
|
-
["`musket --help`", ["grey", "italic"]],
|
|
876
|
-
["to see available commands.", "white"]
|
|
877
|
-
], " ");
|
|
878
|
-
}).parseAsync(process.argv).catch((e) => e);
|
|
879
|
-
}
|
|
880
|
-
};
|
|
881
|
-
|
|
882
|
-
//#endregion
|
|
883
|
-
//#region src/Kernel.ts
|
|
884
|
-
var Kernel = class Kernel extends ConsoleKernel {
|
|
885
|
-
constructor(app) {
|
|
886
|
-
super(app);
|
|
887
|
-
this.app = app;
|
|
888
|
-
}
|
|
889
|
-
static init(app) {
|
|
890
|
-
const instance = new Kernel(app);
|
|
891
|
-
Promise.all([instance.loadRequirements()]).then(([e]) => e.run());
|
|
892
|
-
}
|
|
893
|
-
async run() {
|
|
894
|
-
await Musket.parse(this);
|
|
895
|
-
process.exit(0);
|
|
896
|
-
}
|
|
897
|
-
async loadRequirements() {
|
|
898
|
-
this.cwd = nodepath.join(process.cwd(), this.basePath);
|
|
899
|
-
this.modulePath = FileSystem.findModulePkg("@h3ravel/core", this.cwd) ?? "";
|
|
900
|
-
this.consolePath = FileSystem.findModulePkg("@h3ravel/console", this.cwd) ?? "";
|
|
901
|
-
try {
|
|
902
|
-
this.modulePackage = await import(nodepath.join(this.modulePath, "package.json"));
|
|
903
|
-
} catch {
|
|
904
|
-
this.modulePackage = { version: "N/A" };
|
|
905
|
-
}
|
|
906
|
-
try {
|
|
907
|
-
this.consolePackage = await import(nodepath.join(this.consolePath, "package.json"));
|
|
908
|
-
} catch {
|
|
909
|
-
this.consolePackage = { version: "N/A" };
|
|
910
|
-
}
|
|
911
|
-
return this;
|
|
912
|
-
}
|
|
913
|
-
};
|
|
914
|
-
|
|
915
372
|
//#endregion
|
|
916
373
|
//#region src/Providers/ConsoleServiceProvider.ts
|
|
917
374
|
/**
|
|
918
375
|
* Handles CLI commands and tooling.
|
|
919
376
|
*
|
|
920
|
-
* Register DatabaseManager and QueryBuilder.
|
|
921
|
-
* Set up ORM models and relationships.
|
|
922
|
-
* Register migration and seeder commands.
|
|
923
|
-
*
|
|
924
377
|
* Auto-Registered when in CLI mode
|
|
925
378
|
*/
|
|
926
379
|
var ConsoleServiceProvider = class extends ServiceProvider {
|
|
@@ -932,7 +385,22 @@ var ConsoleServiceProvider = class extends ServiceProvider {
|
|
|
932
385
|
runsInConsole = true;
|
|
933
386
|
register() {}
|
|
934
387
|
boot() {
|
|
935
|
-
|
|
388
|
+
const DIST_DIR = `/${env("DIST_DIR", ".h3ravel/serve")}/`.replaceAll("//", "");
|
|
389
|
+
Kernel.init(this.app, {
|
|
390
|
+
logo: altLogo,
|
|
391
|
+
resolver: new ContainerResolver(this.app).resolveMethodParams,
|
|
392
|
+
tsDownConfig: TsdownConfig_default,
|
|
393
|
+
packages: [{
|
|
394
|
+
name: "@h3ravel/core",
|
|
395
|
+
alias: "H3ravel Framework"
|
|
396
|
+
}, {
|
|
397
|
+
name: "@h3ravel/musket",
|
|
398
|
+
alias: "Musket CLI"
|
|
399
|
+
}],
|
|
400
|
+
cliName: "musket",
|
|
401
|
+
hideMusketInfo: true,
|
|
402
|
+
discoveryPaths: [app_path("Console/Commands/*.js").replace("/src/", DIST_DIR)]
|
|
403
|
+
});
|
|
936
404
|
process.on("SIGINT", () => {
|
|
937
405
|
process.exit(0);
|
|
938
406
|
});
|
|
@@ -943,5 +411,5 @@ var ConsoleServiceProvider = class extends ServiceProvider {
|
|
|
943
411
|
};
|
|
944
412
|
|
|
945
413
|
//#endregion
|
|
946
|
-
export { BuildCommand,
|
|
414
|
+
export { BuildCommand, ConsoleServiceProvider, MakeCommand, PostinstallCommand, TsDownConfig };
|
|
947
415
|
//# sourceMappingURL=index.js.map
|