@navios/commander 0.5.2 → 0.7.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/CHANGELOG.md +37 -0
- package/README.md +24 -13
- package/dist/src/commander.application.d.mts +124 -6
- package/dist/src/commander.application.d.mts.map +1 -1
- package/dist/src/commander.factory.d.mts +31 -3
- package/dist/src/commander.factory.d.mts.map +1 -1
- package/dist/src/decorators/cli-module.decorator.d.mts +36 -1
- package/dist/src/decorators/cli-module.decorator.d.mts.map +1 -1
- package/dist/src/decorators/command.decorator.d.mts +44 -1
- package/dist/src/decorators/command.decorator.d.mts.map +1 -1
- package/dist/src/index.d.mts +1 -1
- package/dist/src/index.d.mts.map +1 -1
- package/dist/src/interfaces/command-handler.interface.d.mts +33 -0
- package/dist/src/interfaces/command-handler.interface.d.mts.map +1 -1
- package/dist/src/interfaces/commander-execution-context.interface.d.mts +43 -0
- package/dist/src/interfaces/commander-execution-context.interface.d.mts.map +1 -1
- package/dist/src/interfaces/index.d.mts +0 -1
- package/dist/src/interfaces/index.d.mts.map +1 -1
- package/dist/src/metadata/cli-module.metadata.d.mts +46 -1
- package/dist/src/metadata/cli-module.metadata.d.mts.map +1 -1
- package/dist/src/metadata/command.metadata.d.mts +48 -1
- package/dist/src/metadata/command.metadata.d.mts.map +1 -1
- package/dist/src/services/cli-parser.service.d.mts +32 -1
- package/dist/src/services/cli-parser.service.d.mts.map +1 -1
- package/dist/src/services/module-loader.service.d.mts +44 -5
- package/dist/src/services/module-loader.service.d.mts.map +1 -1
- package/dist/src/tokens/execution-context.token.d.mts +25 -3
- package/dist/src/tokens/execution-context.token.d.mts.map +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsdown.config.d.mts +3 -0
- package/dist/tsdown.config.d.mts.map +1 -0
- package/lib/index.cjs +7752 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +670 -0
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.mts +670 -101
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +7540 -598
- package/lib/index.mjs.map +1 -1
- package/package.json +8 -8
- package/project.json +2 -2
- package/src/commander.application.mts +138 -18
- package/src/commander.factory.mts +32 -4
- package/src/decorators/cli-module.decorator.mts +37 -2
- package/src/decorators/command.decorator.mts +45 -2
- package/src/index.mts +4 -1
- package/src/interfaces/command-handler.interface.mts +33 -0
- package/src/interfaces/commander-execution-context.interface.mts +43 -0
- package/src/interfaces/index.mts +0 -1
- package/src/metadata/cli-module.metadata.mts +48 -7
- package/src/metadata/command.metadata.mts +48 -1
- package/src/services/__tests__/cli-parser.service.spec.mts +15 -11
- package/src/services/cli-parser.service.mts +35 -3
- package/src/services/module-loader.service.mts +45 -6
- package/src/tokens/execution-context.token.mts +29 -5
- package/tsdown.config.mts +33 -0
- package/dist/src/interfaces/cli-module.interface.d.mts +0 -5
- package/dist/src/interfaces/cli-module.interface.d.mts.map +0 -1
- package/dist/src/interfaces/module.interface.d.mts +0 -5
- package/dist/src/interfaces/module.interface.d.mts.map +0 -1
- package/dist/tsup.config.d.mts +0 -3
- package/dist/tsup.config.d.mts.map +0 -1
- package/lib/_tsup-dts-rollup.d.mts +0 -489
- package/lib/_tsup-dts-rollup.d.ts +0 -489
- package/lib/index.d.ts +0 -101
- package/lib/index.js +0 -642
- package/lib/index.js.map +0 -1
- package/src/interfaces/module.interface.mts +0 -4
- package/tsup.config.mts +0 -12
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.7.1] - 2025-12-20
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Fixed package.json exports to use correct CommonJS file extensions (`.cjs` and `.d.cts`)
|
|
13
|
+
|
|
14
|
+
## [0.7.0] - 2025-12-18
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- **Comprehensive JSDoc Documentation**: Added detailed JSDoc comments to all public APIs including:
|
|
19
|
+
- `CommanderFactory` class and `create` method
|
|
20
|
+
- `CommanderApplication` class and all methods (`init`, `run`, `executeCommand`, `getAllCommands`, `getContainer`, `close`)
|
|
21
|
+
- `Command` decorator function and `CommandOptions` interface
|
|
22
|
+
- `CliModule` decorator function and `CliModuleOptions` interface
|
|
23
|
+
- `CommandHandler` interface with generic type parameter
|
|
24
|
+
- `CommanderExecutionContext` class and all methods (`getCommand`, `getCommandPath`, `getOptions`)
|
|
25
|
+
- `CommandExecutionContext` injection token
|
|
26
|
+
- `CommandMetadata` and `CliModuleMetadata` interfaces
|
|
27
|
+
- Metadata utility functions (`getCommandMetadata`, `extractCommandMetadata`, `hasCommandMetadata`, `getCliModuleMetadata`, `extractCliModuleMetadata`, `hasCliModuleMetadata`)
|
|
28
|
+
- `CliParserService` class and `ParsedCliArgs` interface
|
|
29
|
+
- `CliModuleLoaderService` class and `CommandWithMetadata` interface
|
|
30
|
+
|
|
31
|
+
### Documentation
|
|
32
|
+
|
|
33
|
+
- Complete JSDoc comments for better IDE support and developer experience
|
|
34
|
+
- Enhanced type information and parameter descriptions
|
|
35
|
+
- Added usage examples in JSDoc comments for all public APIs
|
|
36
|
+
- Improved discoverability of API features through comprehensive documentation
|
|
37
|
+
- Updated README to accurately reflect the ExecutionContext API
|
package/README.md
CHANGED
|
@@ -23,6 +23,7 @@ Commands are defined using the `@Command` decorator. Each command must implement
|
|
|
23
23
|
|
|
24
24
|
```typescript
|
|
25
25
|
import { Command, CommandHandler } from '@navios/commander'
|
|
26
|
+
|
|
26
27
|
import { z } from 'zod'
|
|
27
28
|
|
|
28
29
|
const greetOptionsSchema = z.object({
|
|
@@ -49,6 +50,7 @@ Modules organize commands and can import other modules:
|
|
|
49
50
|
|
|
50
51
|
```typescript
|
|
51
52
|
import { CliModule } from '@navios/commander'
|
|
53
|
+
|
|
52
54
|
import { GreetCommand } from './greet.command'
|
|
53
55
|
|
|
54
56
|
@CliModule({
|
|
@@ -63,6 +65,7 @@ Use `CommanderFactory` to create and run your CLI application:
|
|
|
63
65
|
|
|
64
66
|
```typescript
|
|
65
67
|
import { CommanderFactory } from '@navios/commander'
|
|
68
|
+
|
|
66
69
|
import { AppModule } from './app.module'
|
|
67
70
|
|
|
68
71
|
async function bootstrap() {
|
|
@@ -87,8 +90,9 @@ node dist/cli.js greet --name World --greeting Hi
|
|
|
87
90
|
### Advanced Example with Dependency Injection
|
|
88
91
|
|
|
89
92
|
```typescript
|
|
90
|
-
import { Command, CommandHandler
|
|
91
|
-
import {
|
|
93
|
+
import { CliModule, Command, CommandHandler } from '@navios/commander'
|
|
94
|
+
import { inject, Injectable } from '@navios/di'
|
|
95
|
+
|
|
92
96
|
import { z } from 'zod'
|
|
93
97
|
|
|
94
98
|
// Service
|
|
@@ -108,7 +112,9 @@ const userOptionsSchema = z.object({
|
|
|
108
112
|
path: 'user:show',
|
|
109
113
|
optionsSchema: userOptionsSchema,
|
|
110
114
|
})
|
|
111
|
-
export class ShowUserCommand implements CommandHandler<
|
|
115
|
+
export class ShowUserCommand implements CommandHandler<
|
|
116
|
+
z.infer<typeof userOptionsSchema>
|
|
117
|
+
> {
|
|
112
118
|
private userService = inject(UserService)
|
|
113
119
|
|
|
114
120
|
async execute(options: { userId: string }) {
|
|
@@ -134,18 +140,18 @@ export class AppModule {}
|
|
|
134
140
|
The `ExecutionContext` provides access to the current command execution information, including the module metadata, command metadata, command path, and options. This is useful for middleware, guards, or any service that needs context about the current command execution.
|
|
135
141
|
|
|
136
142
|
```typescript
|
|
137
|
-
import { Command, CommandHandler,
|
|
138
|
-
import {
|
|
143
|
+
import { Command, CommandHandler, CommandExecutionContext } from '@navios/commander'
|
|
144
|
+
import { inject, Injectable } from '@navios/di'
|
|
139
145
|
|
|
140
146
|
@Injectable()
|
|
141
147
|
class CommandLogger {
|
|
142
|
-
private executionContext = inject(
|
|
148
|
+
private executionContext = inject(CommandExecutionContext)
|
|
143
149
|
|
|
144
150
|
logCommandInfo() {
|
|
145
151
|
const ctx = this.executionContext
|
|
146
152
|
console.log('Command Path:', ctx.getCommandPath())
|
|
147
153
|
console.log('Command Options:', ctx.getOptions())
|
|
148
|
-
console.log('
|
|
154
|
+
console.log('Command Metadata:', ctx.getCommand())
|
|
149
155
|
}
|
|
150
156
|
}
|
|
151
157
|
|
|
@@ -161,7 +167,7 @@ export class ExampleCommand implements CommandHandler {
|
|
|
161
167
|
```
|
|
162
168
|
|
|
163
169
|
The `ExecutionContext` provides the following methods:
|
|
164
|
-
|
|
170
|
+
|
|
165
171
|
- `getCommand()` - Returns the command metadata
|
|
166
172
|
- `getCommandPath()` - Returns the command path (e.g., 'user:create')
|
|
167
173
|
- `getOptions()` - Returns the validated command options
|
|
@@ -187,6 +193,7 @@ For advanced use cases where you need to execute commands programmatically (e.g.
|
|
|
187
193
|
|
|
188
194
|
```typescript
|
|
189
195
|
import { CommanderFactory } from '@navios/commander'
|
|
196
|
+
|
|
190
197
|
import { AppModule } from './app.module'
|
|
191
198
|
|
|
192
199
|
async function bootstrap() {
|
|
@@ -206,6 +213,7 @@ bootstrap()
|
|
|
206
213
|
```
|
|
207
214
|
|
|
208
215
|
This is useful for:
|
|
216
|
+
|
|
209
217
|
- Unit and integration testing
|
|
210
218
|
- Building CLI tools that wrap other CLI tools
|
|
211
219
|
- Programmatic automation workflows
|
|
@@ -219,6 +227,7 @@ This is useful for:
|
|
|
219
227
|
Defines a CLI command.
|
|
220
228
|
|
|
221
229
|
**Options:**
|
|
230
|
+
|
|
222
231
|
- `path: string` - The command path (e.g., 'user:create', 'db:migrate')
|
|
223
232
|
- `optionsSchema?: ZodSchema` - Optional Zod schema for validating command options
|
|
224
233
|
|
|
@@ -227,6 +236,7 @@ Defines a CLI command.
|
|
|
227
236
|
Defines a CLI module.
|
|
228
237
|
|
|
229
238
|
**Options:**
|
|
239
|
+
|
|
230
240
|
- `commands?: ClassType[]` - Array of command classes
|
|
231
241
|
- `imports?: ClassType[]` - Array of other modules to import
|
|
232
242
|
|
|
@@ -242,14 +252,13 @@ interface CommandHandler<TOptions = any> {
|
|
|
242
252
|
}
|
|
243
253
|
```
|
|
244
254
|
|
|
245
|
-
#### `
|
|
255
|
+
#### `Module` (alias for `NaviosModule`)
|
|
246
256
|
|
|
247
|
-
Optional lifecycle hooks for modules.
|
|
257
|
+
Optional lifecycle hooks for modules. This is an alias for `NaviosModule` from `@navios/core`.
|
|
248
258
|
|
|
249
259
|
```typescript
|
|
250
|
-
interface
|
|
251
|
-
onModuleInit
|
|
252
|
-
onModuleDestroy?(): void | Promise<void>
|
|
260
|
+
interface NaviosModule {
|
|
261
|
+
onModuleInit?: () => Promise<void> | void
|
|
253
262
|
}
|
|
254
263
|
```
|
|
255
264
|
|
|
@@ -260,6 +269,7 @@ interface CliModule {
|
|
|
260
269
|
Factory class for creating CLI applications.
|
|
261
270
|
|
|
262
271
|
**Methods:**
|
|
272
|
+
|
|
263
273
|
- `static async create(appModule, options?)` - Creates a new CommanderApplication
|
|
264
274
|
|
|
265
275
|
#### `CommanderApplication`
|
|
@@ -267,6 +277,7 @@ Factory class for creating CLI applications.
|
|
|
267
277
|
Main application class.
|
|
268
278
|
|
|
269
279
|
**Methods:**
|
|
280
|
+
|
|
270
281
|
- `async init()` - Initializes the application
|
|
271
282
|
- `async run(argv)` - Parses command-line arguments and executes the appropriate command (default usage)
|
|
272
283
|
- `async executeCommand(path, options?)` - Executes a command programmatically with options (advanced usage)
|
|
@@ -1,29 +1,147 @@
|
|
|
1
|
-
import type { ClassTypeWithInstance } from '@navios/
|
|
2
|
-
import { Container } from '@navios/
|
|
3
|
-
|
|
1
|
+
import type { ClassTypeWithInstance, NaviosModule } from '@navios/core';
|
|
2
|
+
import { Container } from '@navios/core';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for CommanderApplication.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
4
8
|
export interface CommanderApplicationOptions {
|
|
5
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Main application class for managing CLI command execution.
|
|
12
|
+
*
|
|
13
|
+
* This class handles module loading, command registration, and command execution.
|
|
14
|
+
* It provides both programmatic and CLI-based command execution capabilities.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const app = await CommanderFactory.create(AppModule)
|
|
19
|
+
* await app.init()
|
|
20
|
+
* await app.run(process.argv)
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
6
23
|
export declare class CommanderApplication {
|
|
7
24
|
private moduleLoader;
|
|
8
25
|
private cliParser;
|
|
9
26
|
protected container: Container;
|
|
10
27
|
private appModule;
|
|
11
28
|
private options;
|
|
29
|
+
/**
|
|
30
|
+
* Indicates whether the application has been initialized.
|
|
31
|
+
* Set to `true` after `init()` is called successfully.
|
|
32
|
+
*/
|
|
12
33
|
isInitialized: boolean;
|
|
13
|
-
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
* Sets up the application with the provided module and options.
|
|
37
|
+
* This is called automatically by CommanderFactory.create().
|
|
38
|
+
*/
|
|
39
|
+
setup(appModule: ClassTypeWithInstance<NaviosModule>, options?: CommanderApplicationOptions): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the dependency injection container used by this application.
|
|
42
|
+
*
|
|
43
|
+
* @returns The Container instance
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const container = app.getContainer()
|
|
48
|
+
* const service = await container.get(MyService)
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
14
51
|
getContainer(): Container;
|
|
52
|
+
/**
|
|
53
|
+
* Initializes the application by loading all modules and registering commands.
|
|
54
|
+
*
|
|
55
|
+
* This method must be called before executing commands or running the CLI.
|
|
56
|
+
* It traverses the module tree, loads all imported modules, and collects command metadata.
|
|
57
|
+
*
|
|
58
|
+
* @throws {Error} If the app module is not set (setup() was not called)
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const app = await CommanderFactory.create(AppModule)
|
|
63
|
+
* await app.init() // Must be called before run() or executeCommand()
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
15
66
|
init(): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Executes a command programmatically with the provided options.
|
|
69
|
+
*
|
|
70
|
+
* This method is useful for testing, automation, or programmatic workflows.
|
|
71
|
+
* The options will be validated against the command's Zod schema if one is provided.
|
|
72
|
+
*
|
|
73
|
+
* @param commandPath - The command path (e.g., 'greet', 'user:create')
|
|
74
|
+
* @param options - The command options object (will be validated if schema exists)
|
|
75
|
+
* @throws {Error} If the application is not initialized
|
|
76
|
+
* @throws {Error} If the command is not found
|
|
77
|
+
* @throws {Error} If the command does not implement the execute method
|
|
78
|
+
* @throws {ZodError} If options validation fails
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* await app.executeCommand('greet', {
|
|
83
|
+
* name: 'World',
|
|
84
|
+
* greeting: 'Hi'
|
|
85
|
+
* })
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
16
88
|
executeCommand(commandPath: string, options?: any): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Gets all registered commands with their paths and class references.
|
|
91
|
+
*
|
|
92
|
+
* @returns An array of objects containing the command path and class
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const commands = app.getAllCommands()
|
|
97
|
+
* commands.forEach(({ path }) => {
|
|
98
|
+
* console.log(`Available: ${path}`)
|
|
99
|
+
* })
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
17
102
|
getAllCommands(): {
|
|
18
103
|
path: string;
|
|
19
104
|
class: ClassTypeWithInstance<any>;
|
|
20
105
|
}[];
|
|
21
106
|
/**
|
|
22
|
-
* Runs the CLI application by parsing
|
|
23
|
-
*
|
|
107
|
+
* Runs the CLI application by parsing command-line arguments and executing the appropriate command.
|
|
108
|
+
*
|
|
109
|
+
* This is the main entry point for CLI usage. It parses `argv`, validates options,
|
|
110
|
+
* and executes the matching command. Supports help command (`help`, `--help`, `-h`)
|
|
111
|
+
* which displays all available commands.
|
|
112
|
+
*
|
|
113
|
+
* @param argv - Command-line arguments array (defaults to `process.argv`)
|
|
114
|
+
* @throws {Error} If the application is not initialized
|
|
115
|
+
* @throws {Error} If no command is provided
|
|
116
|
+
* @throws {Error} If the command is not found
|
|
117
|
+
* @throws {ZodError} If options validation fails
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* // Parse and execute from process.argv
|
|
122
|
+
* await app.run()
|
|
123
|
+
*
|
|
124
|
+
* // Or provide custom arguments
|
|
125
|
+
* await app.run(['node', 'cli.js', 'greet', '--name', 'World'])
|
|
126
|
+
* ```
|
|
24
127
|
*/
|
|
25
128
|
run(argv?: string[]): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* @internal
|
|
131
|
+
* Disposes of resources used by the application.
|
|
132
|
+
*/
|
|
26
133
|
dispose(): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Closes the application and cleans up resources.
|
|
136
|
+
*
|
|
137
|
+
* This should be called when the application is no longer needed to free up resources.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* await app.run(process.argv)
|
|
142
|
+
* await app.close()
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
27
145
|
close(): Promise<void>;
|
|
28
146
|
}
|
|
29
147
|
//# sourceMappingURL=commander.application.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commander.application.d.mts","sourceRoot":"","sources":["../../src/commander.application.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"commander.application.d.mts","sourceRoot":"","sources":["../../src/commander.application.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EAErB,YAAY,EACb,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,SAAS,EAAsB,MAAM,cAAc,CAAA;AAQ5D;;;;GAIG;AACH,MAAM,WAAW,2BAA2B;CAAG;AAE/C;;;;;;;;;;;;GAYG;AACH,qBACa,oBAAoB;IAC/B,OAAO,CAAC,YAAY,CAAiC;IACrD,OAAO,CAAC,SAAS,CAA2B;IAC5C,SAAS,CAAC,SAAS,YAAoB;IAEvC,OAAO,CAAC,SAAS,CAAmD;IACpE,OAAO,CAAC,OAAO,CAAkC;IAEjD;;;OAGG;IACH,aAAa,UAAQ;IAErB;;;;OAIG;IACG,KAAK,CACT,SAAS,EAAE,qBAAqB,CAAC,YAAY,CAAC,EAC9C,OAAO,GAAE,2BAAgC;IAM3C;;;;;;;;;;OAUG;IACH,YAAY;IAIZ;;;;;;;;;;;;;OAaG;IACG,IAAI;IAUV;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,GAAQ;IAuD3D;;;;;;;;;;;;OAYG;IACH,cAAc;cAIJ,MAAM;eACL,qBAAqB,CAAC,GAAG,CAAC;;IAarC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,GAAG,CAAC,IAAI,GAAE,MAAM,EAAiB;IAgDvC;;;OAGG;IACG,OAAO;IAMb;;;;;;;;;;OAUG;IACG,KAAK;CAGZ"}
|
|
@@ -1,8 +1,36 @@
|
|
|
1
|
-
import type { ClassTypeWithInstance } from '@navios/
|
|
1
|
+
import type { ClassTypeWithInstance, NaviosModule } from '@navios/core';
|
|
2
2
|
import type { CommanderApplicationOptions } from './commander.application.mjs';
|
|
3
|
-
import type { Module } from './interfaces/index.mjs';
|
|
4
3
|
import { CommanderApplication } from './commander.application.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* Factory class for creating and configuring CLI applications.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { CommanderFactory } from '@navios/commander'
|
|
10
|
+
* import { AppModule } from './app.module'
|
|
11
|
+
*
|
|
12
|
+
* async function bootstrap() {
|
|
13
|
+
* const app = await CommanderFactory.create(AppModule)
|
|
14
|
+
* await app.init()
|
|
15
|
+
* await app.run(process.argv)
|
|
16
|
+
* await app.close()
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
5
20
|
export declare class CommanderFactory {
|
|
6
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new CommanderApplication instance and configures it with the provided module.
|
|
23
|
+
*
|
|
24
|
+
* @param appModule - The root CLI module class that contains commands and/or imports other modules
|
|
25
|
+
* @param options - Optional configuration options for the application
|
|
26
|
+
* @returns A promise that resolves to a configured CommanderApplication instance
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const app = await CommanderFactory.create(AppModule)
|
|
31
|
+
* await app.init()
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
static create(appModule: ClassTypeWithInstance<NaviosModule>, options?: CommanderApplicationOptions): Promise<CommanderApplication>;
|
|
7
35
|
}
|
|
8
36
|
//# sourceMappingURL=commander.factory.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commander.factory.d.mts","sourceRoot":"","sources":["../../src/commander.factory.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,
|
|
1
|
+
{"version":3,"file":"commander.factory.d.mts","sourceRoot":"","sources":["../../src/commander.factory.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAIvE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAA;AAE9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAElE;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,gBAAgB;IAC3B;;;;;;;;;;;;OAYG;WACU,MAAM,CACjB,SAAS,EAAE,qBAAqB,CAAC,YAAY,CAAC,EAC9C,OAAO,GAAE,2BAAgC;CAO5C"}
|
|
@@ -1,7 +1,42 @@
|
|
|
1
|
-
import type { ClassType } from '@navios/
|
|
1
|
+
import type { ClassType } from '@navios/core';
|
|
2
|
+
/**
|
|
3
|
+
* Options for the `@CliModule` decorator.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
2
7
|
export interface CliModuleOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Array or Set of command classes to register in this module.
|
|
10
|
+
* Commands must be decorated with `@Command`.
|
|
11
|
+
*/
|
|
3
12
|
commands?: ClassType[] | Set<ClassType>;
|
|
13
|
+
/**
|
|
14
|
+
* Array or Set of other CLI modules to import.
|
|
15
|
+
* Imported modules' commands will be available in this module.
|
|
16
|
+
*/
|
|
4
17
|
imports?: ClassType[] | Set<ClassType>;
|
|
5
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Decorator that marks a class as a CLI module.
|
|
21
|
+
*
|
|
22
|
+
* Modules organize commands and can import other modules to compose larger CLI applications.
|
|
23
|
+
* The module can optionally implement `NaviosModule` interface for lifecycle hooks.
|
|
24
|
+
*
|
|
25
|
+
* @param options - Configuration options for the module
|
|
26
|
+
* @returns A class decorator function
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { CliModule } from '@navios/commander'
|
|
31
|
+
* import { GreetCommand } from './greet.command'
|
|
32
|
+
* import { UserModule } from './user.module'
|
|
33
|
+
*
|
|
34
|
+
* @CliModule({
|
|
35
|
+
* commands: [GreetCommand],
|
|
36
|
+
* imports: [UserModule]
|
|
37
|
+
* })
|
|
38
|
+
* export class AppModule {}
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
6
41
|
export declare function CliModule({ commands, imports }?: CliModuleOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
|
|
7
42
|
//# sourceMappingURL=cli-module.decorator.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-module.decorator.d.mts","sourceRoot":"","sources":["../../../src/decorators/cli-module.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"cli-module.decorator.d.mts","sourceRoot":"","sources":["../../../src/decorators/cli-module.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAM7C;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAA;IACvC;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAA;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,SAAS,CACvB,EAAE,QAAa,EAAE,OAAY,EAAE,GAAE,gBAGhC,IAEO,QAAQ,SAAS,EAAE,SAAS,qBAAqB,eAqB1D"}
|
|
@@ -1,8 +1,51 @@
|
|
|
1
|
-
import type { ClassType } from '@navios/
|
|
1
|
+
import type { ClassType } from '@navios/core';
|
|
2
2
|
import type { ZodObject } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* Options for the `@Command` decorator.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
3
8
|
export interface CommandOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The command path that users will invoke from the CLI.
|
|
11
|
+
* Can be a single word (e.g., 'greet') or multi-word with colons (e.g., 'user:create', 'db:migrate').
|
|
12
|
+
*/
|
|
4
13
|
path: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional Zod schema for validating command options.
|
|
16
|
+
* If provided, options will be validated and parsed according to this schema.
|
|
17
|
+
*/
|
|
5
18
|
optionsSchema?: ZodObject;
|
|
6
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Decorator that marks a class as a CLI command.
|
|
22
|
+
*
|
|
23
|
+
* The decorated class must implement the `CommandHandler` interface with an `execute` method.
|
|
24
|
+
* The command will be automatically registered when its module is loaded.
|
|
25
|
+
*
|
|
26
|
+
* @param options - Configuration options for the command
|
|
27
|
+
* @returns A class decorator function
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { Command, CommandHandler } from '@navios/commander'
|
|
32
|
+
* import { z } from 'zod'
|
|
33
|
+
*
|
|
34
|
+
* const optionsSchema = z.object({
|
|
35
|
+
* name: z.string(),
|
|
36
|
+
* greeting: z.string().optional().default('Hello')
|
|
37
|
+
* })
|
|
38
|
+
*
|
|
39
|
+
* @Command({
|
|
40
|
+
* path: 'greet',
|
|
41
|
+
* optionsSchema: optionsSchema
|
|
42
|
+
* })
|
|
43
|
+
* export class GreetCommand implements CommandHandler<z.infer<typeof optionsSchema>> {
|
|
44
|
+
* async execute(options) {
|
|
45
|
+
* console.log(`${options.greeting}, ${options.name}!`)
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
7
50
|
export declare function Command({ path, optionsSchema }: CommandOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
|
|
8
51
|
//# sourceMappingURL=command.decorator.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.decorator.d.mts","sourceRoot":"","sources":["../../../src/decorators/command.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"command.decorator.d.mts","sourceRoot":"","sources":["../../../src/decorators/command.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAMpC;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;;OAGG;IACH,aAAa,CAAC,EAAE,SAAS,CAAA;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,OAAO,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,cAAc,IAC5C,QAAQ,SAAS,EAAE,SAAS,qBAAqB,eAenE"}
|
package/dist/src/index.d.mts
CHANGED
package/dist/src/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/index.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/index.mts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA;AAG5B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA"}
|
|
@@ -1,4 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface that all command classes must implement.
|
|
3
|
+
*
|
|
4
|
+
* Commands decorated with `@Command` must implement this interface.
|
|
5
|
+
* The `execute` method is called when the command is invoked.
|
|
6
|
+
*
|
|
7
|
+
* @template TOptions - The type of options that the command accepts
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { Command, CommandHandler } from '@navios/commander'
|
|
12
|
+
* import { z } from 'zod'
|
|
13
|
+
*
|
|
14
|
+
* const optionsSchema = z.object({
|
|
15
|
+
* name: z.string()
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* type Options = z.infer<typeof optionsSchema>
|
|
19
|
+
*
|
|
20
|
+
* @Command({ path: 'greet', optionsSchema })
|
|
21
|
+
* export class GreetCommand implements CommandHandler<Options> {
|
|
22
|
+
* async execute(options: Options) {
|
|
23
|
+
* console.log(`Hello, ${options.name}!`)
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
1
28
|
export interface CommandHandler<TOptions = any> {
|
|
29
|
+
/**
|
|
30
|
+
* Executes the command with the provided options.
|
|
31
|
+
*
|
|
32
|
+
* @param options - The validated command options (validated against the command's schema if provided)
|
|
33
|
+
* @returns A promise or void
|
|
34
|
+
*/
|
|
2
35
|
execute(options: TOptions): void | Promise<void>;
|
|
3
36
|
}
|
|
4
37
|
//# sourceMappingURL=command-handler.interface.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-handler.interface.d.mts","sourceRoot":"","sources":["../../../src/interfaces/command-handler.interface.mts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc,CAAC,QAAQ,GAAG,GAAG;IAC5C,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACjD"}
|
|
1
|
+
{"version":3,"file":"command-handler.interface.d.mts","sourceRoot":"","sources":["../../../src/interfaces/command-handler.interface.mts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,cAAc,CAAC,QAAQ,GAAG,GAAG;IAC5C;;;;;OAKG;IACH,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACjD"}
|
|
@@ -1,11 +1,54 @@
|
|
|
1
1
|
import type { CommandMetadata } from '../metadata/command.metadata.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Execution context for a command execution.
|
|
4
|
+
*
|
|
5
|
+
* Provides access to command metadata, path, and validated options during command execution.
|
|
6
|
+
* This context is automatically injected and available via the `CommandExecutionContext` token.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { inject, Injectable } from '@navios/di'
|
|
11
|
+
* import { CommandExecutionContext } from '@navios/commander'
|
|
12
|
+
*
|
|
13
|
+
* @Injectable()
|
|
14
|
+
* class CommandLogger {
|
|
15
|
+
* private ctx = inject(CommandExecutionContext)
|
|
16
|
+
*
|
|
17
|
+
* log() {
|
|
18
|
+
* console.log('Command:', this.ctx.getCommandPath())
|
|
19
|
+
* console.log('Options:', this.ctx.getOptions())
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
2
24
|
export declare class CommanderExecutionContext {
|
|
3
25
|
private readonly command;
|
|
4
26
|
private readonly commandPath;
|
|
5
27
|
private readonly options;
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
* Creates a new execution context.
|
|
31
|
+
*/
|
|
6
32
|
constructor(command: CommandMetadata, commandPath: string, options: any);
|
|
33
|
+
/**
|
|
34
|
+
* Gets the command metadata.
|
|
35
|
+
*
|
|
36
|
+
* @returns The command metadata including path and options schema
|
|
37
|
+
*/
|
|
7
38
|
getCommand(): CommandMetadata;
|
|
39
|
+
/**
|
|
40
|
+
* Gets the command path that was invoked.
|
|
41
|
+
*
|
|
42
|
+
* @returns The command path (e.g., 'greet', 'user:create')
|
|
43
|
+
*/
|
|
8
44
|
getCommandPath(): string;
|
|
45
|
+
/**
|
|
46
|
+
* Gets the validated command options.
|
|
47
|
+
*
|
|
48
|
+
* Options are validated against the command's Zod schema if one was provided.
|
|
49
|
+
*
|
|
50
|
+
* @returns The validated options object
|
|
51
|
+
*/
|
|
9
52
|
getOptions(): any;
|
|
10
53
|
}
|
|
11
54
|
//# sourceMappingURL=commander-execution-context.interface.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commander-execution-context.interface.d.mts","sourceRoot":"","sources":["../../../src/interfaces/commander-execution-context.interface.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAA;AAEvE,qBAAa,yBAAyB;
|
|
1
|
+
{"version":3,"file":"commander-execution-context.interface.d.mts","sourceRoot":"","sources":["../../../src/interfaces/commander-execution-context.interface.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAA;AAEvE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,yBAAyB;IAMlC,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAP1B;;;OAGG;gBAEgB,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,GAAG;IAG/B;;;;OAIG;IACH,UAAU,IAAI,eAAe;IAI7B;;;;OAIG;IACH,cAAc,IAAI,MAAM;IAIxB;;;;;;OAMG;IACH,UAAU,IAAI,GAAG;CAGlB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/interfaces/index.mts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/interfaces/index.mts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAA;AAC/C,cAAc,6CAA6C,CAAA"}
|