@h3ravel/console 11.0.7 → 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/fire.cjs +2 -0
- package/bin/fire.js +2 -0
- package/dist/Utils-CpiQZ3n9.cjs +122 -0
- package/dist/Utils-CpiQZ3n9.cjs.map +1 -0
- package/dist/Utils-Dvclc4Pc.js +73 -0
- package/dist/Utils-Dvclc4Pc.js.map +1 -0
- package/dist/Utils-cBgwEyTl.d.ts +20 -0
- package/dist/Utils-rIdzILgO.d.cts +20 -0
- package/dist/Utils.cjs +3 -217
- package/dist/Utils.d.cts +2 -0
- package/dist/Utils.d.ts +2 -0
- package/dist/Utils.js +3 -9
- package/dist/index.cjs +790 -949
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +173 -295
- package/dist/index.d.ts +173 -295
- package/dist/index.js +789 -44
- package/dist/index.js.map +1 -0
- package/package.json +35 -23
- package/bin/chunk-6Z5DP356.js +0 -1
- package/bin/lexer-DQCqS3nf-XQPNMZG6.js +0 -4
- package/bin/run.cjs +0 -26
- package/bin/run.js +0 -26
- package/dist/Commands/Command.cjs +0 -104
- package/dist/Commands/Command.js +0 -7
- package/dist/Commands/MakeCommand.cjs +0 -433
- package/dist/Commands/MakeCommand.js +0 -9
- package/dist/Commands/MigrateCommand.cjs +0 -200
- package/dist/Commands/MigrateCommand.js +0 -8
- package/dist/Commands/ServeCommand.cjs +0 -159
- package/dist/Commands/ServeCommand.js +0 -8
- package/dist/Contracts/ICommand.cjs +0 -18
- package/dist/Contracts/ICommand.js +0 -1
- package/dist/IO/app.cjs +0 -946
- package/dist/IO/app.js +0 -17
- package/dist/IO/providers.cjs +0 -930
- package/dist/IO/providers.js +0 -16
- package/dist/Kernel.cjs +0 -890
- package/dist/Kernel.js +0 -14
- package/dist/Musket.cjs +0 -835
- package/dist/Musket.js +0 -13
- package/dist/Providers/ConsoleServiceProvider.cjs +0 -912
- package/dist/Providers/ConsoleServiceProvider.js +0 -15
- package/dist/Signature.cjs +0 -172
- package/dist/Signature.js +0 -7
- package/dist/chunk-23QH5R54.js +0 -27
- package/dist/chunk-2O2AYFAG.js +0 -63
- package/dist/chunk-3ASEWMRX.js +0 -37
- package/dist/chunk-3FVPHQCH.js +0 -151
- package/dist/chunk-3RX6CLNR.js +0 -32
- package/dist/chunk-3VCNSA6P.js +0 -14
- package/dist/chunk-3WHUADTN.js +0 -6
- package/dist/chunk-6OCHCPBP.js +0 -36
- package/dist/chunk-6OIH6FS4.js +0 -32
- package/dist/chunk-7EWRZPTX.js +0 -63
- package/dist/chunk-7PUQ5ZIN.js +0 -6
- package/dist/chunk-A5AONVOH.js +0 -6
- package/dist/chunk-ADIVRUAJ.js +0 -27
- package/dist/chunk-CCEWV2BR.js +0 -39
- package/dist/chunk-CTQ6DUT2.js +0 -8
- package/dist/chunk-DXQTBFGG.js +0 -31
- package/dist/chunk-E4SSLXFT.js +0 -63
- package/dist/chunk-E5XIGIEX.js +0 -14
- package/dist/chunk-EIOQKTRM.js +0 -104
- package/dist/chunk-FOSDCKCR.js +0 -106
- package/dist/chunk-G4OE26TZ.js +0 -33
- package/dist/chunk-GVGO5OAK.js +0 -8
- package/dist/chunk-GXRCTWKL.js +0 -16
- package/dist/chunk-HVKW7JK4.js +0 -8
- package/dist/chunk-IGEFNODG.js +0 -22
- package/dist/chunk-JXL4VJHZ.js +0 -36
- package/dist/chunk-K3GOQSS3.js +0 -6
- package/dist/chunk-KCJKQP37.js +0 -133
- package/dist/chunk-KMIFCLXG.js +0 -16
- package/dist/chunk-KZA3MC77.js +0 -151
- package/dist/chunk-LLL3V7LB.js +0 -6
- package/dist/chunk-LQ6DL2HS.js +0 -68
- package/dist/chunk-M4ZRDJJ2.js +0 -68
- package/dist/chunk-MAQAT3PU.js +0 -32
- package/dist/chunk-MPXPSSLJ.js +0 -133
- package/dist/chunk-NADN2PHB.js +0 -0
- package/dist/chunk-NFRXMBRP.js +0 -24
- package/dist/chunk-NVPKTRMT.js +0 -7
- package/dist/chunk-O45AB4MX.js +0 -83
- package/dist/chunk-ORPRWIQ2.js +0 -33
- package/dist/chunk-P7M5PEDY.js +0 -18
- package/dist/chunk-PBNCVQZC.js +0 -6
- package/dist/chunk-PMV4TMFS.js +0 -151
- package/dist/chunk-POF4JGTX.js +0 -186
- package/dist/chunk-PYSJMSNM.js +0 -27
- package/dist/chunk-Q3OMG6YH.js +0 -186
- package/dist/chunk-QCNBVSFO.js +0 -68
- package/dist/chunk-QMEO4OUR.js +0 -151
- package/dist/chunk-QSQNELZQ.js +0 -83
- package/dist/chunk-RRP7K5LI.js +0 -36
- package/dist/chunk-SHUYVCID.js +0 -6
- package/dist/chunk-SP4JKAUC.js +0 -63
- package/dist/chunk-T6OOKENF.js +0 -6
- package/dist/chunk-TBDROT3I.js +0 -6356
- package/dist/chunk-TH2RWMWA.js +0 -133
- package/dist/chunk-TJZCDDEV.js +0 -36
- package/dist/chunk-TN5SV7LF.js +0 -133
- package/dist/chunk-U6TOLKGJ.js +0 -22
- package/dist/chunk-UCOXL3OM.js +0 -0
- package/dist/chunk-URLTFJET.js +0 -68
- package/dist/chunk-UWCTG2LX.js +0 -24
- package/dist/chunk-WO2BXMBQ.js +0 -6
- package/dist/chunk-XAWZUZVP.js +0 -32
- package/dist/chunk-XCOSZXAE.js +0 -133
- package/dist/chunk-XD2Q7LWE.js +0 -24
- package/dist/chunk-XSL373TG.js +0 -36
- package/dist/chunk-XUYTJO6X.js +0 -104
- package/dist/chunk-YAYU7VOK.js +0 -8
- package/dist/chunk-YRUCICBV.js +0 -24
- package/dist/chunk-Z5XE72Q5.js +0 -68
- package/dist/chunk-ZTIO25VB.js +0 -8
- package/dist/lexer-DQCqS3nf-6W2BHF4T.js +0 -68
- package/dist/run.cjs +0 -943
- package/dist/run.js +0 -14
package/dist/index.cjs
CHANGED
|
@@ -1,972 +1,813 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Command: () => Command,
|
|
35
|
-
ConsoleServiceProvider: () => ConsoleServiceProvider,
|
|
36
|
-
Kernel: () => Kernel,
|
|
37
|
-
MakeCommand: () => MakeCommand,
|
|
38
|
-
MigrateCommand: () => MigrateCommand,
|
|
39
|
-
Musket: () => Musket,
|
|
40
|
-
ServeCommand: () => ServeCommand,
|
|
41
|
-
Signature: () => Signature,
|
|
42
|
-
TableGuesser: () => TableGuesser,
|
|
43
|
-
Utils: () => Utils
|
|
44
|
-
});
|
|
45
|
-
module.exports = __toCommonJS(index_exports);
|
|
1
|
+
const require_Utils = require('./Utils-CpiQZ3n9.cjs');
|
|
2
|
+
let fs_promises = require("fs/promises");
|
|
3
|
+
fs_promises = require_Utils.__toESM(fs_promises);
|
|
4
|
+
let path = require("path");
|
|
5
|
+
path = require_Utils.__toESM(path);
|
|
6
|
+
let __h3ravel_core = require("@h3ravel/core");
|
|
7
|
+
__h3ravel_core = require_Utils.__toESM(__h3ravel_core);
|
|
8
|
+
let __h3ravel_shared = require("@h3ravel/shared");
|
|
9
|
+
__h3ravel_shared = require_Utils.__toESM(__h3ravel_shared);
|
|
10
|
+
let node_fs_promises = require("node:fs/promises");
|
|
11
|
+
node_fs_promises = require_Utils.__toESM(node_fs_promises);
|
|
12
|
+
let __h3ravel_support = require("@h3ravel/support");
|
|
13
|
+
__h3ravel_support = require_Utils.__toESM(__h3ravel_support);
|
|
14
|
+
let dayjs = require("dayjs");
|
|
15
|
+
dayjs = require_Utils.__toESM(dayjs);
|
|
16
|
+
let node_fs = require("node:fs");
|
|
17
|
+
node_fs = require_Utils.__toESM(node_fs);
|
|
18
|
+
let node_path = require("node:path");
|
|
19
|
+
node_path = require_Utils.__toESM(node_path);
|
|
20
|
+
require("@h3ravel/console");
|
|
21
|
+
require("@h3ravel/http");
|
|
22
|
+
require("@h3ravel/router");
|
|
23
|
+
require("@h3ravel/database");
|
|
24
|
+
require("@h3ravel/cache");
|
|
25
|
+
require("@h3ravel/queue");
|
|
26
|
+
require("@h3ravel/mail");
|
|
27
|
+
require("@h3ravel/config");
|
|
28
|
+
let commander = require("commander");
|
|
29
|
+
commander = require_Utils.__toESM(commander);
|
|
30
|
+
let child_process = require("child_process");
|
|
31
|
+
child_process = require_Utils.__toESM(child_process);
|
|
32
|
+
let tsdown = require("tsdown");
|
|
33
|
+
tsdown = require_Utils.__toESM(tsdown);
|
|
46
34
|
|
|
47
|
-
|
|
48
|
-
var Command = class {
|
|
49
|
-
static {
|
|
50
|
-
__name(this, "Command");
|
|
51
|
-
}
|
|
52
|
-
app;
|
|
53
|
-
kernel;
|
|
54
|
-
constructor(app, kernel) {
|
|
55
|
-
this.app = app;
|
|
56
|
-
this.kernel = kernel;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* The name and signature of the console command.
|
|
60
|
-
*
|
|
61
|
-
* @var string
|
|
62
|
-
*/
|
|
63
|
-
signature;
|
|
64
|
-
/**
|
|
65
|
-
* A dictionary of signatures or what not.
|
|
66
|
-
*
|
|
67
|
-
* @var object
|
|
68
|
-
*/
|
|
69
|
-
dictionary = {};
|
|
70
|
-
/**
|
|
71
|
-
* The console command description.
|
|
72
|
-
*
|
|
73
|
-
* @var string
|
|
74
|
-
*/
|
|
75
|
-
description;
|
|
76
|
-
/**
|
|
77
|
-
* The console command input.
|
|
78
|
-
*
|
|
79
|
-
* @var object
|
|
80
|
-
*/
|
|
81
|
-
input = {
|
|
82
|
-
options: {},
|
|
83
|
-
arguments: {}
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Execute the console command.
|
|
87
|
-
*/
|
|
88
|
-
async handle(..._args) {
|
|
89
|
-
}
|
|
90
|
-
setApplication(app) {
|
|
91
|
-
this.app = app;
|
|
92
|
-
}
|
|
93
|
-
setInput(options, args, regArgs, dictionary) {
|
|
94
|
-
this.dictionary = dictionary;
|
|
95
|
-
this.input.options = options;
|
|
96
|
-
this.input.arguments = regArgs.map((e, i) => ({
|
|
97
|
-
[e.name()]: args[i]
|
|
98
|
-
})).reduce((e, x) => Object.assign(e, x), {});
|
|
99
|
-
}
|
|
100
|
-
getSignature() {
|
|
101
|
-
return this.signature;
|
|
102
|
-
}
|
|
103
|
-
getDescription() {
|
|
104
|
-
return this.description;
|
|
105
|
-
}
|
|
106
|
-
option(key, def) {
|
|
107
|
-
return this.input.options[key] ?? def;
|
|
108
|
-
}
|
|
109
|
-
options(key) {
|
|
110
|
-
if (key) {
|
|
111
|
-
return this.input.options[key];
|
|
112
|
-
}
|
|
113
|
-
return this.input.options;
|
|
114
|
-
}
|
|
115
|
-
argument(key, def) {
|
|
116
|
-
return this.input.arguments[key] ?? def;
|
|
117
|
-
}
|
|
118
|
-
arguments() {
|
|
119
|
-
return this.input.arguments;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
35
|
+
//#region src/Commands/Command.ts
|
|
36
|
+
var Command = class extends __h3ravel_core.ConsoleCommand {};
|
|
122
37
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/logo.ts
|
|
40
|
+
const logo = String.raw`
|
|
41
|
+
111
|
|
42
|
+
111111111
|
|
43
|
+
1111111111 111111
|
|
44
|
+
111111 111 111111
|
|
45
|
+
111111 111 111111
|
|
46
|
+
11111 111 11111
|
|
47
|
+
1111111 111 1111111
|
|
48
|
+
111 11111 111 111111 111 1111 1111 11111111 1111
|
|
49
|
+
111 11111 1111 111111 111 1111 1111 1111 11111 1111
|
|
50
|
+
111 11111 11111 111 1111 1111 111111111111 111111111111 1111 1111111 1111
|
|
51
|
+
111 111111 1111 111 111111111111 111111 11111 1111 111 1111 11111111 1111 1111
|
|
52
|
+
111 111 11111111 111 1101 1101 111111111 11111111 1111 1111111111111111101
|
|
53
|
+
111 1111111111111111 1111 111 1111 1111 111 11111011 1111 111 1111111 1101 1111
|
|
54
|
+
111 11111 1110111111111111 111 1111 1111 1111111101 1111 111111111 1111011 111111111 1111
|
|
55
|
+
1111111 111110111110 111 1111 1111 111111 1111 11011101 10111 11111 1111
|
|
56
|
+
11011 111111 11 11111
|
|
57
|
+
111111 11101 111111
|
|
58
|
+
111111 111 111111
|
|
59
|
+
111111 111 111111
|
|
60
|
+
111111111
|
|
61
|
+
110
|
|
62
|
+
`;
|
|
63
|
+
const altLogo = String.raw`
|
|
64
|
+
_ _ _____ _
|
|
65
|
+
| | | |___ / _ __ __ ___ _____| |
|
|
66
|
+
| |_| | |_ \| '__/ _ \ \ / / _ \ |
|
|
67
|
+
| _ |___) | | | (_| |\ V / __/ |
|
|
68
|
+
|_| |_|____/|_| \__,_| \_/ \___|_|
|
|
126
69
|
|
|
127
|
-
|
|
128
|
-
var import_path = require("path");
|
|
129
|
-
var import_fs = require("fs");
|
|
130
|
-
function sync_default(start, callback) {
|
|
131
|
-
let dir = (0, import_path.resolve)(".", start);
|
|
132
|
-
let tmp, stats = (0, import_fs.statSync)(dir);
|
|
133
|
-
if (!stats.isDirectory()) {
|
|
134
|
-
dir = (0, import_path.dirname)(dir);
|
|
135
|
-
}
|
|
136
|
-
while (true) {
|
|
137
|
-
tmp = callback(dir, (0, import_fs.readdirSync)(dir));
|
|
138
|
-
if (tmp) return (0, import_path.resolve)(dir, tmp);
|
|
139
|
-
dir = (0, import_path.dirname)(tmp = dir);
|
|
140
|
-
if (tmp === dir) break;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
__name(sync_default, "default");
|
|
70
|
+
`;
|
|
144
71
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
var
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
console.log(this.textFormat(name, color[status]), import_chalk.default.gray(".".repeat(dots)), value);
|
|
200
|
-
if (exit) process.exit(0);
|
|
201
|
-
}, "split"),
|
|
202
|
-
quiet: /* @__PURE__ */ __name(() => {
|
|
203
|
-
process.exit(0);
|
|
204
|
-
}, "quiet")
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
static findModulePkg(moduleId, cwd) {
|
|
208
|
-
const parts = moduleId.replace(/\\/g, "/").split("/");
|
|
209
|
-
let packageName = "";
|
|
210
|
-
if (parts.length > 0 && parts[0][0] === "@") {
|
|
211
|
-
packageName += parts.shift() + "/";
|
|
212
|
-
}
|
|
213
|
-
packageName += parts.shift();
|
|
214
|
-
const packageJson = import_path2.default.join(cwd ?? process.cwd(), "node_modules", packageName);
|
|
215
|
-
const resolved = this.findUpConfig(packageJson, "package", [
|
|
216
|
-
"json"
|
|
217
|
-
]);
|
|
218
|
-
if (!resolved) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
return import_path2.default.join(import_path2.default.dirname(resolved), parts.join("/"));
|
|
222
|
-
}
|
|
223
|
-
static async getMigrationPaths(cwd, migrator, defaultPath, path3) {
|
|
224
|
-
if (path3) {
|
|
225
|
-
return [
|
|
226
|
-
join(cwd, path3)
|
|
227
|
-
];
|
|
228
|
-
}
|
|
229
|
-
return [
|
|
230
|
-
...migrator.getPaths(),
|
|
231
|
-
join(cwd, defaultPath)
|
|
232
|
-
];
|
|
233
|
-
}
|
|
234
|
-
static twoColumnDetail(name, value) {
|
|
235
|
-
const regex = /\x1b\[\d+m/g;
|
|
236
|
-
const width = Math.min(process.stdout.columns, 100);
|
|
237
|
-
const dots = Math.max(width - name.replace(regex, "").length - value.replace(regex, "").length - 10, 0);
|
|
238
|
-
return console.log(name, import_chalk.default.gray(".".repeat(dots)), value);
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Check if file exists
|
|
242
|
-
*
|
|
243
|
-
* @param path
|
|
244
|
-
* @returns
|
|
245
|
-
*/
|
|
246
|
-
static async fileExists(path3) {
|
|
247
|
-
try {
|
|
248
|
-
await (0, import_promises.access)(path3);
|
|
249
|
-
return true;
|
|
250
|
-
} catch {
|
|
251
|
-
return false;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
static findUpConfig(cwd, name, extensions) {
|
|
255
|
-
return sync_default(cwd, (_dir, names) => {
|
|
256
|
-
for (const ext of extensions) {
|
|
257
|
-
const filename = `${name}.${ext}`;
|
|
258
|
-
if (names.includes(filename)) {
|
|
259
|
-
return filename;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return false;
|
|
263
|
-
});
|
|
264
|
-
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/Commands/ListCommand.ts
|
|
74
|
+
var ListCommand = class extends Command {
|
|
75
|
+
/**
|
|
76
|
+
* The name and signature of the console command.
|
|
77
|
+
*
|
|
78
|
+
* @var string
|
|
79
|
+
*/
|
|
80
|
+
signature = "list";
|
|
81
|
+
/**
|
|
82
|
+
* The console command description.
|
|
83
|
+
*
|
|
84
|
+
* @var string
|
|
85
|
+
*/
|
|
86
|
+
description = "List all available commands";
|
|
87
|
+
async handle() {
|
|
88
|
+
const options = [{
|
|
89
|
+
short: "-h",
|
|
90
|
+
long: "--help",
|
|
91
|
+
description: "Display help for the given command. When no command is given display help for the list command"
|
|
92
|
+
}].concat(this.program.options).map((e) => {
|
|
93
|
+
return __h3ravel_shared.Logger.describe(__h3ravel_shared.Logger.log(" " + [e.short, e.long].filter((e$1) => !!e$1).join(", "), "green", false), e.description, 25, false).join("");
|
|
94
|
+
});
|
|
95
|
+
const grouped = this.program.commands.map((e) => {
|
|
96
|
+
return __h3ravel_shared.Logger.describe(__h3ravel_shared.Logger.log(" " + e.name(), "green", false), e.description(), 25, false).join("");
|
|
97
|
+
}).reduce((acc, cmd) => {
|
|
98
|
+
/** strip colors before checking prefix */
|
|
99
|
+
const clean = cmd.replace(/\x1b\[\d+m/g, "");
|
|
100
|
+
const prefix = clean.includes(":") ? clean.split(":")[0].trim() : "__root__";
|
|
101
|
+
acc[prefix] ??= [];
|
|
102
|
+
/** keep original with colors */
|
|
103
|
+
acc[prefix].push(cmd);
|
|
104
|
+
return acc;
|
|
105
|
+
}, {});
|
|
106
|
+
const list = Object.entries(grouped).map(([group, cmds]) => {
|
|
107
|
+
const label = group === "__root__" ? "" : group;
|
|
108
|
+
return [__h3ravel_shared.Logger.log(label, "yellow", false), cmds.join("\n")].join("\n");
|
|
109
|
+
});
|
|
110
|
+
/** Ootput the app version */
|
|
111
|
+
__h3ravel_shared.Logger.log([["H3ravel Framework", "white"], [this.kernel.modulePackage.version, "green"]], " ");
|
|
112
|
+
console.log("");
|
|
113
|
+
console.log(altLogo);
|
|
114
|
+
console.log("");
|
|
115
|
+
__h3ravel_shared.Logger.log("Usage:", "yellow");
|
|
116
|
+
__h3ravel_shared.Logger.log(" command [options] [arguments]", "white");
|
|
117
|
+
console.log("");
|
|
118
|
+
/** Ootput the options */
|
|
119
|
+
__h3ravel_shared.Logger.log("Options:", "yellow");
|
|
120
|
+
console.log(options.join("\n").trim());
|
|
121
|
+
console.log("");
|
|
122
|
+
/** Ootput the commands */
|
|
123
|
+
__h3ravel_shared.Logger.log("Available Commands:", "yellow");
|
|
124
|
+
console.log(list.join("\n\n").trim());
|
|
125
|
+
}
|
|
265
126
|
};
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
127
|
+
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region ../filesystem/dist/index.js
|
|
130
|
+
var Helpers = class {
|
|
131
|
+
static findModulePkg(moduleId, cwd) {
|
|
132
|
+
const parts = moduleId.replace(/\\/g, "/").split("/");
|
|
133
|
+
let packageName = "";
|
|
134
|
+
if (parts.length > 0 && parts[0][0] === "@") packageName += parts.shift() + "/";
|
|
135
|
+
packageName += parts.shift();
|
|
136
|
+
const packageJson = path.default.join(cwd ?? process.cwd(), "node_modules", packageName);
|
|
137
|
+
const resolved = this.findUpConfig(packageJson, "package", ["json"]);
|
|
138
|
+
if (!resolved) return;
|
|
139
|
+
return path.default.join(path.default.dirname(resolved), parts.join("/"));
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Check if file exists
|
|
143
|
+
*
|
|
144
|
+
* @param path
|
|
145
|
+
* @returns
|
|
146
|
+
*/
|
|
147
|
+
static async fileExists(path$1$1) {
|
|
148
|
+
try {
|
|
149
|
+
await (0, fs_promises.access)(path$1$1);
|
|
150
|
+
return true;
|
|
151
|
+
} catch {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
static findUpConfig(cwd, name, extensions) {
|
|
156
|
+
return require_Utils.sync_default(cwd, (_dir, names) => {
|
|
157
|
+
for (const ext of extensions) {
|
|
158
|
+
const filename = `${name}.${ext}`;
|
|
159
|
+
if (names.includes(filename)) return filename;
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
299
164
|
};
|
|
300
165
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
var import_chalk2 = __toESM(require("chalk"), 1);
|
|
304
|
-
var import_dayjs = __toESM(require("dayjs"), 1);
|
|
305
|
-
var import_node_fs = require("fs");
|
|
306
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/Commands/MakeCommand.ts
|
|
307
168
|
var MakeCommand = class extends Command {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
{
|
|
321
|
-
|
|
322
|
-
|
|
169
|
+
/**
|
|
170
|
+
* The name and signature of the console command.
|
|
171
|
+
*
|
|
172
|
+
* @var string
|
|
173
|
+
*/
|
|
174
|
+
signature = `#make:
|
|
175
|
+
{controller : Create a new controller class.
|
|
176
|
+
| {--a|api : Exclude the create and edit methods from the controller}
|
|
177
|
+
| {--m|model= : Generate a resource controller for the given model}
|
|
178
|
+
| {--r|resource : Generate a resource controller class}
|
|
179
|
+
| {--force : Create the controller even if it already exists}
|
|
180
|
+
}
|
|
181
|
+
{resource : Create a new resource.
|
|
182
|
+
| {--c|collection : Create a resource collection}
|
|
183
|
+
| {--force : Create the resource even if it already exists}
|
|
184
|
+
}
|
|
185
|
+
{migration : Generates a new database migration class.
|
|
186
|
+
| {--l|type=ts : The file type to generate}
|
|
187
|
+
| {--t|table : The table to migrate}
|
|
188
|
+
| {--c|create : The table to be created}
|
|
189
|
+
}
|
|
190
|
+
{factory : Create a new model factory.}
|
|
191
|
+
{seeder : Create a new seeder class.}
|
|
192
|
+
{view : Create a new view.
|
|
193
|
+
| {--force : Create the view even if it already exists}
|
|
194
|
+
}
|
|
195
|
+
{model : Create a new Eloquent model class.
|
|
196
|
+
| {--api : Indicates if the generated controller should be an API resource controller}
|
|
197
|
+
| {--c|controller : Create a new controller for the model}
|
|
198
|
+
| {--f|factory : Create a new factory for the model}
|
|
199
|
+
| {--m|migration : Create a new migration file for the model}
|
|
200
|
+
| {--r|resource : Indicates if the generated controller should be a resource controller}
|
|
201
|
+
| {--a|all : Generate a migration, seeder, factory, policy, resource controller, and form request classes for the model}
|
|
202
|
+
| {--s|seed : Create a new seeder for the model}
|
|
203
|
+
| {--t|type=ts : The file type to generate}
|
|
204
|
+
| {--force : Create the model even if it already exists}
|
|
205
|
+
}
|
|
323
206
|
{^name : The name of the [name] to generate}
|
|
324
207
|
`;
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
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
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
208
|
+
/**
|
|
209
|
+
* The console command description.
|
|
210
|
+
*
|
|
211
|
+
* @var string
|
|
212
|
+
*/
|
|
213
|
+
description = "Generate component classes";
|
|
214
|
+
async handle() {
|
|
215
|
+
const command = this.dictionary.baseCommand ?? this.dictionary.name;
|
|
216
|
+
const methods = {
|
|
217
|
+
controller: "makeController",
|
|
218
|
+
resource: "makeResource",
|
|
219
|
+
migration: "makeMigration",
|
|
220
|
+
factory: "makeFactory",
|
|
221
|
+
seeder: "makeSeeder",
|
|
222
|
+
model: "makeModel",
|
|
223
|
+
view: "makeView"
|
|
224
|
+
};
|
|
225
|
+
try {
|
|
226
|
+
await this?.[methods[command]]();
|
|
227
|
+
} catch (e) {
|
|
228
|
+
__h3ravel_shared.Logger.error(e);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Create a new controller class.
|
|
233
|
+
*/
|
|
234
|
+
async makeController() {
|
|
235
|
+
const type = this.option("api") ? "-resource" : "";
|
|
236
|
+
const name = this.argument("name");
|
|
237
|
+
const force = this.option("force");
|
|
238
|
+
const path$5 = node_path.default.join(app_path("Http/Controllers"), name + ".ts");
|
|
239
|
+
const crtlrPath = Helpers.findModulePkg("@h3ravel/http", this.kernel.cwd) ?? "";
|
|
240
|
+
const stubPath = node_path.default.join(crtlrPath, `dist/stubs/controller${type}.stub`);
|
|
241
|
+
/** Check if the controller already exists */
|
|
242
|
+
if (!force && (0, node_fs.existsSync)(path$5)) __h3ravel_shared.Logger.error(`ERORR: ${name} controller already exists`);
|
|
243
|
+
let stub = await (0, node_fs_promises.readFile)(stubPath, "utf-8");
|
|
244
|
+
stub = stub.replace(/{{ name }}/g, name);
|
|
245
|
+
await (0, node_fs_promises.writeFile)(path$5, stub);
|
|
246
|
+
__h3ravel_shared.Logger.split("INFO: Controller Created", __h3ravel_shared.Logger.log(node_path.default.basename(path$5), "gray", false));
|
|
247
|
+
}
|
|
248
|
+
makeResource() {
|
|
249
|
+
__h3ravel_shared.Logger.success("Resource support is not yet available");
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Generate a new database migration class
|
|
253
|
+
*/
|
|
254
|
+
async makeMigration() {
|
|
255
|
+
const name = this.argument("name");
|
|
256
|
+
const datePrefix = (0, dayjs.default)().format("YYYY_MM_DD_HHmmss");
|
|
257
|
+
const path$5 = node_path.default.join(database_path("migrations"), `${datePrefix}_${name}.ts`);
|
|
258
|
+
const crtlrPath = require_Utils.Utils.findModulePkg("@h3ravel/database", this.kernel.cwd) ?? "";
|
|
259
|
+
let create = this.option("create", false);
|
|
260
|
+
let table = this.option("table");
|
|
261
|
+
if (!table && typeof create === "string") {
|
|
262
|
+
table = create;
|
|
263
|
+
create = true;
|
|
264
|
+
}
|
|
265
|
+
if (!table) {
|
|
266
|
+
const guessed = require_Utils.TableGuesser.guess(name);
|
|
267
|
+
table = guessed[0];
|
|
268
|
+
create = !!guessed[1];
|
|
269
|
+
}
|
|
270
|
+
const stubPath = node_path.default.join(crtlrPath, this.getMigrationStubName(table, create));
|
|
271
|
+
let stub = await (0, node_fs_promises.readFile)(stubPath, "utf-8");
|
|
272
|
+
if (table !== null) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
|
|
273
|
+
__h3ravel_shared.Logger.info("INFO: Creating Migration");
|
|
274
|
+
await this.kernel.ensureDirectoryExists(node_path.default.dirname(path$5));
|
|
275
|
+
await (0, node_fs_promises.writeFile)(path$5, stub);
|
|
276
|
+
__h3ravel_shared.Logger.split("INFO: Migration Created", __h3ravel_shared.Logger.log(node_path.default.basename(path$5), "gray", false));
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Create a new model factory
|
|
280
|
+
*/
|
|
281
|
+
makeFactory() {
|
|
282
|
+
__h3ravel_shared.Logger.success("Factory support is not yet available");
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Create a new seeder class
|
|
286
|
+
*/
|
|
287
|
+
makeSeeder() {
|
|
288
|
+
__h3ravel_shared.Logger.success("Seeder support is not yet available");
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Generate a new Arquebus model class
|
|
292
|
+
*/
|
|
293
|
+
async makeModel() {
|
|
294
|
+
const type = this.option("type", "ts");
|
|
295
|
+
const name = this.argument("name");
|
|
296
|
+
const force = this.argument("force");
|
|
297
|
+
const path$5 = node_path.default.join(app_path("Models"), name.toLowerCase(), "." + type);
|
|
298
|
+
/** Check if the model already exists */
|
|
299
|
+
if (!force && (0, node_fs.existsSync)(path$5)) __h3ravel_shared.Logger.error(`ERORR: ${name} view already exists`);
|
|
300
|
+
const crtlrPath = require_Utils.Utils.findModulePkg("@h3ravel/database", this.kernel.cwd) ?? "";
|
|
301
|
+
const stubPath = node_path.default.join(crtlrPath, `dist/stubs/model-${type}.stub`);
|
|
302
|
+
let stub = await (0, node_fs_promises.readFile)(stubPath, "utf-8");
|
|
303
|
+
stub = stub.replace(/{{ name }}/g, name);
|
|
304
|
+
await (0, node_fs_promises.writeFile)(path$5, stub);
|
|
305
|
+
__h3ravel_shared.Logger.split("INFO: Model Created", __h3ravel_shared.Logger.log(node_path.default.basename(path$5), "gray", false));
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Create a new view.
|
|
309
|
+
*/
|
|
310
|
+
async makeView() {
|
|
311
|
+
const name = this.argument("name");
|
|
312
|
+
const force = this.option("force");
|
|
313
|
+
const path$5 = node_path.default.join(base_path("src/resources/views"), name + ".edge");
|
|
314
|
+
if (name.includes("/")) await (0, node_fs_promises.mkdir)((0, __h3ravel_support.beforeLast)(path$5, "/"), { recursive: true });
|
|
315
|
+
/** Check if the view already exists */
|
|
316
|
+
if (!force && (0, node_fs.existsSync)(path$5)) __h3ravel_shared.Logger.error(`ERORR: ${name} view already exists`);
|
|
317
|
+
await (0, node_fs_promises.writeFile)(path$5, `{{-- src/resources/views/${name}.edge --}}`);
|
|
318
|
+
__h3ravel_shared.Logger.split("INFO: View Created", __h3ravel_shared.Logger.log(`src/resources/views/${name}.edge`, "gray", false));
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Ge the database migration file name
|
|
322
|
+
*
|
|
323
|
+
* @param table
|
|
324
|
+
* @param create
|
|
325
|
+
* @param type
|
|
326
|
+
* @returns
|
|
327
|
+
*/
|
|
328
|
+
getMigrationStubName(table, create = false, type = "ts") {
|
|
329
|
+
let stub;
|
|
330
|
+
if (!table) stub = `migration-${type}.stub`;
|
|
331
|
+
else if (create) stub = `migration.create-${type}.stub`;
|
|
332
|
+
else stub = `migration.update-${type}.stub`;
|
|
333
|
+
return "dist/stubs/" + stub;
|
|
334
|
+
}
|
|
436
335
|
};
|
|
437
336
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
337
|
+
//#endregion
|
|
338
|
+
//#region src/Signature.ts
|
|
339
|
+
var Signature = class Signature {
|
|
340
|
+
/**
|
|
341
|
+
* Helper to parse options inside a block of text
|
|
342
|
+
*
|
|
343
|
+
* @param block
|
|
344
|
+
* @returns
|
|
345
|
+
*/
|
|
346
|
+
static parseOptions(block) {
|
|
347
|
+
const options = [];
|
|
348
|
+
/**
|
|
349
|
+
* Match { ... } blocks at top level
|
|
350
|
+
*/
|
|
351
|
+
const regex = /\{([^{}]+(?:\{[^{}]*\}[^{}]*)*)\}/g;
|
|
352
|
+
let match;
|
|
353
|
+
while ((match = regex.exec(block)) !== null) {
|
|
354
|
+
const shared = "^" === match[1][0] || /:[#^]/.test(match[1]);
|
|
355
|
+
const isHidden = (["#", "^"].includes(match[1][0]) || /:[#^]/.test(match[1])) && !shared;
|
|
356
|
+
const content = match[1].trim().replace(/[#^]/, "");
|
|
357
|
+
/**
|
|
358
|
+
* Split by first ':' to separate name and description+nested
|
|
359
|
+
*/
|
|
360
|
+
const colonIndex = content.indexOf(":");
|
|
361
|
+
if (colonIndex === -1) {
|
|
362
|
+
/**
|
|
363
|
+
* No description, treat whole as name
|
|
364
|
+
*/
|
|
365
|
+
options.push({ name: content });
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
const namePart = content.substring(0, colonIndex).trim();
|
|
369
|
+
let rest = content.substring(colonIndex + 1).trim();
|
|
370
|
+
/**
|
|
371
|
+
* Check for nested options after '|'
|
|
372
|
+
*/
|
|
373
|
+
let description = rest;
|
|
374
|
+
let nestedOptions;
|
|
375
|
+
const pipeIndex = rest.indexOf("|");
|
|
376
|
+
if (pipeIndex !== -1) {
|
|
377
|
+
description = rest.substring(0, pipeIndex).trim();
|
|
378
|
+
/**
|
|
379
|
+
* nestedText should start with '{' and end with ')', clean it
|
|
380
|
+
* Also Remove trailing ')' if present
|
|
381
|
+
*/
|
|
382
|
+
const cleanedNestedText = rest.substring(pipeIndex + 1).trim().replace(/^\{/, "").trim();
|
|
383
|
+
/**
|
|
384
|
+
* Parse nested options recursively
|
|
385
|
+
*/
|
|
386
|
+
nestedOptions = Signature.parseOptions("{" + cleanedNestedText + "}");
|
|
387
|
+
} else
|
|
388
|
+
/**
|
|
389
|
+
* Trim the string
|
|
390
|
+
*/
|
|
391
|
+
description = description.trim();
|
|
392
|
+
/**
|
|
393
|
+
* Parse name modifiers (?, *, ?*)
|
|
394
|
+
*/
|
|
395
|
+
let name = namePart;
|
|
396
|
+
let required = /[^a-zA-Z0-9_|-]/.test(name);
|
|
397
|
+
let multiple = false;
|
|
398
|
+
if (name.endsWith("?*")) {
|
|
399
|
+
required = false;
|
|
400
|
+
multiple = true;
|
|
401
|
+
name = name.slice(0, -2);
|
|
402
|
+
} else if (name.endsWith("*")) {
|
|
403
|
+
multiple = true;
|
|
404
|
+
name = name.slice(0, -1);
|
|
405
|
+
} else if (name.endsWith("?")) {
|
|
406
|
+
required = false;
|
|
407
|
+
name = name.slice(0, -1);
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Check if it's a flag option (starts with --)
|
|
411
|
+
*/
|
|
412
|
+
const isFlag = name.startsWith("--");
|
|
413
|
+
let flags;
|
|
414
|
+
let defaultValue;
|
|
415
|
+
if (isFlag) {
|
|
416
|
+
/**
|
|
417
|
+
* Parse flags and default values
|
|
418
|
+
*/
|
|
419
|
+
const flagParts = name.split("|").map((s) => s.trim());
|
|
420
|
+
flags = [];
|
|
421
|
+
for (let part of flagParts) {
|
|
422
|
+
if (part.startsWith("--") && part.slice(2).length === 1) part = "-" + part.slice(2);
|
|
423
|
+
else if (part.startsWith("-") && !part.startsWith("--") && part.slice(1).length > 1) part = "--" + part.slice(1);
|
|
424
|
+
else if (!part.startsWith("-") && part.slice(1).length > 1) part = "--" + part;
|
|
425
|
+
const eqIndex = part.indexOf("=");
|
|
426
|
+
if (eqIndex !== -1) {
|
|
427
|
+
flags.push(part.substring(0, eqIndex));
|
|
428
|
+
const val = part.substring(eqIndex + 1);
|
|
429
|
+
if (val === "*") defaultValue = [];
|
|
430
|
+
else if (val === "true" || val === "false" || !val && !required) defaultValue = val === "true";
|
|
431
|
+
else if (!isNaN(Number(val))) defaultValue = Number(val);
|
|
432
|
+
else defaultValue = val;
|
|
433
|
+
} else flags.push(part);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
options.push({
|
|
437
|
+
name: isFlag ? flags[flags.length - 1] : name,
|
|
438
|
+
required,
|
|
439
|
+
multiple,
|
|
440
|
+
description,
|
|
441
|
+
flags,
|
|
442
|
+
shared,
|
|
443
|
+
isFlag,
|
|
444
|
+
isHidden,
|
|
445
|
+
defaultValue,
|
|
446
|
+
nestedOptions
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
return options;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Helper to parse a command's signature
|
|
453
|
+
*
|
|
454
|
+
* @param signature
|
|
455
|
+
* @param commandClass
|
|
456
|
+
* @returns
|
|
457
|
+
*/
|
|
458
|
+
static parseSignature(signature, commandClass) {
|
|
459
|
+
const lines = signature.split("\n").map((l) => l.trim()).filter((l) => l.length > 0);
|
|
460
|
+
const isHidden = ["#", "^"].includes(lines[0][0]) || /:[#^]/.test(lines[0]);
|
|
461
|
+
const baseCommand = lines[0].replace(/[^\w=:-]/g, "");
|
|
462
|
+
const description = commandClass.getDescription();
|
|
463
|
+
const isNamespaceCommand = baseCommand.endsWith(":");
|
|
464
|
+
/**
|
|
465
|
+
* Join the rest lines to a single string for parsing
|
|
466
|
+
*/
|
|
467
|
+
const rest = lines.slice(1).join(" ");
|
|
468
|
+
/**
|
|
469
|
+
* Parse all top-level options/subcommands
|
|
470
|
+
*/
|
|
471
|
+
const allOptions = Signature.parseOptions(rest);
|
|
472
|
+
if (isNamespaceCommand)
|
|
473
|
+
/**
|
|
474
|
+
* Separate subcommands (those without flags) and base options (flags)
|
|
475
|
+
* Here we assume subcommands are those without flags (isFlag false)
|
|
476
|
+
* and base options are flags or options after subcommands
|
|
477
|
+
|
|
478
|
+
* For simplicity, treat all top-level options as subcommands
|
|
479
|
+
* and assume base command options come after subcommands in signature (not shown in example)
|
|
480
|
+
*/
|
|
481
|
+
return {
|
|
482
|
+
baseCommand: baseCommand.slice(0, -1),
|
|
483
|
+
isNamespaceCommand,
|
|
484
|
+
subCommands: allOptions.filter((e) => !e.flags && !e.isHidden),
|
|
485
|
+
description,
|
|
486
|
+
commandClass,
|
|
487
|
+
options: allOptions.filter((e) => !!e.flags),
|
|
488
|
+
isHidden
|
|
489
|
+
};
|
|
490
|
+
else return {
|
|
491
|
+
baseCommand,
|
|
492
|
+
isNamespaceCommand,
|
|
493
|
+
options: allOptions,
|
|
494
|
+
description,
|
|
495
|
+
commandClass,
|
|
496
|
+
isHidden
|
|
497
|
+
};
|
|
498
|
+
}
|
|
583
499
|
};
|
|
584
500
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
const pipeIndex = rest.indexOf("|");
|
|
634
|
-
if (pipeIndex !== -1) {
|
|
635
|
-
description = rest.substring(0, pipeIndex).trim();
|
|
636
|
-
const nestedText = rest.substring(pipeIndex + 1).trim();
|
|
637
|
-
const cleanedNestedText = nestedText.replace(/^\{/, "").trim();
|
|
638
|
-
nestedOptions = _Signature.parseOptions("{" + cleanedNestedText + "}");
|
|
639
|
-
} else {
|
|
640
|
-
description = description.trim();
|
|
641
|
-
}
|
|
642
|
-
let name = namePart;
|
|
643
|
-
let required = /[^a-zA-Z0-9_|-]/.test(name);
|
|
644
|
-
let multiple = false;
|
|
645
|
-
if (name.endsWith("?*")) {
|
|
646
|
-
required = false;
|
|
647
|
-
multiple = true;
|
|
648
|
-
name = name.slice(0, -2);
|
|
649
|
-
} else if (name.endsWith("*")) {
|
|
650
|
-
multiple = true;
|
|
651
|
-
name = name.slice(0, -1);
|
|
652
|
-
} else if (name.endsWith("?")) {
|
|
653
|
-
required = false;
|
|
654
|
-
name = name.slice(0, -1);
|
|
655
|
-
}
|
|
656
|
-
const isFlag = name.startsWith("--");
|
|
657
|
-
let flags;
|
|
658
|
-
let defaultValue;
|
|
659
|
-
if (isFlag) {
|
|
660
|
-
const flagParts = name.split("|").map((s) => s.trim());
|
|
661
|
-
flags = [];
|
|
662
|
-
for (let part of flagParts) {
|
|
663
|
-
if (part.startsWith("--") && part.slice(2).length === 1) {
|
|
664
|
-
part = "-" + part.slice(2);
|
|
665
|
-
} else if (part.startsWith("-") && !part.startsWith("--") && part.slice(1).length > 1) {
|
|
666
|
-
part = "--" + part.slice(1);
|
|
667
|
-
} else if (!part.startsWith("-") && part.slice(1).length > 1) {
|
|
668
|
-
part = "--" + part;
|
|
669
|
-
}
|
|
670
|
-
const eqIndex = part.indexOf("=");
|
|
671
|
-
if (eqIndex !== -1) {
|
|
672
|
-
flags.push(part.substring(0, eqIndex));
|
|
673
|
-
const val = part.substring(eqIndex + 1);
|
|
674
|
-
if (val === "*") {
|
|
675
|
-
defaultValue = [];
|
|
676
|
-
} else if (val === "true" || val === "false" || !val && !required) {
|
|
677
|
-
defaultValue = val === "true";
|
|
678
|
-
} else if (!isNaN(Number(val))) {
|
|
679
|
-
defaultValue = Number(val);
|
|
680
|
-
} else {
|
|
681
|
-
defaultValue = val;
|
|
682
|
-
}
|
|
683
|
-
} else {
|
|
684
|
-
flags.push(part);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
options.push({
|
|
689
|
-
name: isFlag ? flags[flags.length - 1] : name,
|
|
690
|
-
required,
|
|
691
|
-
multiple,
|
|
692
|
-
description,
|
|
693
|
-
flags,
|
|
694
|
-
shared,
|
|
695
|
-
isFlag,
|
|
696
|
-
isHidden,
|
|
697
|
-
defaultValue,
|
|
698
|
-
nestedOptions
|
|
699
|
-
});
|
|
700
|
-
}
|
|
701
|
-
return options;
|
|
702
|
-
}
|
|
703
|
-
/**
|
|
704
|
-
* Helper to parse a command's signature
|
|
705
|
-
*
|
|
706
|
-
* @param signature
|
|
707
|
-
* @param commandClass
|
|
708
|
-
* @returns
|
|
709
|
-
*/
|
|
710
|
-
static parseSignature(signature, commandClass) {
|
|
711
|
-
const lines = signature.split("\n").map((l) => l.trim()).filter((l) => l.length > 0);
|
|
712
|
-
const isHidden = [
|
|
713
|
-
"#",
|
|
714
|
-
"^"
|
|
715
|
-
].includes(lines[0][0]) || /:[#^]/.test(lines[0]);
|
|
716
|
-
const baseCommand = lines[0].replace(/[^\w=:-]/g, "");
|
|
717
|
-
const description = commandClass.getDescription();
|
|
718
|
-
const isNamespaceCommand = baseCommand.endsWith(":");
|
|
719
|
-
const rest = lines.slice(1).join(" ");
|
|
720
|
-
const allOptions = _Signature.parseOptions(rest);
|
|
721
|
-
if (isNamespaceCommand) {
|
|
722
|
-
return {
|
|
723
|
-
baseCommand: baseCommand.slice(0, -1),
|
|
724
|
-
isNamespaceCommand,
|
|
725
|
-
subCommands: allOptions.filter((e) => !e.flags && !e.isHidden),
|
|
726
|
-
description,
|
|
727
|
-
commandClass,
|
|
728
|
-
options: allOptions.filter((e) => !!e.flags),
|
|
729
|
-
isHidden
|
|
730
|
-
};
|
|
731
|
-
} else {
|
|
732
|
-
return {
|
|
733
|
-
baseCommand,
|
|
734
|
-
isNamespaceCommand,
|
|
735
|
-
options: allOptions,
|
|
736
|
-
description,
|
|
737
|
-
commandClass,
|
|
738
|
-
isHidden
|
|
739
|
-
};
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
};
|
|
501
|
+
//#endregion
|
|
502
|
+
//#region ../../node_modules/.pnpm/@rollup+plugin-run@3.1.0/node_modules/@rollup/plugin-run/dist/es/index.js
|
|
503
|
+
function run(opts = {}) {
|
|
504
|
+
let input;
|
|
505
|
+
let proc;
|
|
506
|
+
const args = opts.args || [];
|
|
507
|
+
const allowRestarts = opts.allowRestarts || false;
|
|
508
|
+
const overrideInput = opts.input;
|
|
509
|
+
const forkOptions = opts.options || opts;
|
|
510
|
+
delete forkOptions.args;
|
|
511
|
+
delete forkOptions.allowRestarts;
|
|
512
|
+
return {
|
|
513
|
+
name: "run",
|
|
514
|
+
buildStart(options) {
|
|
515
|
+
let inputs = overrideInput !== null && overrideInput !== void 0 ? overrideInput : options.input;
|
|
516
|
+
if (typeof inputs === "string") inputs = [inputs];
|
|
517
|
+
if (typeof inputs === "object") inputs = Object.values(inputs);
|
|
518
|
+
if (inputs.length > 1) throw new Error(`@rollup/plugin-run must have a single entry point; consider setting the \`input\` option`);
|
|
519
|
+
input = (0, path.resolve)(inputs[0]);
|
|
520
|
+
},
|
|
521
|
+
generateBundle(_outputOptions, _bundle, isWrite) {
|
|
522
|
+
if (!isWrite) this.error(`@rollup/plugin-run currently only works with bundles that are written to disk`);
|
|
523
|
+
},
|
|
524
|
+
writeBundle(outputOptions, bundle) {
|
|
525
|
+
const forkBundle = (dir$1, entryFileName$1) => {
|
|
526
|
+
if (proc) proc.kill();
|
|
527
|
+
proc = (0, child_process.fork)((0, path.join)(dir$1, entryFileName$1), args, forkOptions);
|
|
528
|
+
};
|
|
529
|
+
const dir = outputOptions.dir || (0, path.dirname)(outputOptions.file);
|
|
530
|
+
const entryFileName = Object.keys(bundle).find((fileName) => {
|
|
531
|
+
const chunk = bundle[fileName];
|
|
532
|
+
return chunk.isEntry && chunk.facadeModuleId === input;
|
|
533
|
+
});
|
|
534
|
+
if (entryFileName) {
|
|
535
|
+
forkBundle(dir, entryFileName);
|
|
536
|
+
if (allowRestarts) {
|
|
537
|
+
process.stdin.resume();
|
|
538
|
+
process.stdin.setEncoding("utf8");
|
|
539
|
+
process.stdin.on("data", (data) => {
|
|
540
|
+
const line = data.toString().trim().toLowerCase();
|
|
541
|
+
if (line === "rs" || line === "restart" || data.toString().charCodeAt(0) === 11) forkBundle(dir, entryFileName);
|
|
542
|
+
else if (line === "cls" || line === "clear" || data.toString().charCodeAt(0) === 12) console.clear();
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
} else this.error(`@rollup/plugin-run could not find output chunk`);
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
}
|
|
743
549
|
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
].join(" ");
|
|
788
|
-
import_commander.program.name("musket").version(`${cliVersion}
|
|
789
|
-
${localVersion}`);
|
|
790
|
-
import_commander.program.command("init").description("Initialize H3ravel.").action(async () => {
|
|
791
|
-
this.output.success(`Initialized: H3ravel has been initialized!`);
|
|
792
|
-
});
|
|
793
|
-
for (let i = 0; i < this.commands.length; i++) {
|
|
794
|
-
const command = this.commands[i];
|
|
795
|
-
const instance = command.commandClass;
|
|
796
|
-
if (command.isNamespaceCommand && command.subCommands) {
|
|
797
|
-
const cmd = command.isHidden ? import_commander.program : import_commander.program.command(command.baseCommand).description(command.description ?? "").action(async () => {
|
|
798
|
-
instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command);
|
|
799
|
-
await instance.handle();
|
|
800
|
-
});
|
|
801
|
-
if ((command.options?.length ?? 0) > 0) {
|
|
802
|
-
command.options?.filter((v, i2, a) => a.findIndex((t) => t.name === v.name) === i2).forEach((opt) => {
|
|
803
|
-
this.makeOption(opt, cmd);
|
|
804
|
-
});
|
|
805
|
-
}
|
|
806
|
-
command.subCommands.filter((v, i2, a) => !v.shared && a.findIndex((t) => t.name === v.name) === i2).forEach((sub) => {
|
|
807
|
-
const cmd2 = import_commander.program.command(`${command.baseCommand}:${sub.name}`).description(sub.description || "").action(async () => {
|
|
808
|
-
instance.setInput(cmd2.opts(), cmd2.args, cmd2.registeredArguments, sub);
|
|
809
|
-
await instance.handle();
|
|
810
|
-
});
|
|
811
|
-
command.subCommands?.filter((e) => e.shared).forEach((opt) => {
|
|
812
|
-
this.makeOption(opt, cmd2, false, sub);
|
|
813
|
-
});
|
|
814
|
-
command.options?.filter((e) => e.shared).forEach((opt) => {
|
|
815
|
-
this.makeOption(opt, cmd2, false, sub);
|
|
816
|
-
});
|
|
817
|
-
if (sub.nestedOptions) {
|
|
818
|
-
sub.nestedOptions.filter((v, i2, a) => a.findIndex((t) => t.name === v.name) === i2).forEach((opt) => {
|
|
819
|
-
this.makeOption(opt, cmd2);
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
|
-
});
|
|
823
|
-
} else {
|
|
824
|
-
const cmd = import_commander.program.command(command.baseCommand).description(command.description ?? "");
|
|
825
|
-
command?.options?.filter((v, i2, a) => a.findIndex((t) => t.name === v.name) === i2).forEach((opt) => {
|
|
826
|
-
this.makeOption(opt, cmd, true);
|
|
827
|
-
});
|
|
828
|
-
cmd.action(async () => {
|
|
829
|
-
instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command);
|
|
830
|
-
await instance.handle();
|
|
831
|
-
});
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
return import_commander.program;
|
|
835
|
-
}
|
|
836
|
-
makeOption(opt, cmd, parse, parent) {
|
|
837
|
-
const description = opt.description?.replace(/\[(\w+)\]/g, (_, k) => parent?.[k] ?? `[${k}]`) ?? "";
|
|
838
|
-
const type = opt.name.replaceAll("-", "");
|
|
839
|
-
if (opt.isFlag) {
|
|
840
|
-
if (parse) {
|
|
841
|
-
const flags = opt.flags?.map((f) => f.length === 1 ? `-${f}` : `--${f}`).join(", ");
|
|
842
|
-
cmd.option(flags || "", description, String(opt.defaultValue) || void 0);
|
|
843
|
-
} else {
|
|
844
|
-
cmd.option(opt.flags?.join(", ") + (opt.required ? ` <${type}>` : ""), description, opt.defaultValue);
|
|
845
|
-
}
|
|
846
|
-
} else {
|
|
847
|
-
cmd.argument(opt.required ? `<${opt.name}>` : `[${opt.name}]`, description, opt.defaultValue);
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
static async parse(kernel) {
|
|
851
|
-
return (await new _Musket(kernel.app, kernel).build()).parseAsync();
|
|
852
|
-
}
|
|
550
|
+
//#endregion
|
|
551
|
+
//#region src/TsdownConfig.ts
|
|
552
|
+
const env = process.env.NODE_ENV || "development";
|
|
553
|
+
const outDir = env === "development" ? ".h3ravel/serve" : "dist";
|
|
554
|
+
const TsDownConfig = {
|
|
555
|
+
outDir,
|
|
556
|
+
entry: ["src/**/*.ts"],
|
|
557
|
+
format: ["esm"],
|
|
558
|
+
target: "node22",
|
|
559
|
+
sourcemap: env === "development",
|
|
560
|
+
clean: true,
|
|
561
|
+
shims: true,
|
|
562
|
+
copy: [
|
|
563
|
+
{
|
|
564
|
+
from: "public",
|
|
565
|
+
to: outDir
|
|
566
|
+
},
|
|
567
|
+
"src/resources",
|
|
568
|
+
"src/database"
|
|
569
|
+
],
|
|
570
|
+
env: env === "development" ? {
|
|
571
|
+
NODE_ENV: env,
|
|
572
|
+
SRC_PATH: outDir
|
|
573
|
+
} : {},
|
|
574
|
+
watch: env === "development" && process.env.CLI_BUILD !== "true" ? [
|
|
575
|
+
".env",
|
|
576
|
+
".env.*",
|
|
577
|
+
"src",
|
|
578
|
+
"../../packages"
|
|
579
|
+
] : false,
|
|
580
|
+
dts: false,
|
|
581
|
+
logLevel: "silent",
|
|
582
|
+
nodeProtocol: true,
|
|
583
|
+
skipNodeModulesBundle: true,
|
|
584
|
+
plugins: env === "development" && process.env.CLI_BUILD !== "true" ? [run({
|
|
585
|
+
env: Object.assign({}, process.env, {
|
|
586
|
+
NODE_ENV: env,
|
|
587
|
+
SRC_PATH: outDir
|
|
588
|
+
}),
|
|
589
|
+
execArgv: ["-r", "source-map-support/register"],
|
|
590
|
+
allowRestarts: false,
|
|
591
|
+
input: process.cwd() + "/src/server.ts"
|
|
592
|
+
})] : []
|
|
853
593
|
};
|
|
594
|
+
var TsdownConfig_default = TsDownConfig;
|
|
854
595
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
596
|
+
//#endregion
|
|
597
|
+
//#region src/Musket.ts
|
|
598
|
+
/**
|
|
599
|
+
* Musket is H3ravel's CLI tool
|
|
600
|
+
*/
|
|
601
|
+
var Musket = class Musket {
|
|
602
|
+
commands = [];
|
|
603
|
+
constructor(app, kernel) {
|
|
604
|
+
this.app = app;
|
|
605
|
+
this.kernel = kernel;
|
|
606
|
+
}
|
|
607
|
+
async build() {
|
|
608
|
+
this.loadBaseCommands();
|
|
609
|
+
await this.loadDiscoveredCommands();
|
|
610
|
+
return this.initialize();
|
|
611
|
+
}
|
|
612
|
+
loadBaseCommands() {
|
|
613
|
+
[new MakeCommand(this.app, this.kernel), new ListCommand(this.app, this.kernel)].forEach((e) => this.addCommand(e));
|
|
614
|
+
}
|
|
615
|
+
async loadDiscoveredCommands() {
|
|
616
|
+
const commands = [...this.app.registeredCommands.map((cmd) => new cmd(this.app, this.kernel))];
|
|
617
|
+
/**
|
|
618
|
+
* Musket Commands auto registration
|
|
619
|
+
*/
|
|
620
|
+
const providers_path = app_path("Console/Commands/*.js").replace("/src/", "/.h3ravel/serve/");
|
|
621
|
+
/** Add the App Commands */
|
|
622
|
+
for await (const cmd of (0, node_fs_promises.glob)(providers_path)) {
|
|
623
|
+
const name = node_path.default.basename(cmd).replace(".js", "");
|
|
624
|
+
try {
|
|
625
|
+
const cmdClass = (await import(cmd))[name];
|
|
626
|
+
commands.push(new cmdClass(this.app, this.kernel));
|
|
627
|
+
} catch {}
|
|
628
|
+
}
|
|
629
|
+
commands.forEach((e) => this.addCommand(e));
|
|
630
|
+
}
|
|
631
|
+
addCommand(command) {
|
|
632
|
+
this.commands.push(Signature.parseSignature(command.getSignature(), command));
|
|
633
|
+
}
|
|
634
|
+
initialize() {
|
|
635
|
+
/** Init the Musket Version */
|
|
636
|
+
const cliVersion = __h3ravel_shared.Logger.parse([["Musket CLI:", "white"], [this.kernel.consolePackage.version, "green"]], " ", false);
|
|
637
|
+
/** Init the App Version */
|
|
638
|
+
const localVersion = __h3ravel_shared.Logger.parse([["H3ravel Framework:", "white"], [this.kernel.modulePackage.version, "green"]], " ", false);
|
|
639
|
+
const additional = {
|
|
640
|
+
quiet: ["-q, --quiet", "Do not output any message"],
|
|
641
|
+
silent: ["--silent", "Do not output any message"],
|
|
642
|
+
verbose: ["-v, --verbose <number>", "Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug"],
|
|
643
|
+
interaction: ["-n, --no-interaction", "Do not ask any interactive question"]
|
|
644
|
+
};
|
|
645
|
+
/** Init Commander */
|
|
646
|
+
commander.program.name("musket").version(`${cliVersion}\n${localVersion}`).addOption(new commander.Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).option(additional.quiet[0], additional.quiet[1]).option(additional.verbose[0], additional.verbose[1]).option(additional.interaction[0], additional.interaction[1]).description(altLogo).action(async () => {
|
|
647
|
+
const instance = new ListCommand(this.app, this.kernel);
|
|
648
|
+
instance.setInput(commander.program.opts(), commander.program.args, commander.program.registeredArguments, {}, commander.program);
|
|
649
|
+
instance.handle();
|
|
650
|
+
});
|
|
651
|
+
/** Create the init Command */
|
|
652
|
+
commander.program.command("init").description("Initialize H3ravel.").action(async () => {
|
|
653
|
+
__h3ravel_shared.Logger.success("Initialized: H3ravel has been initialized!");
|
|
654
|
+
});
|
|
655
|
+
/** Loop through all the available commands */
|
|
656
|
+
for (let i = 0; i < this.commands.length; i++) {
|
|
657
|
+
const command = this.commands[i];
|
|
658
|
+
const instance = command.commandClass;
|
|
659
|
+
if (command.isNamespaceCommand && command.subCommands) {
|
|
660
|
+
/**
|
|
661
|
+
* Initialize the base command
|
|
662
|
+
*/
|
|
663
|
+
const cmd = command.isHidden ? commander.program : commander.program.command(command.baseCommand).description(command.description ?? "").addOption(new commander.Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).option(additional.quiet[0], additional.quiet[1]).option(additional.verbose[0], additional.verbose[1]).option(additional.interaction[0], additional.interaction[1]).action(async () => {
|
|
664
|
+
instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command, commander.program);
|
|
665
|
+
await instance.handle();
|
|
666
|
+
});
|
|
667
|
+
/**
|
|
668
|
+
* Add options to the base command if it has any
|
|
669
|
+
*/
|
|
670
|
+
if ((command.options?.length ?? 0) > 0) command.options?.filter((v, i$1, a) => a.findIndex((t) => t.name === v.name) === i$1).forEach((opt) => {
|
|
671
|
+
this.makeOption(opt, cmd);
|
|
672
|
+
});
|
|
673
|
+
/**
|
|
674
|
+
* Initialize the sub commands
|
|
675
|
+
*/
|
|
676
|
+
command.subCommands.filter((v, i$1, a) => !v.shared && a.findIndex((t) => t.name === v.name) === i$1).forEach((sub) => {
|
|
677
|
+
const cmd$1 = commander.program.command(`${command.baseCommand}:${sub.name}`).description(sub.description || "").addOption(new commander.Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).option(additional.quiet[0], additional.quiet[1]).option(additional.verbose[0], additional.verbose[1]).option(additional.interaction[0], additional.interaction[1]).action(async () => {
|
|
678
|
+
instance.setInput(cmd$1.opts(), cmd$1.args, cmd$1.registeredArguments, sub, commander.program);
|
|
679
|
+
await instance.handle();
|
|
680
|
+
});
|
|
681
|
+
/**
|
|
682
|
+
* Add the shared arguments here
|
|
683
|
+
*/
|
|
684
|
+
command.subCommands?.filter((e) => e.shared).forEach((opt) => {
|
|
685
|
+
this.makeOption(opt, cmd$1, false, sub);
|
|
686
|
+
});
|
|
687
|
+
/**
|
|
688
|
+
* Add the shared options here
|
|
689
|
+
*/
|
|
690
|
+
command.options?.filter((e) => e.shared).forEach((opt) => {
|
|
691
|
+
this.makeOption(opt, cmd$1, false, sub);
|
|
692
|
+
});
|
|
693
|
+
/**
|
|
694
|
+
* Add options to the sub command if it has any
|
|
695
|
+
*/
|
|
696
|
+
if (sub.nestedOptions) sub.nestedOptions.filter((v, i$1, a) => a.findIndex((t) => t.name === v.name) === i$1).forEach((opt) => {
|
|
697
|
+
this.makeOption(opt, cmd$1);
|
|
698
|
+
});
|
|
699
|
+
});
|
|
700
|
+
} else {
|
|
701
|
+
/**
|
|
702
|
+
* Initialize command with options
|
|
703
|
+
*/
|
|
704
|
+
const cmd = commander.program.command(command.baseCommand).description(command.description ?? "").addOption(new commander.Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).option(additional.quiet[0], additional.quiet[1]).option(additional.verbose[0], additional.verbose[1]).option(additional.interaction[0], additional.interaction[1]);
|
|
705
|
+
command?.options?.filter((v, i$1, a) => a.findIndex((t) => t.name === v.name) === i$1).forEach((opt) => {
|
|
706
|
+
this.makeOption(opt, cmd, true);
|
|
707
|
+
});
|
|
708
|
+
cmd.action(async () => {
|
|
709
|
+
instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command, commander.program);
|
|
710
|
+
await instance.handle();
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
/** Rebuild the app on every command except fire so we wont need TS */
|
|
715
|
+
commander.program.hook("preAction", async (_, cmd) => {
|
|
716
|
+
if (cmd.name() !== "fire") await (0, tsdown.build)({
|
|
717
|
+
...TsdownConfig_default,
|
|
718
|
+
watch: false,
|
|
719
|
+
plugins: []
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
return commander.program;
|
|
723
|
+
}
|
|
724
|
+
makeOption(opt, cmd, parse, parent) {
|
|
725
|
+
const description = opt.description?.replace(/\[(\w+)\]/g, (_, k) => parent?.[k] ?? `[${k}]`) ?? "";
|
|
726
|
+
const type = opt.name.replaceAll("-", "");
|
|
727
|
+
if (opt.isFlag) if (parse) {
|
|
728
|
+
const flags = opt.flags?.map((f) => f.length === 1 ? `-${f}` : `--${f}`).join(", ").replaceAll("----", "--").replaceAll("---", "-");
|
|
729
|
+
cmd.option(flags || "", description, String(opt.defaultValue) || void 0);
|
|
730
|
+
} else cmd.option(opt.flags?.join(", ") + (opt.required ? ` <${type}>` : ""), description, opt.defaultValue);
|
|
731
|
+
else cmd.argument(opt.required ? `<${opt.name}>` : `[${opt.name}]`, description, opt.defaultValue);
|
|
732
|
+
}
|
|
733
|
+
static async parse(kernel) {
|
|
734
|
+
return (await new Musket(kernel.app, kernel).build()).parseAsync();
|
|
735
|
+
}
|
|
908
736
|
};
|
|
909
737
|
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
var
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
738
|
+
//#endregion
|
|
739
|
+
//#region src/Kernel.ts
|
|
740
|
+
var Kernel = class Kernel extends __h3ravel_core.ConsoleKernel {
|
|
741
|
+
constructor(app) {
|
|
742
|
+
super(app);
|
|
743
|
+
this.app = app;
|
|
744
|
+
}
|
|
745
|
+
static init(app) {
|
|
746
|
+
const instance = new Kernel(app);
|
|
747
|
+
Promise.all([instance.loadRequirements()]).then(([e]) => e.run());
|
|
748
|
+
}
|
|
749
|
+
async run() {
|
|
750
|
+
await Musket.parse(this);
|
|
751
|
+
process.exit(0);
|
|
752
|
+
}
|
|
753
|
+
async loadRequirements() {
|
|
754
|
+
this.cwd = node_path.default.join(process.cwd(), this.basePath);
|
|
755
|
+
this.modulePath = Helpers.findModulePkg("@h3ravel/core", this.cwd) ?? "";
|
|
756
|
+
this.consolePath = Helpers.findModulePkg("@h3ravel/console", this.cwd) ?? "";
|
|
757
|
+
try {
|
|
758
|
+
this.modulePackage = await import(node_path.default.join(this.modulePath, "package.json"));
|
|
759
|
+
} catch {
|
|
760
|
+
this.modulePackage = { version: "N/A" };
|
|
761
|
+
}
|
|
762
|
+
try {
|
|
763
|
+
this.consolePackage = await import(node_path.default.join(this.consolePath, "package.json"));
|
|
764
|
+
} catch {
|
|
765
|
+
this.consolePackage = { version: "N/A" };
|
|
766
|
+
}
|
|
767
|
+
return this;
|
|
768
|
+
}
|
|
929
769
|
};
|
|
930
770
|
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
771
|
+
//#endregion
|
|
772
|
+
//#region src/Providers/ConsoleServiceProvider.ts
|
|
773
|
+
/**
|
|
774
|
+
* Handles CLI commands and tooling.
|
|
775
|
+
*
|
|
776
|
+
* Register DatabaseManager and QueryBuilder.
|
|
777
|
+
* Set up ORM models and relationships.
|
|
778
|
+
* Register migration and seeder commands.
|
|
779
|
+
*
|
|
780
|
+
* Auto-Registered when in CLI mode
|
|
781
|
+
*/
|
|
782
|
+
var ConsoleServiceProvider = class extends __h3ravel_core.ServiceProvider {
|
|
783
|
+
static priority = 992;
|
|
784
|
+
/**
|
|
785
|
+
* Indicate that this service provider only runs in console
|
|
786
|
+
*/
|
|
787
|
+
static console = true;
|
|
788
|
+
register() {}
|
|
789
|
+
boot() {
|
|
790
|
+
Kernel.init(this.app);
|
|
791
|
+
process.on("SIGINT", () => {
|
|
792
|
+
process.exit(0);
|
|
793
|
+
});
|
|
794
|
+
process.on("SIGTERM", () => {
|
|
795
|
+
process.exit(0);
|
|
796
|
+
});
|
|
797
|
+
}
|
|
955
798
|
};
|
|
956
799
|
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
Utils
|
|
972
|
-
});
|
|
800
|
+
//#endregion
|
|
801
|
+
exports.Command = Command;
|
|
802
|
+
exports.ConsoleServiceProvider = ConsoleServiceProvider;
|
|
803
|
+
exports.Kernel = Kernel;
|
|
804
|
+
exports.ListCommand = ListCommand;
|
|
805
|
+
exports.MakeCommand = MakeCommand;
|
|
806
|
+
exports.Musket = Musket;
|
|
807
|
+
exports.Signature = Signature;
|
|
808
|
+
exports.TableGuesser = require_Utils.TableGuesser;
|
|
809
|
+
exports.TsDownConfig = TsDownConfig;
|
|
810
|
+
exports.Utils = require_Utils.Utils;
|
|
811
|
+
exports.altLogo = altLogo;
|
|
812
|
+
exports.logo = logo;
|
|
813
|
+
//# sourceMappingURL=index.cjs.map
|