@h3ravel/console 11.0.7 → 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.
Files changed (119) hide show
  1. package/bin/fire.cjs +2 -0
  2. package/bin/fire.js +2 -0
  3. package/dist/Utils-7OrjoB1C.d.cts +22 -0
  4. package/dist/Utils-B1kpj9-1.cjs +130 -0
  5. package/dist/Utils-B1kpj9-1.cjs.map +1 -0
  6. package/dist/Utils-DAJvoXlr.js +86 -0
  7. package/dist/Utils-DAJvoXlr.js.map +1 -0
  8. package/dist/Utils-DxnHOGMz.d.ts +22 -0
  9. package/dist/Utils.cjs +3 -217
  10. package/dist/Utils.d.cts +2 -0
  11. package/dist/Utils.d.ts +2 -0
  12. package/dist/Utils.js +3 -9
  13. package/dist/index.cjs +885 -933
  14. package/dist/index.cjs.map +1 -0
  15. package/dist/index.d.cts +270 -290
  16. package/dist/index.d.ts +270 -290
  17. package/dist/index.js +899 -44
  18. package/dist/index.js.map +1 -0
  19. package/package.json +35 -23
  20. package/bin/chunk-6Z5DP356.js +0 -1
  21. package/bin/lexer-DQCqS3nf-XQPNMZG6.js +0 -4
  22. package/bin/run.cjs +0 -26
  23. package/bin/run.js +0 -26
  24. package/dist/Commands/Command.cjs +0 -104
  25. package/dist/Commands/Command.js +0 -7
  26. package/dist/Commands/MakeCommand.cjs +0 -433
  27. package/dist/Commands/MakeCommand.js +0 -9
  28. package/dist/Commands/MigrateCommand.cjs +0 -200
  29. package/dist/Commands/MigrateCommand.js +0 -8
  30. package/dist/Commands/ServeCommand.cjs +0 -159
  31. package/dist/Commands/ServeCommand.js +0 -8
  32. package/dist/Contracts/ICommand.cjs +0 -18
  33. package/dist/Contracts/ICommand.js +0 -1
  34. package/dist/IO/app.cjs +0 -946
  35. package/dist/IO/app.js +0 -17
  36. package/dist/IO/providers.cjs +0 -930
  37. package/dist/IO/providers.js +0 -16
  38. package/dist/Kernel.cjs +0 -890
  39. package/dist/Kernel.js +0 -14
  40. package/dist/Musket.cjs +0 -835
  41. package/dist/Musket.js +0 -13
  42. package/dist/Providers/ConsoleServiceProvider.cjs +0 -912
  43. package/dist/Providers/ConsoleServiceProvider.js +0 -15
  44. package/dist/Signature.cjs +0 -172
  45. package/dist/Signature.js +0 -7
  46. package/dist/chunk-23QH5R54.js +0 -27
  47. package/dist/chunk-2O2AYFAG.js +0 -63
  48. package/dist/chunk-3ASEWMRX.js +0 -37
  49. package/dist/chunk-3FVPHQCH.js +0 -151
  50. package/dist/chunk-3RX6CLNR.js +0 -32
  51. package/dist/chunk-3VCNSA6P.js +0 -14
  52. package/dist/chunk-3WHUADTN.js +0 -6
  53. package/dist/chunk-6OCHCPBP.js +0 -36
  54. package/dist/chunk-6OIH6FS4.js +0 -32
  55. package/dist/chunk-7EWRZPTX.js +0 -63
  56. package/dist/chunk-7PUQ5ZIN.js +0 -6
  57. package/dist/chunk-A5AONVOH.js +0 -6
  58. package/dist/chunk-ADIVRUAJ.js +0 -27
  59. package/dist/chunk-CCEWV2BR.js +0 -39
  60. package/dist/chunk-CTQ6DUT2.js +0 -8
  61. package/dist/chunk-DXQTBFGG.js +0 -31
  62. package/dist/chunk-E4SSLXFT.js +0 -63
  63. package/dist/chunk-E5XIGIEX.js +0 -14
  64. package/dist/chunk-EIOQKTRM.js +0 -104
  65. package/dist/chunk-FOSDCKCR.js +0 -106
  66. package/dist/chunk-G4OE26TZ.js +0 -33
  67. package/dist/chunk-GVGO5OAK.js +0 -8
  68. package/dist/chunk-GXRCTWKL.js +0 -16
  69. package/dist/chunk-HVKW7JK4.js +0 -8
  70. package/dist/chunk-IGEFNODG.js +0 -22
  71. package/dist/chunk-JXL4VJHZ.js +0 -36
  72. package/dist/chunk-K3GOQSS3.js +0 -6
  73. package/dist/chunk-KCJKQP37.js +0 -133
  74. package/dist/chunk-KMIFCLXG.js +0 -16
  75. package/dist/chunk-KZA3MC77.js +0 -151
  76. package/dist/chunk-LLL3V7LB.js +0 -6
  77. package/dist/chunk-LQ6DL2HS.js +0 -68
  78. package/dist/chunk-M4ZRDJJ2.js +0 -68
  79. package/dist/chunk-MAQAT3PU.js +0 -32
  80. package/dist/chunk-MPXPSSLJ.js +0 -133
  81. package/dist/chunk-NADN2PHB.js +0 -0
  82. package/dist/chunk-NFRXMBRP.js +0 -24
  83. package/dist/chunk-NVPKTRMT.js +0 -7
  84. package/dist/chunk-O45AB4MX.js +0 -83
  85. package/dist/chunk-ORPRWIQ2.js +0 -33
  86. package/dist/chunk-P7M5PEDY.js +0 -18
  87. package/dist/chunk-PBNCVQZC.js +0 -6
  88. package/dist/chunk-PMV4TMFS.js +0 -151
  89. package/dist/chunk-POF4JGTX.js +0 -186
  90. package/dist/chunk-PYSJMSNM.js +0 -27
  91. package/dist/chunk-Q3OMG6YH.js +0 -186
  92. package/dist/chunk-QCNBVSFO.js +0 -68
  93. package/dist/chunk-QMEO4OUR.js +0 -151
  94. package/dist/chunk-QSQNELZQ.js +0 -83
  95. package/dist/chunk-RRP7K5LI.js +0 -36
  96. package/dist/chunk-SHUYVCID.js +0 -6
  97. package/dist/chunk-SP4JKAUC.js +0 -63
  98. package/dist/chunk-T6OOKENF.js +0 -6
  99. package/dist/chunk-TBDROT3I.js +0 -6356
  100. package/dist/chunk-TH2RWMWA.js +0 -133
  101. package/dist/chunk-TJZCDDEV.js +0 -36
  102. package/dist/chunk-TN5SV7LF.js +0 -133
  103. package/dist/chunk-U6TOLKGJ.js +0 -22
  104. package/dist/chunk-UCOXL3OM.js +0 -0
  105. package/dist/chunk-URLTFJET.js +0 -68
  106. package/dist/chunk-UWCTG2LX.js +0 -24
  107. package/dist/chunk-WO2BXMBQ.js +0 -6
  108. package/dist/chunk-XAWZUZVP.js +0 -32
  109. package/dist/chunk-XCOSZXAE.js +0 -133
  110. package/dist/chunk-XD2Q7LWE.js +0 -24
  111. package/dist/chunk-XSL373TG.js +0 -36
  112. package/dist/chunk-XUYTJO6X.js +0 -104
  113. package/dist/chunk-YAYU7VOK.js +0 -8
  114. package/dist/chunk-YRUCICBV.js +0 -24
  115. package/dist/chunk-Z5XE72Q5.js +0 -68
  116. package/dist/chunk-ZTIO25VB.js +0 -8
  117. package/dist/lexer-DQCqS3nf-6W2BHF4T.js +0 -68
  118. package/dist/run.cjs +0 -943
  119. package/dist/run.js +0 -14
@@ -1,912 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
-
31
- // src/Providers/ConsoleServiceProvider.ts
32
- var ConsoleServiceProvider_exports = {};
33
- __export(ConsoleServiceProvider_exports, {
34
- ConsoleServiceProvider: () => ConsoleServiceProvider
35
- });
36
- module.exports = __toCommonJS(ConsoleServiceProvider_exports);
37
- var import_node_events = require("events");
38
-
39
- // src/Utils.ts
40
- var import_promises = require("fs/promises");
41
- var import_chalk = __toESM(require("chalk"), 1);
42
-
43
- // ../../node_modules/.pnpm/escalade@3.2.0/node_modules/escalade/sync/index.mjs
44
- var import_path = require("path");
45
- var import_fs = require("fs");
46
- function sync_default(start, callback) {
47
- let dir = (0, import_path.resolve)(".", start);
48
- let tmp, stats = (0, import_fs.statSync)(dir);
49
- if (!stats.isDirectory()) {
50
- dir = (0, import_path.dirname)(dir);
51
- }
52
- while (true) {
53
- tmp = callback(dir, (0, import_fs.readdirSync)(dir));
54
- if (tmp) return (0, import_path.resolve)(dir, tmp);
55
- dir = (0, import_path.dirname)(tmp = dir);
56
- if (tmp === dir) break;
57
- }
58
- }
59
- __name(sync_default, "default");
60
-
61
- // src/Utils.ts
62
- var import_path2 = __toESM(require("path"), 1);
63
- var join = import_path2.default.join;
64
- var Utils = class {
65
- static {
66
- __name(this, "Utils");
67
- }
68
- /**
69
- * Wraps text with chalk
70
- *
71
- * @param txt
72
- * @param color
73
- * @returns
74
- */
75
- static textFormat(txt, color) {
76
- return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
77
- }
78
- /**
79
- * Ouput formater object
80
- *
81
- * @returns
82
- */
83
- static output() {
84
- return {
85
- success: /* @__PURE__ */ __name((msg, exit = false) => {
86
- console.log(import_chalk.default.green("\u2713"), this.textFormat(msg, import_chalk.default.bgGreen), "\n");
87
- if (exit) process.exit(0);
88
- }, "success"),
89
- info: /* @__PURE__ */ __name((msg, exit = false) => {
90
- console.log(import_chalk.default.blue("\u2139"), this.textFormat(msg, import_chalk.default.bgBlue), "\n");
91
- if (exit) process.exit(0);
92
- }, "info"),
93
- error: /* @__PURE__ */ __name((msg, exit = true) => {
94
- if (msg instanceof Error) {
95
- if (msg.message) {
96
- console.error(import_chalk.default.red("\u2716"), this.textFormat("ERROR:" + msg.message, import_chalk.default.bgRed));
97
- }
98
- console.error(import_chalk.default.red(`${msg.detail ? `${msg.detail}
99
- ` : ""}${msg.stack}`), "\n");
100
- } else {
101
- console.error(import_chalk.default.red("\u2716"), this.textFormat(msg, import_chalk.default.bgRed), "\n");
102
- }
103
- if (exit) process.exit(1);
104
- }, "error"),
105
- split: /* @__PURE__ */ __name((name, value, status, exit = false) => {
106
- status ??= "info";
107
- const color = {
108
- success: import_chalk.default.bgGreen,
109
- info: import_chalk.default.bgBlue,
110
- error: import_chalk.default.bgRed
111
- };
112
- const regex = /\x1b\[\d+m/g;
113
- const width = Math.min(process.stdout.columns, 100);
114
- const dots = Math.max(width - name.replace(regex, "").length - value.replace(regex, "").length - 10, 0);
115
- console.log(this.textFormat(name, color[status]), import_chalk.default.gray(".".repeat(dots)), value);
116
- if (exit) process.exit(0);
117
- }, "split"),
118
- quiet: /* @__PURE__ */ __name(() => {
119
- process.exit(0);
120
- }, "quiet")
121
- };
122
- }
123
- static findModulePkg(moduleId, cwd) {
124
- const parts = moduleId.replace(/\\/g, "/").split("/");
125
- let packageName = "";
126
- if (parts.length > 0 && parts[0][0] === "@") {
127
- packageName += parts.shift() + "/";
128
- }
129
- packageName += parts.shift();
130
- const packageJson = import_path2.default.join(cwd ?? process.cwd(), "node_modules", packageName);
131
- const resolved = this.findUpConfig(packageJson, "package", [
132
- "json"
133
- ]);
134
- if (!resolved) {
135
- return;
136
- }
137
- return import_path2.default.join(import_path2.default.dirname(resolved), parts.join("/"));
138
- }
139
- static async getMigrationPaths(cwd, migrator, defaultPath, path3) {
140
- if (path3) {
141
- return [
142
- join(cwd, path3)
143
- ];
144
- }
145
- return [
146
- ...migrator.getPaths(),
147
- join(cwd, defaultPath)
148
- ];
149
- }
150
- static twoColumnDetail(name, value) {
151
- const regex = /\x1b\[\d+m/g;
152
- const width = Math.min(process.stdout.columns, 100);
153
- const dots = Math.max(width - name.replace(regex, "").length - value.replace(regex, "").length - 10, 0);
154
- return console.log(name, import_chalk.default.gray(".".repeat(dots)), value);
155
- }
156
- /**
157
- * Check if file exists
158
- *
159
- * @param path
160
- * @returns
161
- */
162
- static async fileExists(path3) {
163
- try {
164
- await (0, import_promises.access)(path3);
165
- return true;
166
- } catch {
167
- return false;
168
- }
169
- }
170
- static findUpConfig(cwd, name, extensions) {
171
- return sync_default(cwd, (_dir, names) => {
172
- for (const ext of extensions) {
173
- const filename = `${name}.${ext}`;
174
- if (names.includes(filename)) {
175
- return filename;
176
- }
177
- }
178
- return false;
179
- });
180
- }
181
- };
182
- var TableGuesser = class TableGuesser2 {
183
- static {
184
- __name(this, "TableGuesser");
185
- }
186
- static CREATE_PATTERNS = [
187
- /^create_(\w+)_table$/,
188
- /^create_(\w+)$/
189
- ];
190
- static CHANGE_PATTERNS = [
191
- /.+_(to|from|in)_(\w+)_table$/,
192
- /.+_(to|from|in)_(\w+)$/
193
- ];
194
- static guess(migration) {
195
- for (const pattern of TableGuesser2.CREATE_PATTERNS) {
196
- const matches = migration.match(pattern);
197
- if (matches) {
198
- return [
199
- matches[1],
200
- true
201
- ];
202
- }
203
- }
204
- for (const pattern of TableGuesser2.CHANGE_PATTERNS) {
205
- const matches = migration.match(pattern);
206
- if (matches) {
207
- return [
208
- matches[2],
209
- false
210
- ];
211
- }
212
- }
213
- return [];
214
- }
215
- };
216
-
217
- // src/Commands/MakeCommand.ts
218
- var import_promises2 = require("fs/promises");
219
-
220
- // src/Commands/Command.ts
221
- var Command = class {
222
- static {
223
- __name(this, "Command");
224
- }
225
- app;
226
- kernel;
227
- constructor(app, kernel) {
228
- this.app = app;
229
- this.kernel = kernel;
230
- }
231
- /**
232
- * The name and signature of the console command.
233
- *
234
- * @var string
235
- */
236
- signature;
237
- /**
238
- * A dictionary of signatures or what not.
239
- *
240
- * @var object
241
- */
242
- dictionary = {};
243
- /**
244
- * The console command description.
245
- *
246
- * @var string
247
- */
248
- description;
249
- /**
250
- * The console command input.
251
- *
252
- * @var object
253
- */
254
- input = {
255
- options: {},
256
- arguments: {}
257
- };
258
- /**
259
- * Execute the console command.
260
- */
261
- async handle(..._args) {
262
- }
263
- setApplication(app) {
264
- this.app = app;
265
- }
266
- setInput(options, args, regArgs, dictionary) {
267
- this.dictionary = dictionary;
268
- this.input.options = options;
269
- this.input.arguments = regArgs.map((e, i) => ({
270
- [e.name()]: args[i]
271
- })).reduce((e, x) => Object.assign(e, x), {});
272
- }
273
- getSignature() {
274
- return this.signature;
275
- }
276
- getDescription() {
277
- return this.description;
278
- }
279
- option(key, def) {
280
- return this.input.options[key] ?? def;
281
- }
282
- options(key) {
283
- if (key) {
284
- return this.input.options[key];
285
- }
286
- return this.input.options;
287
- }
288
- argument(key, def) {
289
- return this.input.arguments[key] ?? def;
290
- }
291
- arguments() {
292
- return this.input.arguments;
293
- }
294
- };
295
-
296
- // src/Commands/MakeCommand.ts
297
- var import_chalk2 = __toESM(require("chalk"), 1);
298
- var import_dayjs = __toESM(require("dayjs"), 1);
299
- var import_node_fs = require("fs");
300
- var import_node_path = __toESM(require("path"), 1);
301
- var MakeCommand = class extends Command {
302
- static {
303
- __name(this, "MakeCommand");
304
- }
305
- /**
306
- * The name and signature of the console command.
307
- *
308
- * @var string
309
- */
310
- signature = `#make:
311
- {controller : Generates a new controller class. | {--a|api : Generate an API resource controller} | {--force : Overide existing controller.} }
312
- {resource : Generates a new API resource class.}
313
- {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} }
314
- {factory : Generates a new database factory class.}
315
- {seeder : Generates a new database seeder class.}
316
- {model : Generates a new Arquebus model class. | {--t|type=ts : The file type to generate}}
317
- {^name : The name of the [name] to generate}
318
- `;
319
- /**
320
- * The console command description.
321
- *
322
- * @var string
323
- */
324
- description = "Generate component classes";
325
- async handle() {
326
- const command = this.dictionary.baseCommand;
327
- const methods = {
328
- controller: "makeController",
329
- resource: "makeResource",
330
- migration: "makeMigration",
331
- factory: "makeFactory",
332
- seeder: "makeSeeder",
333
- model: "makeModel"
334
- };
335
- try {
336
- await this?.[methods[command]]();
337
- } catch (e) {
338
- this.kernel.output.error(e);
339
- }
340
- }
341
- /**
342
- * Generate a new controller class.
343
- */
344
- async makeController() {
345
- const type = this.option("api") ? "-resource" : "";
346
- const name = this.argument("name");
347
- const force = this.option("force");
348
- const path3 = import_node_path.default.join(app_path("Http/Controllers"), name + ".ts");
349
- const dbPath = Utils.findModulePkg("@h3ravel/http", this.kernel.cwd) ?? "";
350
- const stubPath = import_node_path.default.join(dbPath, `dist/stubs/controller${type}.stub`);
351
- if (!force && (0, import_node_fs.existsSync)(path3)) {
352
- this.kernel.output.error(`ERORR: ${name} controller already exists`);
353
- }
354
- let stub = await (0, import_promises2.readFile)(stubPath, "utf-8");
355
- stub = stub.replace(/{{ name }}/g, name);
356
- await (0, import_promises2.writeFile)(path3, stub);
357
- this.kernel.output.split(`INFO: Controller Created`, import_chalk2.default.gray(import_node_path.default.basename(path3)));
358
- }
359
- makeResource() {
360
- this.kernel.output.success(`Resource support is not yet available`);
361
- }
362
- /**
363
- * Generate a new database migration class
364
- */
365
- async makeMigration() {
366
- const name = this.argument("name");
367
- const datePrefix = (0, import_dayjs.default)().format("YYYY_MM_DD_HHmmss");
368
- const path3 = import_node_path.default.join(database_path("migrations"), `${datePrefix}_${name}.ts`);
369
- const dbPath = Utils.findModulePkg("@h3ravel/database", this.kernel.cwd) ?? "";
370
- let create = this.option("create", false);
371
- let table = this.option("table");
372
- if (!table && typeof create === "string") {
373
- table = create;
374
- create = true;
375
- }
376
- if (!table) {
377
- const guessed = TableGuesser.guess(name);
378
- table = guessed[0];
379
- create = !!guessed[1];
380
- }
381
- const stubPath = import_node_path.default.join(dbPath, this.getMigrationStubName(table, create));
382
- let stub = await (0, import_promises2.readFile)(stubPath, "utf-8");
383
- if (table !== null) {
384
- stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
385
- }
386
- this.kernel.output.info("INFO: Creating Migration");
387
- await this.kernel.ensureDirectoryExists(import_node_path.default.dirname(path3));
388
- await (0, import_promises2.writeFile)(path3, stub);
389
- this.kernel.output.split(`INFO: Migration Created`, import_chalk2.default.gray(import_node_path.default.basename(path3)));
390
- }
391
- makeFactory() {
392
- this.kernel.output.success(`Factory support is not yet available`);
393
- }
394
- makeSeeder() {
395
- this.kernel.output.success(`Seeder support is not yet available`);
396
- }
397
- /**
398
- * Generate a new Arquebus model class
399
- */
400
- async makeModel() {
401
- const type = this.option("type", "ts");
402
- const name = this.argument("name");
403
- const path3 = import_node_path.default.join(app_path("Models"), name.toLowerCase() + "." + type);
404
- const dbPath = Utils.findModulePkg("@h3ravel/database", this.kernel.cwd) ?? "";
405
- const stubPath = import_node_path.default.join(dbPath, `dist/stubs/model-${type}.stub`);
406
- let stub = await (0, import_promises2.readFile)(stubPath, "utf-8");
407
- stub = stub.replace(/{{ name }}/g, name);
408
- await (0, import_promises2.writeFile)(path3, stub);
409
- this.kernel.output.split(`INFO: Model Created`, import_chalk2.default.gray(import_node_path.default.basename(path3)));
410
- }
411
- /**
412
- * Ge the database migration file name
413
- *
414
- * @param table
415
- * @param create
416
- * @param type
417
- * @returns
418
- */
419
- getMigrationStubName(table, create = false, type = "ts") {
420
- let stub;
421
- if (!table) {
422
- stub = `migration-${type}.stub`;
423
- } else if (create) {
424
- stub = `migration.create-${type}.stub`;
425
- } else {
426
- stub = `migration.update-${type}.stub`;
427
- }
428
- return "dist/stubs/" + stub;
429
- }
430
- };
431
-
432
- // src/Commands/MigrateCommand.ts
433
- var MigrateCommand = class extends Command {
434
- static {
435
- __name(this, "MigrateCommand");
436
- }
437
- /**
438
- * The name and signature of the console command.
439
- *
440
- * @var string
441
- */
442
- signature = `migrate:
443
- {fresh : Drop all tables and re-run all migrations.}
444
- {install : Create the migration repository.}
445
- {refresh : Reset and re-run all migrations.}
446
- {reset : Rollback all database migrations.}
447
- {rollback : Rollback the last database migration.}
448
- {status : Show the status of each migration.}
449
- {publish : Publish any migration files from installed packages.}
450
- {^--s|seed : Seed the database}
451
- `;
452
- /**
453
- * The console command description.
454
- *
455
- * @var string
456
- */
457
- description = "Run all pending migrations.";
458
- /**
459
- * Execute the console command.
460
- */
461
- async handle() {
462
- const command = this.dictionary.name ?? this.dictionary.baseCommand;
463
- const methods = {
464
- migrate: "migrateRun",
465
- fresh: "migrateFresh",
466
- install: "migrateInstall",
467
- refresh: "migrateRefresh",
468
- reset: "migrateReset",
469
- rollback: "migrateRollback",
470
- status: "migrateStatus",
471
- publish: "migratePublish"
472
- };
473
- await this?.[methods[command]]();
474
- }
475
- /**
476
- * Run all pending migrations.
477
- */
478
- async migrateRun() {
479
- this.kernel.output.success(`Running migrations are not yet supported.`);
480
- }
481
- /**
482
- * Drop all tables and re-run all migrations.
483
- */
484
- async migrateFresh() {
485
- this.kernel.output.success(`Drop all tables and re-run all migrations.`);
486
- }
487
- /**
488
- * Create the migration repository.
489
- */
490
- async migrateInstall() {
491
- this.kernel.output.success(`Create the migration repository.`);
492
- }
493
- /**
494
- * Reset and re-run all migrations.
495
- */
496
- async migrateRefresh() {
497
- this.kernel.output.success(`Resetting and re-running migrations is not yet supported.`);
498
- }
499
- /**
500
- * Rollback all database migrations.
501
- */
502
- async migrateReset() {
503
- this.kernel.output.success(`Rolling back all migration is not yet supported.`);
504
- }
505
- /**
506
- * Rollback the last database migration.
507
- */
508
- async migrateRollback() {
509
- this.kernel.output.success(`Rolling back the last migration is not yet supported.`);
510
- }
511
- /**
512
- * Show the status of each migration.
513
- */
514
- async migrateStatus() {
515
- const path3 = app_path();
516
- this.kernel.output.success(`Show the status of each migration.`);
517
- }
518
- /**
519
- * Publish any migration files from installed packages.
520
- */
521
- async migratePublish() {
522
- this.kernel.output.success(`Publish any migration files from installed packages.`);
523
- }
524
- };
525
-
526
- // src/Commands/ServeCommand.ts
527
- var import_node_child_process = require("child_process");
528
- var ServeCommand = class extends Command {
529
- static {
530
- __name(this, "ServeCommand");
531
- }
532
- /**
533
- * The name and signature of the console command.
534
- *
535
- * @var string
536
- */
537
- signature = "serve";
538
- /**
539
- * The console command description.
540
- *
541
- * @var string
542
- */
543
- description = "Start the Developement Server";
544
- async handle() {
545
- try {
546
- await this.serve();
547
- } catch (e) {
548
- this.kernel.output.error(e);
549
- }
550
- }
551
- async serve() {
552
- const child = (0, import_node_child_process.spawn)("tsup-node", {
553
- stdio: "inherit",
554
- shell: true,
555
- env: Object.assign({}, process.env, {
556
- NODE_ENV: "development"
557
- }),
558
- detached: false
559
- });
560
- const cleanup = /* @__PURE__ */ __name(() => {
561
- console.log(111111);
562
- if (child.pid) {
563
- process.kill(child.pid, "SIGTERM");
564
- }
565
- }, "cleanup");
566
- process.on("SIGINT", () => child.kill("SIGINT"));
567
- process.on("SIGTERM", () => child.kill("SIGTERM"));
568
- process.on("SIGINT", () => {
569
- cleanup();
570
- process.exit(0);
571
- });
572
- process.on("SIGTERM", () => {
573
- cleanup();
574
- process.exit(0);
575
- });
576
- }
577
- };
578
-
579
- // src/Signature.ts
580
- var Signature = class _Signature {
581
- static {
582
- __name(this, "Signature");
583
- }
584
- /**
585
- * Helper to parse options inside a block of text
586
- *
587
- * @param block
588
- * @returns
589
- */
590
- static parseOptions(block) {
591
- const options = [];
592
- const regex = /\{([^{}]+(?:\{[^{}]*\}[^{}]*)*)\}/g;
593
- let match;
594
- while ((match = regex.exec(block)) !== null) {
595
- const shared = "^" === match[1][0] || /:[#^]/.test(match[1]);
596
- const isHidden = ([
597
- "#",
598
- "^"
599
- ].includes(match[1][0]) || /:[#^]/.test(match[1])) && !shared;
600
- const content = match[1].trim().replace(/[#^]/, "");
601
- const colonIndex = content.indexOf(":");
602
- if (colonIndex === -1) {
603
- options.push({
604
- name: content
605
- });
606
- continue;
607
- }
608
- const namePart = content.substring(0, colonIndex).trim();
609
- let rest = content.substring(colonIndex + 1).trim();
610
- let description = rest;
611
- let nestedOptions;
612
- const pipeIndex = rest.indexOf("|");
613
- if (pipeIndex !== -1) {
614
- description = rest.substring(0, pipeIndex).trim();
615
- const nestedText = rest.substring(pipeIndex + 1).trim();
616
- const cleanedNestedText = nestedText.replace(/^\{/, "").trim();
617
- nestedOptions = _Signature.parseOptions("{" + cleanedNestedText + "}");
618
- } else {
619
- description = description.trim();
620
- }
621
- let name = namePart;
622
- let required = /[^a-zA-Z0-9_|-]/.test(name);
623
- let multiple = false;
624
- if (name.endsWith("?*")) {
625
- required = false;
626
- multiple = true;
627
- name = name.slice(0, -2);
628
- } else if (name.endsWith("*")) {
629
- multiple = true;
630
- name = name.slice(0, -1);
631
- } else if (name.endsWith("?")) {
632
- required = false;
633
- name = name.slice(0, -1);
634
- }
635
- const isFlag = name.startsWith("--");
636
- let flags;
637
- let defaultValue;
638
- if (isFlag) {
639
- const flagParts = name.split("|").map((s) => s.trim());
640
- flags = [];
641
- for (let part of flagParts) {
642
- if (part.startsWith("--") && part.slice(2).length === 1) {
643
- part = "-" + part.slice(2);
644
- } else if (part.startsWith("-") && !part.startsWith("--") && part.slice(1).length > 1) {
645
- part = "--" + part.slice(1);
646
- } else if (!part.startsWith("-") && part.slice(1).length > 1) {
647
- part = "--" + part;
648
- }
649
- const eqIndex = part.indexOf("=");
650
- if (eqIndex !== -1) {
651
- flags.push(part.substring(0, eqIndex));
652
- const val = part.substring(eqIndex + 1);
653
- if (val === "*") {
654
- defaultValue = [];
655
- } else if (val === "true" || val === "false" || !val && !required) {
656
- defaultValue = val === "true";
657
- } else if (!isNaN(Number(val))) {
658
- defaultValue = Number(val);
659
- } else {
660
- defaultValue = val;
661
- }
662
- } else {
663
- flags.push(part);
664
- }
665
- }
666
- }
667
- options.push({
668
- name: isFlag ? flags[flags.length - 1] : name,
669
- required,
670
- multiple,
671
- description,
672
- flags,
673
- shared,
674
- isFlag,
675
- isHidden,
676
- defaultValue,
677
- nestedOptions
678
- });
679
- }
680
- return options;
681
- }
682
- /**
683
- * Helper to parse a command's signature
684
- *
685
- * @param signature
686
- * @param commandClass
687
- * @returns
688
- */
689
- static parseSignature(signature, commandClass) {
690
- const lines = signature.split("\n").map((l) => l.trim()).filter((l) => l.length > 0);
691
- const isHidden = [
692
- "#",
693
- "^"
694
- ].includes(lines[0][0]) || /:[#^]/.test(lines[0]);
695
- const baseCommand = lines[0].replace(/[^\w=:-]/g, "");
696
- const description = commandClass.getDescription();
697
- const isNamespaceCommand = baseCommand.endsWith(":");
698
- const rest = lines.slice(1).join(" ");
699
- const allOptions = _Signature.parseOptions(rest);
700
- if (isNamespaceCommand) {
701
- return {
702
- baseCommand: baseCommand.slice(0, -1),
703
- isNamespaceCommand,
704
- subCommands: allOptions.filter((e) => !e.flags && !e.isHidden),
705
- description,
706
- commandClass,
707
- options: allOptions.filter((e) => !!e.flags),
708
- isHidden
709
- };
710
- } else {
711
- return {
712
- baseCommand,
713
- isNamespaceCommand,
714
- options: allOptions,
715
- description,
716
- commandClass,
717
- isHidden
718
- };
719
- }
720
- }
721
- };
722
-
723
- // src/Musket.ts
724
- var import_chalk3 = __toESM(require("chalk"), 1);
725
- var import_commander = require("commander");
726
- var Musket = class _Musket {
727
- static {
728
- __name(this, "Musket");
729
- }
730
- app;
731
- kernel;
732
- output = Utils.output();
733
- commands = [];
734
- constructor(app, kernel) {
735
- this.app = app;
736
- this.kernel = kernel;
737
- }
738
- async build() {
739
- this.loadBaseCommands();
740
- await this.loadDiscoveredCommands();
741
- return this.initialize();
742
- }
743
- loadBaseCommands() {
744
- const commands = [
745
- new ServeCommand(this.app, this.kernel),
746
- new MakeCommand(this.app, this.kernel),
747
- new MigrateCommand(this.app, this.kernel)
748
- ];
749
- commands.forEach((e) => this.addCommand(e));
750
- }
751
- async loadDiscoveredCommands() {
752
- const commands = [];
753
- commands.forEach((e) => this.addCommand(e));
754
- }
755
- addCommand(command) {
756
- this.commands.push(Signature.parseSignature(command.getSignature(), command));
757
- }
758
- initialize() {
759
- const cliVersion = [
760
- "H3ravel Version:",
761
- import_chalk3.default.green(this.kernel.consolePackage.version)
762
- ].join(" ");
763
- const localVersion = [
764
- "Musket Version:",
765
- import_chalk3.default.green(this.kernel.modulePackage.version || "None")
766
- ].join(" ");
767
- import_commander.program.name("musket").version(`${cliVersion}
768
- ${localVersion}`);
769
- import_commander.program.command("init").description("Initialize H3ravel.").action(async () => {
770
- this.output.success(`Initialized: H3ravel has been initialized!`);
771
- });
772
- for (let i = 0; i < this.commands.length; i++) {
773
- const command = this.commands[i];
774
- const instance = command.commandClass;
775
- if (command.isNamespaceCommand && command.subCommands) {
776
- const cmd = command.isHidden ? import_commander.program : import_commander.program.command(command.baseCommand).description(command.description ?? "").action(async () => {
777
- instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command);
778
- await instance.handle();
779
- });
780
- if ((command.options?.length ?? 0) > 0) {
781
- command.options?.filter((v, i2, a) => a.findIndex((t) => t.name === v.name) === i2).forEach((opt) => {
782
- this.makeOption(opt, cmd);
783
- });
784
- }
785
- command.subCommands.filter((v, i2, a) => !v.shared && a.findIndex((t) => t.name === v.name) === i2).forEach((sub) => {
786
- const cmd2 = import_commander.program.command(`${command.baseCommand}:${sub.name}`).description(sub.description || "").action(async () => {
787
- instance.setInput(cmd2.opts(), cmd2.args, cmd2.registeredArguments, sub);
788
- await instance.handle();
789
- });
790
- command.subCommands?.filter((e) => e.shared).forEach((opt) => {
791
- this.makeOption(opt, cmd2, false, sub);
792
- });
793
- command.options?.filter((e) => e.shared).forEach((opt) => {
794
- this.makeOption(opt, cmd2, false, sub);
795
- });
796
- if (sub.nestedOptions) {
797
- sub.nestedOptions.filter((v, i2, a) => a.findIndex((t) => t.name === v.name) === i2).forEach((opt) => {
798
- this.makeOption(opt, cmd2);
799
- });
800
- }
801
- });
802
- } else {
803
- const cmd = import_commander.program.command(command.baseCommand).description(command.description ?? "");
804
- command?.options?.filter((v, i2, a) => a.findIndex((t) => t.name === v.name) === i2).forEach((opt) => {
805
- this.makeOption(opt, cmd, true);
806
- });
807
- cmd.action(async () => {
808
- instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command);
809
- await instance.handle();
810
- });
811
- }
812
- }
813
- return import_commander.program;
814
- }
815
- makeOption(opt, cmd, parse, parent) {
816
- const description = opt.description?.replace(/\[(\w+)\]/g, (_, k) => parent?.[k] ?? `[${k}]`) ?? "";
817
- const type = opt.name.replaceAll("-", "");
818
- if (opt.isFlag) {
819
- if (parse) {
820
- const flags = opt.flags?.map((f) => f.length === 1 ? `-${f}` : `--${f}`).join(", ");
821
- cmd.option(flags || "", description, String(opt.defaultValue) || void 0);
822
- } else {
823
- cmd.option(opt.flags?.join(", ") + (opt.required ? ` <${type}>` : ""), description, opt.defaultValue);
824
- }
825
- } else {
826
- cmd.argument(opt.required ? `<${opt.name}>` : `[${opt.name}]`, description, opt.defaultValue);
827
- }
828
- }
829
- static async parse(kernel) {
830
- return (await new _Musket(kernel.app, kernel).build()).parseAsync();
831
- }
832
- };
833
-
834
- // src/Kernel.ts
835
- var import_promises3 = require("fs/promises");
836
- var import_node_path2 = __toESM(require("path"), 1);
837
- var Kernel = class _Kernel {
838
- static {
839
- __name(this, "Kernel");
840
- }
841
- app;
842
- cwd;
843
- output = Utils.output();
844
- basePath = "";
845
- modulePath;
846
- consolePath;
847
- modulePackage;
848
- consolePackage;
849
- constructor(app, basePath) {
850
- this.app = app;
851
- }
852
- static init(app) {
853
- const instance = new _Kernel(app);
854
- Promise.all([
855
- instance.loadRequirements()
856
- ]).then(([e]) => e.run());
857
- }
858
- async run() {
859
- await Musket.parse(this);
860
- process.exit(0);
861
- }
862
- async ensureDirectoryExists(dir) {
863
- await (0, import_promises3.mkdir)(dir, {
864
- recursive: true
865
- });
866
- }
867
- async loadRequirements() {
868
- this.cwd = import_node_path2.default.join(process.cwd(), this.basePath);
869
- this.modulePath = Utils.findModulePkg("@h3ravel/core", this.cwd) ?? "";
870
- this.consolePath = Utils.findModulePkg("@h3ravel/console", this.cwd) ?? "";
871
- try {
872
- this.modulePackage = await import(import_node_path2.default.join(this.modulePath, "package.json"));
873
- } catch {
874
- this.modulePackage = {
875
- version: "N/A"
876
- };
877
- }
878
- try {
879
- this.consolePackage = await import(import_node_path2.default.join(this.consolePath, "package.json"));
880
- } catch {
881
- this.consolePackage = {
882
- version: "N/A"
883
- };
884
- }
885
- return this;
886
- }
887
- };
888
-
889
- // src/Providers/ConsoleServiceProvider.ts
890
- var import_core = require("@h3ravel/core");
891
- var ConsoleServiceProvider = class extends import_core.ServiceProvider {
892
- static {
893
- __name(this, "ConsoleServiceProvider");
894
- }
895
- static priority = 992;
896
- register() {
897
- }
898
- boot() {
899
- Kernel.init(this.app);
900
- new import_node_events.EventEmitter().once("SIGINT", () => process.exit(0));
901
- process.on("SIGINT", () => {
902
- process.exit(0);
903
- });
904
- process.on("SIGTERM", () => {
905
- process.exit(0);
906
- });
907
- }
908
- };
909
- // Annotate the CommonJS export names for ESM import in node:
910
- 0 && (module.exports = {
911
- ConsoleServiceProvider
912
- });