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