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