@h3ravel/console 11.0.0 → 11.0.1

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