@decaf-ts/cli 0.7.0 → 0.9.0
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/lib/cjs/CliWrapper.cjs +28 -27
- package/lib/cjs/CliWrapper.cjs.map +1 -0
- package/lib/cjs/banners.cjs +2 -1
- package/lib/cjs/banners.cjs.map +1 -0
- package/lib/cjs/bin/cli.cjs +4 -3
- package/lib/cjs/bin/cli.cjs.map +1 -0
- package/lib/cjs/build-module/cli-module.cjs +4 -3
- package/lib/cjs/build-module/cli-module.cjs.map +1 -0
- package/lib/cjs/constants.cjs +1 -0
- package/lib/cjs/constants.cjs.map +1 -0
- package/lib/cjs/environment.cjs +1 -0
- package/lib/cjs/environment.cjs.map +1 -0
- package/lib/cjs/index.cjs +1 -0
- package/lib/cjs/index.cjs.map +1 -0
- package/lib/cjs/logging.cjs +1 -0
- package/lib/cjs/logging.cjs.map +1 -0
- package/lib/cjs/release-module/cli-module.cjs +6 -5
- package/lib/cjs/release-module/cli-module.cjs.map +1 -0
- package/lib/cjs/slogans.cjs +1 -0
- package/lib/cjs/slogans.cjs.map +1 -0
- package/lib/cjs/types.cjs +1 -0
- package/lib/cjs/types.cjs.map +1 -0
- package/lib/cjs/utils/command-forwarder.cjs +3 -2
- package/lib/cjs/utils/command-forwarder.cjs.map +1 -0
- package/lib/cjs/utils-module/cli-module.cjs +8 -7
- package/lib/cjs/utils-module/cli-module.cjs.map +1 -0
- package/lib/cjs/utils.cjs +2 -1
- package/lib/cjs/utils.cjs.map +1 -0
- package/lib/cjs/version.cjs +2 -1
- package/lib/cjs/version.cjs.map +1 -0
- package/lib/esm/version.js +1 -1
- package/lib/types/CliWrapper.d.cts +156 -0
- package/lib/types/CliWrapper.d.mts +156 -0
- package/lib/types/banners.d.cts +3 -0
- package/lib/types/banners.d.mts +3 -0
- package/lib/types/bin/cli.d.cts +25 -0
- package/lib/types/bin/cli.d.mts +25 -0
- package/lib/types/build-module/cli-module.d.cts +2 -0
- package/lib/types/build-module/cli-module.d.mts +2 -0
- package/lib/types/constants.d.cts +8 -0
- package/lib/types/constants.d.mts +8 -0
- package/lib/types/environment.d.cts +7 -0
- package/lib/types/environment.d.mts +7 -0
- package/lib/types/index.d.cts +16 -0
- package/lib/types/index.d.mts +16 -0
- package/lib/types/logging.d.cts +3 -0
- package/lib/types/logging.d.mts +3 -0
- package/lib/types/release-module/cli-module.d.cts +2 -0
- package/lib/types/release-module/cli-module.d.mts +2 -0
- package/lib/types/slogans.d.cts +40 -0
- package/lib/types/slogans.d.mts +40 -0
- package/lib/types/types.d.cts +11 -0
- package/lib/types/types.d.mts +11 -0
- package/lib/types/utils/command-forwarder.d.cts +10 -0
- package/lib/types/utils/command-forwarder.d.mts +10 -0
- package/lib/types/utils-module/cli-module.d.cts +2 -0
- package/lib/types/utils-module/cli-module.d.mts +2 -0
- package/lib/types/utils.d.cts +70 -0
- package/lib/types/utils.d.mts +70 -0
- package/lib/types/version.d.cts +14 -0
- package/lib/types/version.d.mts +14 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +4 -4
- package/lib/cjs/CliWrapper.js.map +0 -1
- package/lib/cjs/banners.js.map +0 -1
- package/lib/cjs/bin/cli.js.map +0 -1
- package/lib/cjs/build-module/cli-module.js.map +0 -1
- package/lib/cjs/constants.js.map +0 -1
- package/lib/cjs/environment.js.map +0 -1
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/logging.js.map +0 -1
- package/lib/cjs/release-module/cli-module.js.map +0 -1
- package/lib/cjs/slogans.js.map +0 -1
- package/lib/cjs/types.js.map +0 -1
- package/lib/cjs/utils/command-forwarder.js.map +0 -1
- package/lib/cjs/utils-module/cli-module.js.map +0 -1
- package/lib/cjs/utils.js.map +0 -1
- package/lib/cjs/version.js.map +0 -1
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { LoggedClass } from "@decaf-ts/logging";
|
|
3
|
+
/**
|
|
4
|
+
* @description Utility class to handle CLI functionality from all Decaf modules
|
|
5
|
+
* @summary This class provides a wrapper around Commander.js to handle CLI commands from different Decaf modules.
|
|
6
|
+
* It crawls the filesystem to find CLI modules, loads them, and registers their commands.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} [basePath] The base path to look for modules in. Defaults to `./`
|
|
9
|
+
* @param {number} [crawlLevels] Number of folder levels to crawl to find modules from the basePath. Defaults to 4
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Create a new CLI wrapper and run it with custom options
|
|
13
|
+
* const cli = new CliWrapper('./src', 2);
|
|
14
|
+
* cli.run(process.argv).then(() => {
|
|
15
|
+
* console.log('CLI commands executed successfully');
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* @class CliWrapper
|
|
19
|
+
*/
|
|
20
|
+
export declare class CliWrapper extends LoggedClass {
|
|
21
|
+
private basePath;
|
|
22
|
+
private crawlLevels;
|
|
23
|
+
private _command?;
|
|
24
|
+
private modules;
|
|
25
|
+
private includedModuleNames;
|
|
26
|
+
private readonly rootPath;
|
|
27
|
+
private moduleSlogans;
|
|
28
|
+
private globalSlogans;
|
|
29
|
+
private readonly logLevelAttached;
|
|
30
|
+
private bannerPrinted;
|
|
31
|
+
private static env;
|
|
32
|
+
constructor(basePath?: string, crawlLevels?: number);
|
|
33
|
+
/**
|
|
34
|
+
* @description Retrieves and initializes the Commander Command object
|
|
35
|
+
* @summary Lazy-loads the Command object, initializing it with the package name, description, and version
|
|
36
|
+
* @return {Command} The initialized Command object
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
private get command();
|
|
40
|
+
/**
|
|
41
|
+
* @description Loads and registers a module from a file
|
|
42
|
+
* @summary Dynamically imports a CLI module from the specified file path, initializes it, and registers it in the modules collection
|
|
43
|
+
*
|
|
44
|
+
* @param {string} filePath Path to the module file to load
|
|
45
|
+
* @param {string} rootPath Repository root path to find the package.json
|
|
46
|
+
* @return {Promise<string>} A promise that resolves to the module name
|
|
47
|
+
*
|
|
48
|
+
* @private
|
|
49
|
+
* @mermaid
|
|
50
|
+
* sequenceDiagram
|
|
51
|
+
* participant CliWrapper
|
|
52
|
+
* participant CLIUtils
|
|
53
|
+
* participant Module
|
|
54
|
+
*
|
|
55
|
+
* CliWrapper->>CLIUtils: loadFromFile(filePath)
|
|
56
|
+
* CLIUtils-->>CliWrapper: module
|
|
57
|
+
* CliWrapper->>CliWrapper: Get module name
|
|
58
|
+
* CliWrapper->>Command: new Command()
|
|
59
|
+
* Command-->>CliWrapper: cmd
|
|
60
|
+
* CliWrapper->>CLIUtils: initialize(cmd, path.dirname(rootPath))
|
|
61
|
+
* CliWrapper->>Module: module()
|
|
62
|
+
* Note over CliWrapper,Module: Handle Promise if needed
|
|
63
|
+
* Module-->>CliWrapper: Command instance
|
|
64
|
+
* CliWrapper->>CliWrapper: Store in modules[name]
|
|
65
|
+
* CliWrapper-->>CliWrapper: Return name
|
|
66
|
+
*/
|
|
67
|
+
private load;
|
|
68
|
+
private registerModule;
|
|
69
|
+
/**
|
|
70
|
+
* @description Finds and loads all CLI modules in the basePath
|
|
71
|
+
* @summary Uses the crawl method to find all CLI modules in the specified base path,
|
|
72
|
+
* then loads and registers each module as a subcommand
|
|
73
|
+
*
|
|
74
|
+
* @return {Promise<void>} A promise that resolves when all modules are loaded
|
|
75
|
+
*
|
|
76
|
+
* @private
|
|
77
|
+
* @mermaid
|
|
78
|
+
* sequenceDiagram
|
|
79
|
+
* participant CliWrapper
|
|
80
|
+
* participant Filesystem
|
|
81
|
+
* participant Module
|
|
82
|
+
*
|
|
83
|
+
* CliWrapper->>Filesystem: Join basePath with cwd
|
|
84
|
+
* CliWrapper->>CliWrapper: crawl(basePath, crawlLevels)
|
|
85
|
+
* CliWrapper-->>CliWrapper: modules[]
|
|
86
|
+
* loop For each module
|
|
87
|
+
* alt Not @decaf-ts/cli
|
|
88
|
+
* CliWrapper->>CliWrapper: load(module, cwd)
|
|
89
|
+
* CliWrapper-->>CliWrapper: name
|
|
90
|
+
* CliWrapper->>CliWrapper: Check if command exists
|
|
91
|
+
* alt Command doesn't exist
|
|
92
|
+
* CliWrapper->>Command: command(name).addCommand(modules[name])
|
|
93
|
+
* end
|
|
94
|
+
* end
|
|
95
|
+
* end
|
|
96
|
+
* CliWrapper->>Console: Log loaded modules
|
|
97
|
+
*/
|
|
98
|
+
private boot;
|
|
99
|
+
private loadIncludedModules;
|
|
100
|
+
private loadModulesFromPath;
|
|
101
|
+
private getScopePackageRoots;
|
|
102
|
+
private findEnclosingNodeModules;
|
|
103
|
+
private getSiblingPackageRoots;
|
|
104
|
+
private getHostPath;
|
|
105
|
+
private getPackageNameFromRoot;
|
|
106
|
+
private ensureLogLevelSupport;
|
|
107
|
+
private updateLogLevel;
|
|
108
|
+
private resolveLogLevel;
|
|
109
|
+
/**
|
|
110
|
+
* @description Recursively searches for CLI module files in the directory structure
|
|
111
|
+
* @summary Crawls the basePath up to the specified number of folder levels to find files named according to CLI_FILE_NAME
|
|
112
|
+
*
|
|
113
|
+
* @param {string} basePath The absolute base path to start searching in
|
|
114
|
+
* @param {number} [levels=2] The maximum number of directory levels to crawl
|
|
115
|
+
* @return {string[]} An array of file paths to CLI modules
|
|
116
|
+
*
|
|
117
|
+
* @private
|
|
118
|
+
*/
|
|
119
|
+
private crawl;
|
|
120
|
+
private findModuleRoot;
|
|
121
|
+
protected getSlogan(priorityModule?: string): string;
|
|
122
|
+
private otherSlogans;
|
|
123
|
+
private buildBalancedSloganPool;
|
|
124
|
+
private repeatToLength;
|
|
125
|
+
private ensureGlobalSlogans;
|
|
126
|
+
private collectSlogansFromPath;
|
|
127
|
+
private collectSlogansFromScope;
|
|
128
|
+
private collectSlogansFromSiblingPackages;
|
|
129
|
+
private extractSloganStrings;
|
|
130
|
+
private isCommandInstance;
|
|
131
|
+
protected printBanner(args?: string[]): () => void;
|
|
132
|
+
private getPriorityModule;
|
|
133
|
+
/**
|
|
134
|
+
* @description Executes the CLI with the provided arguments
|
|
135
|
+
* @summary Boots the CLI by loading all modules, then parses and executes the command specified in the arguments
|
|
136
|
+
*
|
|
137
|
+
* @param {string[]} [args=process.argv] Command line arguments to parse and execute
|
|
138
|
+
* @return {Promise<void>} A promise that resolves when the command execution is complete
|
|
139
|
+
*
|
|
140
|
+
* @mermaid
|
|
141
|
+
* sequenceDiagram
|
|
142
|
+
* participant Client
|
|
143
|
+
* participant CliWrapper
|
|
144
|
+
* participant Command
|
|
145
|
+
*
|
|
146
|
+
* Client->>CliWrapper: run(args)
|
|
147
|
+
* CliWrapper->>CliWrapper: boot()
|
|
148
|
+
* Note over CliWrapper: Loads all modules
|
|
149
|
+
* CliWrapper->>Command: parseAsync(args)
|
|
150
|
+
* Command-->>CliWrapper: result
|
|
151
|
+
* CliWrapper-->>Client: result
|
|
152
|
+
*/
|
|
153
|
+
run(args?: string[]): Promise<Command>;
|
|
154
|
+
static accumulateEnvironment(obj: object): void;
|
|
155
|
+
static getEnv(): any;
|
|
156
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { LoggedClass } from "@decaf-ts/logging";
|
|
3
|
+
/**
|
|
4
|
+
* @description Utility class to handle CLI functionality from all Decaf modules
|
|
5
|
+
* @summary This class provides a wrapper around Commander.js to handle CLI commands from different Decaf modules.
|
|
6
|
+
* It crawls the filesystem to find CLI modules, loads them, and registers their commands.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} [basePath] The base path to look for modules in. Defaults to `./`
|
|
9
|
+
* @param {number} [crawlLevels] Number of folder levels to crawl to find modules from the basePath. Defaults to 4
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Create a new CLI wrapper and run it with custom options
|
|
13
|
+
* const cli = new CliWrapper('./src', 2);
|
|
14
|
+
* cli.run(process.argv).then(() => {
|
|
15
|
+
* console.log('CLI commands executed successfully');
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* @class CliWrapper
|
|
19
|
+
*/
|
|
20
|
+
export declare class CliWrapper extends LoggedClass {
|
|
21
|
+
private basePath;
|
|
22
|
+
private crawlLevels;
|
|
23
|
+
private _command?;
|
|
24
|
+
private modules;
|
|
25
|
+
private includedModuleNames;
|
|
26
|
+
private readonly rootPath;
|
|
27
|
+
private moduleSlogans;
|
|
28
|
+
private globalSlogans;
|
|
29
|
+
private readonly logLevelAttached;
|
|
30
|
+
private bannerPrinted;
|
|
31
|
+
private static env;
|
|
32
|
+
constructor(basePath?: string, crawlLevels?: number);
|
|
33
|
+
/**
|
|
34
|
+
* @description Retrieves and initializes the Commander Command object
|
|
35
|
+
* @summary Lazy-loads the Command object, initializing it with the package name, description, and version
|
|
36
|
+
* @return {Command} The initialized Command object
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
private get command();
|
|
40
|
+
/**
|
|
41
|
+
* @description Loads and registers a module from a file
|
|
42
|
+
* @summary Dynamically imports a CLI module from the specified file path, initializes it, and registers it in the modules collection
|
|
43
|
+
*
|
|
44
|
+
* @param {string} filePath Path to the module file to load
|
|
45
|
+
* @param {string} rootPath Repository root path to find the package.json
|
|
46
|
+
* @return {Promise<string>} A promise that resolves to the module name
|
|
47
|
+
*
|
|
48
|
+
* @private
|
|
49
|
+
* @mermaid
|
|
50
|
+
* sequenceDiagram
|
|
51
|
+
* participant CliWrapper
|
|
52
|
+
* participant CLIUtils
|
|
53
|
+
* participant Module
|
|
54
|
+
*
|
|
55
|
+
* CliWrapper->>CLIUtils: loadFromFile(filePath)
|
|
56
|
+
* CLIUtils-->>CliWrapper: module
|
|
57
|
+
* CliWrapper->>CliWrapper: Get module name
|
|
58
|
+
* CliWrapper->>Command: new Command()
|
|
59
|
+
* Command-->>CliWrapper: cmd
|
|
60
|
+
* CliWrapper->>CLIUtils: initialize(cmd, path.dirname(rootPath))
|
|
61
|
+
* CliWrapper->>Module: module()
|
|
62
|
+
* Note over CliWrapper,Module: Handle Promise if needed
|
|
63
|
+
* Module-->>CliWrapper: Command instance
|
|
64
|
+
* CliWrapper->>CliWrapper: Store in modules[name]
|
|
65
|
+
* CliWrapper-->>CliWrapper: Return name
|
|
66
|
+
*/
|
|
67
|
+
private load;
|
|
68
|
+
private registerModule;
|
|
69
|
+
/**
|
|
70
|
+
* @description Finds and loads all CLI modules in the basePath
|
|
71
|
+
* @summary Uses the crawl method to find all CLI modules in the specified base path,
|
|
72
|
+
* then loads and registers each module as a subcommand
|
|
73
|
+
*
|
|
74
|
+
* @return {Promise<void>} A promise that resolves when all modules are loaded
|
|
75
|
+
*
|
|
76
|
+
* @private
|
|
77
|
+
* @mermaid
|
|
78
|
+
* sequenceDiagram
|
|
79
|
+
* participant CliWrapper
|
|
80
|
+
* participant Filesystem
|
|
81
|
+
* participant Module
|
|
82
|
+
*
|
|
83
|
+
* CliWrapper->>Filesystem: Join basePath with cwd
|
|
84
|
+
* CliWrapper->>CliWrapper: crawl(basePath, crawlLevels)
|
|
85
|
+
* CliWrapper-->>CliWrapper: modules[]
|
|
86
|
+
* loop For each module
|
|
87
|
+
* alt Not @decaf-ts/cli
|
|
88
|
+
* CliWrapper->>CliWrapper: load(module, cwd)
|
|
89
|
+
* CliWrapper-->>CliWrapper: name
|
|
90
|
+
* CliWrapper->>CliWrapper: Check if command exists
|
|
91
|
+
* alt Command doesn't exist
|
|
92
|
+
* CliWrapper->>Command: command(name).addCommand(modules[name])
|
|
93
|
+
* end
|
|
94
|
+
* end
|
|
95
|
+
* end
|
|
96
|
+
* CliWrapper->>Console: Log loaded modules
|
|
97
|
+
*/
|
|
98
|
+
private boot;
|
|
99
|
+
private loadIncludedModules;
|
|
100
|
+
private loadModulesFromPath;
|
|
101
|
+
private getScopePackageRoots;
|
|
102
|
+
private findEnclosingNodeModules;
|
|
103
|
+
private getSiblingPackageRoots;
|
|
104
|
+
private getHostPath;
|
|
105
|
+
private getPackageNameFromRoot;
|
|
106
|
+
private ensureLogLevelSupport;
|
|
107
|
+
private updateLogLevel;
|
|
108
|
+
private resolveLogLevel;
|
|
109
|
+
/**
|
|
110
|
+
* @description Recursively searches for CLI module files in the directory structure
|
|
111
|
+
* @summary Crawls the basePath up to the specified number of folder levels to find files named according to CLI_FILE_NAME
|
|
112
|
+
*
|
|
113
|
+
* @param {string} basePath The absolute base path to start searching in
|
|
114
|
+
* @param {number} [levels=2] The maximum number of directory levels to crawl
|
|
115
|
+
* @return {string[]} An array of file paths to CLI modules
|
|
116
|
+
*
|
|
117
|
+
* @private
|
|
118
|
+
*/
|
|
119
|
+
private crawl;
|
|
120
|
+
private findModuleRoot;
|
|
121
|
+
protected getSlogan(priorityModule?: string): string;
|
|
122
|
+
private otherSlogans;
|
|
123
|
+
private buildBalancedSloganPool;
|
|
124
|
+
private repeatToLength;
|
|
125
|
+
private ensureGlobalSlogans;
|
|
126
|
+
private collectSlogansFromPath;
|
|
127
|
+
private collectSlogansFromScope;
|
|
128
|
+
private collectSlogansFromSiblingPackages;
|
|
129
|
+
private extractSloganStrings;
|
|
130
|
+
private isCommandInstance;
|
|
131
|
+
protected printBanner(args?: string[]): () => void;
|
|
132
|
+
private getPriorityModule;
|
|
133
|
+
/**
|
|
134
|
+
* @description Executes the CLI with the provided arguments
|
|
135
|
+
* @summary Boots the CLI by loading all modules, then parses and executes the command specified in the arguments
|
|
136
|
+
*
|
|
137
|
+
* @param {string[]} [args=process.argv] Command line arguments to parse and execute
|
|
138
|
+
* @return {Promise<void>} A promise that resolves when the command execution is complete
|
|
139
|
+
*
|
|
140
|
+
* @mermaid
|
|
141
|
+
* sequenceDiagram
|
|
142
|
+
* participant Client
|
|
143
|
+
* participant CliWrapper
|
|
144
|
+
* participant Command
|
|
145
|
+
*
|
|
146
|
+
* Client->>CliWrapper: run(args)
|
|
147
|
+
* CliWrapper->>CliWrapper: boot()
|
|
148
|
+
* Note over CliWrapper: Loads all modules
|
|
149
|
+
* CliWrapper->>Command: parseAsync(args)
|
|
150
|
+
* Command-->>CliWrapper: result
|
|
151
|
+
* CliWrapper-->>Client: result
|
|
152
|
+
*/
|
|
153
|
+
run(args?: string[]): Promise<Command>;
|
|
154
|
+
static accumulateEnvironment(obj: object): void;
|
|
155
|
+
static getEnv(): any;
|
|
156
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BIN_CALL_PLACEHOLDER - DO NOT REMOVE
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @description Decaf-ts' CLI entry point
|
|
6
|
+
* @summary This file serves as the main executable entry point for the Decaf CLI. It creates a CliWrapper instance
|
|
7
|
+
* and runs it with the process arguments. The CLI will crawl the current working directory for files called
|
|
8
|
+
* CLI_FILE_NAME within the @decaf-ts namespace and load them as subcommands.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Run a module command
|
|
12
|
+
* $ npx decaf <module name> <module command> ...<module command options>
|
|
13
|
+
*
|
|
14
|
+
* // Get help for a specific module
|
|
15
|
+
* $ npx decaf help <module name>
|
|
16
|
+
*
|
|
17
|
+
* // List all imported modules
|
|
18
|
+
* $ npx decaf list
|
|
19
|
+
*
|
|
20
|
+
* // Get general CLI help
|
|
21
|
+
* $ npx decaf help
|
|
22
|
+
*
|
|
23
|
+
* @memberOf module:CLI
|
|
24
|
+
*/
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BIN_CALL_PLACEHOLDER - DO NOT REMOVE
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @description Decaf-ts' CLI entry point
|
|
6
|
+
* @summary This file serves as the main executable entry point for the Decaf CLI. It creates a CliWrapper instance
|
|
7
|
+
* and runs it with the process arguments. The CLI will crawl the current working directory for files called
|
|
8
|
+
* CLI_FILE_NAME within the @decaf-ts namespace and load them as subcommands.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Run a module command
|
|
12
|
+
* $ npx decaf <module name> <module command> ...<module command options>
|
|
13
|
+
*
|
|
14
|
+
* // Get help for a specific module
|
|
15
|
+
* $ npx decaf help <module name>
|
|
16
|
+
*
|
|
17
|
+
* // List all imported modules
|
|
18
|
+
* $ npx decaf list
|
|
19
|
+
*
|
|
20
|
+
* // Get general CLI help
|
|
21
|
+
* $ npx decaf help
|
|
22
|
+
*
|
|
23
|
+
* @memberOf module:CLI
|
|
24
|
+
*/
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description The filename that identifies Decaf CLI modules
|
|
3
|
+
* @summary The standard filename for CLI module files where each library must export a single CliModule function
|
|
4
|
+
*
|
|
5
|
+
* @const CLI_FILE_NAME
|
|
6
|
+
* @memberOf module:CLI
|
|
7
|
+
*/
|
|
8
|
+
export declare const CLI_FILE_NAME = "cli-module";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description The filename that identifies Decaf CLI modules
|
|
3
|
+
* @summary The standard filename for CLI module files where each library must export a single CliModule function
|
|
4
|
+
*
|
|
5
|
+
* @const CLI_FILE_NAME
|
|
6
|
+
* @memberOf module:CLI
|
|
7
|
+
*/
|
|
8
|
+
export declare const CLI_FILE_NAME = "cli-module";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LoggingConfig } from "@decaf-ts/logging";
|
|
2
|
+
export type DecafCliEnvironment = LoggingConfig & {
|
|
3
|
+
banner: boolean;
|
|
4
|
+
cliModuleRoot: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const DefaultCliEnvironment: DecafCliEnvironment;
|
|
7
|
+
export declare const DecafCLieEnvironment: any;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LoggingConfig } from "@decaf-ts/logging";
|
|
2
|
+
export type DecafCliEnvironment = LoggingConfig & {
|
|
3
|
+
banner: boolean;
|
|
4
|
+
cliModuleRoot: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const DefaultCliEnvironment: DecafCliEnvironment;
|
|
7
|
+
export declare const DecafCLieEnvironment: any;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "./CliWrapper.cjs";
|
|
2
|
+
export * from "./environment.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* @description Decaf-ts' CLI module
|
|
5
|
+
* @summary This file will crawl the current working directory for files called {@link CLI_FILE_NAME}
|
|
6
|
+
* within the @decaf-ts namespace and load them as subcommands. It serves as the main entry point
|
|
7
|
+
* for the CLI functionality, exporting the CliWrapper class and VERSION constant.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* run module command - $ npx decaf <module name> <module command> ...<module command options>
|
|
11
|
+
* get module help - $ npx decaf help <module name>;
|
|
12
|
+
* list imported modules - $ npx decaf list;
|
|
13
|
+
* get cli help - $ npx decaf help;
|
|
14
|
+
*
|
|
15
|
+
* @module CLI
|
|
16
|
+
*/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "./CliWrapper.js";
|
|
2
|
+
export * from "./environment.js";
|
|
3
|
+
/**
|
|
4
|
+
* @description Decaf-ts' CLI module
|
|
5
|
+
* @summary This file will crawl the current working directory for files called {@link CLI_FILE_NAME}
|
|
6
|
+
* within the @decaf-ts namespace and load them as subcommands. It serves as the main entry point
|
|
7
|
+
* for the CLI functionality, exporting the CliWrapper class and VERSION constant.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* run module command - $ npx decaf <module name> <module command> ...<module command options>
|
|
11
|
+
* get module help - $ npx decaf help <module name>;
|
|
12
|
+
* list imported modules - $ npx decaf list;
|
|
13
|
+
* get cli help - $ npx decaf help;
|
|
14
|
+
*
|
|
15
|
+
* @module CLI
|
|
16
|
+
*/
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Logger } from "@decaf-ts/logging";
|
|
2
|
+
/**
|
|
3
|
+
* @description Reads and parses slogans from workdocs/assets/slogans.json.
|
|
4
|
+
* @summary Attempts to read a slogans.json file from the workdocs/assets directory at the given base path and returns its parsed contents as an array.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} basePath - The base directory path where workdocs/assets/slogans.json should exist.
|
|
7
|
+
* @return {any[] | undefined} The parsed array from slogans.json, or undefined if the file doesn't exist.
|
|
8
|
+
*
|
|
9
|
+
* @function readSlogans
|
|
10
|
+
*
|
|
11
|
+
* @memberOf module:utils
|
|
12
|
+
*/
|
|
13
|
+
export declare function readSlogans(log: Logger, basePath: string): {
|
|
14
|
+
Slogan: string;
|
|
15
|
+
}[] | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* @description Collects slogans from a base path and all @decaf scoped packages.
|
|
18
|
+
* @summary Recursively collects slogans.json files from the given base path and all subdirectories under node_modules/@decaf/*. Results are stored in an object keyed by the package name (from package.json).
|
|
19
|
+
*
|
|
20
|
+
* @param {string} basePath - The base directory path to start collecting from.
|
|
21
|
+
* @return {Record<string, any[]>} An object mapping package names to their slogans arrays.
|
|
22
|
+
*
|
|
23
|
+
* @function collectSlogans
|
|
24
|
+
*
|
|
25
|
+
* @memberOf module:utils
|
|
26
|
+
*/
|
|
27
|
+
export declare function collectSlogans(log: Logger, basePath: string): Record<string, any[]>;
|
|
28
|
+
/**
|
|
29
|
+
* @description Flattens collected slogans with weighted selection for a priority package.
|
|
30
|
+
* @summary Given a collection of slogans and a priority package name, returns a flat array where slogans from the priority package have a 30-40% chance of appearing at any given position.
|
|
31
|
+
*
|
|
32
|
+
* @param {Record<string, any[]>} slogansMap - Object mapping package names to slogan arrays.
|
|
33
|
+
* @param {string} priorityPackage - The package name whose slogans should be prioritized.
|
|
34
|
+
* @return {any[]} A flat array of all slogans with weighted distribution.
|
|
35
|
+
*
|
|
36
|
+
* @function flattenSlogansWithPriority
|
|
37
|
+
*
|
|
38
|
+
* @memberOf module:utils
|
|
39
|
+
*/
|
|
40
|
+
export declare function flattenSlogansWithPriority(log: Logger, slogansMap: Record<string, any[]>, priorityPackage: string): any[];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Logger } from "@decaf-ts/logging";
|
|
2
|
+
/**
|
|
3
|
+
* @description Reads and parses slogans from workdocs/assets/slogans.json.
|
|
4
|
+
* @summary Attempts to read a slogans.json file from the workdocs/assets directory at the given base path and returns its parsed contents as an array.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} basePath - The base directory path where workdocs/assets/slogans.json should exist.
|
|
7
|
+
* @return {any[] | undefined} The parsed array from slogans.json, or undefined if the file doesn't exist.
|
|
8
|
+
*
|
|
9
|
+
* @function readSlogans
|
|
10
|
+
*
|
|
11
|
+
* @memberOf module:utils
|
|
12
|
+
*/
|
|
13
|
+
export declare function readSlogans(log: Logger, basePath: string): {
|
|
14
|
+
Slogan: string;
|
|
15
|
+
}[] | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* @description Collects slogans from a base path and all @decaf scoped packages.
|
|
18
|
+
* @summary Recursively collects slogans.json files from the given base path and all subdirectories under node_modules/@decaf/*. Results are stored in an object keyed by the package name (from package.json).
|
|
19
|
+
*
|
|
20
|
+
* @param {string} basePath - The base directory path to start collecting from.
|
|
21
|
+
* @return {Record<string, any[]>} An object mapping package names to their slogans arrays.
|
|
22
|
+
*
|
|
23
|
+
* @function collectSlogans
|
|
24
|
+
*
|
|
25
|
+
* @memberOf module:utils
|
|
26
|
+
*/
|
|
27
|
+
export declare function collectSlogans(log: Logger, basePath: string): Record<string, any[]>;
|
|
28
|
+
/**
|
|
29
|
+
* @description Flattens collected slogans with weighted selection for a priority package.
|
|
30
|
+
* @summary Given a collection of slogans and a priority package name, returns a flat array where slogans from the priority package have a 30-40% chance of appearing at any given position.
|
|
31
|
+
*
|
|
32
|
+
* @param {Record<string, any[]>} slogansMap - Object mapping package names to slogan arrays.
|
|
33
|
+
* @param {string} priorityPackage - The package name whose slogans should be prioritized.
|
|
34
|
+
* @return {any[]} A flat array of all slogans with weighted distribution.
|
|
35
|
+
*
|
|
36
|
+
* @function flattenSlogansWithPriority
|
|
37
|
+
*
|
|
38
|
+
* @memberOf module:utils
|
|
39
|
+
*/
|
|
40
|
+
export declare function flattenSlogansWithPriority(log: Logger, slogansMap: Record<string, any[]>, priorityPackage: string): any[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
/**
|
|
3
|
+
* @description Function type for Decaf CLI modules
|
|
4
|
+
* @summary Defines the signature for CLI module functions that each Decaf module must export under the CLI_FILE_NAME file
|
|
5
|
+
* The function should return a Command object or a Promise that resolves to a Command object
|
|
6
|
+
*
|
|
7
|
+
* @typedef {Function} CliModule
|
|
8
|
+
* @return {Command|Promise<Command>} A Command object or Promise that resolves to a Command object
|
|
9
|
+
* @memberOf module:CLI
|
|
10
|
+
*/
|
|
11
|
+
export type CliModule = () => Command | Promise<Command>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
/**
|
|
3
|
+
* @description Function type for Decaf CLI modules
|
|
4
|
+
* @summary Defines the signature for CLI module functions that each Decaf module must export under the CLI_FILE_NAME file
|
|
5
|
+
* The function should return a Command object or a Promise that resolves to a Command object
|
|
6
|
+
*
|
|
7
|
+
* @typedef {Function} CliModule
|
|
8
|
+
* @return {Command|Promise<Command>} A Command object or Promise that resolves to a Command object
|
|
9
|
+
* @memberOf module:CLI
|
|
10
|
+
*/
|
|
11
|
+
export type CliModule = () => Command | Promise<Command>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
export type OptionSpec = {
|
|
3
|
+
name: string;
|
|
4
|
+
flag: string;
|
|
5
|
+
type: "boolean" | "string";
|
|
6
|
+
allowFalse?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function parseOptionalBoolean(value?: string): boolean;
|
|
9
|
+
export declare function buildValueMap(command: Command, specs: OptionSpec[]): Record<string, unknown>;
|
|
10
|
+
export declare function runUtilsCommand(utilsCommand: object, values: Record<string, unknown>, invoker: Command): Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
export type OptionSpec = {
|
|
3
|
+
name: string;
|
|
4
|
+
flag: string;
|
|
5
|
+
type: "boolean" | "string";
|
|
6
|
+
allowFalse?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function parseOptionalBoolean(value?: string): boolean;
|
|
9
|
+
export declare function buildValueMap(command: Command, specs: OptionSpec[]): Record<string, unknown>;
|
|
10
|
+
export declare function runUtilsCommand(utilsCommand: object, values: Record<string, unknown>, invoker: Command): Promise<void>;
|