@h3ravel/console 11.1.0 → 11.2.1

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,151 @@
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
- import "@h3ravel/console";
14
11
  import "@h3ravel/http";
15
12
  import "@h3ravel/router";
13
+ import "@h3ravel/database";
16
14
  import "@h3ravel/cache";
17
15
  import "@h3ravel/queue";
18
16
  import "@h3ravel/mail";
19
17
  import "@h3ravel/config";
20
- import { Logger } from "@h3ravel/shared";
21
- import { program } from "commander";
18
+ import { Option, program } from "commander";
22
19
  import { fork } from "child_process";
20
+ import { build } from "tsdown";
23
21
 
24
22
  //#region src/Commands/Command.ts
25
- var Command = class {
26
- constructor(app, kernel) {
27
- this.app = app;
28
- this.kernel = kernel;
29
- }
23
+ var Command = class extends ConsoleCommand {};
24
+
25
+ //#endregion
26
+ //#region src/logo.ts
27
+ const logo = String.raw`
28
+ 111
29
+ 111111111
30
+ 1111111111 111111
31
+ 111111 111 111111
32
+ 111111 111 111111
33
+ 11111 111 11111
34
+ 1111111 111 1111111
35
+ 111 11111 111 111111 111 1111 1111 11111111 1111
36
+ 111 11111 1111 111111 111 1111 1111 1111 11111 1111
37
+ 111 11111 11111 111 1111 1111 111111111111 111111111111 1111 1111111 1111
38
+ 111 111111 1111 111 111111111111 111111 11111 1111 111 1111 11111111 1111 1111
39
+ 111 111 11111111 111 1101 1101 111111111 11111111 1111 1111111111111111101
40
+ 111 1111111111111111 1111 111 1111 1111 111 11111011 1111 111 1111111 1101 1111
41
+ 111 11111 1110111111111111 111 1111 1111 1111111101 1111 111111111 1111011 111111111 1111
42
+ 1111111 111110111110 111 1111 1111 111111 1111 11011101 10111 11111 1111
43
+ 11011 111111 11 11111
44
+ 111111 11101 111111
45
+ 111111 111 111111
46
+ 111111 111 111111
47
+ 111111111
48
+ 110
49
+ `;
50
+ const altLogo = String.raw`
51
+ _ _ _____ _
52
+ | | | |___ / _ __ __ ___ _____| |
53
+ | |_| | |_ \| '__/ _ \ \ / / _ \ |
54
+ | _ |___) | | | (_| |\ V / __/ |
55
+ |_| |_|____/|_| \__,_| \_/ \___|_|
56
+
57
+ `;
58
+
59
+ //#endregion
60
+ //#region src/Commands/ListCommand.ts
61
+ var ListCommand = class extends Command {
30
62
  /**
31
63
  * The name and signature of the console command.
32
64
  *
33
65
  * @var string
34
66
  */
35
- signature;
36
- /**
37
- * A dictionary of signatures or what not.
38
- *
39
- * @var object
40
- */
41
- dictionary = {};
67
+ signature = "list";
42
68
  /**
43
69
  * The console command description.
44
70
  *
45
71
  * @var string
46
72
  */
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;
73
+ description = "List all available commands";
74
+ async handle() {
75
+ const options = [{
76
+ short: "-h",
77
+ long: "--help",
78
+ description: "Display help for the given command. When no command is given display help for the list command"
79
+ }].concat(this.program.options).map((e) => {
80
+ return Logger.describe(Logger.log(" " + [e.short, e.long].filter((e$1) => !!e$1).join(", "), "green", false), e.description, 25, false).join("");
81
+ });
82
+ const grouped = this.program.commands.map((e) => {
83
+ return Logger.describe(Logger.log(" " + e.name(), "green", false), e.description(), 25, false).join("");
84
+ }).reduce((acc, cmd) => {
85
+ /** strip colors before checking prefix */
86
+ const clean = cmd.replace(/\x1b\[\d+m/g, "");
87
+ const prefix = clean.includes(":") ? clean.split(":")[0].trim() : "__root__";
88
+ acc[prefix] ??= [];
89
+ /** keep original with colors */
90
+ acc[prefix].push(cmd);
91
+ return acc;
92
+ }, {});
93
+ const list = Object.entries(grouped).map(([group, cmds]) => {
94
+ const label = group === "__root__" ? "" : group;
95
+ return [Logger.log(label, "yellow", false), cmds.join("\n")].join("\n");
96
+ });
97
+ /** Ootput the app version */
98
+ Logger.log([["H3ravel Framework", "white"], [this.kernel.modulePackage.version, "green"]], " ");
99
+ console.log("");
100
+ console.log(altLogo);
101
+ console.log("");
102
+ Logger.log("Usage:", "yellow");
103
+ Logger.log(" command [options] [arguments]", "white");
104
+ console.log("");
105
+ /** Ootput the options */
106
+ Logger.log("Options:", "yellow");
107
+ console.log(options.join("\n").trim());
108
+ console.log("");
109
+ /** Ootput the commands */
110
+ Logger.log("Available Commands:", "yellow");
111
+ console.log(list.join("\n\n").trim());
87
112
  }
88
113
  };
89
114
 
90
115
  //#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
- `;
116
+ //#region ../filesystem/dist/index.js
117
+ var Helpers = class {
118
+ static findModulePkg(moduleId, cwd) {
119
+ const parts = moduleId.replace(/\\/g, "/").split("/");
120
+ let packageName = "";
121
+ if (parts.length > 0 && parts[0][0] === "@") packageName += parts.shift() + "/";
122
+ packageName += parts.shift();
123
+ const packageJson = path.join(cwd ?? process.cwd(), "node_modules", packageName);
124
+ const resolved = this.findUpConfig(packageJson, "package", ["json"]);
125
+ if (!resolved) return;
126
+ return path.join(path.dirname(resolved), parts.join("/"));
127
+ }
104
128
  /**
105
- * The console command description.
106
- *
107
- * @var string
129
+ * Check if file exists
130
+ *
131
+ * @param path
132
+ * @returns
108
133
  */
109
- description = "Fire up the developement server";
110
- async handle() {
134
+ static async fileExists(path$1) {
111
135
  try {
112
- await this.fire();
113
- } catch (e) {
114
- this.kernel.output.error(e);
136
+ await access(path$1);
137
+ return true;
138
+ } catch {
139
+ return false;
115
140
  }
116
141
  }
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)
142
+ static findUpConfig(cwd, name, extensions) {
143
+ return sync_default(cwd, (_dir, names) => {
144
+ for (const ext of extensions) {
145
+ const filename = `${name}.${ext}`;
146
+ if (names.includes(filename)) return filename;
147
+ }
148
+ return false;
144
149
  });
145
150
  }
146
151
  };
@@ -154,12 +159,37 @@ var MakeCommand = class extends Command {
154
159
  * @var string
155
160
  */
156
161
  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}}
162
+ {controller : Create a new controller class.
163
+ | {--a|api : Exclude the create and edit methods from the controller}
164
+ | {--m|model= : Generate a resource controller for the given model}
165
+ | {--r|resource : Generate a resource controller class}
166
+ | {--force : Create the controller even if it already exists}
167
+ }
168
+ {resource : Create a new resource.
169
+ | {--c|collection : Create a resource collection}
170
+ | {--force : Create the resource even if it already exists}
171
+ }
172
+ {migration : Generates a new database migration class.
173
+ | {--l|type=ts : The file type to generate}
174
+ | {--t|table : The table to migrate}
175
+ | {--c|create : The table to be created}
176
+ }
177
+ {factory : Create a new model factory.}
178
+ {seeder : Create a new seeder class.}
179
+ {view : Create a new view.
180
+ | {--force : Create the view even if it already exists}
181
+ }
182
+ {model : Create a new Eloquent model class.
183
+ | {--api : Indicates if the generated controller should be an API resource controller}
184
+ | {--c|controller : Create a new controller for the model}
185
+ | {--f|factory : Create a new factory for the model}
186
+ | {--m|migration : Create a new migration file for the model}
187
+ | {--r|resource : Indicates if the generated controller should be a resource controller}
188
+ | {--a|all : Generate a migration, seeder, factory, policy, resource controller, and form request classes for the model}
189
+ | {--s|seed : Create a new seeder for the model}
190
+ | {--t|type=ts : The file type to generate}
191
+ | {--force : Create the model even if it already exists}
192
+ }
163
193
  {^name : The name of the [name] to generate}
164
194
  `;
165
195
  /**
@@ -169,39 +199,41 @@ var MakeCommand = class extends Command {
169
199
  */
170
200
  description = "Generate component classes";
171
201
  async handle() {
172
- const command = this.dictionary.baseCommand;
202
+ const command = this.dictionary.baseCommand ?? this.dictionary.name;
173
203
  const methods = {
174
204
  controller: "makeController",
175
205
  resource: "makeResource",
176
206
  migration: "makeMigration",
177
207
  factory: "makeFactory",
178
208
  seeder: "makeSeeder",
179
- model: "makeModel"
209
+ model: "makeModel",
210
+ view: "makeView"
180
211
  };
181
212
  try {
182
213
  await this?.[methods[command]]();
183
214
  } catch (e) {
184
- this.kernel.output.error(e);
215
+ Logger.error(e);
185
216
  }
186
217
  }
187
218
  /**
188
- * Generate a new controller class.
219
+ * Create a new controller class.
189
220
  */
190
221
  async makeController() {
191
222
  const type = this.option("api") ? "-resource" : "";
192
223
  const name = this.argument("name");
193
224
  const force = this.option("force");
194
225
  const path$1 = nodepath.join(app_path("Http/Controllers"), name + ".ts");
195
- const crtlrPath = Utils.findModulePkg("@h3ravel/http", this.kernel.cwd) ?? "";
226
+ const crtlrPath = Helpers.findModulePkg("@h3ravel/http", this.kernel.cwd) ?? "";
196
227
  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`);
228
+ /** Check if the controller already exists */
229
+ if (!force && existsSync(path$1)) Logger.error(`ERORR: ${name} controller already exists`);
198
230
  let stub = await readFile(stubPath, "utf-8");
199
231
  stub = stub.replace(/{{ name }}/g, name);
200
232
  await writeFile(path$1, stub);
201
- this.kernel.output.split(`INFO: Controller Created`, chalk.gray(nodepath.basename(path$1)));
233
+ Logger.split("INFO: Controller Created", Logger.log(nodepath.basename(path$1), "gray", false));
202
234
  }
203
235
  makeResource() {
204
- this.kernel.output.success(`Resource support is not yet available`);
236
+ Logger.success("Resource support is not yet available");
205
237
  }
206
238
  /**
207
239
  * Generate a new database migration class
@@ -225,16 +257,22 @@ var MakeCommand = class extends Command {
225
257
  const stubPath = nodepath.join(crtlrPath, this.getMigrationStubName(table, create));
226
258
  let stub = await readFile(stubPath, "utf-8");
227
259
  if (table !== null) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
228
- this.kernel.output.info("INFO: Creating Migration");
260
+ Logger.info("INFO: Creating Migration");
229
261
  await this.kernel.ensureDirectoryExists(nodepath.dirname(path$1));
230
262
  await writeFile(path$1, stub);
231
- this.kernel.output.split(`INFO: Migration Created`, chalk.gray(nodepath.basename(path$1)));
263
+ Logger.split("INFO: Migration Created", Logger.log(nodepath.basename(path$1), "gray", false));
232
264
  }
265
+ /**
266
+ * Create a new model factory
267
+ */
233
268
  makeFactory() {
234
- this.kernel.output.success(`Factory support is not yet available`);
269
+ Logger.success("Factory support is not yet available");
235
270
  }
271
+ /**
272
+ * Create a new seeder class
273
+ */
236
274
  makeSeeder() {
237
- this.kernel.output.success(`Seeder support is not yet available`);
275
+ Logger.success("Seeder support is not yet available");
238
276
  }
239
277
  /**
240
278
  * Generate a new Arquebus model class
@@ -242,13 +280,29 @@ var MakeCommand = class extends Command {
242
280
  async makeModel() {
243
281
  const type = this.option("type", "ts");
244
282
  const name = this.argument("name");
245
- const path$1 = nodepath.join(app_path("Models"), name.toLowerCase() + "." + type);
283
+ const force = this.argument("force");
284
+ const path$1 = nodepath.join(app_path("Models"), name.toLowerCase(), "." + type);
285
+ /** Check if the model already exists */
286
+ if (!force && existsSync(path$1)) Logger.error(`ERORR: ${name} view already exists`);
246
287
  const crtlrPath = Utils.findModulePkg("@h3ravel/database", this.kernel.cwd) ?? "";
247
288
  const stubPath = nodepath.join(crtlrPath, `dist/stubs/model-${type}.stub`);
248
289
  let stub = await readFile(stubPath, "utf-8");
249
290
  stub = stub.replace(/{{ name }}/g, name);
250
291
  await writeFile(path$1, stub);
251
- this.kernel.output.split(`INFO: Model Created`, chalk.gray(nodepath.basename(path$1)));
292
+ Logger.split("INFO: Model Created", Logger.log(nodepath.basename(path$1), "gray", false));
293
+ }
294
+ /**
295
+ * Create a new view.
296
+ */
297
+ async makeView() {
298
+ const name = this.argument("name");
299
+ const force = this.option("force");
300
+ const path$1 = nodepath.join(base_path("src/resources/views"), name + ".edge");
301
+ if (name.includes("/")) await mkdir(beforeLast(path$1, "/"), { recursive: true });
302
+ /** Check if the view already exists */
303
+ if (!force && existsSync(path$1)) Logger.error(`ERORR: ${name} view already exists`);
304
+ await writeFile(path$1, `{{-- src/resources/views/${name}.edge --}}`);
305
+ Logger.split("INFO: View Created", Logger.log(`src/resources/views/${name}.edge`, "gray", false));
252
306
  }
253
307
  /**
254
308
  * Ge the database migration file name
@@ -267,181 +321,6 @@ var MakeCommand = class extends Command {
267
321
  }
268
322
  };
269
323
 
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
324
  //#endregion
446
325
  //#region src/Signature.ts
447
326
  var Signature = class Signature {
@@ -474,7 +353,7 @@ var Signature = class Signature {
474
353
  continue;
475
354
  }
476
355
  const namePart = content.substring(0, colonIndex).trim();
477
- let rest = content.substring(colonIndex + 1).trim();
356
+ const rest = content.substring(colonIndex + 1).trim();
478
357
  /**
479
358
  * Check for nested options after '|'
480
359
  */
@@ -606,13 +485,107 @@ var Signature = class Signature {
606
485
  }
607
486
  };
608
487
 
488
+ //#endregion
489
+ //#region ../../node_modules/.pnpm/@rollup+plugin-run@3.1.0/node_modules/@rollup/plugin-run/dist/es/index.js
490
+ function run(opts = {}) {
491
+ let input;
492
+ let proc;
493
+ const args = opts.args || [];
494
+ const allowRestarts = opts.allowRestarts || false;
495
+ const overrideInput = opts.input;
496
+ const forkOptions = opts.options || opts;
497
+ delete forkOptions.args;
498
+ delete forkOptions.allowRestarts;
499
+ return {
500
+ name: "run",
501
+ buildStart(options) {
502
+ let inputs = overrideInput !== null && overrideInput !== void 0 ? overrideInput : options.input;
503
+ if (typeof inputs === "string") inputs = [inputs];
504
+ if (typeof inputs === "object") inputs = Object.values(inputs);
505
+ if (inputs.length > 1) throw new Error(`@rollup/plugin-run must have a single entry point; consider setting the \`input\` option`);
506
+ input = resolve(inputs[0]);
507
+ },
508
+ generateBundle(_outputOptions, _bundle, isWrite) {
509
+ if (!isWrite) this.error(`@rollup/plugin-run currently only works with bundles that are written to disk`);
510
+ },
511
+ writeBundle(outputOptions, bundle) {
512
+ const forkBundle = (dir$1, entryFileName$1) => {
513
+ if (proc) proc.kill();
514
+ proc = fork(join(dir$1, entryFileName$1), args, forkOptions);
515
+ };
516
+ const dir = outputOptions.dir || dirname(outputOptions.file);
517
+ const entryFileName = Object.keys(bundle).find((fileName) => {
518
+ const chunk = bundle[fileName];
519
+ return chunk.isEntry && chunk.facadeModuleId === input;
520
+ });
521
+ if (entryFileName) {
522
+ forkBundle(dir, entryFileName);
523
+ if (allowRestarts) {
524
+ process.stdin.resume();
525
+ process.stdin.setEncoding("utf8");
526
+ process.stdin.on("data", (data) => {
527
+ const line = data.toString().trim().toLowerCase();
528
+ if (line === "rs" || line === "restart" || data.toString().charCodeAt(0) === 11) forkBundle(dir, entryFileName);
529
+ else if (line === "cls" || line === "clear" || data.toString().charCodeAt(0) === 12) console.clear();
530
+ });
531
+ }
532
+ } else this.error(`@rollup/plugin-run could not find output chunk`);
533
+ }
534
+ };
535
+ }
536
+
537
+ //#endregion
538
+ //#region src/TsdownConfig.ts
539
+ const env = process.env.NODE_ENV || "development";
540
+ const outDir = env === "development" ? ".h3ravel/serve" : "dist";
541
+ const TsDownConfig = {
542
+ outDir,
543
+ entry: ["src/**/*.ts"],
544
+ format: ["esm"],
545
+ target: "node22",
546
+ sourcemap: env === "development",
547
+ clean: true,
548
+ shims: true,
549
+ copy: [
550
+ {
551
+ from: "public",
552
+ to: outDir
553
+ },
554
+ "src/resources",
555
+ "src/database"
556
+ ],
557
+ env: env === "development" ? {
558
+ NODE_ENV: env,
559
+ SRC_PATH: outDir
560
+ } : {},
561
+ watch: env === "development" && process.env.CLI_BUILD !== "true" ? [
562
+ ".env",
563
+ ".env.*",
564
+ "src",
565
+ "../../packages"
566
+ ] : false,
567
+ dts: false,
568
+ logLevel: "silent",
569
+ nodeProtocol: true,
570
+ skipNodeModulesBundle: true,
571
+ plugins: env === "development" && process.env.CLI_BUILD !== "true" ? [run({
572
+ env: Object.assign({}, process.env, {
573
+ NODE_ENV: env,
574
+ SRC_PATH: outDir
575
+ }),
576
+ execArgv: ["-r", "source-map-support/register"],
577
+ allowRestarts: false,
578
+ input: process.cwd() + "/src/server.ts"
579
+ })] : []
580
+ };
581
+ var TsdownConfig_default = TsDownConfig;
582
+
609
583
  //#endregion
610
584
  //#region src/Musket.ts
611
585
  /**
612
586
  * Musket is H3ravel's CLI tool
613
587
  */
614
588
  var Musket = class Musket {
615
- output = Logger.log();
616
589
  commands = [];
617
590
  constructor(app, kernel) {
618
591
  this.app = app;
@@ -624,11 +597,7 @@ var Musket = class Musket {
624
597
  return this.initialize();
625
598
  }
626
599
  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));
600
+ [new MakeCommand(this.app, this.kernel), new ListCommand(this.app, this.kernel)].forEach((e) => this.addCommand(e));
632
601
  }
633
602
  async loadDiscoveredCommands() {
634
603
  const commands = [...this.app.registeredCommands.map((cmd) => new cmd(this.app, this.kernel))];
@@ -650,12 +619,31 @@ var Musket = class Musket {
650
619
  this.commands.push(Signature.parseSignature(command.getSignature(), command));
651
620
  }
652
621
  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}`);
622
+ /** Init the Musket Version */
623
+ const cliVersion = Logger.parse([["Musket CLI:", "white"], [this.kernel.consolePackage.version, "green"]], " ", false);
624
+ /** Init the App Version */
625
+ const localVersion = Logger.parse([["H3ravel Framework:", "white"], [this.kernel.modulePackage.version, "green"]], " ", false);
626
+ const additional = {
627
+ quiet: ["-q, --quiet", "Do not output any message"],
628
+ silent: ["--silent", "Do not output any message"],
629
+ verbose: ["-v, --verbose <number>", "Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug"],
630
+ lock: ["--lock", "Locked and loaded, do not ask any interactive question"]
631
+ };
632
+ /** Init Commander */
633
+ program.name("musket").version(`${cliVersion}\n${localVersion}`).description(altLogo).addOption(new Option(additional.quiet[0], additional.quiet[1]).implies({ silent: true })).addOption(new Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).addOption(new Option(additional.verbose[0], additional.verbose[1]).choices([
634
+ "1",
635
+ "2",
636
+ "3"
637
+ ])).addOption(new Option(additional.lock[0], additional.lock[1])).action(async () => {
638
+ const instance = new ListCommand(this.app, this.kernel);
639
+ instance.setInput(program.opts(), program.args, program.registeredArguments, {}, program);
640
+ instance.handle();
641
+ });
642
+ /** Create the init Command */
656
643
  program.command("init").description("Initialize H3ravel.").action(async () => {
657
- this.output.success(`Initialized: H3ravel has been initialized!`);
644
+ Logger.success("Initialized: H3ravel has been initialized!");
658
645
  });
646
+ /** Loop through all the available commands */
659
647
  for (let i = 0; i < this.commands.length; i++) {
660
648
  const command = this.commands[i];
661
649
  const instance = command.commandClass;
@@ -663,8 +651,12 @@ var Musket = class Musket {
663
651
  /**
664
652
  * Initialize the base command
665
653
  */
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);
654
+ const cmd = command.isHidden ? program : program.command(command.baseCommand).description(command.description ?? "").addOption(new Option(additional.quiet[0], additional.quiet[1]).implies({ silent: true })).addOption(new Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).addOption(new Option(additional.verbose[0], additional.verbose[1]).choices([
655
+ "1",
656
+ "2",
657
+ "3"
658
+ ])).addOption(new Option(additional.lock[0], additional.lock[1])).action(async () => {
659
+ instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command, program);
668
660
  await instance.handle();
669
661
  });
670
662
  /**
@@ -677,8 +669,12 @@ var Musket = class Musket {
677
669
  * Initialize the sub commands
678
670
  */
679
671
  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);
672
+ const cmd$1 = program.command(`${command.baseCommand}:${sub.name}`).description(sub.description || "").addOption(new Option(additional.quiet[0], additional.quiet[1]).implies({ silent: true })).addOption(new Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).addOption(new Option(additional.verbose[0], additional.verbose[1]).choices([
673
+ "1",
674
+ "2",
675
+ "3"
676
+ ])).addOption(new Option(additional.lock[0], additional.lock[1])).action(async () => {
677
+ instance.setInput(cmd$1.opts(), cmd$1.args, cmd$1.registeredArguments, sub, program);
682
678
  await instance.handle();
683
679
  });
684
680
  /**
@@ -709,11 +705,19 @@ var Musket = class Musket {
709
705
  this.makeOption(opt, cmd, true);
710
706
  });
711
707
  cmd.action(async () => {
712
- instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command);
708
+ instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command, program);
713
709
  await instance.handle();
714
710
  });
715
711
  }
716
712
  }
713
+ /** Rebuild the app on every command except fire so we wont need TS */
714
+ program.hook("preAction", async (_, cmd) => {
715
+ if (cmd.name() !== "fire") await build({
716
+ ...TsdownConfig_default,
717
+ watch: false,
718
+ plugins: []
719
+ });
720
+ });
717
721
  return program;
718
722
  }
719
723
  makeOption(opt, cmd, parse, parent) {
@@ -732,15 +736,9 @@ var Musket = class Musket {
732
736
 
733
737
  //#endregion
734
738
  //#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;
739
+ var Kernel = class Kernel extends ConsoleKernel {
743
740
  constructor(app) {
741
+ super(app);
744
742
  this.app = app;
745
743
  }
746
744
  static init(app) {
@@ -751,13 +749,10 @@ var Kernel = class Kernel {
751
749
  await Musket.parse(this);
752
750
  process.exit(0);
753
751
  }
754
- async ensureDirectoryExists(dir) {
755
- await mkdir(dir, { recursive: true });
756
- }
757
752
  async loadRequirements() {
758
753
  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) ?? "";
754
+ this.modulePath = Helpers.findModulePkg("@h3ravel/core", this.cwd) ?? "";
755
+ this.consolePath = Helpers.findModulePkg("@h3ravel/console", this.cwd) ?? "";
761
756
  try {
762
757
  this.modulePackage = await import(nodepath.join(this.modulePath, "package.json"));
763
758
  } catch {
@@ -802,99 +797,5 @@ var ConsoleServiceProvider = class extends ServiceProvider {
802
797
  };
803
798
 
804
799
  //#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 };
800
+ export { Command, ConsoleServiceProvider, Kernel, ListCommand, MakeCommand, Musket, Signature, TableGuesser, TsDownConfig, Utils, altLogo, logo };
900
801
  //# sourceMappingURL=index.js.map