@h3ravel/console 11.0.7 → 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 (119) 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 -933
  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 +35 -23
  20. package/bin/chunk-6Z5DP356.js +0 -1
  21. package/bin/lexer-DQCqS3nf-XQPNMZG6.js +0 -4
  22. package/bin/run.cjs +0 -26
  23. package/bin/run.js +0 -26
  24. package/dist/Commands/Command.cjs +0 -104
  25. package/dist/Commands/Command.js +0 -7
  26. package/dist/Commands/MakeCommand.cjs +0 -433
  27. package/dist/Commands/MakeCommand.js +0 -9
  28. package/dist/Commands/MigrateCommand.cjs +0 -200
  29. package/dist/Commands/MigrateCommand.js +0 -8
  30. package/dist/Commands/ServeCommand.cjs +0 -159
  31. package/dist/Commands/ServeCommand.js +0 -8
  32. package/dist/Contracts/ICommand.cjs +0 -18
  33. package/dist/Contracts/ICommand.js +0 -1
  34. package/dist/IO/app.cjs +0 -946
  35. package/dist/IO/app.js +0 -17
  36. package/dist/IO/providers.cjs +0 -930
  37. package/dist/IO/providers.js +0 -16
  38. package/dist/Kernel.cjs +0 -890
  39. package/dist/Kernel.js +0 -14
  40. package/dist/Musket.cjs +0 -835
  41. package/dist/Musket.js +0 -13
  42. package/dist/Providers/ConsoleServiceProvider.cjs +0 -912
  43. package/dist/Providers/ConsoleServiceProvider.js +0 -15
  44. package/dist/Signature.cjs +0 -172
  45. package/dist/Signature.js +0 -7
  46. package/dist/chunk-23QH5R54.js +0 -27
  47. package/dist/chunk-2O2AYFAG.js +0 -63
  48. package/dist/chunk-3ASEWMRX.js +0 -37
  49. package/dist/chunk-3FVPHQCH.js +0 -151
  50. package/dist/chunk-3RX6CLNR.js +0 -32
  51. package/dist/chunk-3VCNSA6P.js +0 -14
  52. package/dist/chunk-3WHUADTN.js +0 -6
  53. package/dist/chunk-6OCHCPBP.js +0 -36
  54. package/dist/chunk-6OIH6FS4.js +0 -32
  55. package/dist/chunk-7EWRZPTX.js +0 -63
  56. package/dist/chunk-7PUQ5ZIN.js +0 -6
  57. package/dist/chunk-A5AONVOH.js +0 -6
  58. package/dist/chunk-ADIVRUAJ.js +0 -27
  59. package/dist/chunk-CCEWV2BR.js +0 -39
  60. package/dist/chunk-CTQ6DUT2.js +0 -8
  61. package/dist/chunk-DXQTBFGG.js +0 -31
  62. package/dist/chunk-E4SSLXFT.js +0 -63
  63. package/dist/chunk-E5XIGIEX.js +0 -14
  64. package/dist/chunk-EIOQKTRM.js +0 -104
  65. package/dist/chunk-FOSDCKCR.js +0 -106
  66. package/dist/chunk-G4OE26TZ.js +0 -33
  67. package/dist/chunk-GVGO5OAK.js +0 -8
  68. package/dist/chunk-GXRCTWKL.js +0 -16
  69. package/dist/chunk-HVKW7JK4.js +0 -8
  70. package/dist/chunk-IGEFNODG.js +0 -22
  71. package/dist/chunk-JXL4VJHZ.js +0 -36
  72. package/dist/chunk-K3GOQSS3.js +0 -6
  73. package/dist/chunk-KCJKQP37.js +0 -133
  74. package/dist/chunk-KMIFCLXG.js +0 -16
  75. package/dist/chunk-KZA3MC77.js +0 -151
  76. package/dist/chunk-LLL3V7LB.js +0 -6
  77. package/dist/chunk-LQ6DL2HS.js +0 -68
  78. package/dist/chunk-M4ZRDJJ2.js +0 -68
  79. package/dist/chunk-MAQAT3PU.js +0 -32
  80. package/dist/chunk-MPXPSSLJ.js +0 -133
  81. package/dist/chunk-NADN2PHB.js +0 -0
  82. package/dist/chunk-NFRXMBRP.js +0 -24
  83. package/dist/chunk-NVPKTRMT.js +0 -7
  84. package/dist/chunk-O45AB4MX.js +0 -83
  85. package/dist/chunk-ORPRWIQ2.js +0 -33
  86. package/dist/chunk-P7M5PEDY.js +0 -18
  87. package/dist/chunk-PBNCVQZC.js +0 -6
  88. package/dist/chunk-PMV4TMFS.js +0 -151
  89. package/dist/chunk-POF4JGTX.js +0 -186
  90. package/dist/chunk-PYSJMSNM.js +0 -27
  91. package/dist/chunk-Q3OMG6YH.js +0 -186
  92. package/dist/chunk-QCNBVSFO.js +0 -68
  93. package/dist/chunk-QMEO4OUR.js +0 -151
  94. package/dist/chunk-QSQNELZQ.js +0 -83
  95. package/dist/chunk-RRP7K5LI.js +0 -36
  96. package/dist/chunk-SHUYVCID.js +0 -6
  97. package/dist/chunk-SP4JKAUC.js +0 -63
  98. package/dist/chunk-T6OOKENF.js +0 -6
  99. package/dist/chunk-TBDROT3I.js +0 -6356
  100. package/dist/chunk-TH2RWMWA.js +0 -133
  101. package/dist/chunk-TJZCDDEV.js +0 -36
  102. package/dist/chunk-TN5SV7LF.js +0 -133
  103. package/dist/chunk-U6TOLKGJ.js +0 -22
  104. package/dist/chunk-UCOXL3OM.js +0 -0
  105. package/dist/chunk-URLTFJET.js +0 -68
  106. package/dist/chunk-UWCTG2LX.js +0 -24
  107. package/dist/chunk-WO2BXMBQ.js +0 -6
  108. package/dist/chunk-XAWZUZVP.js +0 -32
  109. package/dist/chunk-XCOSZXAE.js +0 -133
  110. package/dist/chunk-XD2Q7LWE.js +0 -24
  111. package/dist/chunk-XSL373TG.js +0 -36
  112. package/dist/chunk-XUYTJO6X.js +0 -104
  113. package/dist/chunk-YAYU7VOK.js +0 -8
  114. package/dist/chunk-YRUCICBV.js +0 -24
  115. package/dist/chunk-Z5XE72Q5.js +0 -68
  116. package/dist/chunk-ZTIO25VB.js +0 -8
  117. package/dist/lexer-DQCqS3nf-6W2BHF4T.js +0 -68
  118. package/dist/run.cjs +0 -943
  119. package/dist/run.js +0 -14
package/dist/index.js CHANGED
@@ -1,45 +1,900 @@
1
- import "./chunk-NADN2PHB.js";
2
- import "./chunk-NVPKTRMT.js";
3
- import "./chunk-UWCTG2LX.js";
4
- import "./chunk-ADIVRUAJ.js";
5
- import {
6
- ConsoleServiceProvider
7
- } from "./chunk-6OIH6FS4.js";
8
- import {
9
- Kernel
10
- } from "./chunk-QCNBVSFO.js";
11
- import {
12
- Musket
13
- } from "./chunk-KCJKQP37.js";
14
- import {
15
- MigrateCommand
16
- } from "./chunk-EIOQKTRM.js";
17
- import {
18
- ServeCommand
19
- } from "./chunk-7EWRZPTX.js";
20
- import {
21
- Signature
22
- } from "./chunk-3FVPHQCH.js";
23
- import {
24
- MakeCommand
25
- } from "./chunk-PMV4TMFS.js";
26
- import {
27
- TableGuesser,
28
- Utils
29
- } from "./chunk-POF4JGTX.js";
30
- import {
31
- Command
32
- } from "./chunk-O45AB4MX.js";
33
- import "./chunk-SHUYVCID.js";
34
- export {
35
- Command,
36
- ConsoleServiceProvider,
37
- Kernel,
38
- MakeCommand,
39
- MigrateCommand,
40
- Musket,
41
- ServeCommand,
42
- Signature,
43
- TableGuesser,
44
- Utils
1
+ import { TableGuesser, Utils } from "./Utils-DAJvoXlr.js";
2
+ import { dirname, join, resolve } from "path";
3
+ import preferredPM from "preferred-pm";
4
+ import { execa } from "execa";
5
+ import { glob, mkdir, readFile, writeFile } from "node:fs/promises";
6
+ import chalk from "chalk";
7
+ import dayjs from "dayjs";
8
+ import { existsSync } from "node:fs";
9
+ import nodepath from "node:path";
10
+ import { Migrate, MigrationCreator } from "@h3ravel/arquebus/migrations";
11
+ import { arquebusConfig } from "@h3ravel/database";
12
+ import { Application, ServiceProvider } from "@h3ravel/core";
13
+ import "@h3ravel/console";
14
+ import "@h3ravel/http";
15
+ import "@h3ravel/router";
16
+ import "@h3ravel/cache";
17
+ import "@h3ravel/queue";
18
+ import "@h3ravel/mail";
19
+ import "@h3ravel/config";
20
+ import { Logger } from "@h3ravel/shared";
21
+ import { program } from "commander";
22
+ import { fork } from "child_process";
23
+
24
+ //#region src/Commands/Command.ts
25
+ var Command = class {
26
+ constructor(app, kernel) {
27
+ this.app = app;
28
+ this.kernel = kernel;
29
+ }
30
+ /**
31
+ * The name and signature of the console command.
32
+ *
33
+ * @var string
34
+ */
35
+ signature;
36
+ /**
37
+ * A dictionary of signatures or what not.
38
+ *
39
+ * @var object
40
+ */
41
+ dictionary = {};
42
+ /**
43
+ * The console command description.
44
+ *
45
+ * @var string
46
+ */
47
+ description;
48
+ /**
49
+ * The console command input.
50
+ *
51
+ * @var object
52
+ */
53
+ input = {
54
+ options: {},
55
+ arguments: {}
56
+ };
57
+ /**
58
+ * Execute the console command.
59
+ */
60
+ async handle(..._args) {}
61
+ setApplication(app) {
62
+ this.app = app;
63
+ }
64
+ setInput(options, args, regArgs, dictionary) {
65
+ this.dictionary = dictionary;
66
+ this.input.options = options;
67
+ this.input.arguments = regArgs.map((e, i) => ({ [e.name()]: args[i] })).reduce((e, x) => Object.assign(e, x), {});
68
+ }
69
+ getSignature() {
70
+ return this.signature;
71
+ }
72
+ getDescription() {
73
+ return this.description;
74
+ }
75
+ option(key, def) {
76
+ return this.input.options[key] ?? def;
77
+ }
78
+ options(key) {
79
+ if (key) return this.input.options[key];
80
+ return this.input.options;
81
+ }
82
+ argument(key, def) {
83
+ return this.input.arguments[key] ?? def;
84
+ }
85
+ arguments() {
86
+ return this.input.arguments;
87
+ }
45
88
  };
89
+
90
+ //#endregion
91
+ //#region src/Commands/FireCommand.ts
92
+ var FireCommand = class extends Command {
93
+ /**
94
+ * The name and signature of the console command.
95
+ *
96
+ * @var string
97
+ */
98
+ signature = `fire:
99
+ {--a|host=localhost : The host address to serve the application on}
100
+ {--p|port=3000 : The port to serve the application on}
101
+ {--t|tries=10 : The max number of ports to attempt to serve from}
102
+ {--d|debug : Show extra debug info, like registered service providers and more}
103
+ `;
104
+ /**
105
+ * The console command description.
106
+ *
107
+ * @var string
108
+ */
109
+ description = "Fire up the developement server";
110
+ async handle() {
111
+ try {
112
+ await this.fire();
113
+ } catch (e) {
114
+ this.kernel.output.error(e);
115
+ }
116
+ }
117
+ async fire() {
118
+ const outDir$1 = ".h3ravel/serve";
119
+ const pm = (await preferredPM(base_path()))?.name ?? "pnpm";
120
+ const port = this.option("port");
121
+ const host = this.option("host");
122
+ const tries = this.option("tries");
123
+ const ENV_VARS = {
124
+ EXTENDED_DEBUG: this.option("debug") ? "true" : "false",
125
+ CLI_BUILD: "false",
126
+ NODE_ENV: "development",
127
+ SRC_PATH: outDir$1,
128
+ HOSTNAME: host,
129
+ RETRIES: tries,
130
+ PORT: port
131
+ };
132
+ await execa(pm, [
133
+ "tsdown",
134
+ "--silent",
135
+ "--config-loader",
136
+ "unconfig",
137
+ "-c",
138
+ "tsdown.default.config.ts"
139
+ ], {
140
+ stdout: "inherit",
141
+ stderr: "inherit",
142
+ cwd: base_path(),
143
+ env: Object.assign({}, process.env, ENV_VARS)
144
+ });
145
+ }
146
+ };
147
+
148
+ //#endregion
149
+ //#region src/Commands/MakeCommand.ts
150
+ var MakeCommand = class extends Command {
151
+ /**
152
+ * The name and signature of the console command.
153
+ *
154
+ * @var string
155
+ */
156
+ signature = `#make:
157
+ {controller : Generates a new controller class. | {--a|api : Generate an API resource controller} | {--force : Overide existing controller.} }
158
+ {resource : Generates a new API resource class.}
159
+ {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} }
160
+ {factory : Generates a new database factory class.}
161
+ {seeder : Generates a new database seeder class.}
162
+ {model : Generates a new Arquebus model class. | {--t|type=ts : The file type to generate}}
163
+ {^name : The name of the [name] to generate}
164
+ `;
165
+ /**
166
+ * The console command description.
167
+ *
168
+ * @var string
169
+ */
170
+ description = "Generate component classes";
171
+ async handle() {
172
+ const command = this.dictionary.baseCommand;
173
+ const methods = {
174
+ controller: "makeController",
175
+ resource: "makeResource",
176
+ migration: "makeMigration",
177
+ factory: "makeFactory",
178
+ seeder: "makeSeeder",
179
+ model: "makeModel"
180
+ };
181
+ try {
182
+ await this?.[methods[command]]();
183
+ } catch (e) {
184
+ this.kernel.output.error(e);
185
+ }
186
+ }
187
+ /**
188
+ * Generate a new controller class.
189
+ */
190
+ async makeController() {
191
+ const type = this.option("api") ? "-resource" : "";
192
+ const name = this.argument("name");
193
+ const force = this.option("force");
194
+ const path$1 = nodepath.join(app_path("Http/Controllers"), name + ".ts");
195
+ const crtlrPath = Utils.findModulePkg("@h3ravel/http", this.kernel.cwd) ?? "";
196
+ const stubPath = nodepath.join(crtlrPath, `dist/stubs/controller${type}.stub`);
197
+ if (!force && existsSync(path$1)) this.kernel.output.error(`ERORR: ${name} controller already exists`);
198
+ let stub = await readFile(stubPath, "utf-8");
199
+ stub = stub.replace(/{{ name }}/g, name);
200
+ await writeFile(path$1, stub);
201
+ this.kernel.output.split(`INFO: Controller Created`, chalk.gray(nodepath.basename(path$1)));
202
+ }
203
+ makeResource() {
204
+ this.kernel.output.success(`Resource support is not yet available`);
205
+ }
206
+ /**
207
+ * Generate a new database migration class
208
+ */
209
+ async makeMigration() {
210
+ const name = this.argument("name");
211
+ const datePrefix = dayjs().format("YYYY_MM_DD_HHmmss");
212
+ const path$1 = nodepath.join(database_path("migrations"), `${datePrefix}_${name}.ts`);
213
+ const crtlrPath = Utils.findModulePkg("@h3ravel/database", this.kernel.cwd) ?? "";
214
+ let create = this.option("create", false);
215
+ let table = this.option("table");
216
+ if (!table && typeof create === "string") {
217
+ table = create;
218
+ create = true;
219
+ }
220
+ if (!table) {
221
+ const guessed = TableGuesser.guess(name);
222
+ table = guessed[0];
223
+ create = !!guessed[1];
224
+ }
225
+ const stubPath = nodepath.join(crtlrPath, this.getMigrationStubName(table, create));
226
+ let stub = await readFile(stubPath, "utf-8");
227
+ if (table !== null) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
228
+ this.kernel.output.info("INFO: Creating Migration");
229
+ await this.kernel.ensureDirectoryExists(nodepath.dirname(path$1));
230
+ await writeFile(path$1, stub);
231
+ this.kernel.output.split(`INFO: Migration Created`, chalk.gray(nodepath.basename(path$1)));
232
+ }
233
+ makeFactory() {
234
+ this.kernel.output.success(`Factory support is not yet available`);
235
+ }
236
+ makeSeeder() {
237
+ this.kernel.output.success(`Seeder support is not yet available`);
238
+ }
239
+ /**
240
+ * Generate a new Arquebus model class
241
+ */
242
+ async makeModel() {
243
+ const type = this.option("type", "ts");
244
+ const name = this.argument("name");
245
+ const path$1 = nodepath.join(app_path("Models"), name.toLowerCase() + "." + type);
246
+ const crtlrPath = Utils.findModulePkg("@h3ravel/database", this.kernel.cwd) ?? "";
247
+ const stubPath = nodepath.join(crtlrPath, `dist/stubs/model-${type}.stub`);
248
+ let stub = await readFile(stubPath, "utf-8");
249
+ stub = stub.replace(/{{ name }}/g, name);
250
+ await writeFile(path$1, stub);
251
+ this.kernel.output.split(`INFO: Model Created`, chalk.gray(nodepath.basename(path$1)));
252
+ }
253
+ /**
254
+ * Ge the database migration file name
255
+ *
256
+ * @param table
257
+ * @param create
258
+ * @param type
259
+ * @returns
260
+ */
261
+ getMigrationStubName(table, create = false, type = "ts") {
262
+ let stub;
263
+ if (!table) stub = `migration-${type}.stub`;
264
+ else if (create) stub = `migration.create-${type}.stub`;
265
+ else stub = `migration.update-${type}.stub`;
266
+ return "dist/stubs/" + stub;
267
+ }
268
+ };
269
+
270
+ //#endregion
271
+ //#region src/Commands/MigrateCommand.ts
272
+ var MigrateCommand = class extends Command {
273
+ /**
274
+ * The current database connection
275
+ */
276
+ connection;
277
+ /**
278
+ * The base path for all database operations
279
+ */
280
+ databasePath = database_path();
281
+ /**
282
+ * The name and signature of the console command.
283
+ *
284
+ * @var string
285
+ */
286
+ signature = `migrate:
287
+ {fresh : Drop all tables and re-run all migrations.}
288
+ {install : Create the migration repository.}
289
+ {refresh : Reset and re-run all migrations.}
290
+ {reset : Rollback all database migrations.}
291
+ {rollback : Rollback the last database migration.}
292
+ {status : Show the status of each migration.}
293
+ {publish : Publish any migration files from installed packages. | {package : The package to publish migrations from}}
294
+ {^--s|seed : Seed the database}
295
+ {^--c|connection=mysql : The database connection to use}
296
+ `;
297
+ /**
298
+ * The console command description.
299
+ *
300
+ * @var string
301
+ */
302
+ description = "Run all pending migrations.";
303
+ /**
304
+ * Execute the console command.
305
+ */
306
+ async handle() {
307
+ const command = this.dictionary.name ?? this.dictionary.baseCommand;
308
+ this.connection = Object.entries(arquebusConfig(config("database"))).find(([client]) => client === config("database.default"))?.at(1);
309
+ this.connection.migrations = {
310
+ path: "migrations",
311
+ table: "migrations"
312
+ };
313
+ await this?.[{
314
+ migrate: "migrateRun",
315
+ fresh: "migrateFresh",
316
+ install: "migrateInstall",
317
+ refresh: "migrateRefresh",
318
+ reset: "migrateReset",
319
+ rollback: "migrateRollback",
320
+ status: "migrateStatus",
321
+ publish: "migratePublish"
322
+ }[command]]();
323
+ }
324
+ /**
325
+ * Run all pending migrations.
326
+ */
327
+ async migrateRun() {
328
+ try {
329
+ await new Migrate(this.databasePath).run(this.connection, this.options(), true);
330
+ } catch (e) {
331
+ this.kernel.output.error("ERROR: " + e);
332
+ }
333
+ }
334
+ /**
335
+ * Drop all tables and re-run all migrations.
336
+ */
337
+ async migrateFresh() {
338
+ try {
339
+ await new Migrate(this.databasePath).fresh(this.connection, this.options(), true);
340
+ } catch (e) {
341
+ this.kernel.output.error("ERROR: " + e);
342
+ }
343
+ }
344
+ /**
345
+ * Create the migration repository.
346
+ */
347
+ async migrateInstall() {
348
+ try {
349
+ const migrate = new Migrate(this.databasePath);
350
+ const { migrator } = await migrate.setupConnection(this.connection);
351
+ await migrate.prepareDatabase(migrator);
352
+ this.kernel.output.success(`Migration repository installed.`);
353
+ } catch (e) {
354
+ this.kernel.output.error("ERROR: " + e);
355
+ }
356
+ }
357
+ /**
358
+ * Reset and re-run all migrations.
359
+ */
360
+ async migrateRefresh() {
361
+ try {
362
+ await new Migrate(this.databasePath).refresh(this.connection, this.options(), true);
363
+ } catch (e) {
364
+ this.kernel.output.error("ERROR: " + e);
365
+ }
366
+ }
367
+ /**
368
+ * Rollback all database migrations.
369
+ */
370
+ async migrateReset() {
371
+ try {
372
+ await new Migrate(this.databasePath).reset(this.connection, this.options(), true);
373
+ } catch (e) {
374
+ this.kernel.output.error("ERROR: " + e);
375
+ }
376
+ }
377
+ /**
378
+ * Rollback the last database migration.
379
+ */
380
+ async migrateRollback() {
381
+ try {
382
+ await new Migrate(this.databasePath).rollback(this.connection, this.options(), true);
383
+ } catch (e) {
384
+ this.kernel.output.error("ERROR: " + e);
385
+ }
386
+ }
387
+ /**
388
+ * Show the status of each migration.
389
+ */
390
+ async migrateStatus() {
391
+ const migrations = await new Migrate(this.databasePath, void 0, (msg, sts) => {
392
+ const hint = this.kernel.output.parse([[" Did you forget to run", "white"], ["`musket migrate:install`?", "grey"]], " ", false);
393
+ if (sts) this.kernel.output[sts](msg + hint, sts === "error", true);
394
+ }).status(this.connection, this.options(), true);
395
+ try {
396
+ if (migrations.length > 0) {
397
+ this.kernel.output.twoColumnLog("Migration name", "Batch / Status");
398
+ migrations.forEach((migration) => {
399
+ const status = migration.ran ? `[${migration.batch}] ${chalk.green("Ran")}` : chalk.yellow("Pending");
400
+ this.kernel.output.twoColumnLog(migration.name, status);
401
+ });
402
+ } else this.kernel.output.info("No migrations found");
403
+ } catch (e) {
404
+ this.kernel.output.error(["ERROR: " + e, "Did you run musket migrate:install"]);
405
+ }
406
+ }
407
+ /**
408
+ * Publish any migration files from installed packages.
409
+ */
410
+ async migratePublish() {
411
+ const name = this.argument("package");
412
+ try {
413
+ /** Find the requested package */
414
+ const packagePath = Utils.findModulePkg(name) ?? null;
415
+ if (!packagePath) throw new Error("Package not found");
416
+ /** Get the package,json and instanciate the migration creator */
417
+ const pkgJson = await import(nodepath.join(packagePath, "package.json"));
418
+ const creator = new MigrationCreator(nodepath.join(packagePath, pkgJson.migrations ?? "migrations"));
419
+ const info = this.kernel.output.parse([[" Publishing migrations from", "white"], [`${pkgJson.name}@${pkgJson.version}`, chalk.italic.gray]], " ", false);
420
+ this.kernel.output.info(`INFO: ${info}`);
421
+ try {
422
+ /** Publish any existing migrations */
423
+ await creator.publish(this.databasePath, (fileName) => {
424
+ this.kernel.output.twoColumnLog(fileName, chalk.green("PUBLISHED"));
425
+ });
426
+ } catch {
427
+ this.kernel.output.error([`ERROR: ${name} has no publishable migrations.`]);
428
+ }
429
+ } catch (e) {
430
+ const hint = this.kernel.output.parse([[" Did you forget to run", "white"], [`\`${await Utils.installCommand(name)}\``, "grey"]], " ", false);
431
+ const error = this.kernel.output.parse([
432
+ ["Package `", "white"],
433
+ [name, "grey"],
434
+ ["` not found", "white"]
435
+ ], "", false);
436
+ this.kernel.output.error([
437
+ "ERROR: " + error,
438
+ hint + "?",
439
+ String(e)
440
+ ]);
441
+ }
442
+ }
443
+ };
444
+
445
+ //#endregion
446
+ //#region src/Signature.ts
447
+ var Signature = class Signature {
448
+ /**
449
+ * Helper to parse options inside a block of text
450
+ *
451
+ * @param block
452
+ * @returns
453
+ */
454
+ static parseOptions(block) {
455
+ const options = [];
456
+ /**
457
+ * Match { ... } blocks at top level
458
+ */
459
+ const regex = /\{([^{}]+(?:\{[^{}]*\}[^{}]*)*)\}/g;
460
+ let match;
461
+ while ((match = regex.exec(block)) !== null) {
462
+ const shared = "^" === match[1][0] || /:[#^]/.test(match[1]);
463
+ const isHidden = (["#", "^"].includes(match[1][0]) || /:[#^]/.test(match[1])) && !shared;
464
+ const content = match[1].trim().replace(/[#^]/, "");
465
+ /**
466
+ * Split by first ':' to separate name and description+nested
467
+ */
468
+ const colonIndex = content.indexOf(":");
469
+ if (colonIndex === -1) {
470
+ /**
471
+ * No description, treat whole as name
472
+ */
473
+ options.push({ name: content });
474
+ continue;
475
+ }
476
+ const namePart = content.substring(0, colonIndex).trim();
477
+ let rest = content.substring(colonIndex + 1).trim();
478
+ /**
479
+ * Check for nested options after '|'
480
+ */
481
+ let description = rest;
482
+ let nestedOptions;
483
+ const pipeIndex = rest.indexOf("|");
484
+ if (pipeIndex !== -1) {
485
+ description = rest.substring(0, pipeIndex).trim();
486
+ /**
487
+ * nestedText should start with '{' and end with ')', clean it
488
+ * Also Remove trailing ')' if present
489
+ */
490
+ const cleanedNestedText = rest.substring(pipeIndex + 1).trim().replace(/^\{/, "").trim();
491
+ /**
492
+ * Parse nested options recursively
493
+ */
494
+ nestedOptions = Signature.parseOptions("{" + cleanedNestedText + "}");
495
+ } else
496
+ /**
497
+ * Trim the string
498
+ */
499
+ description = description.trim();
500
+ /**
501
+ * Parse name modifiers (?, *, ?*)
502
+ */
503
+ let name = namePart;
504
+ let required = /[^a-zA-Z0-9_|-]/.test(name);
505
+ let multiple = false;
506
+ if (name.endsWith("?*")) {
507
+ required = false;
508
+ multiple = true;
509
+ name = name.slice(0, -2);
510
+ } else if (name.endsWith("*")) {
511
+ multiple = true;
512
+ name = name.slice(0, -1);
513
+ } else if (name.endsWith("?")) {
514
+ required = false;
515
+ name = name.slice(0, -1);
516
+ }
517
+ /**
518
+ * Check if it's a flag option (starts with --)
519
+ */
520
+ const isFlag = name.startsWith("--");
521
+ let flags;
522
+ let defaultValue;
523
+ if (isFlag) {
524
+ /**
525
+ * Parse flags and default values
526
+ */
527
+ const flagParts = name.split("|").map((s) => s.trim());
528
+ flags = [];
529
+ for (let part of flagParts) {
530
+ if (part.startsWith("--") && part.slice(2).length === 1) part = "-" + part.slice(2);
531
+ else if (part.startsWith("-") && !part.startsWith("--") && part.slice(1).length > 1) part = "--" + part.slice(1);
532
+ else if (!part.startsWith("-") && part.slice(1).length > 1) part = "--" + part;
533
+ const eqIndex = part.indexOf("=");
534
+ if (eqIndex !== -1) {
535
+ flags.push(part.substring(0, eqIndex));
536
+ const val = part.substring(eqIndex + 1);
537
+ if (val === "*") defaultValue = [];
538
+ else if (val === "true" || val === "false" || !val && !required) defaultValue = val === "true";
539
+ else if (!isNaN(Number(val))) defaultValue = Number(val);
540
+ else defaultValue = val;
541
+ } else flags.push(part);
542
+ }
543
+ }
544
+ options.push({
545
+ name: isFlag ? flags[flags.length - 1] : name,
546
+ required,
547
+ multiple,
548
+ description,
549
+ flags,
550
+ shared,
551
+ isFlag,
552
+ isHidden,
553
+ defaultValue,
554
+ nestedOptions
555
+ });
556
+ }
557
+ return options;
558
+ }
559
+ /**
560
+ * Helper to parse a command's signature
561
+ *
562
+ * @param signature
563
+ * @param commandClass
564
+ * @returns
565
+ */
566
+ static parseSignature(signature, commandClass) {
567
+ const lines = signature.split("\n").map((l) => l.trim()).filter((l) => l.length > 0);
568
+ const isHidden = ["#", "^"].includes(lines[0][0]) || /:[#^]/.test(lines[0]);
569
+ const baseCommand = lines[0].replace(/[^\w=:-]/g, "");
570
+ const description = commandClass.getDescription();
571
+ const isNamespaceCommand = baseCommand.endsWith(":");
572
+ /**
573
+ * Join the rest lines to a single string for parsing
574
+ */
575
+ const rest = lines.slice(1).join(" ");
576
+ /**
577
+ * Parse all top-level options/subcommands
578
+ */
579
+ const allOptions = Signature.parseOptions(rest);
580
+ if (isNamespaceCommand)
581
+ /**
582
+ * Separate subcommands (those without flags) and base options (flags)
583
+ * Here we assume subcommands are those without flags (isFlag false)
584
+ * and base options are flags or options after subcommands
585
+
586
+ * For simplicity, treat all top-level options as subcommands
587
+ * and assume base command options come after subcommands in signature (not shown in example)
588
+ */
589
+ return {
590
+ baseCommand: baseCommand.slice(0, -1),
591
+ isNamespaceCommand,
592
+ subCommands: allOptions.filter((e) => !e.flags && !e.isHidden),
593
+ description,
594
+ commandClass,
595
+ options: allOptions.filter((e) => !!e.flags),
596
+ isHidden
597
+ };
598
+ else return {
599
+ baseCommand,
600
+ isNamespaceCommand,
601
+ options: allOptions,
602
+ description,
603
+ commandClass,
604
+ isHidden
605
+ };
606
+ }
607
+ };
608
+
609
+ //#endregion
610
+ //#region src/Musket.ts
611
+ /**
612
+ * Musket is H3ravel's CLI tool
613
+ */
614
+ var Musket = class Musket {
615
+ output = Logger.log();
616
+ commands = [];
617
+ constructor(app, kernel) {
618
+ this.app = app;
619
+ this.kernel = kernel;
620
+ }
621
+ async build() {
622
+ this.loadBaseCommands();
623
+ await this.loadDiscoveredCommands();
624
+ return this.initialize();
625
+ }
626
+ loadBaseCommands() {
627
+ [
628
+ new FireCommand(this.app, this.kernel),
629
+ new MakeCommand(this.app, this.kernel),
630
+ new MigrateCommand(this.app, this.kernel)
631
+ ].forEach((e) => this.addCommand(e));
632
+ }
633
+ async loadDiscoveredCommands() {
634
+ const commands = [...this.app.registeredCommands.map((cmd) => new cmd(this.app, this.kernel))];
635
+ /**
636
+ * Musket Commands auto registration
637
+ */
638
+ const providers_path = app_path("Console/Commands/*.js").replace("/src/", "/.h3ravel/serve/");
639
+ /** Add the App Commands */
640
+ for await (const cmd of glob(providers_path)) {
641
+ const name = nodepath.basename(cmd).replace(".js", "");
642
+ try {
643
+ const cmdClass = (await import(cmd))[name];
644
+ commands.push(new cmdClass(this.app, this.kernel));
645
+ } catch {}
646
+ }
647
+ commands.forEach((e) => this.addCommand(e));
648
+ }
649
+ addCommand(command) {
650
+ this.commands.push(Signature.parseSignature(command.getSignature(), command));
651
+ }
652
+ initialize() {
653
+ const cliVersion = ["H3ravel Version:", chalk.green(this.kernel.consolePackage.version)].join(" ");
654
+ const localVersion = ["Musket Version:", chalk.green(this.kernel.modulePackage.version || "None")].join(" ");
655
+ program.name("musket").version(`${cliVersion}\n${localVersion}`);
656
+ program.command("init").description("Initialize H3ravel.").action(async () => {
657
+ this.output.success(`Initialized: H3ravel has been initialized!`);
658
+ });
659
+ for (let i = 0; i < this.commands.length; i++) {
660
+ const command = this.commands[i];
661
+ const instance = command.commandClass;
662
+ if (command.isNamespaceCommand && command.subCommands) {
663
+ /**
664
+ * Initialize the base command
665
+ */
666
+ const cmd = command.isHidden ? program : program.command(command.baseCommand).description(command.description ?? "").action(async () => {
667
+ instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command);
668
+ await instance.handle();
669
+ });
670
+ /**
671
+ * Add options to the base command if it has any
672
+ */
673
+ if ((command.options?.length ?? 0) > 0) command.options?.filter((v, i$1, a) => a.findIndex((t) => t.name === v.name) === i$1).forEach((opt) => {
674
+ this.makeOption(opt, cmd);
675
+ });
676
+ /**
677
+ * Initialize the sub commands
678
+ */
679
+ command.subCommands.filter((v, i$1, a) => !v.shared && a.findIndex((t) => t.name === v.name) === i$1).forEach((sub) => {
680
+ const cmd$1 = program.command(`${command.baseCommand}:${sub.name}`).description(sub.description || "").action(async () => {
681
+ instance.setInput(cmd$1.opts(), cmd$1.args, cmd$1.registeredArguments, sub);
682
+ await instance.handle();
683
+ });
684
+ /**
685
+ * Add the shared arguments here
686
+ */
687
+ command.subCommands?.filter((e) => e.shared).forEach((opt) => {
688
+ this.makeOption(opt, cmd$1, false, sub);
689
+ });
690
+ /**
691
+ * Add the shared options here
692
+ */
693
+ command.options?.filter((e) => e.shared).forEach((opt) => {
694
+ this.makeOption(opt, cmd$1, false, sub);
695
+ });
696
+ /**
697
+ * Add options to the sub command if it has any
698
+ */
699
+ if (sub.nestedOptions) sub.nestedOptions.filter((v, i$1, a) => a.findIndex((t) => t.name === v.name) === i$1).forEach((opt) => {
700
+ this.makeOption(opt, cmd$1);
701
+ });
702
+ });
703
+ } else {
704
+ /**
705
+ * Initialize command with options
706
+ */
707
+ const cmd = program.command(command.baseCommand).description(command.description ?? "");
708
+ command?.options?.filter((v, i$1, a) => a.findIndex((t) => t.name === v.name) === i$1).forEach((opt) => {
709
+ this.makeOption(opt, cmd, true);
710
+ });
711
+ cmd.action(async () => {
712
+ instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command);
713
+ await instance.handle();
714
+ });
715
+ }
716
+ }
717
+ return program;
718
+ }
719
+ makeOption(opt, cmd, parse, parent) {
720
+ const description = opt.description?.replace(/\[(\w+)\]/g, (_, k) => parent?.[k] ?? `[${k}]`) ?? "";
721
+ const type = opt.name.replaceAll("-", "");
722
+ if (opt.isFlag) if (parse) {
723
+ const flags = opt.flags?.map((f) => f.length === 1 ? `-${f}` : `--${f}`).join(", ").replaceAll("----", "--").replaceAll("---", "-");
724
+ cmd.option(flags || "", description, String(opt.defaultValue) || void 0);
725
+ } else cmd.option(opt.flags?.join(", ") + (opt.required ? ` <${type}>` : ""), description, opt.defaultValue);
726
+ else cmd.argument(opt.required ? `<${opt.name}>` : `[${opt.name}]`, description, opt.defaultValue);
727
+ }
728
+ static async parse(kernel) {
729
+ return (await new Musket(kernel.app, kernel).build()).parseAsync();
730
+ }
731
+ };
732
+
733
+ //#endregion
734
+ //#region src/Kernel.ts
735
+ var Kernel = class Kernel {
736
+ cwd;
737
+ output = Logger.log();
738
+ basePath = "";
739
+ modulePath;
740
+ consolePath;
741
+ modulePackage;
742
+ consolePackage;
743
+ constructor(app) {
744
+ this.app = app;
745
+ }
746
+ static init(app) {
747
+ const instance = new Kernel(app);
748
+ Promise.all([instance.loadRequirements()]).then(([e]) => e.run());
749
+ }
750
+ async run() {
751
+ await Musket.parse(this);
752
+ process.exit(0);
753
+ }
754
+ async ensureDirectoryExists(dir) {
755
+ await mkdir(dir, { recursive: true });
756
+ }
757
+ async loadRequirements() {
758
+ this.cwd = nodepath.join(process.cwd(), this.basePath);
759
+ this.modulePath = Utils.findModulePkg("@h3ravel/core", this.cwd) ?? "";
760
+ this.consolePath = Utils.findModulePkg("@h3ravel/console", this.cwd) ?? "";
761
+ try {
762
+ this.modulePackage = await import(nodepath.join(this.modulePath, "package.json"));
763
+ } catch {
764
+ this.modulePackage = { version: "N/A" };
765
+ }
766
+ try {
767
+ this.consolePackage = await import(nodepath.join(this.consolePath, "package.json"));
768
+ } catch {
769
+ this.consolePackage = { version: "N/A" };
770
+ }
771
+ return this;
772
+ }
773
+ };
774
+
775
+ //#endregion
776
+ //#region src/Providers/ConsoleServiceProvider.ts
777
+ /**
778
+ * Handles CLI commands and tooling.
779
+ *
780
+ * Register DatabaseManager and QueryBuilder.
781
+ * Set up ORM models and relationships.
782
+ * Register migration and seeder commands.
783
+ *
784
+ * Auto-Registered when in CLI mode
785
+ */
786
+ var ConsoleServiceProvider = class extends ServiceProvider {
787
+ static priority = 992;
788
+ /**
789
+ * Indicate that this service provider only runs in console
790
+ */
791
+ static console = true;
792
+ register() {}
793
+ boot() {
794
+ Kernel.init(this.app);
795
+ process.on("SIGINT", () => {
796
+ process.exit(0);
797
+ });
798
+ process.on("SIGTERM", () => {
799
+ process.exit(0);
800
+ });
801
+ }
802
+ };
803
+
804
+ //#endregion
805
+ //#region ../../node_modules/.pnpm/@rollup+plugin-run@3.1.0/node_modules/@rollup/plugin-run/dist/es/index.js
806
+ function run(opts = {}) {
807
+ let input;
808
+ let proc;
809
+ const args = opts.args || [];
810
+ const allowRestarts = opts.allowRestarts || false;
811
+ const overrideInput = opts.input;
812
+ const forkOptions = opts.options || opts;
813
+ delete forkOptions.args;
814
+ delete forkOptions.allowRestarts;
815
+ return {
816
+ name: "run",
817
+ buildStart(options) {
818
+ let inputs = overrideInput !== null && overrideInput !== void 0 ? overrideInput : options.input;
819
+ if (typeof inputs === "string") inputs = [inputs];
820
+ if (typeof inputs === "object") inputs = Object.values(inputs);
821
+ if (inputs.length > 1) throw new Error(`@rollup/plugin-run must have a single entry point; consider setting the \`input\` option`);
822
+ input = resolve(inputs[0]);
823
+ },
824
+ generateBundle(_outputOptions, _bundle, isWrite) {
825
+ if (!isWrite) this.error(`@rollup/plugin-run currently only works with bundles that are written to disk`);
826
+ },
827
+ writeBundle(outputOptions, bundle) {
828
+ const forkBundle = (dir$1, entryFileName$1) => {
829
+ if (proc) proc.kill();
830
+ proc = fork(join(dir$1, entryFileName$1), args, forkOptions);
831
+ };
832
+ const dir = outputOptions.dir || dirname(outputOptions.file);
833
+ const entryFileName = Object.keys(bundle).find((fileName) => {
834
+ const chunk = bundle[fileName];
835
+ return chunk.isEntry && chunk.facadeModuleId === input;
836
+ });
837
+ if (entryFileName) {
838
+ forkBundle(dir, entryFileName);
839
+ if (allowRestarts) {
840
+ process.stdin.resume();
841
+ process.stdin.setEncoding("utf8");
842
+ process.stdin.on("data", (data) => {
843
+ const line = data.toString().trim().toLowerCase();
844
+ if (line === "rs" || line === "restart" || data.toString().charCodeAt(0) === 11) forkBundle(dir, entryFileName);
845
+ else if (line === "cls" || line === "clear" || data.toString().charCodeAt(0) === 12) console.clear();
846
+ });
847
+ }
848
+ } else this.error(`@rollup/plugin-run could not find output chunk`);
849
+ }
850
+ };
851
+ }
852
+
853
+ //#endregion
854
+ //#region src/TsdownConfig.ts
855
+ const env = process.env.NODE_ENV || "development";
856
+ const outDir = env === "development" ? ".h3ravel/serve" : "dist";
857
+ const TsDownConfig = {
858
+ outDir,
859
+ entry: ["src/**/*.ts"],
860
+ format: ["esm"],
861
+ target: "node22",
862
+ sourcemap: env === "development",
863
+ clean: true,
864
+ shims: true,
865
+ copy: [
866
+ {
867
+ from: "public",
868
+ to: outDir
869
+ },
870
+ "src/resources",
871
+ "src/database"
872
+ ],
873
+ env: env === "development" ? {
874
+ NODE_ENV: env,
875
+ SRC_PATH: outDir
876
+ } : {},
877
+ watch: env === "development" && process.env.CLI_BUILD !== "true" ? [
878
+ ".env",
879
+ ".env.*",
880
+ "src",
881
+ "../../packages"
882
+ ] : false,
883
+ dts: false,
884
+ logLevel: "silent",
885
+ nodeProtocol: true,
886
+ skipNodeModulesBundle: true,
887
+ plugins: env === "development" && process.env.CLI_BUILD !== "true" ? [run({
888
+ env: Object.assign({}, process.env, {
889
+ NODE_ENV: env,
890
+ SRC_PATH: outDir
891
+ }),
892
+ execArgv: ["-r", "source-map-support/register"],
893
+ allowRestarts: false,
894
+ input: process.cwd() + "/src/server.ts"
895
+ })] : []
896
+ };
897
+
898
+ //#endregion
899
+ export { Command, ConsoleServiceProvider, FireCommand, Kernel, MakeCommand, MigrateCommand, Musket, Signature, TableGuesser, TsDownConfig, Utils };
900
+ //# sourceMappingURL=index.js.map