@h3ravel/console 11.2.0 → 11.3.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.d.cts CHANGED
@@ -1,7 +1,6 @@
1
- import { TableGuesser, Utils } from "./Utils-rIdzILgO.cjs";
1
+ import { TableGuesser, Utils } from "./Utils-CxAcuqeI.cjs";
2
2
  import { Application, ConsoleCommand, ConsoleKernel, ServiceProvider } from "@h3ravel/core";
3
- import * as commander0 from "commander";
4
- import { program } from "commander";
3
+ import { Command as Command$1 } from "commander";
5
4
  import { Options } from "tsdown";
6
5
 
7
6
  //#region src/Commands/Command.d.ts
@@ -75,6 +74,24 @@ declare class MakeCommand extends Command {
75
74
  getMigrationStubName(table?: string, create?: boolean, type?: 'ts' | 'js'): string;
76
75
  }
77
76
  //#endregion
77
+ //#region src/Commands/PostinstallCommand.d.ts
78
+ declare class PostinstallCommand extends Command {
79
+ /**
80
+ * The name and signature of the console command.
81
+ *
82
+ * @var string
83
+ */
84
+ protected signature: string;
85
+ /**
86
+ * The console command description.
87
+ *
88
+ * @var string
89
+ */
90
+ protected description: string;
91
+ handle(): Promise<void>;
92
+ private createSqliteDB;
93
+ }
94
+ //#endregion
78
95
  //#region src/Contracts/ICommand.d.ts
79
96
  type CommandOption = {
80
97
  name: string;
@@ -144,13 +161,13 @@ declare class Musket {
144
161
  private kernel;
145
162
  private commands;
146
163
  constructor(app: Application, kernel: Kernel);
147
- build(): Promise<commander0.Command>;
164
+ build(): Promise<Command$1>;
148
165
  private loadBaseCommands;
149
166
  private loadDiscoveredCommands;
150
167
  addCommand(command: Command): void;
151
168
  private initialize;
152
- makeOption(opt: CommandOption, cmd: typeof program, parse?: boolean, parent?: any): void;
153
- static parse(kernel: Kernel): Promise<commander0.Command>;
169
+ makeOption(opt: CommandOption, cmd: Command$1, parse?: boolean, parent?: any): void;
170
+ static parse(kernel: Kernel): Promise<Command$1>;
154
171
  }
155
172
  //#endregion
156
173
  //#region src/Providers/ConsoleServiceProvider.d.ts
@@ -195,5 +212,5 @@ declare class Signature {
195
212
  //#region src/TsdownConfig.d.ts
196
213
  declare const TsDownConfig: Options;
197
214
  //#endregion
198
- export { Command, CommandOption, ConsoleServiceProvider, Kernel, ListCommand, MakeCommand, Musket, ParsedCommand, Signature, TableGuesser, TsDownConfig, Utils, altLogo, logo };
215
+ export { Command, CommandOption, ConsoleServiceProvider, Kernel, ListCommand, MakeCommand, Musket, ParsedCommand, PostinstallCommand, Signature, TableGuesser, TsDownConfig, Utils, altLogo, logo };
199
216
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { TableGuesser, Utils } from "./Utils-cBgwEyTl.js";
1
+ import { TableGuesser, Utils } from "./Utils-CbqNJtIj.js";
2
2
  import { Application, ConsoleCommand, ConsoleKernel, ServiceProvider } from "@h3ravel/core";
3
- import * as commander0 from "commander";
4
- import { program } from "commander";
3
+ import { Command as Command$1 } from "commander";
5
4
  import { Options } from "tsdown";
6
5
 
7
6
  //#region src/Commands/Command.d.ts
@@ -75,6 +74,24 @@ declare class MakeCommand extends Command {
75
74
  getMigrationStubName(table?: string, create?: boolean, type?: 'ts' | 'js'): string;
76
75
  }
77
76
  //#endregion
77
+ //#region src/Commands/PostinstallCommand.d.ts
78
+ declare class PostinstallCommand extends Command {
79
+ /**
80
+ * The name and signature of the console command.
81
+ *
82
+ * @var string
83
+ */
84
+ protected signature: string;
85
+ /**
86
+ * The console command description.
87
+ *
88
+ * @var string
89
+ */
90
+ protected description: string;
91
+ handle(): Promise<void>;
92
+ private createSqliteDB;
93
+ }
94
+ //#endregion
78
95
  //#region src/Contracts/ICommand.d.ts
79
96
  type CommandOption = {
80
97
  name: string;
@@ -144,13 +161,13 @@ declare class Musket {
144
161
  private kernel;
145
162
  private commands;
146
163
  constructor(app: Application, kernel: Kernel);
147
- build(): Promise<commander0.Command>;
164
+ build(): Promise<Command$1>;
148
165
  private loadBaseCommands;
149
166
  private loadDiscoveredCommands;
150
167
  addCommand(command: Command): void;
151
168
  private initialize;
152
- makeOption(opt: CommandOption, cmd: typeof program, parse?: boolean, parent?: any): void;
153
- static parse(kernel: Kernel): Promise<commander0.Command>;
169
+ makeOption(opt: CommandOption, cmd: Command$1, parse?: boolean, parent?: any): void;
170
+ static parse(kernel: Kernel): Promise<Command$1>;
154
171
  }
155
172
  //#endregion
156
173
  //#region src/Providers/ConsoleServiceProvider.d.ts
@@ -195,5 +212,5 @@ declare class Signature {
195
212
  //#region src/TsdownConfig.d.ts
196
213
  declare const TsDownConfig: Options;
197
214
  //#endregion
198
- export { Command, CommandOption, ConsoleServiceProvider, Kernel, ListCommand, MakeCommand, Musket, ParsedCommand, Signature, TableGuesser, TsDownConfig, Utils, altLogo, logo };
215
+ export { Command, CommandOption, ConsoleServiceProvider, Kernel, ListCommand, MakeCommand, Musket, ParsedCommand, PostinstallCommand, Signature, TableGuesser, TsDownConfig, Utils, altLogo, logo };
199
216
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,14 +1,11 @@
1
- import { TableGuesser, Utils, sync_default } from "./Utils-Dvclc4Pc.js";
2
- import { access } from "fs/promises";
3
- import path, { dirname, join, resolve } from "path";
1
+ import { TableGuesser, Utils } from "./Utils-Dn22CO9s.js";
4
2
  import { Application, ConsoleCommand, ConsoleKernel, ServiceProvider } from "@h3ravel/core";
5
- import { Logger } from "@h3ravel/shared";
3
+ import { FileSystem, Logger } from "@h3ravel/shared";
6
4
  import { glob, mkdir, readFile, writeFile } from "node:fs/promises";
7
5
  import { beforeLast } from "@h3ravel/support";
8
6
  import dayjs from "dayjs";
9
7
  import { existsSync } from "node:fs";
10
8
  import nodepath from "node:path";
11
- import "@h3ravel/console";
12
9
  import "@h3ravel/http";
13
10
  import "@h3ravel/router";
14
11
  import "@h3ravel/database";
@@ -17,6 +14,7 @@ import "@h3ravel/queue";
17
14
  import "@h3ravel/mail";
18
15
  import "@h3ravel/config";
19
16
  import { Option, program } from "commander";
17
+ import { dirname, join, resolve } from "path";
20
18
  import { fork } from "child_process";
21
19
  import { build } from "tsdown";
22
20
 
@@ -113,44 +111,6 @@ var ListCommand = class extends Command {
113
111
  }
114
112
  };
115
113
 
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
114
  //#endregion
155
115
  //#region src/Commands/MakeCommand.ts
156
116
  var MakeCommand = class extends Command {
@@ -223,15 +183,15 @@ var MakeCommand = class extends Command {
223
183
  const type = this.option("api") ? "-resource" : "";
224
184
  const name = this.argument("name");
225
185
  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) ?? "";
186
+ const path = nodepath.join(app_path("Http/Controllers"), name + ".ts");
187
+ const crtlrPath = FileSystem.findModulePkg("@h3ravel/http", this.kernel.cwd) ?? "";
228
188
  const stubPath = nodepath.join(crtlrPath, `dist/stubs/controller${type}.stub`);
229
189
  /** Check if the controller already exists */
230
- if (!force && existsSync(path$1)) Logger.error(`ERORR: ${name} controller already exists`);
190
+ if (!force && existsSync(path)) Logger.error(`ERORR: ${name} controller already exists`);
231
191
  let stub = await readFile(stubPath, "utf-8");
232
192
  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));
193
+ await writeFile(path, stub);
194
+ Logger.split("INFO: Controller Created", Logger.log(nodepath.basename(path), "gray", false));
235
195
  }
236
196
  makeResource() {
237
197
  Logger.success("Resource support is not yet available");
@@ -242,8 +202,8 @@ var MakeCommand = class extends Command {
242
202
  async makeMigration() {
243
203
  const name = this.argument("name");
244
204
  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) ?? "";
205
+ const path = nodepath.join(database_path("migrations"), `${datePrefix}_${name}.ts`);
206
+ const crtlrPath = FileSystem.findModulePkg("@h3ravel/database", this.kernel.cwd) ?? "";
247
207
  let create = this.option("create", false);
248
208
  let table = this.option("table");
249
209
  if (!table && typeof create === "string") {
@@ -259,9 +219,9 @@ var MakeCommand = class extends Command {
259
219
  let stub = await readFile(stubPath, "utf-8");
260
220
  if (table !== null) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
261
221
  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));
222
+ await this.kernel.ensureDirectoryExists(nodepath.dirname(path));
223
+ await writeFile(path, stub);
224
+ Logger.split("INFO: Migration Created", Logger.log(nodepath.basename(path), "gray", false));
265
225
  }
266
226
  /**
267
227
  * Create a new model factory
@@ -282,15 +242,15 @@ var MakeCommand = class extends Command {
282
242
  const type = this.option("type", "ts");
283
243
  const name = this.argument("name");
284
244
  const force = this.argument("force");
285
- const path$1 = nodepath.join(app_path("Models"), name.toLowerCase(), "." + type);
245
+ const path = nodepath.join(app_path("Models"), name.toLowerCase(), "." + type);
286
246
  /** 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) ?? "";
247
+ if (!force && existsSync(path)) Logger.error(`ERORR: ${name} view already exists`);
248
+ const crtlrPath = FileSystem.findModulePkg("@h3ravel/database", this.kernel.cwd) ?? "";
289
249
  const stubPath = nodepath.join(crtlrPath, `dist/stubs/model-${type}.stub`);
290
250
  let stub = await readFile(stubPath, "utf-8");
291
251
  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));
252
+ await writeFile(path, stub);
253
+ Logger.split("INFO: Model Created", Logger.log(nodepath.basename(path), "gray", false));
294
254
  }
295
255
  /**
296
256
  * Create a new view.
@@ -298,11 +258,11 @@ var MakeCommand = class extends Command {
298
258
  async makeView() {
299
259
  const name = this.argument("name");
300
260
  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 });
261
+ const path = nodepath.join(base_path("src/resources/views"), name + ".edge");
262
+ if (name.includes("/")) await mkdir(beforeLast(path, "/"), { recursive: true });
303
263
  /** 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 --}}`);
264
+ if (!force && existsSync(path)) Logger.error(`ERORR: ${name} view already exists`);
265
+ await writeFile(path, `{{-- src/resources/views/${name}.edge --}}`);
306
266
  Logger.split("INFO: View Created", Logger.log(`src/resources/views/${name}.edge`, "gray", false));
307
267
  }
308
268
  /**
@@ -322,6 +282,30 @@ var MakeCommand = class extends Command {
322
282
  }
323
283
  };
324
284
 
285
+ //#endregion
286
+ //#region src/Commands/PostinstallCommand.ts
287
+ var PostinstallCommand = class extends Command {
288
+ /**
289
+ * The name and signature of the console command.
290
+ *
291
+ * @var string
292
+ */
293
+ signature = "postinstall";
294
+ /**
295
+ * The console command description.
296
+ *
297
+ * @var string
298
+ */
299
+ description = "Default post installation command";
300
+ async handle() {
301
+ this.createSqliteDB();
302
+ }
303
+ async createSqliteDB() {
304
+ if (!await FileSystem.fileExists(database_path())) await mkdir(database_path(), { recursive: true });
305
+ if (!await FileSystem.fileExists(database_path("db.sqlite"))) await writeFile(database_path("db.sqlite"), "");
306
+ }
307
+ };
308
+
325
309
  //#endregion
326
310
  //#region src/Signature.ts
327
311
  var Signature = class Signature {
@@ -354,7 +338,7 @@ var Signature = class Signature {
354
338
  continue;
355
339
  }
356
340
  const namePart = content.substring(0, colonIndex).trim();
357
- let rest = content.substring(colonIndex + 1).trim();
341
+ const rest = content.substring(colonIndex + 1).trim();
358
342
  /**
359
343
  * Check for nested options after '|'
360
344
  */
@@ -598,7 +582,11 @@ var Musket = class Musket {
598
582
  return this.initialize();
599
583
  }
600
584
  loadBaseCommands() {
601
- [new MakeCommand(this.app, this.kernel), new ListCommand(this.app, this.kernel)].forEach((e) => this.addCommand(e));
585
+ [
586
+ new MakeCommand(this.app, this.kernel),
587
+ new ListCommand(this.app, this.kernel),
588
+ new PostinstallCommand(this.app, this.kernel)
589
+ ].forEach((e) => this.addCommand(e));
602
590
  }
603
591
  async loadDiscoveredCommands() {
604
592
  const commands = [...this.app.registeredCommands.map((cmd) => new cmd(this.app, this.kernel))];
@@ -628,10 +616,14 @@ var Musket = class Musket {
628
616
  quiet: ["-q, --quiet", "Do not output any message"],
629
617
  silent: ["--silent", "Do not output any message"],
630
618
  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"]
619
+ lock: ["--lock", "Locked and loaded, do not ask any interactive question"]
632
620
  };
633
621
  /** 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 () => {
622
+ 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([
623
+ "1",
624
+ "2",
625
+ "3"
626
+ ])).addOption(new Option(additional.lock[0], additional.lock[1])).action(async () => {
635
627
  const instance = new ListCommand(this.app, this.kernel);
636
628
  instance.setInput(program.opts(), program.args, program.registeredArguments, {}, program);
637
629
  instance.handle();
@@ -648,7 +640,11 @@ var Musket = class Musket {
648
640
  /**
649
641
  * Initialize the base command
650
642
  */
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 () => {
643
+ 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([
644
+ "1",
645
+ "2",
646
+ "3"
647
+ ])).addOption(new Option(additional.lock[0], additional.lock[1])).action(async () => {
652
648
  instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command, program);
653
649
  await instance.handle();
654
650
  });
@@ -662,7 +658,11 @@ var Musket = class Musket {
662
658
  * Initialize the sub commands
663
659
  */
664
660
  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 () => {
661
+ 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([
662
+ "1",
663
+ "2",
664
+ "3"
665
+ ])).addOption(new Option(additional.lock[0], additional.lock[1])).action(async () => {
666
666
  instance.setInput(cmd$1.opts(), cmd$1.args, cmd$1.registeredArguments, sub, program);
667
667
  await instance.handle();
668
668
  });
@@ -689,7 +689,7 @@ var Musket = class Musket {
689
689
  /**
690
690
  * Initialize command with options
691
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]);
692
+ const cmd = program.command(command.baseCommand).description(command.description ?? "");
693
693
  command?.options?.filter((v, i$1, a) => a.findIndex((t) => t.name === v.name) === i$1).forEach((opt) => {
694
694
  this.makeOption(opt, cmd, true);
695
695
  });
@@ -740,8 +740,8 @@ var Kernel = class Kernel extends ConsoleKernel {
740
740
  }
741
741
  async loadRequirements() {
742
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) ?? "";
743
+ this.modulePath = FileSystem.findModulePkg("@h3ravel/core", this.cwd) ?? "";
744
+ this.consolePath = FileSystem.findModulePkg("@h3ravel/console", this.cwd) ?? "";
745
745
  try {
746
746
  this.modulePackage = await import(nodepath.join(this.modulePath, "package.json"));
747
747
  } catch {
@@ -786,5 +786,5 @@ var ConsoleServiceProvider = class extends ServiceProvider {
786
786
  };
787
787
 
788
788
  //#endregion
789
- export { Command, ConsoleServiceProvider, Kernel, ListCommand, MakeCommand, Musket, Signature, TableGuesser, TsDownConfig, Utils, altLogo, logo };
789
+ export { Command, ConsoleServiceProvider, Kernel, ListCommand, MakeCommand, Musket, PostinstallCommand, Signature, TableGuesser, TsDownConfig, Utils, altLogo, logo };
790
790
  //# sourceMappingURL=index.js.map