@h3ravel/console 11.0.7 → 11.2.0

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