@h3ravel/musket 0.6.1 → 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 +3 -5
- package/dist/index.cjs +28 -10
- package/dist/index.d.ts +32 -21
- package/dist/index.js +28 -10
- package/package.json +1 -1
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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",
|
|
@@ -845,21 +845,28 @@ var Musket = class Musket {
|
|
|
845
845
|
if (this.resolver) return await this.resolver(cmd, "handle");
|
|
846
846
|
await cmd.handle(this.app);
|
|
847
847
|
}
|
|
848
|
-
static async parse(kernel, config = {}, extraCommands = []) {
|
|
848
|
+
static async parse(kernel, config = {}, extraCommands = [], returnExit = false) {
|
|
849
|
+
let exitCode = 0;
|
|
850
|
+
if (typeof extraCommands === "boolean") {
|
|
851
|
+
returnExit = extraCommands;
|
|
852
|
+
extraCommands = [];
|
|
853
|
+
}
|
|
849
854
|
const commands = config.baseCommands?.concat(extraCommands)?.map((e) => new e(kernel.app, kernel));
|
|
850
855
|
const cli = new Musket(kernel.app, kernel, commands, config.resolver, config.tsDownConfig).configure(config);
|
|
851
|
-
if (config.
|
|
856
|
+
if (config.name) cli.name = config.name;
|
|
852
857
|
const command = (await cli.build()).exitOverride((e) => {
|
|
858
|
+
exitCode = e.exitCode;
|
|
853
859
|
if (e.exitCode <= 0) return;
|
|
854
860
|
__h3ravel_shared.Logger.log("Unknown command or argument.", "white");
|
|
855
861
|
__h3ravel_shared.Logger.log([
|
|
856
862
|
["Run", "white"],
|
|
857
|
-
[`\`${config.
|
|
863
|
+
[`\`${config.name} --help\``, ["grey", "italic"]],
|
|
858
864
|
["to see available commands.", "white"]
|
|
859
865
|
], " ");
|
|
860
866
|
});
|
|
861
|
-
if (!config.skipParsing) await command.parseAsync(process.argv).catch((e) =>
|
|
867
|
+
if (!config.skipParsing) await command.parseAsync(process.argv).catch((e) => void 0);
|
|
862
868
|
if (cli.app) cli.app.musket = cli;
|
|
869
|
+
if (returnExit === true) return exitCode;
|
|
863
870
|
return command;
|
|
864
871
|
}
|
|
865
872
|
};
|
|
@@ -908,8 +915,8 @@ var Kernel = class Kernel {
|
|
|
908
915
|
/**
|
|
909
916
|
* Run the CLI IO
|
|
910
917
|
*/
|
|
911
|
-
async run() {
|
|
912
|
-
return await Musket.parse(this, this.config, this.getRegisteredCommands());
|
|
918
|
+
async run(returnExit) {
|
|
919
|
+
return await Musket.parse(this, this.config, this.getRegisteredCommands(), returnExit);
|
|
913
920
|
}
|
|
914
921
|
/**
|
|
915
922
|
* Set the configuration for the CLI
|
|
@@ -966,23 +973,27 @@ var Kernel = class Kernel {
|
|
|
966
973
|
return Array.from(this.commands);
|
|
967
974
|
}
|
|
968
975
|
/**
|
|
969
|
-
*
|
|
976
|
+
* Prepares the CLI for execution
|
|
970
977
|
*/
|
|
971
978
|
bootstrap() {
|
|
979
|
+
let version = this.config.version;
|
|
972
980
|
const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
973
981
|
this.cwd ??= node_path.default.join(process.cwd(), this.basePath);
|
|
974
982
|
if (!this.config.hideMusketInfo) try {
|
|
975
983
|
const pkg = require$1(node_path.default.join(process.cwd(), "package.json"));
|
|
976
|
-
pkg.name = this.config.
|
|
984
|
+
pkg.name = this.config.name ?? pkg.name;
|
|
977
985
|
this.modules.push(pkg);
|
|
978
986
|
} catch {}
|
|
979
987
|
for (let i = 0; i < this.packages.length; i++) try {
|
|
980
988
|
const item = this.packages[i];
|
|
981
989
|
const name = typeof item === "string" ? item : item.name;
|
|
982
990
|
const alias = typeof item === "string" ? item : item.alias;
|
|
991
|
+
const base = typeof item === "string" ? false : item.base;
|
|
983
992
|
const modulePath = __h3ravel_shared.FileSystem.findModulePkg(name, this.cwd) ?? "";
|
|
984
993
|
const pkg = require$1(node_path.default.join(modulePath, "package.json"));
|
|
985
994
|
pkg.alias = alias;
|
|
995
|
+
pkg.base = base;
|
|
996
|
+
if (base === true && version) pkg.version = version;
|
|
986
997
|
this.modules.push(pkg);
|
|
987
998
|
} catch (e) {
|
|
988
999
|
this.modules.push({
|
|
@@ -990,6 +1001,13 @@ var Kernel = class Kernel {
|
|
|
990
1001
|
name: "Unknown"
|
|
991
1002
|
});
|
|
992
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
|
+
}
|
|
993
1011
|
return this;
|
|
994
1012
|
}
|
|
995
1013
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -53,17 +53,29 @@ type ParsedCommand = {
|
|
|
53
53
|
*/
|
|
54
54
|
options?: CommandOption[];
|
|
55
55
|
};
|
|
56
|
-
|
|
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
|
|
68
|
+
* The name of the CLI app we're running
|
|
63
69
|
*
|
|
64
70
|
* @default musket
|
|
65
71
|
*/
|
|
66
|
-
|
|
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?:
|
|
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?:
|
|
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,19 +163,19 @@ 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?:
|
|
166
|
+
static init<A extends Application>(app: A, config?: KernelConfig): Promise<commander0.Command>;
|
|
156
167
|
/**
|
|
157
168
|
* Run the CLI IO
|
|
158
169
|
*/
|
|
159
|
-
run(): Promise<commander0.Command>;
|
|
170
|
+
run<E extends boolean = false>(returnExit?: E): Promise<E extends true ? number : commander0.Command>;
|
|
160
171
|
/**
|
|
161
172
|
* Set the configuration for the CLI
|
|
162
173
|
*/
|
|
163
|
-
setConfig(config:
|
|
174
|
+
setConfig(config: KernelConfig): this;
|
|
164
175
|
/**
|
|
165
176
|
* Get the configuration for the CLI
|
|
166
177
|
*/
|
|
167
|
-
getConfig():
|
|
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:
|
|
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():
|
|
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
|
-
*
|
|
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
|
-
|
|
408
|
+
name: string;
|
|
398
409
|
private config;
|
|
399
410
|
private commands;
|
|
400
411
|
private program;
|
|
401
|
-
constructor(app: Application, kernel: Kernel, baseCommands?: Command[], resolver?:
|
|
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:
|
|
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(kernel: Kernel, config:
|
|
444
|
-
static parse(kernel: Kernel, config:
|
|
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,
|
|
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
|
-
|
|
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.
|
|
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",
|
|
@@ -821,21 +821,28 @@ var Musket = class Musket {
|
|
|
821
821
|
if (this.resolver) return await this.resolver(cmd, "handle");
|
|
822
822
|
await cmd.handle(this.app);
|
|
823
823
|
}
|
|
824
|
-
static async parse(kernel, config = {}, extraCommands = []) {
|
|
824
|
+
static async parse(kernel, config = {}, extraCommands = [], returnExit = false) {
|
|
825
|
+
let exitCode = 0;
|
|
826
|
+
if (typeof extraCommands === "boolean") {
|
|
827
|
+
returnExit = extraCommands;
|
|
828
|
+
extraCommands = [];
|
|
829
|
+
}
|
|
825
830
|
const commands = config.baseCommands?.concat(extraCommands)?.map((e) => new e(kernel.app, kernel));
|
|
826
831
|
const cli = new Musket(kernel.app, kernel, commands, config.resolver, config.tsDownConfig).configure(config);
|
|
827
|
-
if (config.
|
|
832
|
+
if (config.name) cli.name = config.name;
|
|
828
833
|
const command = (await cli.build()).exitOverride((e) => {
|
|
834
|
+
exitCode = e.exitCode;
|
|
829
835
|
if (e.exitCode <= 0) return;
|
|
830
836
|
Logger.log("Unknown command or argument.", "white");
|
|
831
837
|
Logger.log([
|
|
832
838
|
["Run", "white"],
|
|
833
|
-
[`\`${config.
|
|
839
|
+
[`\`${config.name} --help\``, ["grey", "italic"]],
|
|
834
840
|
["to see available commands.", "white"]
|
|
835
841
|
], " ");
|
|
836
842
|
});
|
|
837
|
-
if (!config.skipParsing) await command.parseAsync(process.argv).catch((e) =>
|
|
843
|
+
if (!config.skipParsing) await command.parseAsync(process.argv).catch((e) => void 0);
|
|
838
844
|
if (cli.app) cli.app.musket = cli;
|
|
845
|
+
if (returnExit === true) return exitCode;
|
|
839
846
|
return command;
|
|
840
847
|
}
|
|
841
848
|
};
|
|
@@ -884,8 +891,8 @@ var Kernel = class Kernel {
|
|
|
884
891
|
/**
|
|
885
892
|
* Run the CLI IO
|
|
886
893
|
*/
|
|
887
|
-
async run() {
|
|
888
|
-
return await Musket.parse(this, this.config, this.getRegisteredCommands());
|
|
894
|
+
async run(returnExit) {
|
|
895
|
+
return await Musket.parse(this, this.config, this.getRegisteredCommands(), returnExit);
|
|
889
896
|
}
|
|
890
897
|
/**
|
|
891
898
|
* Set the configuration for the CLI
|
|
@@ -942,23 +949,27 @@ var Kernel = class Kernel {
|
|
|
942
949
|
return Array.from(this.commands);
|
|
943
950
|
}
|
|
944
951
|
/**
|
|
945
|
-
*
|
|
952
|
+
* Prepares the CLI for execution
|
|
946
953
|
*/
|
|
947
954
|
bootstrap() {
|
|
955
|
+
let version = this.config.version;
|
|
948
956
|
const require = createRequire(import.meta.url);
|
|
949
957
|
this.cwd ??= path.join(process.cwd(), this.basePath);
|
|
950
958
|
if (!this.config.hideMusketInfo) try {
|
|
951
959
|
const pkg = require(path.join(process.cwd(), "package.json"));
|
|
952
|
-
pkg.name = this.config.
|
|
960
|
+
pkg.name = this.config.name ?? pkg.name;
|
|
953
961
|
this.modules.push(pkg);
|
|
954
962
|
} catch {}
|
|
955
963
|
for (let i = 0; i < this.packages.length; i++) try {
|
|
956
964
|
const item = this.packages[i];
|
|
957
965
|
const name = typeof item === "string" ? item : item.name;
|
|
958
966
|
const alias = typeof item === "string" ? item : item.alias;
|
|
967
|
+
const base = typeof item === "string" ? false : item.base;
|
|
959
968
|
const modulePath = FileSystem.findModulePkg(name, this.cwd) ?? "";
|
|
960
969
|
const pkg = require(path.join(modulePath, "package.json"));
|
|
961
970
|
pkg.alias = alias;
|
|
971
|
+
pkg.base = base;
|
|
972
|
+
if (base === true && version) pkg.version = version;
|
|
962
973
|
this.modules.push(pkg);
|
|
963
974
|
} catch (e) {
|
|
964
975
|
this.modules.push({
|
|
@@ -966,6 +977,13 @@ var Kernel = class Kernel {
|
|
|
966
977
|
name: "Unknown"
|
|
967
978
|
});
|
|
968
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
|
+
}
|
|
969
987
|
return this;
|
|
970
988
|
}
|
|
971
989
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h3ravel/musket",
|
|
3
|
-
"version": "0.6.
|
|
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",
|