@h3ravel/console 11.0.2 → 11.0.3

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