@h3ravel/musket 0.1.0 → 0.1.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.
@@ -0,0 +1,308 @@
1
+ import * as commander0 from "commander";
2
+ import { Argument, Command as Command$1 } from "commander";
3
+ import { XGeneric } from "@h3ravel/support";
4
+ import { Options } from "tsdown";
5
+
6
+ //#region src/Contracts/ICommand.d.ts
7
+ type CommandOption = {
8
+ name: string;
9
+ shared?: boolean;
10
+ required?: boolean;
11
+ multiple?: boolean;
12
+ placeholder?: string;
13
+ description?: string;
14
+ defaultValue?: string | number | boolean | undefined | string[];
15
+ choices?: string[];
16
+ argParser?: (...args: []) => any;
17
+ /**
18
+ * for options like --Q|queue
19
+ */
20
+ flags?: string[];
21
+ /**
22
+ * true if it's a flag option
23
+ */
24
+ isFlag?: boolean;
25
+ /**
26
+ * true if name begins with '#' or '^'
27
+ */
28
+ isHidden?: boolean;
29
+ /**
30
+ * for nested options
31
+ */
32
+ nestedOptions?: CommandOption[];
33
+ };
34
+ type ParsedCommand = {
35
+ commandClass: Command;
36
+ baseCommand: string;
37
+ description?: string;
38
+ /**
39
+ * true if baseCommand begins with '#' or '^'
40
+ */
41
+ isHidden?: boolean;
42
+ /**
43
+ * true if baseCommand ends with ':'
44
+ */
45
+ isNamespaceCommand: boolean;
46
+ /**
47
+ * for colon-ended commands
48
+ */
49
+ subCommands?: CommandOption[];
50
+ /**
51
+ * for normal commands
52
+ */
53
+ options?: CommandOption[];
54
+ };
55
+ interface InitConfig {
56
+ /**
57
+ * ASCII Art style logo
58
+ */
59
+ logo?: string;
60
+ /**
61
+ * The name of the CLI app we're building
62
+ *
63
+ * @default musket
64
+ */
65
+ cliName?: string;
66
+ /**
67
+ * Don't parse the command, usefull for testing or manual control
68
+ */
69
+ skipParsing?: boolean;
70
+ /**
71
+ * A callback function that should resolve the handle method of every command
72
+ *
73
+ * @param cmd
74
+ * @param met
75
+ * @returns
76
+ */
77
+ resolver?: <X>(cmd: X, met: string) => Promise<X>;
78
+ /**
79
+ * Packages that should show up up when the `-V` flag is passed
80
+ */
81
+ packages?: string[];
82
+ /**
83
+ * If set to true, information about musket CLI like name and
84
+ * version info will not be unexpectedly shown in console
85
+ */
86
+ hideMusketInfo?: boolean;
87
+ /**
88
+ * Commands that should be autoloaded by default
89
+ */
90
+ baseCommands?: typeof Command[];
91
+ /**
92
+ * Paths where musket can search and auto discover commands
93
+ *
94
+ *
95
+ * @example 'Console/Commands/*.js'
96
+ * @example 'dist/app/Console/Commands/*.js'
97
+ * @example ['Console/Commands/*.js', 'src/app/Commands/*.js']
98
+ */
99
+ discoveryPaths?: string | string[];
100
+ }
101
+ //#endregion
102
+ //#region src/Core/Kernel.d.ts
103
+ declare class Kernel {
104
+ app: Application;
105
+ cwd: string;
106
+ output: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
107
+ modules: XGeneric<{
108
+ version: string;
109
+ name: string;
110
+ }>[];
111
+ basePath: string;
112
+ packages: string[];
113
+ private config;
114
+ constructor(app: Application);
115
+ ensureDirectoryExists(dir: string): Promise<void>;
116
+ static init(app: Application, config?: InitConfig): Promise<commander0.Command>;
117
+ private run;
118
+ private loadRequirements;
119
+ }
120
+ //#endregion
121
+ //#region src/Core/Command.d.ts
122
+ declare class Command {
123
+ protected app: Application;
124
+ protected kernel: Kernel;
125
+ constructor(app: Application, kernel: Kernel);
126
+ /**
127
+ * The underlying commander instance.
128
+ *
129
+ * @var Command
130
+ */
131
+ program: Command$1;
132
+ /**
133
+ * The name and signature of the console command.
134
+ *
135
+ * @var string
136
+ */
137
+ protected signature: string;
138
+ /**
139
+ * A dictionary of signatures or what not.
140
+ *
141
+ * @var object
142
+ */
143
+ protected dictionary: Record<string, any>;
144
+ /**
145
+ * The console command description.
146
+ *
147
+ * @var string
148
+ */
149
+ protected description?: string;
150
+ /**
151
+ * The console command input.
152
+ *
153
+ * @var object
154
+ */
155
+ private input;
156
+ /**
157
+ * Execute the console command.
158
+ */
159
+ handle(..._args: any[]): Promise<void>;
160
+ setApplication(app: Application): void;
161
+ setInput(options: XGeneric, args: string[], regArgs: readonly Argument[], dictionary: Record<string, any>, program: Command$1): this;
162
+ setOption(key: string, value: unknown): this;
163
+ setProgram(program: Command$1): this;
164
+ getSignature(): string;
165
+ getDescription(): string | undefined;
166
+ option(key: string, def?: any): any;
167
+ options(key?: string): any;
168
+ argument(key: string, def?: any): any;
169
+ arguments(): Record<string, any>;
170
+ loadBaseFlags(): void;
171
+ /**
172
+ * Check if the command is quiet
173
+ *
174
+ * @returns
175
+ */
176
+ isQuiet(): any;
177
+ /**
178
+ * Check if the command is silent
179
+ *
180
+ * @returns
181
+ */
182
+ isSilent(): any;
183
+ /**
184
+ * Check if the command is non interactive
185
+ *
186
+ * @returns
187
+ */
188
+ isNonInteractive(): boolean;
189
+ /**
190
+ * Get the verbosity of the command
191
+ *
192
+ * @returns
193
+ */
194
+ getVerbosity(): number;
195
+ /**
196
+ * Log an info message
197
+ */
198
+ info(message: string): this;
199
+ /**
200
+ * Log a warning message
201
+ */
202
+ warn(message: string): this;
203
+ /**
204
+ * Log a line message
205
+ */
206
+ line(message: string): this;
207
+ /**
208
+ * Log a new line
209
+ */
210
+ newLine(count?: number): this;
211
+ /**
212
+ * Log a success message
213
+ */
214
+ success(message: string): this;
215
+ /**
216
+ * Log an error message
217
+ */
218
+ error(message: string): this;
219
+ /**
220
+ * Log an error message and terminate execution of the command
221
+ * return an exit code of 1
222
+ *
223
+ * This method is not chainable
224
+ */
225
+ fail(message: string): void;
226
+ /**
227
+ * Log a debug message
228
+ */
229
+ debug(message: string | string[]): this;
230
+ }
231
+ //#endregion
232
+ //#region src/Musket.d.ts
233
+ declare class Musket {
234
+ private app;
235
+ private kernel;
236
+ private baseCommands;
237
+ private resolver?;
238
+ private tsDownConfig;
239
+ /**
240
+ * The name of the CLI app we're building
241
+ *
242
+ * @default musket
243
+ */
244
+ cliName: string;
245
+ private config;
246
+ private commands;
247
+ constructor(app: Application, kernel: Kernel, baseCommands?: Command[], resolver?: (<X>(cmd: X, met: string) => Promise<X>) | undefined, tsDownConfig?: Options);
248
+ build(): Promise<Command$1>;
249
+ private loadBaseCommands;
250
+ /**
251
+ * Provide the configuration to initialize the CLI with
252
+ *
253
+ * @param config
254
+ * @returns
255
+ */
256
+ configure(config: InitConfig): this;
257
+ /**
258
+ * Set the paths where the cli can search and auto discover commands
259
+ *
260
+ * @param paths
261
+ *
262
+ * @example instance.discoverCommandsFrom('Console/Commands/*.js')
263
+ * @example instance.discoverCommandsFrom(['Console/Commands/*.js', 'App/Commands/*.js'])
264
+ *
265
+ * @returns the current cli intance
266
+ */
267
+ discoverCommandsFrom(paths: string | string[]): this;
268
+ private loadDiscoveredCommands;
269
+ addCommand(command: Command): void;
270
+ private initialize;
271
+ rebuild(name: string): Promise<void>;
272
+ private makeOption;
273
+ private handle;
274
+ static parse(kernel: Kernel, config?: InitConfig): Promise<Command$1>;
275
+ }
276
+ //#endregion
277
+ //#region src/Contracts/Application.d.ts
278
+ declare class Application {
279
+ /**
280
+ * The current musket CLI Instance
281
+ */
282
+ musket?: Musket;
283
+ /**
284
+ * Registered commands will be preloaded
285
+ */
286
+ registeredCommands?: typeof Command[];
287
+ }
288
+ //#endregion
289
+ //#region src/Signature.d.ts
290
+ declare class Signature {
291
+ /**
292
+ * Helper to parse options inside a block of text
293
+ *
294
+ * @param block
295
+ * @returns
296
+ */
297
+ static parseOptions(block: string): CommandOption[];
298
+ /**
299
+ * Helper to parse a command's signature
300
+ *
301
+ * @param signature
302
+ * @param commandClass
303
+ * @returns
304
+ */
305
+ static parseSignature(signature: string, commandClass: Command): ParsedCommand;
306
+ }
307
+ //#endregion
308
+ export { Application, Command, CommandOption, InitConfig, Kernel, Musket, ParsedCommand, Signature };
@@ -0,0 +1,308 @@
1
+ import * as commander0 from "commander";
2
+ import { Argument, Command as Command$1 } from "commander";
3
+ import { Options } from "tsdown";
4
+ import { XGeneric } from "@h3ravel/support";
5
+
6
+ //#region src/Contracts/ICommand.d.ts
7
+ type CommandOption = {
8
+ name: string;
9
+ shared?: boolean;
10
+ required?: boolean;
11
+ multiple?: boolean;
12
+ placeholder?: string;
13
+ description?: string;
14
+ defaultValue?: string | number | boolean | undefined | string[];
15
+ choices?: string[];
16
+ argParser?: (...args: []) => any;
17
+ /**
18
+ * for options like --Q|queue
19
+ */
20
+ flags?: string[];
21
+ /**
22
+ * true if it's a flag option
23
+ */
24
+ isFlag?: boolean;
25
+ /**
26
+ * true if name begins with '#' or '^'
27
+ */
28
+ isHidden?: boolean;
29
+ /**
30
+ * for nested options
31
+ */
32
+ nestedOptions?: CommandOption[];
33
+ };
34
+ type ParsedCommand = {
35
+ commandClass: Command;
36
+ baseCommand: string;
37
+ description?: string;
38
+ /**
39
+ * true if baseCommand begins with '#' or '^'
40
+ */
41
+ isHidden?: boolean;
42
+ /**
43
+ * true if baseCommand ends with ':'
44
+ */
45
+ isNamespaceCommand: boolean;
46
+ /**
47
+ * for colon-ended commands
48
+ */
49
+ subCommands?: CommandOption[];
50
+ /**
51
+ * for normal commands
52
+ */
53
+ options?: CommandOption[];
54
+ };
55
+ interface InitConfig {
56
+ /**
57
+ * ASCII Art style logo
58
+ */
59
+ logo?: string;
60
+ /**
61
+ * The name of the CLI app we're building
62
+ *
63
+ * @default musket
64
+ */
65
+ cliName?: string;
66
+ /**
67
+ * Don't parse the command, usefull for testing or manual control
68
+ */
69
+ skipParsing?: boolean;
70
+ /**
71
+ * A callback function that should resolve the handle method of every command
72
+ *
73
+ * @param cmd
74
+ * @param met
75
+ * @returns
76
+ */
77
+ resolver?: <X>(cmd: X, met: string) => Promise<X>;
78
+ /**
79
+ * Packages that should show up up when the `-V` flag is passed
80
+ */
81
+ packages?: string[];
82
+ /**
83
+ * If set to true, information about musket CLI like name and
84
+ * version info will not be unexpectedly shown in console
85
+ */
86
+ hideMusketInfo?: boolean;
87
+ /**
88
+ * Commands that should be autoloaded by default
89
+ */
90
+ baseCommands?: typeof Command[];
91
+ /**
92
+ * Paths where musket can search and auto discover commands
93
+ *
94
+ *
95
+ * @example 'Console/Commands/*.js'
96
+ * @example 'dist/app/Console/Commands/*.js'
97
+ * @example ['Console/Commands/*.js', 'src/app/Commands/*.js']
98
+ */
99
+ discoveryPaths?: string | string[];
100
+ }
101
+ //#endregion
102
+ //#region src/Core/Kernel.d.ts
103
+ declare class Kernel {
104
+ app: Application;
105
+ cwd: string;
106
+ output: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
107
+ modules: XGeneric<{
108
+ version: string;
109
+ name: string;
110
+ }>[];
111
+ basePath: string;
112
+ packages: string[];
113
+ private config;
114
+ constructor(app: Application);
115
+ ensureDirectoryExists(dir: string): Promise<void>;
116
+ static init(app: Application, config?: InitConfig): Promise<commander0.Command>;
117
+ private run;
118
+ private loadRequirements;
119
+ }
120
+ //#endregion
121
+ //#region src/Core/Command.d.ts
122
+ declare class Command {
123
+ protected app: Application;
124
+ protected kernel: Kernel;
125
+ constructor(app: Application, kernel: Kernel);
126
+ /**
127
+ * The underlying commander instance.
128
+ *
129
+ * @var Command
130
+ */
131
+ program: Command$1;
132
+ /**
133
+ * The name and signature of the console command.
134
+ *
135
+ * @var string
136
+ */
137
+ protected signature: string;
138
+ /**
139
+ * A dictionary of signatures or what not.
140
+ *
141
+ * @var object
142
+ */
143
+ protected dictionary: Record<string, any>;
144
+ /**
145
+ * The console command description.
146
+ *
147
+ * @var string
148
+ */
149
+ protected description?: string;
150
+ /**
151
+ * The console command input.
152
+ *
153
+ * @var object
154
+ */
155
+ private input;
156
+ /**
157
+ * Execute the console command.
158
+ */
159
+ handle(..._args: any[]): Promise<void>;
160
+ setApplication(app: Application): void;
161
+ setInput(options: XGeneric, args: string[], regArgs: readonly Argument[], dictionary: Record<string, any>, program: Command$1): this;
162
+ setOption(key: string, value: unknown): this;
163
+ setProgram(program: Command$1): this;
164
+ getSignature(): string;
165
+ getDescription(): string | undefined;
166
+ option(key: string, def?: any): any;
167
+ options(key?: string): any;
168
+ argument(key: string, def?: any): any;
169
+ arguments(): Record<string, any>;
170
+ loadBaseFlags(): void;
171
+ /**
172
+ * Check if the command is quiet
173
+ *
174
+ * @returns
175
+ */
176
+ isQuiet(): any;
177
+ /**
178
+ * Check if the command is silent
179
+ *
180
+ * @returns
181
+ */
182
+ isSilent(): any;
183
+ /**
184
+ * Check if the command is non interactive
185
+ *
186
+ * @returns
187
+ */
188
+ isNonInteractive(): boolean;
189
+ /**
190
+ * Get the verbosity of the command
191
+ *
192
+ * @returns
193
+ */
194
+ getVerbosity(): number;
195
+ /**
196
+ * Log an info message
197
+ */
198
+ info(message: string): this;
199
+ /**
200
+ * Log a warning message
201
+ */
202
+ warn(message: string): this;
203
+ /**
204
+ * Log a line message
205
+ */
206
+ line(message: string): this;
207
+ /**
208
+ * Log a new line
209
+ */
210
+ newLine(count?: number): this;
211
+ /**
212
+ * Log a success message
213
+ */
214
+ success(message: string): this;
215
+ /**
216
+ * Log an error message
217
+ */
218
+ error(message: string): this;
219
+ /**
220
+ * Log an error message and terminate execution of the command
221
+ * return an exit code of 1
222
+ *
223
+ * This method is not chainable
224
+ */
225
+ fail(message: string): void;
226
+ /**
227
+ * Log a debug message
228
+ */
229
+ debug(message: string | string[]): this;
230
+ }
231
+ //#endregion
232
+ //#region src/Musket.d.ts
233
+ declare class Musket {
234
+ private app;
235
+ private kernel;
236
+ private baseCommands;
237
+ private resolver?;
238
+ private tsDownConfig;
239
+ /**
240
+ * The name of the CLI app we're building
241
+ *
242
+ * @default musket
243
+ */
244
+ cliName: string;
245
+ private config;
246
+ private commands;
247
+ constructor(app: Application, kernel: Kernel, baseCommands?: Command[], resolver?: (<X>(cmd: X, met: string) => Promise<X>) | undefined, tsDownConfig?: Options);
248
+ build(): Promise<Command$1>;
249
+ private loadBaseCommands;
250
+ /**
251
+ * Provide the configuration to initialize the CLI with
252
+ *
253
+ * @param config
254
+ * @returns
255
+ */
256
+ configure(config: InitConfig): this;
257
+ /**
258
+ * Set the paths where the cli can search and auto discover commands
259
+ *
260
+ * @param paths
261
+ *
262
+ * @example instance.discoverCommandsFrom('Console/Commands/*.js')
263
+ * @example instance.discoverCommandsFrom(['Console/Commands/*.js', 'App/Commands/*.js'])
264
+ *
265
+ * @returns the current cli intance
266
+ */
267
+ discoverCommandsFrom(paths: string | string[]): this;
268
+ private loadDiscoveredCommands;
269
+ addCommand(command: Command): void;
270
+ private initialize;
271
+ rebuild(name: string): Promise<void>;
272
+ private makeOption;
273
+ private handle;
274
+ static parse(kernel: Kernel, config?: InitConfig): Promise<Command$1>;
275
+ }
276
+ //#endregion
277
+ //#region src/Contracts/Application.d.ts
278
+ declare class Application {
279
+ /**
280
+ * The current musket CLI Instance
281
+ */
282
+ musket?: Musket;
283
+ /**
284
+ * Registered commands will be preloaded
285
+ */
286
+ registeredCommands?: typeof Command[];
287
+ }
288
+ //#endregion
289
+ //#region src/Signature.d.ts
290
+ declare class Signature {
291
+ /**
292
+ * Helper to parse options inside a block of text
293
+ *
294
+ * @param block
295
+ * @returns
296
+ */
297
+ static parseOptions(block: string): CommandOption[];
298
+ /**
299
+ * Helper to parse a command's signature
300
+ *
301
+ * @param signature
302
+ * @param commandClass
303
+ * @returns
304
+ */
305
+ static parseSignature(signature: string, commandClass: Command): ParsedCommand;
306
+ }
307
+ //#endregion
308
+ export { Application, Command, CommandOption, InitConfig, Kernel, Musket, ParsedCommand, Signature };