@h3ravel/console 11.1.0 → 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.
package/dist/index.js CHANGED
@@ -1,146 +1,152 @@
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";
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";
5
6
  import { glob, mkdir, readFile, writeFile } from "node:fs/promises";
6
- import chalk from "chalk";
7
+ import { beforeLast } from "@h3ravel/support";
7
8
  import dayjs from "dayjs";
8
9
  import { existsSync } from "node:fs";
9
10
  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
11
  import "@h3ravel/console";
14
12
  import "@h3ravel/http";
15
13
  import "@h3ravel/router";
14
+ import "@h3ravel/database";
16
15
  import "@h3ravel/cache";
17
16
  import "@h3ravel/queue";
18
17
  import "@h3ravel/mail";
19
18
  import "@h3ravel/config";
20
- import { Logger } from "@h3ravel/shared";
21
- import { program } from "commander";
19
+ import { Option, program } from "commander";
22
20
  import { fork } from "child_process";
21
+ import { build } from "tsdown";
23
22
 
24
23
  //#region src/Commands/Command.ts
25
- var Command = class {
26
- constructor(app, kernel) {
27
- this.app = app;
28
- this.kernel = kernel;
29
- }
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 {
30
63
  /**
31
64
  * The name and signature of the console command.
32
65
  *
33
66
  * @var string
34
67
  */
35
- signature;
36
- /**
37
- * A dictionary of signatures or what not.
38
- *
39
- * @var object
40
- */
41
- dictionary = {};
68
+ signature = "list";
42
69
  /**
43
70
  * The console command description.
44
71
  *
45
72
  * @var string
46
73
  */
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;
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());
87
113
  }
88
114
  };
89
115
 
90
116
  //#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
- `;
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
+ }
104
129
  /**
105
- * The console command description.
106
- *
107
- * @var string
130
+ * Check if file exists
131
+ *
132
+ * @param path
133
+ * @returns
108
134
  */
109
- description = "Fire up the developement server";
110
- async handle() {
135
+ static async fileExists(path$1) {
111
136
  try {
112
- await this.fire();
113
- } catch (e) {
114
- this.kernel.output.error(e);
137
+ await access(path$1);
138
+ return true;
139
+ } catch {
140
+ return false;
115
141
  }
116
142
  }
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)
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;
144
150
  });
145
151
  }
146
152
  };
@@ -154,12 +160,37 @@ var MakeCommand = class extends Command {
154
160
  * @var string
155
161
  */
156
162
  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
+ {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
+ }
163
194
  {^name : The name of the [name] to generate}
164
195
  `;
165
196
  /**
@@ -169,39 +200,41 @@ var MakeCommand = class extends Command {
169
200
  */
170
201
  description = "Generate component classes";
171
202
  async handle() {
172
- const command = this.dictionary.baseCommand;
203
+ const command = this.dictionary.baseCommand ?? this.dictionary.name;
173
204
  const methods = {
174
205
  controller: "makeController",
175
206
  resource: "makeResource",
176
207
  migration: "makeMigration",
177
208
  factory: "makeFactory",
178
209
  seeder: "makeSeeder",
179
- model: "makeModel"
210
+ model: "makeModel",
211
+ view: "makeView"
180
212
  };
181
213
  try {
182
214
  await this?.[methods[command]]();
183
215
  } catch (e) {
184
- this.kernel.output.error(e);
216
+ Logger.error(e);
185
217
  }
186
218
  }
187
219
  /**
188
- * Generate a new controller class.
220
+ * Create a new controller class.
189
221
  */
190
222
  async makeController() {
191
223
  const type = this.option("api") ? "-resource" : "";
192
224
  const name = this.argument("name");
193
225
  const force = this.option("force");
194
226
  const path$1 = nodepath.join(app_path("Http/Controllers"), name + ".ts");
195
- const crtlrPath = Utils.findModulePkg("@h3ravel/http", this.kernel.cwd) ?? "";
227
+ const crtlrPath = Helpers.findModulePkg("@h3ravel/http", this.kernel.cwd) ?? "";
196
228
  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`);
229
+ /** Check if the controller already exists */
230
+ if (!force && existsSync(path$1)) Logger.error(`ERORR: ${name} controller already exists`);
198
231
  let stub = await readFile(stubPath, "utf-8");
199
232
  stub = stub.replace(/{{ name }}/g, name);
200
233
  await writeFile(path$1, stub);
201
- this.kernel.output.split(`INFO: Controller Created`, chalk.gray(nodepath.basename(path$1)));
234
+ Logger.split("INFO: Controller Created", Logger.log(nodepath.basename(path$1), "gray", false));
202
235
  }
203
236
  makeResource() {
204
- this.kernel.output.success(`Resource support is not yet available`);
237
+ Logger.success("Resource support is not yet available");
205
238
  }
206
239
  /**
207
240
  * Generate a new database migration class
@@ -225,16 +258,22 @@ var MakeCommand = class extends Command {
225
258
  const stubPath = nodepath.join(crtlrPath, this.getMigrationStubName(table, create));
226
259
  let stub = await readFile(stubPath, "utf-8");
227
260
  if (table !== null) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
228
- this.kernel.output.info("INFO: Creating Migration");
261
+ Logger.info("INFO: Creating Migration");
229
262
  await this.kernel.ensureDirectoryExists(nodepath.dirname(path$1));
230
263
  await writeFile(path$1, stub);
231
- this.kernel.output.split(`INFO: Migration Created`, chalk.gray(nodepath.basename(path$1)));
264
+ Logger.split("INFO: Migration Created", Logger.log(nodepath.basename(path$1), "gray", false));
232
265
  }
266
+ /**
267
+ * Create a new model factory
268
+ */
233
269
  makeFactory() {
234
- this.kernel.output.success(`Factory support is not yet available`);
270
+ Logger.success("Factory support is not yet available");
235
271
  }
272
+ /**
273
+ * Create a new seeder class
274
+ */
236
275
  makeSeeder() {
237
- this.kernel.output.success(`Seeder support is not yet available`);
276
+ Logger.success("Seeder support is not yet available");
238
277
  }
239
278
  /**
240
279
  * Generate a new Arquebus model class
@@ -242,13 +281,29 @@ var MakeCommand = class extends Command {
242
281
  async makeModel() {
243
282
  const type = this.option("type", "ts");
244
283
  const name = this.argument("name");
245
- const path$1 = nodepath.join(app_path("Models"), name.toLowerCase() + "." + type);
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`);
246
288
  const crtlrPath = Utils.findModulePkg("@h3ravel/database", this.kernel.cwd) ?? "";
247
289
  const stubPath = nodepath.join(crtlrPath, `dist/stubs/model-${type}.stub`);
248
290
  let stub = await readFile(stubPath, "utf-8");
249
291
  stub = stub.replace(/{{ name }}/g, name);
250
292
  await writeFile(path$1, stub);
251
- this.kernel.output.split(`INFO: Model Created`, chalk.gray(nodepath.basename(path$1)));
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));
252
307
  }
253
308
  /**
254
309
  * Ge the database migration file name
@@ -267,181 +322,6 @@ var MakeCommand = class extends Command {
267
322
  }
268
323
  };
269
324
 
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
325
  //#endregion
446
326
  //#region src/Signature.ts
447
327
  var Signature = class Signature {
@@ -606,13 +486,107 @@ var Signature = class Signature {
606
486
  }
607
487
  };
608
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
+
609
584
  //#endregion
610
585
  //#region src/Musket.ts
611
586
  /**
612
587
  * Musket is H3ravel's CLI tool
613
588
  */
614
589
  var Musket = class Musket {
615
- output = Logger.log();
616
590
  commands = [];
617
591
  constructor(app, kernel) {
618
592
  this.app = app;
@@ -624,11 +598,7 @@ var Musket = class Musket {
624
598
  return this.initialize();
625
599
  }
626
600
  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));
601
+ [new MakeCommand(this.app, this.kernel), new ListCommand(this.app, this.kernel)].forEach((e) => this.addCommand(e));
632
602
  }
633
603
  async loadDiscoveredCommands() {
634
604
  const commands = [...this.app.registeredCommands.map((cmd) => new cmd(this.app, this.kernel))];
@@ -650,12 +620,27 @@ var Musket = class Musket {
650
620
  this.commands.push(Signature.parseSignature(command.getSignature(), command));
651
621
  }
652
622
  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}`);
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 */
656
640
  program.command("init").description("Initialize H3ravel.").action(async () => {
657
- this.output.success(`Initialized: H3ravel has been initialized!`);
641
+ Logger.success("Initialized: H3ravel has been initialized!");
658
642
  });
643
+ /** Loop through all the available commands */
659
644
  for (let i = 0; i < this.commands.length; i++) {
660
645
  const command = this.commands[i];
661
646
  const instance = command.commandClass;
@@ -663,8 +648,8 @@ var Musket = class Musket {
663
648
  /**
664
649
  * Initialize the base command
665
650
  */
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);
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);
668
653
  await instance.handle();
669
654
  });
670
655
  /**
@@ -677,8 +662,8 @@ var Musket = class Musket {
677
662
  * Initialize the sub commands
678
663
  */
679
664
  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);
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);
682
667
  await instance.handle();
683
668
  });
684
669
  /**
@@ -704,16 +689,24 @@ var Musket = class Musket {
704
689
  /**
705
690
  * Initialize command with options
706
691
  */
707
- const cmd = program.command(command.baseCommand).description(command.description ?? "");
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]);
708
693
  command?.options?.filter((v, i$1, a) => a.findIndex((t) => t.name === v.name) === i$1).forEach((opt) => {
709
694
  this.makeOption(opt, cmd, true);
710
695
  });
711
696
  cmd.action(async () => {
712
- instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command);
697
+ instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command, program);
713
698
  await instance.handle();
714
699
  });
715
700
  }
716
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
+ });
717
710
  return program;
718
711
  }
719
712
  makeOption(opt, cmd, parse, parent) {
@@ -732,15 +725,9 @@ var Musket = class Musket {
732
725
 
733
726
  //#endregion
734
727
  //#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;
728
+ var Kernel = class Kernel extends ConsoleKernel {
743
729
  constructor(app) {
730
+ super(app);
744
731
  this.app = app;
745
732
  }
746
733
  static init(app) {
@@ -751,13 +738,10 @@ var Kernel = class Kernel {
751
738
  await Musket.parse(this);
752
739
  process.exit(0);
753
740
  }
754
- async ensureDirectoryExists(dir) {
755
- await mkdir(dir, { recursive: true });
756
- }
757
741
  async loadRequirements() {
758
742
  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) ?? "";
743
+ this.modulePath = Helpers.findModulePkg("@h3ravel/core", this.cwd) ?? "";
744
+ this.consolePath = Helpers.findModulePkg("@h3ravel/console", this.cwd) ?? "";
761
745
  try {
762
746
  this.modulePackage = await import(nodepath.join(this.modulePath, "package.json"));
763
747
  } catch {
@@ -802,99 +786,5 @@ var ConsoleServiceProvider = class extends ServiceProvider {
802
786
  };
803
787
 
804
788
  //#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 };
789
+ export { Command, ConsoleServiceProvider, Kernel, ListCommand, MakeCommand, Musket, Signature, TableGuesser, TsDownConfig, Utils, altLogo, logo };
900
790
  //# sourceMappingURL=index.js.map