@kosdev-code/kos-ui-cli 2.1.25 → 2.1.26
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 +346 -4
- package/package.json +4 -3
- package/src/lib/cli.mjs +48 -467
- package/src/lib/generators/api/generate.mjs +105 -0
- package/src/lib/generators/api/lib/generate-api.mjs +452 -0
- package/src/lib/plopfile.mjs +2 -0
- package/src/lib/utils/cli-help-display.mjs +84 -0
- package/src/lib/utils/cli-help-utils.mjs +261 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for CLI help generation
|
|
3
|
+
*
|
|
4
|
+
* Provides intelligent help generation for KOS CLI commands including:
|
|
5
|
+
* - Example value generation based on argument types and names
|
|
6
|
+
* - Relevant argument filtering for concise examples
|
|
7
|
+
* - Command-line example generation with proper formatting
|
|
8
|
+
* - Named argument documentation display
|
|
9
|
+
*
|
|
10
|
+
* @module cli-help-utils
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Generate example values for command-line arguments based on argument names.
|
|
15
|
+
*
|
|
16
|
+
* Uses heuristics to determine appropriate example values based on the argument
|
|
17
|
+
* name and command context. Provides realistic examples for common patterns like
|
|
18
|
+
* names, projects, and boolean flags.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} argName - The argument name (e.g., 'name', 'project', 'singleton')
|
|
21
|
+
* @param {string} command - The command name for context (e.g., 'model', 'api:generate')
|
|
22
|
+
* @returns {string|boolean} Example value appropriate for the argument type
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* generateExampleValue('name', 'model') // Returns 'MyComponent'
|
|
26
|
+
* generateExampleValue('singleton', 'model') // Returns true
|
|
27
|
+
* generateExampleValue('project', 'api:generate') // Returns 'my-ui-lib'
|
|
28
|
+
*/
|
|
29
|
+
export function generateExampleValue(argName, command) {
|
|
30
|
+
switch (argName) {
|
|
31
|
+
case "name":
|
|
32
|
+
case "componentName":
|
|
33
|
+
return command.includes("plugin") ? "MyPlugin" : "MyComponent";
|
|
34
|
+
case "modelName":
|
|
35
|
+
return "my-model";
|
|
36
|
+
case "workspaceName":
|
|
37
|
+
return "my-workspace";
|
|
38
|
+
case "project":
|
|
39
|
+
case "componentProject":
|
|
40
|
+
case "modelProject":
|
|
41
|
+
return "my-ui-lib";
|
|
42
|
+
case "registrationProject":
|
|
43
|
+
return "my-lib";
|
|
44
|
+
case "companionParent":
|
|
45
|
+
return "parent-model";
|
|
46
|
+
case "extensionPoint":
|
|
47
|
+
return "utility";
|
|
48
|
+
case "group":
|
|
49
|
+
return "appearance";
|
|
50
|
+
case "locale":
|
|
51
|
+
return "en";
|
|
52
|
+
case "container":
|
|
53
|
+
case "singleton":
|
|
54
|
+
case "parentAware":
|
|
55
|
+
case "dataServices":
|
|
56
|
+
return true;
|
|
57
|
+
case "dryRun":
|
|
58
|
+
return true;
|
|
59
|
+
default:
|
|
60
|
+
return `my-${argName}`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Filter and prioritize arguments for concise help examples.
|
|
66
|
+
*
|
|
67
|
+
* Selects the most relevant arguments to display in help examples by prioritizing:
|
|
68
|
+
* 1. Name-type arguments (name, componentName, modelName, workspaceName)
|
|
69
|
+
* 2. Project-type arguments (project, componentProject, modelProject)
|
|
70
|
+
* 3. Other non-boolean arguments (up to 2 additional)
|
|
71
|
+
*
|
|
72
|
+
* Boolean flags are excluded from this list and handled separately.
|
|
73
|
+
*
|
|
74
|
+
* @param {string[]} args - All available argument names from the generator
|
|
75
|
+
* @param {string} command - The command name for context
|
|
76
|
+
* @returns {string[]} Filtered list of most relevant arguments to show (typically 2-4 items)
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* getRelevantArgs(['name', 'project', 'singleton', 'dryRun'], 'model')
|
|
80
|
+
* // Returns ['name', 'project']
|
|
81
|
+
*/
|
|
82
|
+
export function getRelevantArgs(args, command) {
|
|
83
|
+
const relevantArgs = [];
|
|
84
|
+
|
|
85
|
+
const booleanArgs = [
|
|
86
|
+
"container",
|
|
87
|
+
"singleton",
|
|
88
|
+
"parentAware",
|
|
89
|
+
"dataServices",
|
|
90
|
+
"dryRun",
|
|
91
|
+
];
|
|
92
|
+
|
|
93
|
+
// Always prefer name-type arguments first
|
|
94
|
+
const nameArgs = [
|
|
95
|
+
"name",
|
|
96
|
+
"componentName",
|
|
97
|
+
"modelName",
|
|
98
|
+
"workspaceName",
|
|
99
|
+
].filter((arg) => args.includes(arg));
|
|
100
|
+
if (nameArgs.length > 0) {
|
|
101
|
+
relevantArgs.push(nameArgs[0]); // Take the first name argument
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Then add project-type arguments
|
|
105
|
+
const projectArgs = [
|
|
106
|
+
"project",
|
|
107
|
+
"componentProject",
|
|
108
|
+
"modelProject",
|
|
109
|
+
"registrationProject",
|
|
110
|
+
].filter((arg) => args.includes(arg));
|
|
111
|
+
if (projectArgs.length > 0) {
|
|
112
|
+
relevantArgs.push(projectArgs[0]); // Take the first project argument
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Add other specific arguments
|
|
116
|
+
const otherArgs = args.filter(
|
|
117
|
+
(arg) =>
|
|
118
|
+
!nameArgs.includes(arg) &&
|
|
119
|
+
!projectArgs.includes(arg) &&
|
|
120
|
+
!booleanArgs.includes(arg) &&
|
|
121
|
+
arg !== "interactive"
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
// Add up to 2 more relevant arguments
|
|
125
|
+
relevantArgs.push(...otherArgs.slice(0, 2));
|
|
126
|
+
|
|
127
|
+
return relevantArgs;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Generate command-line examples for a generator with proper formatting.
|
|
132
|
+
*
|
|
133
|
+
* Creates multiple example commands showing:
|
|
134
|
+
* - Basic usage with most relevant arguments
|
|
135
|
+
* - Advanced usage with boolean flags
|
|
136
|
+
* - Interactive mode invocation (both long and short form)
|
|
137
|
+
*
|
|
138
|
+
* Examples are formatted ready for terminal display with proper indentation.
|
|
139
|
+
*
|
|
140
|
+
* @param {string} command - The command name (e.g., 'model', 'api:generate')
|
|
141
|
+
* @param {Object} namedArguments - Mapping of CLI argument names to prompt names
|
|
142
|
+
* @returns {string[]} Array of formatted example command strings with leading spaces
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* generateCommandExamples('api:generate', { project: 'project', host: 'host' })
|
|
146
|
+
* // Returns:
|
|
147
|
+
* // [
|
|
148
|
+
* // ' kosui api:generate --project my-ui-lib --host http://localhost',
|
|
149
|
+
* // ' kosui api:generate --interactive # Force interactive mode',
|
|
150
|
+
* // ' kosui api:generate -i # Force interactive mode (short form)'
|
|
151
|
+
* // ]
|
|
152
|
+
*/
|
|
153
|
+
export function generateCommandExamples(command, namedArguments) {
|
|
154
|
+
if (!namedArguments) {
|
|
155
|
+
return [` kosui ${command} [options]`];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const args = Object.keys(namedArguments);
|
|
159
|
+
const examples = [];
|
|
160
|
+
|
|
161
|
+
const booleanArgs = [
|
|
162
|
+
"container",
|
|
163
|
+
"singleton",
|
|
164
|
+
"parentAware",
|
|
165
|
+
"dataServices",
|
|
166
|
+
"dryRun",
|
|
167
|
+
];
|
|
168
|
+
|
|
169
|
+
const relevantArgs = getRelevantArgs(args, command);
|
|
170
|
+
|
|
171
|
+
// Build basic example with most important arguments
|
|
172
|
+
const basicArgs = [];
|
|
173
|
+
relevantArgs.forEach((argName) => {
|
|
174
|
+
const value = generateExampleValue(argName, command);
|
|
175
|
+
basicArgs.push(`--${argName} ${value}`);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
if (basicArgs.length > 0) {
|
|
179
|
+
examples.push(` kosui ${command} ${basicArgs.join(" ")}`);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Create advanced example with boolean flags
|
|
183
|
+
const advancedBooleanArgs = [];
|
|
184
|
+
booleanArgs.forEach((argName) => {
|
|
185
|
+
if (args.includes(argName)) {
|
|
186
|
+
advancedBooleanArgs.push(`--${argName}`);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// Show advanced example with boolean flags if any exist
|
|
191
|
+
if (basicArgs.length > 0 && advancedBooleanArgs.length > 0) {
|
|
192
|
+
examples.push(
|
|
193
|
+
` kosui ${command} ${basicArgs
|
|
194
|
+
.slice(0, 2)
|
|
195
|
+
.join(" ")} ${advancedBooleanArgs.join(" ")}`
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// If no basic args, show a minimal example
|
|
200
|
+
if (basicArgs.length === 0) {
|
|
201
|
+
examples.push(` kosui ${command} [options]`);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Always show interactive mode example
|
|
205
|
+
examples.push(` kosui ${command} --interactive # Force interactive mode`);
|
|
206
|
+
examples.push(
|
|
207
|
+
` kosui ${command} -i # Force interactive mode (short form)`
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
return examples;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Display the named arguments help section to the console.
|
|
215
|
+
*
|
|
216
|
+
* Outputs a formatted table showing the mapping between CLI argument names
|
|
217
|
+
* and their corresponding prompt names in the generator schema. This helps
|
|
218
|
+
* users understand which CLI arguments map to which interactive prompts.
|
|
219
|
+
*
|
|
220
|
+
* @param {Object} namedArguments - Mapping of CLI argument names to prompt names
|
|
221
|
+
* (e.g., { 'project': 'project', 'host': 'host' })
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* displayNamedArguments({ project: 'project', host: 'host' })
|
|
225
|
+
* // Outputs:
|
|
226
|
+
* // Named Arguments:
|
|
227
|
+
* // --project Maps to prompt: project
|
|
228
|
+
* // --host Maps to prompt: host
|
|
229
|
+
*/
|
|
230
|
+
export function displayNamedArguments(namedArguments) {
|
|
231
|
+
if (!namedArguments) return;
|
|
232
|
+
|
|
233
|
+
console.log("\nNamed Arguments:");
|
|
234
|
+
Object.entries(namedArguments).forEach(([cliArg, promptName]) => {
|
|
235
|
+
console.log(` --${cliArg} Maps to prompt: ${promptName}`);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Display the examples help section to the console.
|
|
241
|
+
*
|
|
242
|
+
* Outputs formatted command-line examples showing various ways to invoke the
|
|
243
|
+
* command, including basic usage, advanced usage with boolean flags, and
|
|
244
|
+
* interactive mode shortcuts.
|
|
245
|
+
*
|
|
246
|
+
* @param {string} command - The command name (e.g., 'model', 'api:generate')
|
|
247
|
+
* @param {Object} namedArguments - Mapping of CLI argument names to prompt names
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* displayExamples('api:generate', { project: 'project', host: 'host' })
|
|
251
|
+
* // Outputs:
|
|
252
|
+
* // Examples:
|
|
253
|
+
* // kosui api:generate --project my-ui-lib --host http://localhost
|
|
254
|
+
* // kosui api:generate --interactive # Force interactive mode
|
|
255
|
+
* // kosui api:generate -i # Force interactive mode (short form)
|
|
256
|
+
*/
|
|
257
|
+
export function displayExamples(command, namedArguments) {
|
|
258
|
+
console.log("\nExamples:");
|
|
259
|
+
const examples = generateCommandExamples(command, namedArguments);
|
|
260
|
+
examples.forEach((example) => console.log(example));
|
|
261
|
+
}
|