@kosdev-code/kos-ui-cli 2.0.44 → 2.0.45

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 CHANGED
@@ -1,7 +1,484 @@
1
- # sdk-kos-ui-cli
1
+ # KOS UI CLI
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ Command-line interface for KOS workspace management and code generation.
4
4
 
5
- ## Building
5
+ ## Overview
6
6
 
7
- Run `nx build sdk-kos-ui-cli` to build the library.
7
+ The KOS UI CLI (`kosui`) provides tools for:
8
+
9
+ - Generating KOS models with proper architecture patterns
10
+ - Creating OpenAPI type definitions and service wrappers from device APIs
11
+ - Comparing API versions for breaking change detection
12
+ - Managing workspace configurations
13
+ - Scaffolding new KOS projects
14
+
15
+ ## Installation
16
+
17
+ The CLI is installed as part of the KOS SDK workspace:
18
+
19
+ ```bash
20
+ npm install @kosdev-code/kos-ui-cli
21
+ ```
22
+
23
+ Or use directly via npx:
24
+
25
+ ```bash
26
+ npx @kosdev-code/kos-ui-cli <command>
27
+ ```
28
+
29
+ ## Quick Reference
30
+
31
+ | Command | Description | Example |
32
+ |---------|-------------|---------|
33
+ | `model` | Generate KOS models | `kosui model UserProfile` |
34
+ | `api:generate` | Generate API types from OpenAPI | `kosui api:generate --project my-app` |
35
+ | `api:compare` | Compare API versions for compatibility | `kosui api:compare --project my-app --app kos --base v1.8.0 --target v1.9.0` |
36
+ | `workspace` | Workspace utilities | `kosui workspace:list-models` |
37
+
38
+ ## Commands
39
+
40
+ ### kosui api:generate
41
+
42
+ Generate TypeScript types and service wrappers from OpenAPI specifications.
43
+
44
+ Automatically creates type-safe API clients from your device's OpenAPI spec, including:
45
+ - TypeScript type definitions for all endpoints
46
+ - Service wrapper functions with proper error handling
47
+ - Full IntelliSense support for paths, parameters, and responses
48
+ - Filtered output by app namespace
49
+
50
+ #### Options
51
+
52
+ **Required:**
53
+ - `--project <name>` - Target project name (must exist in workspace)
54
+
55
+ **Optional:**
56
+ - `--host <url>` - API host URL (default: inherited from project.json or http://127.0.0.1:8081)
57
+ - `--apps <apps>` - Comma-separated app filters to include specific namespaces (e.g., 'kos,dispense')
58
+ - `--output <path>` - Output path relative to sourceRoot (default: inherited from project.json or 'utils')
59
+ - `--default-version <version>` - Default version for service exports (default: inherited from project.json)
60
+ - `--all-apps-version <version>` - Override all apps to use specific version
61
+
62
+ **Advanced:**
63
+ - `--alias <json>` - Custom export aliases as JSON (e.g., '{"kos":"KOS"}')
64
+ - `--app-version <json>` - Custom versions per app as JSON (e.g., '{"kos":"v2"}')
65
+
66
+ **Note:** Options can be configured in `project.json` under `targets.api.options` and will be inherited if not specified on command line. CLI arguments take precedence over project configuration.
67
+
68
+ #### Examples
69
+
70
+ **Basic usage with project configuration:**
71
+ ```bash
72
+ kosui api:generate --project my-device-models
73
+ ```
74
+
75
+ **Override host and filter by apps:**
76
+ ```bash
77
+ kosui api:generate \
78
+ --project my-device-models \
79
+ --host http://device.local:8081 \
80
+ --apps kos,dispense
81
+ ```
82
+
83
+ **Custom output path and version:**
84
+ ```bash
85
+ kosui api:generate \
86
+ --project my-device-models \
87
+ --output api/types \
88
+ --default-version v2
89
+ ```
90
+
91
+ **Force all apps to specific version:**
92
+ ```bash
93
+ kosui api:generate \
94
+ --project my-device-models \
95
+ --all-apps-version v1
96
+ ```
97
+
98
+ #### What Gets Generated
99
+
100
+ For each app namespace (e.g., `kos`, `dispense`, `freestyle`):
101
+
102
+ 1. **Type definitions** - `utils/services/{app}/{version}/openapi.d.ts`
103
+ - TypeScript types for all endpoints
104
+ - Request/response schemas
105
+ - Path parameter types
106
+
107
+ 2. **Service wrapper** - `utils/services/{app}/{version}/service.ts`
108
+ - Typed `kosServiceRequest` decorator
109
+ - Typed API client
110
+ - Type aliases for IntelliSense
111
+
112
+ 3. **Index files**
113
+ - `utils/openapi-index.ts` - Aggregated type exports
114
+ - `utils/services-index.ts` - Aggregated service exports
115
+
116
+ **Core SDK services** (`kos`, `vfs`, `dispense`, `freestyle`, `handle`, `kosdev.ddk`) are automatically excluded when generating for third-party projects since they're already available in published SDKs.
117
+
118
+ #### Integration with Project Configuration
119
+
120
+ Add default configuration to your project's `project.json`:
121
+
122
+ ```json
123
+ {
124
+ "targets": {
125
+ "api": {
126
+ "executor": "nx:run-commands",
127
+ "options": {
128
+ "command": "kosui api:generate --project my-project",
129
+ "host": "http://127.0.0.1:8081",
130
+ "outputPath": "utils",
131
+ "defaultVersion": "v1",
132
+ "serviceExportAliases": {
133
+ "kos": "KOS",
134
+ "dispense": "DISPENSE"
135
+ },
136
+ "appVersions": {
137
+ "kos": "v2",
138
+ "dispense": "v1"
139
+ }
140
+ }
141
+ }
142
+ }
143
+ }
144
+ ```
145
+
146
+ Then run simply:
147
+ ```bash
148
+ npx nx run my-project:api
149
+ ```
150
+
151
+ #### Using Generated Types
152
+
153
+ ```typescript
154
+ import { kosServiceRequest, type ApiResponse } from './utils/services/kos/v1/service';
155
+ import { DependencyLifecycle } from '@kosdev-code/kos-ui-sdk';
156
+
157
+ // Path constant with type safety
158
+ const PATH_DEVICE_STATUS = '/api/kos/device/status';
159
+
160
+ // Service function with tuple-based error handling
161
+ async function getDeviceStatus(): Promise<ApiResponse<typeof PATH_DEVICE_STATUS, 'get'>> {
162
+ // ... implementation
163
+ }
164
+
165
+ // Using in a model with decorator
166
+ @kosServiceRequest({
167
+ path: PATH_DEVICE_STATUS,
168
+ method: 'get',
169
+ lifecycle: DependencyLifecycle.LOAD
170
+ })
171
+ private onDeviceStatusLoaded(ctx: ExecutionContext<typeof PATH_DEVICE_STATUS>): void {
172
+ const [error, data] = ctx.result;
173
+ if (error) {
174
+ console.error('Failed to load device status:', error);
175
+ return;
176
+ }
177
+ this.status = data.status;
178
+ }
179
+ ```
180
+
181
+ ### kosui api:compare
182
+
183
+ Compare OpenAPI versions to detect breaking changes and API compatibility issues.
184
+
185
+ Analyzes two generated API type definitions to identify:
186
+ - Removed endpoints or HTTP methods
187
+ - New or removed parameters
188
+ - Parameter requirement changes
189
+ - Request body modifications
190
+
191
+ #### Prerequisites
192
+
193
+ Generate types for both versions before comparing:
194
+
195
+ ```bash
196
+ # Connect to base version device and generate types
197
+ kosui api:generate --project my-models --apps kos
198
+
199
+ # Connect to target version device and generate types
200
+ kosui api:generate --project my-models --apps kos
201
+ ```
202
+
203
+ #### Options
204
+
205
+ **Required:**
206
+ - `--project <name>` - Project containing generated API types
207
+ - `--app <name>` - App namespace to compare (kos, dispense, freestyle)
208
+ - `--base <version>` - Base version to compare from
209
+ - `--target <version>` - Target version to compare to
210
+
211
+ **Optional:**
212
+ - `--format <format>` - Output format: console (default), json, markdown
213
+ - `--output <file>` - Write output to file instead of stdout
214
+ - `--apps <apps>` - Compare multiple apps (comma-separated)
215
+
216
+ #### Examples
217
+
218
+ **Basic comparison:**
219
+ ```bash
220
+ kosui api:compare \
221
+ --project device-models \
222
+ --app kos \
223
+ --base v1.8.0 \
224
+ --target v1.9.0
225
+ ```
226
+
227
+ **Generate markdown release notes:**
228
+ ```bash
229
+ kosui api:compare \
230
+ --project device-models \
231
+ --app kos \
232
+ --base v1.8.0 \
233
+ --target v1.9.0 \
234
+ --format markdown \
235
+ --output CHANGELOG-API.md
236
+ ```
237
+
238
+ **JSON output for automation:**
239
+ ```bash
240
+ kosui api:compare \
241
+ --project device-models \
242
+ --app kos \
243
+ --base v1.8.0 \
244
+ --target v1.9.0 \
245
+ --format json
246
+ ```
247
+
248
+ **Compare multiple apps:**
249
+ ```bash
250
+ kosui api:compare \
251
+ --project device-models \
252
+ --apps kos,dispense,freestyle \
253
+ --base v1.8.0 \
254
+ --target v1.9.0
255
+ ```
256
+
257
+ #### Output Formats
258
+
259
+ **Console (default):**
260
+ - Colored terminal output with compatibility status
261
+ - Summary statistics (added/removed/modified endpoints)
262
+ - Breaking changes highlighted
263
+ - Recommendations for safe upgrade
264
+
265
+ **JSON:**
266
+ - Machine-readable format for automation
267
+ - Complete comparison data structure
268
+ - Suitable for CI/CD pipelines
269
+
270
+ **Markdown:**
271
+ - Ready for release notes and documentation
272
+ - Organized sections for breaking/non-breaking changes
273
+ - Suitable for commit messages or changelogs
274
+
275
+ #### Exit Codes
276
+
277
+ The command uses exit codes for automation:
278
+
279
+ - **Exit 0** - Versions are backward compatible
280
+ - **Exit 1** - Breaking changes detected
281
+
282
+ Example CI/CD usage:
283
+ ```bash
284
+ kosui api:compare --project models --app kos --base v1 --target v2
285
+ if [ $? -eq 0 ]; then
286
+ echo "Safe to upgrade"
287
+ else
288
+ echo "Breaking changes detected"
289
+ fi
290
+ ```
291
+
292
+ #### Integration with Build Process
293
+
294
+ Add comparison target to `project.json`:
295
+
296
+ ```json
297
+ {
298
+ "targets": {
299
+ "api:compare": {
300
+ "executor": "nx:run-commands",
301
+ "options": {
302
+ "command": "kosui api:compare --project device-models --app kos --base ${BASE} --target ${TARGET}"
303
+ }
304
+ }
305
+ }
306
+ }
307
+ ```
308
+
309
+ Run via Nx:
310
+ ```bash
311
+ BASE=v1.8.0 TARGET=v1.9.0 npx nx run device-models:api:compare
312
+ ```
313
+
314
+ ### kosui model
315
+
316
+ Generate KOS models with proper architecture patterns.
317
+
318
+ *For detailed model generation documentation, see the KOS UI SDK documentation.*
319
+
320
+ ### kosui workspace
321
+
322
+ Workspace utilities for managing KOS projects.
323
+
324
+ *For workspace command documentation, see the KOS UI SDK documentation.*
325
+
326
+ ## Advanced Usage
327
+
328
+ ### Argument Formats
329
+
330
+ The CLI supports multiple argument formats:
331
+
332
+ **Boolean flags:**
333
+ ```bash
334
+ --singleton # true
335
+ --singleton=false # explicit false
336
+ ```
337
+
338
+ **String values:**
339
+ ```bash
340
+ --name MyModel
341
+ --name=my-model
342
+ --name="My Model"
343
+ ```
344
+
345
+ **Array values:**
346
+ ```bash
347
+ --apps kos,dispense,network
348
+ --apps=kos,dispense
349
+ ```
350
+
351
+ **JSON values:**
352
+ ```bash
353
+ --alias '{"kos":"KOS","dispense":"DISPENSE"}'
354
+ --app-version '{"kos":"v2"}'
355
+ ```
356
+
357
+ ### Help System
358
+
359
+ Get contextual help for any command:
360
+
361
+ ```bash
362
+ kosui --help # General help
363
+ kosui api:generate --help # Command-specific help
364
+ kosui model -h # Shorthand
365
+ ```
366
+
367
+ The help system shows:
368
+ - Command description and purpose
369
+ - Available options with types and defaults
370
+ - Examples for common use cases
371
+
372
+ ## Configuration
373
+
374
+ ### Project-Level Configuration
375
+
376
+ Configure defaults in your project's `project.json` to avoid repeating options:
377
+
378
+ ```json
379
+ {
380
+ "targets": {
381
+ "api": {
382
+ "executor": "nx:run-commands",
383
+ "options": {
384
+ "command": "kosui api:generate --project ${projectName}",
385
+ "host": "http://127.0.0.1:8081",
386
+ "outputPath": "utils",
387
+ "defaultVersion": "v1"
388
+ }
389
+ }
390
+ }
391
+ }
392
+ ```
393
+
394
+ Then run via Nx:
395
+ ```bash
396
+ npx nx run my-project:api
397
+ ```
398
+
399
+ CLI arguments always override project configuration.
400
+
401
+ ### Workspace-Level Configuration
402
+
403
+ For monorepo-wide settings, consider creating a shared configuration file that projects can reference.
404
+
405
+ ## Troubleshooting
406
+
407
+ ### Command Not Found
408
+
409
+ Ensure the package is installed and available in your PATH:
410
+ ```bash
411
+ npm install @kosdev-code/kos-ui-cli
412
+ # or
413
+ npm link # if developing locally
414
+ ```
415
+
416
+ ### OpenAPI Generation Fails
417
+
418
+ **Check device connectivity:**
419
+ ```bash
420
+ curl http://127.0.0.1:8081/api/kos/openapi/api
421
+ ```
422
+
423
+ **Verify project name:**
424
+ ```bash
425
+ npx nx list # List all projects
426
+ ```
427
+
428
+ **Check project.json configuration:**
429
+ - Ensure `sourceRoot` is correctly set
430
+ - Verify target configuration if using `inherit` mode
431
+
432
+ ### Generated Types Have Errors
433
+
434
+ **Regenerate with latest spec:**
435
+ ```bash
436
+ kosui api:generate --project my-project --host http://device.local:8081
437
+ ```
438
+
439
+ **Check for breaking changes in OpenAPI spec:**
440
+ - Compare previous and current OpenAPI specs
441
+ - Update service function signatures as needed
442
+
443
+ ### Version Conflicts
444
+
445
+ When working with multiple API versions:
446
+
447
+ 1. Use `--all-apps-version` to force specific version
448
+ 2. Configure `appVersions` in project.json for per-app versions
449
+ 3. Check `defaultVersion` setting for export aliases
450
+
451
+ ## Development
452
+
453
+ ### Building
454
+
455
+ ```bash
456
+ npx nx run @kosdev-code/kos-ui-cli:build
457
+ ```
458
+
459
+ ### Testing
460
+
461
+ The CLI is tested through manual integration testing:
462
+
463
+ ```bash
464
+ # Link for local development
465
+ npm link
466
+
467
+ # Test commands
468
+ kosui --help
469
+ kosui api:generate --project test-project
470
+ ```
471
+
472
+ ### Contributing
473
+
474
+ See the main [CONTRIBUTING.md](../../../CONTRIBUTING.md) for development guidelines.
475
+
476
+ ## Related Documentation
477
+
478
+ - [KOS UI SDK Documentation](../kos-ui-sdk/README.md)
479
+ - [CODING_STANDARDS.md](../../../CODING_STANDARDS.md)
480
+ - [Workspace Documentation](../../../README.md)
481
+
482
+ ## Support
483
+
484
+ For issues, questions, or feature requests, please refer to the main KOS monorepo documentation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kosdev-code/kos-ui-cli",
3
- "version": "2.0.44",
3
+ "version": "2.0.45",
4
4
  "bin": {
5
5
  "kosui": "./src/lib/cli.mjs"
6
6
  },
@@ -9,18 +9,20 @@
9
9
  ],
10
10
  "type": "module",
11
11
  "dependencies": {
12
+ "chalk": "^5.3.0",
12
13
  "prettier": "^2.6.2",
13
14
  "rimraf": "^5.0.1",
14
15
  "plop": "^3.1.2",
15
16
  "inquirer-directory": "^2.2.0",
16
17
  "figlet": "^1.6.0",
17
- "create-nx-workspace": "18.0.3"
18
+ "create-nx-workspace": "18.0.3",
19
+ "openapi-typescript": "^7.6.1"
18
20
  },
19
21
  "module": "./src/index.js",
20
22
  "main": "./src/index.js",
21
23
  "kos": {
22
24
  "build": {
23
- "gitHash": "898d506eb3c4558ff600ee7c2f062fa286b617e6"
25
+ "gitHash": "7e66917455c898a3f35128681c753862339b5fe3"
24
26
  }
25
27
  },
26
28
  "publishConfig": {