@h3ravel/musket 0.6.2 → 0.6.3

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/README.md CHANGED
@@ -68,14 +68,14 @@ Musket allows passing a `config` object that alters it's behavior and provide so
68
68
  ```ts
69
69
  Kernel.init(app, {
70
70
  packages: ['@h3ravel/shared', '@h3ravel/support'],
71
- cliName: 'musket-cli',
71
+ name: 'musket-cli',
72
72
  discoveryPaths: [path.join(process.cwd(), 'tests/Commands/*.ts')],
73
73
  });
74
74
  ```
75
75
 
76
76
  ### Advanced Initialization
77
77
 
78
- You can also initialize **Musket CLI** with precise controls
78
+ If you need fine grained control with your initialization, `Musket CLI` exposes just the right methods to enable you do just that, when when initializing the CLI in this manner, the `packages` config property is completely ignored, as a work around, chain the `setPackages` method to the Kernel intance to achieve the same results.
79
79
 
80
80
  ```ts
81
81
  import { Kernel } from 'h3ravel/musket';
@@ -86,7 +86,7 @@ const app = new Application();
86
86
  const instance = new Kernel(app)
87
87
  .setCwd(process.cwd())
88
88
  .setConfig({
89
- cliName: 'musket-cli',
89
+ name: 'musket-cli',
90
90
  discoveryPaths: [path.join(process.cwd(), 'tests/Commands/*.ts')],
91
91
  })
92
92
  .setPackages([
@@ -99,8 +99,6 @@ const instance = new Kernel(app)
99
99
  return await instance.run();
100
100
  ```
101
101
 
102
- > NB: Packages in the config will be ignored when initializing in this way, as a work around, chain the `setPackages` method to the Kernel intance and pass your options
103
-
104
102
  ## Creating Commands
105
103
 
106
104
  Commands in Musket extend the base `Command` class and define a **signature** and **handle()** method.
package/dist/index.cjs CHANGED
@@ -590,7 +590,7 @@ var Musket = class Musket {
590
590
  *
591
591
  * @default musket
592
592
  */
593
- cliName = "musket";
593
+ name = "musket";
594
594
  config = {};
595
595
  commands = [];
596
596
  program;
@@ -691,7 +691,7 @@ var Musket = class Musket {
691
691
  /**
692
692
  * Run the base Command if a root command was not defined
693
693
  */
694
- this.program.name(this.cliName).version(moduleVersions).description(this.config.logo ?? altLogo).configureHelp({ showGlobalOptions: true }).addOption(new commander.Option(additional.quiet[0], additional.quiet[1])).addOption(new commander.Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).addOption(new commander.Option(additional.verbose[0], additional.verbose[1]).choices([
694
+ this.program.name(this.name).version(moduleVersions).description(this.config.logo ?? altLogo).configureHelp({ showGlobalOptions: true }).addOption(new commander.Option(additional.quiet[0], additional.quiet[1])).addOption(new commander.Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).addOption(new commander.Option(additional.verbose[0], additional.verbose[1]).choices([
695
695
  "1",
696
696
  "2",
697
697
  "3",
@@ -853,14 +853,14 @@ var Musket = class Musket {
853
853
  }
854
854
  const commands = config.baseCommands?.concat(extraCommands)?.map((e) => new e(kernel.app, kernel));
855
855
  const cli = new Musket(kernel.app, kernel, commands, config.resolver, config.tsDownConfig).configure(config);
856
- if (config.cliName) cli.cliName = config.cliName;
856
+ if (config.name) cli.name = config.name;
857
857
  const command = (await cli.build()).exitOverride((e) => {
858
858
  exitCode = e.exitCode;
859
859
  if (e.exitCode <= 0) return;
860
860
  __h3ravel_shared.Logger.log("Unknown command or argument.", "white");
861
861
  __h3ravel_shared.Logger.log([
862
862
  ["Run", "white"],
863
- [`\`${config.cliName} --help\``, ["grey", "italic"]],
863
+ [`\`${config.name} --help\``, ["grey", "italic"]],
864
864
  ["to see available commands.", "white"]
865
865
  ], " ");
866
866
  });
@@ -973,23 +973,27 @@ var Kernel = class Kernel {
973
973
  return Array.from(this.commands);
974
974
  }
975
975
  /**
976
- * Bootstrap the CLI
976
+ * Prepares the CLI for execution
977
977
  */
978
978
  bootstrap() {
979
+ let version = this.config.version;
979
980
  const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
980
981
  this.cwd ??= node_path.default.join(process.cwd(), this.basePath);
981
982
  if (!this.config.hideMusketInfo) try {
982
983
  const pkg = require$1(node_path.default.join(process.cwd(), "package.json"));
983
- pkg.name = this.config.cliName ?? pkg.name;
984
+ pkg.name = this.config.name ?? pkg.name;
984
985
  this.modules.push(pkg);
985
986
  } catch {}
986
987
  for (let i = 0; i < this.packages.length; i++) try {
987
988
  const item = this.packages[i];
988
989
  const name = typeof item === "string" ? item : item.name;
989
990
  const alias = typeof item === "string" ? item : item.alias;
991
+ const base = typeof item === "string" ? false : item.base;
990
992
  const modulePath = __h3ravel_shared.FileSystem.findModulePkg(name, this.cwd) ?? "";
991
993
  const pkg = require$1(node_path.default.join(modulePath, "package.json"));
992
994
  pkg.alias = alias;
995
+ pkg.base = base;
996
+ if (base === true && version) pkg.version = version;
993
997
  this.modules.push(pkg);
994
998
  } catch (e) {
995
999
  this.modules.push({
@@ -997,6 +1001,13 @@ var Kernel = class Kernel {
997
1001
  name: "Unknown"
998
1002
  });
999
1003
  }
1004
+ if (this.packages.length < 1) {
1005
+ if (!version) version = typeof this.app.version === "function" ? this.app.version() : typeof this.app.getVersion === "function" ? this.app.getVersion() : this.app.version;
1006
+ this.modules.push({
1007
+ version: version ?? "N/A",
1008
+ name: "Musket CLI"
1009
+ });
1010
+ }
1000
1011
  return this;
1001
1012
  }
1002
1013
  };
package/dist/index.d.ts CHANGED
@@ -53,17 +53,29 @@ type ParsedCommand = {
53
53
  */
54
54
  options?: CommandOption[];
55
55
  };
56
- interface InitConfig {
56
+ type PackageMeta = string | {
57
+ name: string;
58
+ alias: string;
59
+ base?: boolean;
60
+ };
61
+ type CommandMethodResolver = <X extends Command>(cmd: X, met: any) => Promise<X>;
62
+ interface KernelConfig {
57
63
  /**
58
64
  * ASCII Art style logo
59
65
  */
60
66
  logo?: string;
61
67
  /**
62
- * The name of the CLI app we're building
68
+ * The name of the CLI app we're running
63
69
  *
64
70
  * @default musket
65
71
  */
66
- cliName?: string;
72
+ name?: string;
73
+ /**
74
+ * The version of the CLI app we're running (if provided, this will overwrite the value of resolved version from packages config marked as base)
75
+ *
76
+ * @default musket
77
+ */
78
+ version?: string;
67
79
  /**
68
80
  * Don't parse the command, usefull for testing or manual control
69
81
  */
@@ -75,7 +87,7 @@ interface InitConfig {
75
87
  * @param met
76
88
  * @returns
77
89
  */
78
- resolver?: <X extends Command>(cmd: X, met: any) => Promise<X>;
90
+ resolver?: CommandMethodResolver;
79
91
  /**
80
92
  * If we need to programmatically run the tsdown build command, we will use this config.
81
93
  */
@@ -83,10 +95,7 @@ interface InitConfig {
83
95
  /**
84
96
  * Packages that should show up up when the `-V` flag is passed
85
97
  */
86
- packages?: (string | {
87
- name: string;
88
- alias: string;
89
- })[];
98
+ packages?: PackageMeta[];
90
99
  /**
91
100
  * If set to true, information about musket CLI like name and
92
101
  * version info will not be unexpectedly shown in console
@@ -126,6 +135,8 @@ declare class Kernel<A extends Application = Application> {
126
135
  modules: XGeneric<{
127
136
  version: string;
128
137
  name: string;
138
+ base?: boolean;
139
+ alias?: string;
129
140
  }>[];
130
141
  /**
131
142
  * The base path for the CLI app
@@ -152,7 +163,7 @@ declare class Kernel<A extends Application = Application> {
152
163
  * @param config
153
164
  * @returns
154
165
  */
155
- static init<A extends Application>(app: A, config?: InitConfig): Promise<commander0.Command>;
166
+ static init<A extends Application>(app: A, config?: KernelConfig): Promise<commander0.Command>;
156
167
  /**
157
168
  * Run the CLI IO
158
169
  */
@@ -160,11 +171,11 @@ declare class Kernel<A extends Application = Application> {
160
171
  /**
161
172
  * Set the configuration for the CLI
162
173
  */
163
- setConfig(config: InitConfig): this;
174
+ setConfig(config: KernelConfig): this;
164
175
  /**
165
176
  * Get the configuration for the CLI
166
177
  */
167
- getConfig(): InitConfig;
178
+ getConfig(): KernelConfig;
168
179
  /**
169
180
  * Set the current working directory
170
181
  */
@@ -176,11 +187,11 @@ declare class Kernel<A extends Application = Application> {
176
187
  /**
177
188
  * Set the packages that should show up up when the -V flag is passed
178
189
  */
179
- setPackages(packages: NonNullable<InitConfig['packages']>): this;
190
+ setPackages(packages: PackageMeta[]): this;
180
191
  /**
181
192
  * Get the packages that should show up up when the -V flag is passed
182
193
  */
183
- getPackages(): NonNullable<InitConfig['packages']>;
194
+ getPackages(): PackageMeta[];
184
195
  /**
185
196
  * Push a list of new commands to commands stack
186
197
  *
@@ -192,7 +203,7 @@ declare class Kernel<A extends Application = Application> {
192
203
  */
193
204
  getRegisteredCommands(): typeof Command[];
194
205
  /**
195
- * Bootstrap the CLI
206
+ * Prepares the CLI for execution
196
207
  */
197
208
  bootstrap(): this;
198
209
  }
@@ -394,11 +405,11 @@ declare class Musket {
394
405
  *
395
406
  * @default musket
396
407
  */
397
- cliName: string;
408
+ name: string;
398
409
  private config;
399
410
  private commands;
400
411
  private program;
401
- constructor(app: Application, kernel: Kernel, baseCommands?: Command[], resolver?: NonNullable<InitConfig["resolver"]> | undefined, tsDownConfig?: UserConfig);
412
+ constructor(app: Application, kernel: Kernel, baseCommands?: Command[], resolver?: CommandMethodResolver | undefined, tsDownConfig?: UserConfig);
402
413
  build(): Promise<Command$1>;
403
414
  private loadBaseCommands;
404
415
  /**
@@ -407,7 +418,7 @@ declare class Musket {
407
418
  * @param config
408
419
  * @returns
409
420
  */
410
- configure(config: InitConfig): this;
421
+ configure(config: KernelConfig): this;
411
422
  /**
412
423
  * Set the paths where the cli can search and auto discover commands
413
424
  *
@@ -440,8 +451,8 @@ declare class Musket {
440
451
  rebuild(name: string): Promise<void>;
441
452
  private makeOption;
442
453
  private handle;
443
- static parse<E extends boolean = false>(kernel: Kernel, config: InitConfig, returnExit?: E): Promise<E extends true ? number : Command$1>;
444
- static parse<E extends boolean = false>(kernel: Kernel, config: InitConfig, commands: typeof Command[], returnExit?: E): Promise<E extends true ? number : Command$1>;
454
+ static parse<E extends boolean = false>(kernel: Kernel, config: KernelConfig, returnExit?: E): Promise<E extends true ? number : Command$1>;
455
+ static parse<E extends boolean = false>(kernel: Kernel, config: KernelConfig, commands: typeof Command[], returnExit?: E): Promise<E extends true ? number : Command$1>;
445
456
  }
446
457
  //#endregion
447
458
  //#region src/Contracts/Application.d.ts
@@ -476,4 +487,4 @@ declare class Signature {
476
487
  static parseSignature(signature: string, commandClass: Command): ParsedCommand;
477
488
  }
478
489
  //#endregion
479
- export { Application, Command, CommandOption, InitConfig, Kernel, Musket, ParsedCommand, Signature };
490
+ export { Application, Command, CommandMethodResolver, CommandOption, Kernel, KernelConfig, Musket, PackageMeta, ParsedCommand, Signature };
package/dist/index.js CHANGED
@@ -566,7 +566,7 @@ var Musket = class Musket {
566
566
  *
567
567
  * @default musket
568
568
  */
569
- cliName = "musket";
569
+ name = "musket";
570
570
  config = {};
571
571
  commands = [];
572
572
  program;
@@ -667,7 +667,7 @@ var Musket = class Musket {
667
667
  /**
668
668
  * Run the base Command if a root command was not defined
669
669
  */
670
- this.program.name(this.cliName).version(moduleVersions).description(this.config.logo ?? altLogo).configureHelp({ showGlobalOptions: true }).addOption(new Option(additional.quiet[0], additional.quiet[1])).addOption(new Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).addOption(new Option(additional.verbose[0], additional.verbose[1]).choices([
670
+ this.program.name(this.name).version(moduleVersions).description(this.config.logo ?? altLogo).configureHelp({ showGlobalOptions: true }).addOption(new Option(additional.quiet[0], additional.quiet[1])).addOption(new Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).addOption(new Option(additional.verbose[0], additional.verbose[1]).choices([
671
671
  "1",
672
672
  "2",
673
673
  "3",
@@ -829,14 +829,14 @@ var Musket = class Musket {
829
829
  }
830
830
  const commands = config.baseCommands?.concat(extraCommands)?.map((e) => new e(kernel.app, kernel));
831
831
  const cli = new Musket(kernel.app, kernel, commands, config.resolver, config.tsDownConfig).configure(config);
832
- if (config.cliName) cli.cliName = config.cliName;
832
+ if (config.name) cli.name = config.name;
833
833
  const command = (await cli.build()).exitOverride((e) => {
834
834
  exitCode = e.exitCode;
835
835
  if (e.exitCode <= 0) return;
836
836
  Logger.log("Unknown command or argument.", "white");
837
837
  Logger.log([
838
838
  ["Run", "white"],
839
- [`\`${config.cliName} --help\``, ["grey", "italic"]],
839
+ [`\`${config.name} --help\``, ["grey", "italic"]],
840
840
  ["to see available commands.", "white"]
841
841
  ], " ");
842
842
  });
@@ -949,23 +949,27 @@ var Kernel = class Kernel {
949
949
  return Array.from(this.commands);
950
950
  }
951
951
  /**
952
- * Bootstrap the CLI
952
+ * Prepares the CLI for execution
953
953
  */
954
954
  bootstrap() {
955
+ let version = this.config.version;
955
956
  const require = createRequire(import.meta.url);
956
957
  this.cwd ??= path.join(process.cwd(), this.basePath);
957
958
  if (!this.config.hideMusketInfo) try {
958
959
  const pkg = require(path.join(process.cwd(), "package.json"));
959
- pkg.name = this.config.cliName ?? pkg.name;
960
+ pkg.name = this.config.name ?? pkg.name;
960
961
  this.modules.push(pkg);
961
962
  } catch {}
962
963
  for (let i = 0; i < this.packages.length; i++) try {
963
964
  const item = this.packages[i];
964
965
  const name = typeof item === "string" ? item : item.name;
965
966
  const alias = typeof item === "string" ? item : item.alias;
967
+ const base = typeof item === "string" ? false : item.base;
966
968
  const modulePath = FileSystem.findModulePkg(name, this.cwd) ?? "";
967
969
  const pkg = require(path.join(modulePath, "package.json"));
968
970
  pkg.alias = alias;
971
+ pkg.base = base;
972
+ if (base === true && version) pkg.version = version;
969
973
  this.modules.push(pkg);
970
974
  } catch (e) {
971
975
  this.modules.push({
@@ -973,6 +977,13 @@ var Kernel = class Kernel {
973
977
  name: "Unknown"
974
978
  });
975
979
  }
980
+ if (this.packages.length < 1) {
981
+ if (!version) version = typeof this.app.version === "function" ? this.app.version() : typeof this.app.getVersion === "function" ? this.app.getVersion() : this.app.version;
982
+ this.modules.push({
983
+ version: version ?? "N/A",
984
+ name: "Musket CLI"
985
+ });
986
+ }
976
987
  return this;
977
988
  }
978
989
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/musket",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "Musket CLI is a framework-agnostic CLI framework designed to allow you build artisan-like CLI apps and for use in the H3ravel framework.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",