@h3ravel/console 11.0.7 → 11.2.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-CpiQZ3n9.cjs +122 -0
  4. package/dist/Utils-CpiQZ3n9.cjs.map +1 -0
  5. package/dist/Utils-Dvclc4Pc.js +73 -0
  6. package/dist/Utils-Dvclc4Pc.js.map +1 -0
  7. package/dist/Utils-cBgwEyTl.d.ts +20 -0
  8. package/dist/Utils-rIdzILgO.d.cts +20 -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 +790 -949
  14. package/dist/index.cjs.map +1 -0
  15. package/dist/index.d.cts +173 -295
  16. package/dist/index.d.ts +173 -295
  17. package/dist/index.js +789 -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,790 @@
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, sync_default } from "./Utils-Dvclc4Pc.js";
2
+ import { access } from "fs/promises";
3
+ import path, { dirname, join, resolve } from "path";
4
+ import { Application, ConsoleCommand, ConsoleKernel, ServiceProvider } from "@h3ravel/core";
5
+ import { Logger } from "@h3ravel/shared";
6
+ import { glob, mkdir, readFile, writeFile } from "node:fs/promises";
7
+ import { beforeLast } from "@h3ravel/support";
8
+ import dayjs from "dayjs";
9
+ import { existsSync } from "node:fs";
10
+ import nodepath from "node:path";
11
+ import "@h3ravel/console";
12
+ import "@h3ravel/http";
13
+ import "@h3ravel/router";
14
+ import "@h3ravel/database";
15
+ import "@h3ravel/cache";
16
+ import "@h3ravel/queue";
17
+ import "@h3ravel/mail";
18
+ import "@h3ravel/config";
19
+ import { Option, program } from "commander";
20
+ import { fork } from "child_process";
21
+ import { build } from "tsdown";
22
+
23
+ //#region src/Commands/Command.ts
24
+ var Command = class extends ConsoleCommand {};
25
+
26
+ //#endregion
27
+ //#region src/logo.ts
28
+ const logo = String.raw`
29
+ 111
30
+ 111111111
31
+ 1111111111 111111
32
+ 111111 111 111111
33
+ 111111 111 111111
34
+ 11111 111 11111
35
+ 1111111 111 1111111
36
+ 111 11111 111 111111 111 1111 1111 11111111 1111
37
+ 111 11111 1111 111111 111 1111 1111 1111 11111 1111
38
+ 111 11111 11111 111 1111 1111 111111111111 111111111111 1111 1111111 1111
39
+ 111 111111 1111 111 111111111111 111111 11111 1111 111 1111 11111111 1111 1111
40
+ 111 111 11111111 111 1101 1101 111111111 11111111 1111 1111111111111111101
41
+ 111 1111111111111111 1111 111 1111 1111 111 11111011 1111 111 1111111 1101 1111
42
+ 111 11111 1110111111111111 111 1111 1111 1111111101 1111 111111111 1111011 111111111 1111
43
+ 1111111 111110111110 111 1111 1111 111111 1111 11011101 10111 11111 1111
44
+ 11011 111111 11 11111
45
+ 111111 11101 111111
46
+ 111111 111 111111
47
+ 111111 111 111111
48
+ 111111111
49
+ 110
50
+ `;
51
+ const altLogo = String.raw`
52
+ _ _ _____ _
53
+ | | | |___ / _ __ __ ___ _____| |
54
+ | |_| | |_ \| '__/ _ \ \ / / _ \ |
55
+ | _ |___) | | | (_| |\ V / __/ |
56
+ |_| |_|____/|_| \__,_| \_/ \___|_|
57
+
58
+ `;
59
+
60
+ //#endregion
61
+ //#region src/Commands/ListCommand.ts
62
+ var ListCommand = class extends Command {
63
+ /**
64
+ * The name and signature of the console command.
65
+ *
66
+ * @var string
67
+ */
68
+ signature = "list";
69
+ /**
70
+ * The console command description.
71
+ *
72
+ * @var string
73
+ */
74
+ description = "List all available commands";
75
+ async handle() {
76
+ const options = [{
77
+ short: "-h",
78
+ long: "--help",
79
+ description: "Display help for the given command. When no command is given display help for the list command"
80
+ }].concat(this.program.options).map((e) => {
81
+ return Logger.describe(Logger.log(" " + [e.short, e.long].filter((e$1) => !!e$1).join(", "), "green", false), e.description, 25, false).join("");
82
+ });
83
+ const grouped = this.program.commands.map((e) => {
84
+ return Logger.describe(Logger.log(" " + e.name(), "green", false), e.description(), 25, false).join("");
85
+ }).reduce((acc, cmd) => {
86
+ /** strip colors before checking prefix */
87
+ const clean = cmd.replace(/\x1b\[\d+m/g, "");
88
+ const prefix = clean.includes(":") ? clean.split(":")[0].trim() : "__root__";
89
+ acc[prefix] ??= [];
90
+ /** keep original with colors */
91
+ acc[prefix].push(cmd);
92
+ return acc;
93
+ }, {});
94
+ const list = Object.entries(grouped).map(([group, cmds]) => {
95
+ const label = group === "__root__" ? "" : group;
96
+ return [Logger.log(label, "yellow", false), cmds.join("\n")].join("\n");
97
+ });
98
+ /** Ootput the app version */
99
+ Logger.log([["H3ravel Framework", "white"], [this.kernel.modulePackage.version, "green"]], " ");
100
+ console.log("");
101
+ console.log(altLogo);
102
+ console.log("");
103
+ Logger.log("Usage:", "yellow");
104
+ Logger.log(" command [options] [arguments]", "white");
105
+ console.log("");
106
+ /** Ootput the options */
107
+ Logger.log("Options:", "yellow");
108
+ console.log(options.join("\n").trim());
109
+ console.log("");
110
+ /** Ootput the commands */
111
+ Logger.log("Available Commands:", "yellow");
112
+ console.log(list.join("\n\n").trim());
113
+ }
45
114
  };
115
+
116
+ //#endregion
117
+ //#region ../filesystem/dist/index.js
118
+ var Helpers = class {
119
+ static findModulePkg(moduleId, cwd) {
120
+ const parts = moduleId.replace(/\\/g, "/").split("/");
121
+ let packageName = "";
122
+ if (parts.length > 0 && parts[0][0] === "@") packageName += parts.shift() + "/";
123
+ packageName += parts.shift();
124
+ const packageJson = path.join(cwd ?? process.cwd(), "node_modules", packageName);
125
+ const resolved = this.findUpConfig(packageJson, "package", ["json"]);
126
+ if (!resolved) return;
127
+ return path.join(path.dirname(resolved), parts.join("/"));
128
+ }
129
+ /**
130
+ * Check if file exists
131
+ *
132
+ * @param path
133
+ * @returns
134
+ */
135
+ static async fileExists(path$1) {
136
+ try {
137
+ await access(path$1);
138
+ return true;
139
+ } catch {
140
+ return false;
141
+ }
142
+ }
143
+ static findUpConfig(cwd, name, extensions) {
144
+ return sync_default(cwd, (_dir, names) => {
145
+ for (const ext of extensions) {
146
+ const filename = `${name}.${ext}`;
147
+ if (names.includes(filename)) return filename;
148
+ }
149
+ return false;
150
+ });
151
+ }
152
+ };
153
+
154
+ //#endregion
155
+ //#region src/Commands/MakeCommand.ts
156
+ var MakeCommand = class extends Command {
157
+ /**
158
+ * The name and signature of the console command.
159
+ *
160
+ * @var string
161
+ */
162
+ signature = `#make:
163
+ {controller : Create a new controller class.
164
+ | {--a|api : Exclude the create and edit methods from the controller}
165
+ | {--m|model= : Generate a resource controller for the given model}
166
+ | {--r|resource : Generate a resource controller class}
167
+ | {--force : Create the controller even if it already exists}
168
+ }
169
+ {resource : Create a new resource.
170
+ | {--c|collection : Create a resource collection}
171
+ | {--force : Create the resource even if it already exists}
172
+ }
173
+ {migration : Generates a new database migration class.
174
+ | {--l|type=ts : The file type to generate}
175
+ | {--t|table : The table to migrate}
176
+ | {--c|create : The table to be created}
177
+ }
178
+ {factory : Create a new model factory.}
179
+ {seeder : Create a new seeder class.}
180
+ {view : Create a new view.
181
+ | {--force : Create the view even if it already exists}
182
+ }
183
+ {model : Create a new Eloquent model class.
184
+ | {--api : Indicates if the generated controller should be an API resource controller}
185
+ | {--c|controller : Create a new controller for the model}
186
+ | {--f|factory : Create a new factory for the model}
187
+ | {--m|migration : Create a new migration file for the model}
188
+ | {--r|resource : Indicates if the generated controller should be a resource controller}
189
+ | {--a|all : Generate a migration, seeder, factory, policy, resource controller, and form request classes for the model}
190
+ | {--s|seed : Create a new seeder for the model}
191
+ | {--t|type=ts : The file type to generate}
192
+ | {--force : Create the model even if it already exists}
193
+ }
194
+ {^name : The name of the [name] to generate}
195
+ `;
196
+ /**
197
+ * The console command description.
198
+ *
199
+ * @var string
200
+ */
201
+ description = "Generate component classes";
202
+ async handle() {
203
+ const command = this.dictionary.baseCommand ?? this.dictionary.name;
204
+ const methods = {
205
+ controller: "makeController",
206
+ resource: "makeResource",
207
+ migration: "makeMigration",
208
+ factory: "makeFactory",
209
+ seeder: "makeSeeder",
210
+ model: "makeModel",
211
+ view: "makeView"
212
+ };
213
+ try {
214
+ await this?.[methods[command]]();
215
+ } catch (e) {
216
+ Logger.error(e);
217
+ }
218
+ }
219
+ /**
220
+ * Create a new controller class.
221
+ */
222
+ async makeController() {
223
+ const type = this.option("api") ? "-resource" : "";
224
+ const name = this.argument("name");
225
+ const force = this.option("force");
226
+ const path$1 = nodepath.join(app_path("Http/Controllers"), name + ".ts");
227
+ const crtlrPath = Helpers.findModulePkg("@h3ravel/http", this.kernel.cwd) ?? "";
228
+ const stubPath = nodepath.join(crtlrPath, `dist/stubs/controller${type}.stub`);
229
+ /** Check if the controller already exists */
230
+ if (!force && existsSync(path$1)) Logger.error(`ERORR: ${name} controller already exists`);
231
+ let stub = await readFile(stubPath, "utf-8");
232
+ stub = stub.replace(/{{ name }}/g, name);
233
+ await writeFile(path$1, stub);
234
+ Logger.split("INFO: Controller Created", Logger.log(nodepath.basename(path$1), "gray", false));
235
+ }
236
+ makeResource() {
237
+ Logger.success("Resource support is not yet available");
238
+ }
239
+ /**
240
+ * Generate a new database migration class
241
+ */
242
+ async makeMigration() {
243
+ const name = this.argument("name");
244
+ const datePrefix = dayjs().format("YYYY_MM_DD_HHmmss");
245
+ const path$1 = nodepath.join(database_path("migrations"), `${datePrefix}_${name}.ts`);
246
+ const crtlrPath = Utils.findModulePkg("@h3ravel/database", this.kernel.cwd) ?? "";
247
+ let create = this.option("create", false);
248
+ let table = this.option("table");
249
+ if (!table && typeof create === "string") {
250
+ table = create;
251
+ create = true;
252
+ }
253
+ if (!table) {
254
+ const guessed = TableGuesser.guess(name);
255
+ table = guessed[0];
256
+ create = !!guessed[1];
257
+ }
258
+ const stubPath = nodepath.join(crtlrPath, this.getMigrationStubName(table, create));
259
+ let stub = await readFile(stubPath, "utf-8");
260
+ if (table !== null) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
261
+ Logger.info("INFO: Creating Migration");
262
+ await this.kernel.ensureDirectoryExists(nodepath.dirname(path$1));
263
+ await writeFile(path$1, stub);
264
+ Logger.split("INFO: Migration Created", Logger.log(nodepath.basename(path$1), "gray", false));
265
+ }
266
+ /**
267
+ * Create a new model factory
268
+ */
269
+ makeFactory() {
270
+ Logger.success("Factory support is not yet available");
271
+ }
272
+ /**
273
+ * Create a new seeder class
274
+ */
275
+ makeSeeder() {
276
+ Logger.success("Seeder support is not yet available");
277
+ }
278
+ /**
279
+ * Generate a new Arquebus model class
280
+ */
281
+ async makeModel() {
282
+ const type = this.option("type", "ts");
283
+ const name = this.argument("name");
284
+ const force = this.argument("force");
285
+ const path$1 = nodepath.join(app_path("Models"), name.toLowerCase(), "." + type);
286
+ /** Check if the model already exists */
287
+ if (!force && existsSync(path$1)) Logger.error(`ERORR: ${name} view already exists`);
288
+ const crtlrPath = Utils.findModulePkg("@h3ravel/database", this.kernel.cwd) ?? "";
289
+ const stubPath = nodepath.join(crtlrPath, `dist/stubs/model-${type}.stub`);
290
+ let stub = await readFile(stubPath, "utf-8");
291
+ stub = stub.replace(/{{ name }}/g, name);
292
+ await writeFile(path$1, stub);
293
+ Logger.split("INFO: Model Created", Logger.log(nodepath.basename(path$1), "gray", false));
294
+ }
295
+ /**
296
+ * Create a new view.
297
+ */
298
+ async makeView() {
299
+ const name = this.argument("name");
300
+ const force = this.option("force");
301
+ const path$1 = nodepath.join(base_path("src/resources/views"), name + ".edge");
302
+ if (name.includes("/")) await mkdir(beforeLast(path$1, "/"), { recursive: true });
303
+ /** Check if the view already exists */
304
+ if (!force && existsSync(path$1)) Logger.error(`ERORR: ${name} view already exists`);
305
+ await writeFile(path$1, `{{-- src/resources/views/${name}.edge --}}`);
306
+ Logger.split("INFO: View Created", Logger.log(`src/resources/views/${name}.edge`, "gray", false));
307
+ }
308
+ /**
309
+ * Ge the database migration file name
310
+ *
311
+ * @param table
312
+ * @param create
313
+ * @param type
314
+ * @returns
315
+ */
316
+ getMigrationStubName(table, create = false, type = "ts") {
317
+ let stub;
318
+ if (!table) stub = `migration-${type}.stub`;
319
+ else if (create) stub = `migration.create-${type}.stub`;
320
+ else stub = `migration.update-${type}.stub`;
321
+ return "dist/stubs/" + stub;
322
+ }
323
+ };
324
+
325
+ //#endregion
326
+ //#region src/Signature.ts
327
+ var Signature = class Signature {
328
+ /**
329
+ * Helper to parse options inside a block of text
330
+ *
331
+ * @param block
332
+ * @returns
333
+ */
334
+ static parseOptions(block) {
335
+ const options = [];
336
+ /**
337
+ * Match { ... } blocks at top level
338
+ */
339
+ const regex = /\{([^{}]+(?:\{[^{}]*\}[^{}]*)*)\}/g;
340
+ let match;
341
+ while ((match = regex.exec(block)) !== null) {
342
+ const shared = "^" === match[1][0] || /:[#^]/.test(match[1]);
343
+ const isHidden = (["#", "^"].includes(match[1][0]) || /:[#^]/.test(match[1])) && !shared;
344
+ const content = match[1].trim().replace(/[#^]/, "");
345
+ /**
346
+ * Split by first ':' to separate name and description+nested
347
+ */
348
+ const colonIndex = content.indexOf(":");
349
+ if (colonIndex === -1) {
350
+ /**
351
+ * No description, treat whole as name
352
+ */
353
+ options.push({ name: content });
354
+ continue;
355
+ }
356
+ const namePart = content.substring(0, colonIndex).trim();
357
+ let rest = content.substring(colonIndex + 1).trim();
358
+ /**
359
+ * Check for nested options after '|'
360
+ */
361
+ let description = rest;
362
+ let nestedOptions;
363
+ const pipeIndex = rest.indexOf("|");
364
+ if (pipeIndex !== -1) {
365
+ description = rest.substring(0, pipeIndex).trim();
366
+ /**
367
+ * nestedText should start with '{' and end with ')', clean it
368
+ * Also Remove trailing ')' if present
369
+ */
370
+ const cleanedNestedText = rest.substring(pipeIndex + 1).trim().replace(/^\{/, "").trim();
371
+ /**
372
+ * Parse nested options recursively
373
+ */
374
+ nestedOptions = Signature.parseOptions("{" + cleanedNestedText + "}");
375
+ } else
376
+ /**
377
+ * Trim the string
378
+ */
379
+ description = description.trim();
380
+ /**
381
+ * Parse name modifiers (?, *, ?*)
382
+ */
383
+ let name = namePart;
384
+ let required = /[^a-zA-Z0-9_|-]/.test(name);
385
+ let multiple = false;
386
+ if (name.endsWith("?*")) {
387
+ required = false;
388
+ multiple = true;
389
+ name = name.slice(0, -2);
390
+ } else if (name.endsWith("*")) {
391
+ multiple = true;
392
+ name = name.slice(0, -1);
393
+ } else if (name.endsWith("?")) {
394
+ required = false;
395
+ name = name.slice(0, -1);
396
+ }
397
+ /**
398
+ * Check if it's a flag option (starts with --)
399
+ */
400
+ const isFlag = name.startsWith("--");
401
+ let flags;
402
+ let defaultValue;
403
+ if (isFlag) {
404
+ /**
405
+ * Parse flags and default values
406
+ */
407
+ const flagParts = name.split("|").map((s) => s.trim());
408
+ flags = [];
409
+ for (let part of flagParts) {
410
+ if (part.startsWith("--") && part.slice(2).length === 1) part = "-" + part.slice(2);
411
+ else if (part.startsWith("-") && !part.startsWith("--") && part.slice(1).length > 1) part = "--" + part.slice(1);
412
+ else if (!part.startsWith("-") && part.slice(1).length > 1) part = "--" + part;
413
+ const eqIndex = part.indexOf("=");
414
+ if (eqIndex !== -1) {
415
+ flags.push(part.substring(0, eqIndex));
416
+ const val = part.substring(eqIndex + 1);
417
+ if (val === "*") defaultValue = [];
418
+ else if (val === "true" || val === "false" || !val && !required) defaultValue = val === "true";
419
+ else if (!isNaN(Number(val))) defaultValue = Number(val);
420
+ else defaultValue = val;
421
+ } else flags.push(part);
422
+ }
423
+ }
424
+ options.push({
425
+ name: isFlag ? flags[flags.length - 1] : name,
426
+ required,
427
+ multiple,
428
+ description,
429
+ flags,
430
+ shared,
431
+ isFlag,
432
+ isHidden,
433
+ defaultValue,
434
+ nestedOptions
435
+ });
436
+ }
437
+ return options;
438
+ }
439
+ /**
440
+ * Helper to parse a command's signature
441
+ *
442
+ * @param signature
443
+ * @param commandClass
444
+ * @returns
445
+ */
446
+ static parseSignature(signature, commandClass) {
447
+ const lines = signature.split("\n").map((l) => l.trim()).filter((l) => l.length > 0);
448
+ const isHidden = ["#", "^"].includes(lines[0][0]) || /:[#^]/.test(lines[0]);
449
+ const baseCommand = lines[0].replace(/[^\w=:-]/g, "");
450
+ const description = commandClass.getDescription();
451
+ const isNamespaceCommand = baseCommand.endsWith(":");
452
+ /**
453
+ * Join the rest lines to a single string for parsing
454
+ */
455
+ const rest = lines.slice(1).join(" ");
456
+ /**
457
+ * Parse all top-level options/subcommands
458
+ */
459
+ const allOptions = Signature.parseOptions(rest);
460
+ if (isNamespaceCommand)
461
+ /**
462
+ * Separate subcommands (those without flags) and base options (flags)
463
+ * Here we assume subcommands are those without flags (isFlag false)
464
+ * and base options are flags or options after subcommands
465
+
466
+ * For simplicity, treat all top-level options as subcommands
467
+ * and assume base command options come after subcommands in signature (not shown in example)
468
+ */
469
+ return {
470
+ baseCommand: baseCommand.slice(0, -1),
471
+ isNamespaceCommand,
472
+ subCommands: allOptions.filter((e) => !e.flags && !e.isHidden),
473
+ description,
474
+ commandClass,
475
+ options: allOptions.filter((e) => !!e.flags),
476
+ isHidden
477
+ };
478
+ else return {
479
+ baseCommand,
480
+ isNamespaceCommand,
481
+ options: allOptions,
482
+ description,
483
+ commandClass,
484
+ isHidden
485
+ };
486
+ }
487
+ };
488
+
489
+ //#endregion
490
+ //#region ../../node_modules/.pnpm/@rollup+plugin-run@3.1.0/node_modules/@rollup/plugin-run/dist/es/index.js
491
+ function run(opts = {}) {
492
+ let input;
493
+ let proc;
494
+ const args = opts.args || [];
495
+ const allowRestarts = opts.allowRestarts || false;
496
+ const overrideInput = opts.input;
497
+ const forkOptions = opts.options || opts;
498
+ delete forkOptions.args;
499
+ delete forkOptions.allowRestarts;
500
+ return {
501
+ name: "run",
502
+ buildStart(options) {
503
+ let inputs = overrideInput !== null && overrideInput !== void 0 ? overrideInput : options.input;
504
+ if (typeof inputs === "string") inputs = [inputs];
505
+ if (typeof inputs === "object") inputs = Object.values(inputs);
506
+ if (inputs.length > 1) throw new Error(`@rollup/plugin-run must have a single entry point; consider setting the \`input\` option`);
507
+ input = resolve(inputs[0]);
508
+ },
509
+ generateBundle(_outputOptions, _bundle, isWrite) {
510
+ if (!isWrite) this.error(`@rollup/plugin-run currently only works with bundles that are written to disk`);
511
+ },
512
+ writeBundle(outputOptions, bundle) {
513
+ const forkBundle = (dir$1, entryFileName$1) => {
514
+ if (proc) proc.kill();
515
+ proc = fork(join(dir$1, entryFileName$1), args, forkOptions);
516
+ };
517
+ const dir = outputOptions.dir || dirname(outputOptions.file);
518
+ const entryFileName = Object.keys(bundle).find((fileName) => {
519
+ const chunk = bundle[fileName];
520
+ return chunk.isEntry && chunk.facadeModuleId === input;
521
+ });
522
+ if (entryFileName) {
523
+ forkBundle(dir, entryFileName);
524
+ if (allowRestarts) {
525
+ process.stdin.resume();
526
+ process.stdin.setEncoding("utf8");
527
+ process.stdin.on("data", (data) => {
528
+ const line = data.toString().trim().toLowerCase();
529
+ if (line === "rs" || line === "restart" || data.toString().charCodeAt(0) === 11) forkBundle(dir, entryFileName);
530
+ else if (line === "cls" || line === "clear" || data.toString().charCodeAt(0) === 12) console.clear();
531
+ });
532
+ }
533
+ } else this.error(`@rollup/plugin-run could not find output chunk`);
534
+ }
535
+ };
536
+ }
537
+
538
+ //#endregion
539
+ //#region src/TsdownConfig.ts
540
+ const env = process.env.NODE_ENV || "development";
541
+ const outDir = env === "development" ? ".h3ravel/serve" : "dist";
542
+ const TsDownConfig = {
543
+ outDir,
544
+ entry: ["src/**/*.ts"],
545
+ format: ["esm"],
546
+ target: "node22",
547
+ sourcemap: env === "development",
548
+ clean: true,
549
+ shims: true,
550
+ copy: [
551
+ {
552
+ from: "public",
553
+ to: outDir
554
+ },
555
+ "src/resources",
556
+ "src/database"
557
+ ],
558
+ env: env === "development" ? {
559
+ NODE_ENV: env,
560
+ SRC_PATH: outDir
561
+ } : {},
562
+ watch: env === "development" && process.env.CLI_BUILD !== "true" ? [
563
+ ".env",
564
+ ".env.*",
565
+ "src",
566
+ "../../packages"
567
+ ] : false,
568
+ dts: false,
569
+ logLevel: "silent",
570
+ nodeProtocol: true,
571
+ skipNodeModulesBundle: true,
572
+ plugins: env === "development" && process.env.CLI_BUILD !== "true" ? [run({
573
+ env: Object.assign({}, process.env, {
574
+ NODE_ENV: env,
575
+ SRC_PATH: outDir
576
+ }),
577
+ execArgv: ["-r", "source-map-support/register"],
578
+ allowRestarts: false,
579
+ input: process.cwd() + "/src/server.ts"
580
+ })] : []
581
+ };
582
+ var TsdownConfig_default = TsDownConfig;
583
+
584
+ //#endregion
585
+ //#region src/Musket.ts
586
+ /**
587
+ * Musket is H3ravel's CLI tool
588
+ */
589
+ var Musket = class Musket {
590
+ commands = [];
591
+ constructor(app, kernel) {
592
+ this.app = app;
593
+ this.kernel = kernel;
594
+ }
595
+ async build() {
596
+ this.loadBaseCommands();
597
+ await this.loadDiscoveredCommands();
598
+ return this.initialize();
599
+ }
600
+ loadBaseCommands() {
601
+ [new MakeCommand(this.app, this.kernel), new ListCommand(this.app, this.kernel)].forEach((e) => this.addCommand(e));
602
+ }
603
+ async loadDiscoveredCommands() {
604
+ const commands = [...this.app.registeredCommands.map((cmd) => new cmd(this.app, this.kernel))];
605
+ /**
606
+ * Musket Commands auto registration
607
+ */
608
+ const providers_path = app_path("Console/Commands/*.js").replace("/src/", "/.h3ravel/serve/");
609
+ /** Add the App Commands */
610
+ for await (const cmd of glob(providers_path)) {
611
+ const name = nodepath.basename(cmd).replace(".js", "");
612
+ try {
613
+ const cmdClass = (await import(cmd))[name];
614
+ commands.push(new cmdClass(this.app, this.kernel));
615
+ } catch {}
616
+ }
617
+ commands.forEach((e) => this.addCommand(e));
618
+ }
619
+ addCommand(command) {
620
+ this.commands.push(Signature.parseSignature(command.getSignature(), command));
621
+ }
622
+ initialize() {
623
+ /** Init the Musket Version */
624
+ const cliVersion = Logger.parse([["Musket CLI:", "white"], [this.kernel.consolePackage.version, "green"]], " ", false);
625
+ /** Init the App Version */
626
+ const localVersion = Logger.parse([["H3ravel Framework:", "white"], [this.kernel.modulePackage.version, "green"]], " ", false);
627
+ const additional = {
628
+ quiet: ["-q, --quiet", "Do not output any message"],
629
+ silent: ["--silent", "Do not output any message"],
630
+ verbose: ["-v, --verbose <number>", "Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug"],
631
+ interaction: ["-n, --no-interaction", "Do not ask any interactive question"]
632
+ };
633
+ /** Init Commander */
634
+ program.name("musket").version(`${cliVersion}\n${localVersion}`).addOption(new Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).option(additional.quiet[0], additional.quiet[1]).option(additional.verbose[0], additional.verbose[1]).option(additional.interaction[0], additional.interaction[1]).description(altLogo).action(async () => {
635
+ const instance = new ListCommand(this.app, this.kernel);
636
+ instance.setInput(program.opts(), program.args, program.registeredArguments, {}, program);
637
+ instance.handle();
638
+ });
639
+ /** Create the init Command */
640
+ program.command("init").description("Initialize H3ravel.").action(async () => {
641
+ Logger.success("Initialized: H3ravel has been initialized!");
642
+ });
643
+ /** Loop through all the available commands */
644
+ for (let i = 0; i < this.commands.length; i++) {
645
+ const command = this.commands[i];
646
+ const instance = command.commandClass;
647
+ if (command.isNamespaceCommand && command.subCommands) {
648
+ /**
649
+ * Initialize the base command
650
+ */
651
+ const cmd = command.isHidden ? program : program.command(command.baseCommand).description(command.description ?? "").addOption(new Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).option(additional.quiet[0], additional.quiet[1]).option(additional.verbose[0], additional.verbose[1]).option(additional.interaction[0], additional.interaction[1]).action(async () => {
652
+ instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command, program);
653
+ await instance.handle();
654
+ });
655
+ /**
656
+ * Add options to the base command if it has any
657
+ */
658
+ if ((command.options?.length ?? 0) > 0) command.options?.filter((v, i$1, a) => a.findIndex((t) => t.name === v.name) === i$1).forEach((opt) => {
659
+ this.makeOption(opt, cmd);
660
+ });
661
+ /**
662
+ * Initialize the sub commands
663
+ */
664
+ command.subCommands.filter((v, i$1, a) => !v.shared && a.findIndex((t) => t.name === v.name) === i$1).forEach((sub) => {
665
+ const cmd$1 = program.command(`${command.baseCommand}:${sub.name}`).description(sub.description || "").addOption(new Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).option(additional.quiet[0], additional.quiet[1]).option(additional.verbose[0], additional.verbose[1]).option(additional.interaction[0], additional.interaction[1]).action(async () => {
666
+ instance.setInput(cmd$1.opts(), cmd$1.args, cmd$1.registeredArguments, sub, program);
667
+ await instance.handle();
668
+ });
669
+ /**
670
+ * Add the shared arguments here
671
+ */
672
+ command.subCommands?.filter((e) => e.shared).forEach((opt) => {
673
+ this.makeOption(opt, cmd$1, false, sub);
674
+ });
675
+ /**
676
+ * Add the shared options here
677
+ */
678
+ command.options?.filter((e) => e.shared).forEach((opt) => {
679
+ this.makeOption(opt, cmd$1, false, sub);
680
+ });
681
+ /**
682
+ * Add options to the sub command if it has any
683
+ */
684
+ if (sub.nestedOptions) sub.nestedOptions.filter((v, i$1, a) => a.findIndex((t) => t.name === v.name) === i$1).forEach((opt) => {
685
+ this.makeOption(opt, cmd$1);
686
+ });
687
+ });
688
+ } else {
689
+ /**
690
+ * Initialize command with options
691
+ */
692
+ const cmd = program.command(command.baseCommand).description(command.description ?? "").addOption(new Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).option(additional.quiet[0], additional.quiet[1]).option(additional.verbose[0], additional.verbose[1]).option(additional.interaction[0], additional.interaction[1]);
693
+ command?.options?.filter((v, i$1, a) => a.findIndex((t) => t.name === v.name) === i$1).forEach((opt) => {
694
+ this.makeOption(opt, cmd, true);
695
+ });
696
+ cmd.action(async () => {
697
+ instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command, program);
698
+ await instance.handle();
699
+ });
700
+ }
701
+ }
702
+ /** Rebuild the app on every command except fire so we wont need TS */
703
+ program.hook("preAction", async (_, cmd) => {
704
+ if (cmd.name() !== "fire") await build({
705
+ ...TsdownConfig_default,
706
+ watch: false,
707
+ plugins: []
708
+ });
709
+ });
710
+ return program;
711
+ }
712
+ makeOption(opt, cmd, parse, parent) {
713
+ const description = opt.description?.replace(/\[(\w+)\]/g, (_, k) => parent?.[k] ?? `[${k}]`) ?? "";
714
+ const type = opt.name.replaceAll("-", "");
715
+ if (opt.isFlag) if (parse) {
716
+ const flags = opt.flags?.map((f) => f.length === 1 ? `-${f}` : `--${f}`).join(", ").replaceAll("----", "--").replaceAll("---", "-");
717
+ cmd.option(flags || "", description, String(opt.defaultValue) || void 0);
718
+ } else cmd.option(opt.flags?.join(", ") + (opt.required ? ` <${type}>` : ""), description, opt.defaultValue);
719
+ else cmd.argument(opt.required ? `<${opt.name}>` : `[${opt.name}]`, description, opt.defaultValue);
720
+ }
721
+ static async parse(kernel) {
722
+ return (await new Musket(kernel.app, kernel).build()).parseAsync();
723
+ }
724
+ };
725
+
726
+ //#endregion
727
+ //#region src/Kernel.ts
728
+ var Kernel = class Kernel extends ConsoleKernel {
729
+ constructor(app) {
730
+ super(app);
731
+ this.app = app;
732
+ }
733
+ static init(app) {
734
+ const instance = new Kernel(app);
735
+ Promise.all([instance.loadRequirements()]).then(([e]) => e.run());
736
+ }
737
+ async run() {
738
+ await Musket.parse(this);
739
+ process.exit(0);
740
+ }
741
+ async loadRequirements() {
742
+ this.cwd = nodepath.join(process.cwd(), this.basePath);
743
+ this.modulePath = Helpers.findModulePkg("@h3ravel/core", this.cwd) ?? "";
744
+ this.consolePath = Helpers.findModulePkg("@h3ravel/console", this.cwd) ?? "";
745
+ try {
746
+ this.modulePackage = await import(nodepath.join(this.modulePath, "package.json"));
747
+ } catch {
748
+ this.modulePackage = { version: "N/A" };
749
+ }
750
+ try {
751
+ this.consolePackage = await import(nodepath.join(this.consolePath, "package.json"));
752
+ } catch {
753
+ this.consolePackage = { version: "N/A" };
754
+ }
755
+ return this;
756
+ }
757
+ };
758
+
759
+ //#endregion
760
+ //#region src/Providers/ConsoleServiceProvider.ts
761
+ /**
762
+ * Handles CLI commands and tooling.
763
+ *
764
+ * Register DatabaseManager and QueryBuilder.
765
+ * Set up ORM models and relationships.
766
+ * Register migration and seeder commands.
767
+ *
768
+ * Auto-Registered when in CLI mode
769
+ */
770
+ var ConsoleServiceProvider = class extends ServiceProvider {
771
+ static priority = 992;
772
+ /**
773
+ * Indicate that this service provider only runs in console
774
+ */
775
+ static console = true;
776
+ register() {}
777
+ boot() {
778
+ Kernel.init(this.app);
779
+ process.on("SIGINT", () => {
780
+ process.exit(0);
781
+ });
782
+ process.on("SIGTERM", () => {
783
+ process.exit(0);
784
+ });
785
+ }
786
+ };
787
+
788
+ //#endregion
789
+ export { Command, ConsoleServiceProvider, Kernel, ListCommand, MakeCommand, Musket, Signature, TableGuesser, TsDownConfig, Utils, altLogo, logo };
790
+ //# sourceMappingURL=index.js.map