@kosdev-code/kos-ui-cli 0.1.0-dev.5162 → 0.1.0-dev.5164

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.
@@ -1,9 +1,7 @@
1
- import devkit from "@nx/devkit";
2
- import { mkdirSync, readFileSync, writeFileSync } from "fs";
1
+ import { mkdirSync, readFileSync, writeFileSync, existsSync } from "fs";
3
2
  import openapiTS, { astToString } from "openapi-typescript";
4
3
  import { join } from "path";
5
-
6
- const { readCachedProjectGraph } = devkit;
4
+ import { getProjectDetails } from "../../../utils/nx-context.mjs";
7
5
 
8
6
  /**
9
7
  * Generate OpenAPI service types for a project
@@ -28,30 +26,39 @@ export async function generateApiTypes(options) {
28
26
  serviceExportAliases: customAliases,
29
27
  defaultVersion: customDefaultVersion,
30
28
  appVersions: customAppVersions,
29
+ allAppsVersion,
31
30
  excludeCore = false,
32
31
  } = options;
33
32
 
34
- let graph, project, host, src, outputPath, serviceExportAliases, defaultVersion, appVersions;
33
+ let projectConfig, host, src, outputPath, serviceExportAliases, defaultVersion, appVersions;
35
34
 
36
35
  try {
37
- graph = readCachedProjectGraph();
38
- project = graph.nodes[projectName];
36
+ // Read project configuration using existing CLI utility
37
+ projectConfig = await getProjectDetails(projectName);
39
38
 
40
39
  // Merge CLI options with project.json config (CLI takes precedence)
41
- host = customHost || project.data.targets.api?.options?.host || "http://127.0.0.1:8081";
42
- outputPath = customOutputPath || project.data.targets.api?.options?.outputPath;
43
- serviceExportAliases = customAliases || project.data.targets.api?.options?.serviceExportAliases || {};
44
- defaultVersion = customDefaultVersion || project.data.targets.api?.options?.defaultVersion;
45
- appVersions = customAppVersions || project.data.targets.api?.options?.appVersions || {};
46
- src = project.data.sourceRoot || project.data.root;
40
+ host = customHost || projectConfig.targets?.api?.options?.host || "http://127.0.0.1:8081";
41
+ outputPath = customOutputPath || projectConfig.targets?.api?.options?.outputPath;
42
+ serviceExportAliases = {
43
+ ...(projectConfig.targets?.api?.options?.serviceExportAliases || {}),
44
+ ...(customAliases || {})
45
+ };
46
+ defaultVersion = customDefaultVersion || projectConfig.targets?.api?.options?.defaultVersion;
47
+ appVersions = {
48
+ ...(projectConfig.targets?.api?.options?.appVersions || {}),
49
+ ...(customAppVersions || {})
50
+ };
51
+ src = projectConfig.sourceRoot || projectConfig.root;
47
52
  } catch (error) {
48
- // Fallback if project graph reading fails
49
- console.warn("Warning: Could not read project graph, using defaults");
53
+ // Fallback if project reading fails
54
+ console.warn("Warning: Could not read project configuration, using defaults");
55
+ console.warn(`Error: ${error.message}`);
50
56
  host = customHost || "http://127.0.0.1:8081";
51
57
  src = `libs/${projectName}/src`;
52
58
  serviceExportAliases = customAliases || {};
53
59
  defaultVersion = customDefaultVersion;
54
60
  appVersions = customAppVersions || {};
61
+ outputPath = customOutputPath;
55
62
  }
56
63
 
57
64
  // Use custom output path if specified, otherwise default to src/utils
@@ -196,26 +203,13 @@ export async function generateApiTypes(options) {
196
203
  },
197
204
  };
198
205
 
199
- // Determine version: use custom app version if provided, otherwise use OpenAPI spec version
200
- const version = appVersions[appName] || fullSpec.info.version || "v1";
201
- let appDir, filename, serviceFilename;
202
-
203
- if (["kos", "ext"].includes(appName) || !appName.includes(".")) {
204
- // For kos, ext, and simple names: utils/services/{appName}/{version}/
205
- appDir = join(servicesDir, appName, version);
206
- filename = "openapi.d.ts";
207
- serviceFilename = "service.ts";
208
- } else {
209
- // For app names with dots: utils/services/{appName}/
210
- // If custom version specified, use versioned folder structure
211
- if (appVersions[appName]) {
212
- appDir = join(servicesDir, appName, version);
213
- } else {
214
- appDir = join(servicesDir, appName);
215
- }
216
- filename = "openapi.d.ts";
217
- serviceFilename = "service.ts";
218
- }
206
+ // Determine version: priority order is allAppsVersion (CLI override), appVersions (per-app config), OpenAPI spec, fallback
207
+ const version = allAppsVersion || appVersions[appName] || fullSpec.info.version || "v1";
208
+
209
+ // All apps now use versioned folder structure: utils/services/{appName}/{version}/
210
+ const appDir = join(servicesDir, appName, version);
211
+ const filename = "openapi.d.ts";
212
+ const serviceFilename = "service.ts";
219
213
 
220
214
  mkdirSync(appDir, { recursive: true });
221
215
  const outFile = join(appDir, filename);
@@ -343,16 +337,11 @@ export default api;
343
337
 
344
338
  writeFileSync(serviceFile, serviceContent);
345
339
 
346
- // Store version info if it's a core service (kos, ext) or has a custom version specified
347
- const versionInfo =
348
- ["kos", "ext"].includes(appName) || !appName.includes(".") || appVersions[appName]
349
- ? version
350
- : null;
351
-
340
+ // All apps now have version info
352
341
  generatedFiles.push({
353
342
  appName,
354
343
  appDir: appDir.replace(servicesDir + "/", ""),
355
- version: versionInfo,
344
+ version: version,
356
345
  pathCount: Object.keys(appData.paths).length,
357
346
  });
358
347
  }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * CLI help display utilities
3
+ *
4
+ * High-level help display functions for the KOS CLI. Coordinates the display
5
+ * of generator-specific help and general CLI help using utilities from
6
+ * cli-help-utils.mjs.
7
+ *
8
+ * @module cli-help-display
9
+ */
10
+ import { displayExamples, displayNamedArguments } from "./cli-help-utils.mjs";
11
+
12
+ /**
13
+ * Display comprehensive help information for a specific generator.
14
+ *
15
+ * Shows the generator's name, description, named arguments mapping, and
16
+ * usage examples. This provides users with all the information needed to
17
+ * use a specific CLI command effectively.
18
+ *
19
+ * @param {string} command - The command name (e.g., 'model', 'api:generate')
20
+ * @param {Object} meta - Generator metadata from the generator's export
21
+ * @param {string} meta.name - Display name for the generator
22
+ * @param {string} meta.description - Brief description of what the generator does
23
+ * @param {Object} meta.namedArguments - Mapping of CLI args to prompt names
24
+ * @param {Object} [generator=null] - Optional plop generator object (fallback for metadata)
25
+ *
26
+ * @example
27
+ * displayGeneratorHelp('api:generate', {
28
+ * name: 'Generate OpenAPI service types',
29
+ * description: 'Generate typed service helpers from OpenAPI specifications',
30
+ * namedArguments: { project: 'project', host: 'host' }
31
+ * })
32
+ */
33
+ export function displayGeneratorHelp(command, meta, generator = null) {
34
+ console.log(`--- ${meta?.name || command} Help ---`);
35
+ console.log(
36
+ meta?.description || generator?.description || "No description available"
37
+ );
38
+
39
+ displayNamedArguments(meta?.namedArguments);
40
+ displayExamples(command, meta?.namedArguments);
41
+ }
42
+
43
+ /**
44
+ * Display general CLI help showing all available generators and global options.
45
+ *
46
+ * Outputs a comprehensive overview of the KOS CLI including:
47
+ * - List of all available generators with descriptions
48
+ * - General usage pattern
49
+ * - Global options that apply to all commands
50
+ * - Help invocation instructions
51
+ *
52
+ * This is displayed when users run `kosui --help` or `kosui` with no command.
53
+ *
54
+ * @param {Object} plop - The plop instance containing registered generators
55
+ *
56
+ * @example
57
+ * displayGeneralHelp(plopInstance)
58
+ * // Outputs:
59
+ * // --- KOS CLI Help ---
60
+ * //
61
+ * // Available Generators:
62
+ * // - model: Generate KOS models
63
+ * // - api:generate: Generate OpenAPI service types
64
+ * // ...
65
+ */
66
+ export function displayGeneralHelp(plop) {
67
+ console.warn("--- KOS CLI Help ---");
68
+ console.log("\nAvailable Generators:");
69
+ plop.getGeneratorList().forEach((g) => {
70
+ console.log(`- ${g.name}: ${g.description}`);
71
+ });
72
+
73
+ console.log("\nUsage:");
74
+ console.log(" kosui <generator> [options]");
75
+ console.log(" kosui <generator> --help # Show generator-specific help");
76
+ console.log("\nGlobal Options:");
77
+ console.log(" --no-cache Disable cache");
78
+ console.log(" --refresh Clear cache and refresh");
79
+ console.log(" --quiet Suppress banner and debug output");
80
+ console.log(
81
+ " --interactive, -i Force interactive mode (ignore provided arguments)"
82
+ );
83
+ console.log(" --help Show this help");
84
+ }
@@ -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
+ }