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