@kosdev-code/kos-ui-cli 2.1.23 → 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 CHANGED
@@ -1,7 +1,349 @@
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
+ - Managing workspace configurations
12
+ - Scaffolding new KOS projects
13
+
14
+ ## Installation
15
+
16
+ The CLI is installed as part of the KOS SDK workspace:
17
+
18
+ ```bash
19
+ npm install @kosdev-code/kos-ui-cli
20
+ ```
21
+
22
+ Or use directly via npx:
23
+
24
+ ```bash
25
+ npx @kosdev-code/kos-ui-cli <command>
26
+ ```
27
+
28
+ ## Quick Reference
29
+
30
+ | Command | Description | Example |
31
+ |---------|-------------|---------|
32
+ | `model` | Generate KOS models | `kosui model UserProfile` |
33
+ | `api:generate` | Generate API types from OpenAPI | `kosui api:generate --project my-app` |
34
+ | `workspace` | Workspace utilities | `kosui workspace:list-models` |
35
+
36
+ ## Commands
37
+
38
+ ### kosui api:generate
39
+
40
+ Generate TypeScript types and service wrappers from OpenAPI specifications.
41
+
42
+ Automatically creates type-safe API clients from your device's OpenAPI spec, including:
43
+ - TypeScript type definitions for all endpoints
44
+ - Service wrapper functions with proper error handling
45
+ - Full IntelliSense support for paths, parameters, and responses
46
+ - Filtered output by app namespace
47
+
48
+ #### Options
49
+
50
+ **Required:**
51
+ - `--project <name>` - Target project name (must exist in workspace)
52
+
53
+ **Optional:**
54
+ - `--host <url>` - API host URL (default: inherited from project.json or http://127.0.0.1:8081)
55
+ - `--apps <apps>` - Comma-separated app filters to include specific namespaces (e.g., 'kos,dispense')
56
+ - `--output <path>` - Output path relative to sourceRoot (default: inherited from project.json or 'utils')
57
+ - `--default-version <version>` - Default version for service exports (default: inherited from project.json)
58
+ - `--all-apps-version <version>` - Override all apps to use specific version
59
+
60
+ **Advanced:**
61
+ - `--alias <json>` - Custom export aliases as JSON (e.g., '{"kos":"KOS"}')
62
+ - `--app-version <json>` - Custom versions per app as JSON (e.g., '{"kos":"v2"}')
63
+
64
+ **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.
65
+
66
+ #### Examples
67
+
68
+ **Basic usage with project configuration:**
69
+ ```bash
70
+ kosui api:generate --project my-device-models
71
+ ```
72
+
73
+ **Override host and filter by apps:**
74
+ ```bash
75
+ kosui api:generate \
76
+ --project my-device-models \
77
+ --host http://device.local:8081 \
78
+ --apps kos,dispense
79
+ ```
80
+
81
+ **Custom output path and version:**
82
+ ```bash
83
+ kosui api:generate \
84
+ --project my-device-models \
85
+ --output api/types \
86
+ --default-version v2
87
+ ```
88
+
89
+ **Force all apps to specific version:**
90
+ ```bash
91
+ kosui api:generate \
92
+ --project my-device-models \
93
+ --all-apps-version v1
94
+ ```
95
+
96
+ #### What Gets Generated
97
+
98
+ For each app namespace (e.g., `kos`, `dispense`, `freestyle`):
99
+
100
+ 1. **Type definitions** - `utils/services/{app}/{version}/openapi.d.ts`
101
+ - TypeScript types for all endpoints
102
+ - Request/response schemas
103
+ - Path parameter types
104
+
105
+ 2. **Service wrapper** - `utils/services/{app}/{version}/service.ts`
106
+ - Typed `kosServiceRequest` decorator
107
+ - Typed API client
108
+ - Type aliases for IntelliSense
109
+
110
+ 3. **Index files**
111
+ - `utils/openapi-index.ts` - Aggregated type exports
112
+ - `utils/services-index.ts` - Aggregated service exports
113
+
114
+ **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.
115
+
116
+ #### Integration with Project Configuration
117
+
118
+ Add default configuration to your project's `project.json`:
119
+
120
+ ```json
121
+ {
122
+ "targets": {
123
+ "api": {
124
+ "executor": "nx:run-commands",
125
+ "options": {
126
+ "command": "kosui api:generate --project my-project",
127
+ "host": "http://127.0.0.1:8081",
128
+ "outputPath": "utils",
129
+ "defaultVersion": "v1",
130
+ "serviceExportAliases": {
131
+ "kos": "KOS",
132
+ "dispense": "DISPENSE"
133
+ },
134
+ "appVersions": {
135
+ "kos": "v2",
136
+ "dispense": "v1"
137
+ }
138
+ }
139
+ }
140
+ }
141
+ }
142
+ ```
143
+
144
+ Then run simply:
145
+ ```bash
146
+ npx nx run my-project:api
147
+ ```
148
+
149
+ #### Using Generated Types
150
+
151
+ ```typescript
152
+ import { kosServiceRequest, type ApiResponse } from './utils/services/kos/v1/service';
153
+ import { DependencyLifecycle } from '@kosdev-code/kos-ui-sdk';
154
+
155
+ // Path constant with type safety
156
+ const PATH_DEVICE_STATUS = '/api/kos/device/status';
157
+
158
+ // Service function with tuple-based error handling
159
+ async function getDeviceStatus(): Promise<ApiResponse<typeof PATH_DEVICE_STATUS, 'get'>> {
160
+ // ... implementation
161
+ }
162
+
163
+ // Using in a model with decorator
164
+ @kosServiceRequest({
165
+ path: PATH_DEVICE_STATUS,
166
+ method: 'get',
167
+ lifecycle: DependencyLifecycle.LOAD
168
+ })
169
+ private onDeviceStatusLoaded(ctx: ExecutionContext<typeof PATH_DEVICE_STATUS>): void {
170
+ const [error, data] = ctx.result;
171
+ if (error) {
172
+ console.error('Failed to load device status:', error);
173
+ return;
174
+ }
175
+ this.status = data.status;
176
+ }
177
+ ```
178
+
179
+ ### kosui model
180
+
181
+ Generate KOS models with proper architecture patterns.
182
+
183
+ *For detailed model generation documentation, see the KOS UI SDK documentation.*
184
+
185
+ ### kosui workspace
186
+
187
+ Workspace utilities for managing KOS projects.
188
+
189
+ *For workspace command documentation, see the KOS UI SDK documentation.*
190
+
191
+ ## Advanced Usage
192
+
193
+ ### Argument Formats
194
+
195
+ The CLI supports multiple argument formats:
196
+
197
+ **Boolean flags:**
198
+ ```bash
199
+ --singleton # true
200
+ --singleton=false # explicit false
201
+ ```
202
+
203
+ **String values:**
204
+ ```bash
205
+ --name MyModel
206
+ --name=my-model
207
+ --name="My Model"
208
+ ```
209
+
210
+ **Array values:**
211
+ ```bash
212
+ --apps kos,dispense,network
213
+ --apps=kos,dispense
214
+ ```
215
+
216
+ **JSON values:**
217
+ ```bash
218
+ --alias '{"kos":"KOS","dispense":"DISPENSE"}'
219
+ --app-version '{"kos":"v2"}'
220
+ ```
221
+
222
+ ### Help System
223
+
224
+ Get contextual help for any command:
225
+
226
+ ```bash
227
+ kosui --help # General help
228
+ kosui api:generate --help # Command-specific help
229
+ kosui model -h # Shorthand
230
+ ```
231
+
232
+ The help system shows:
233
+ - Command description and purpose
234
+ - Available options with types and defaults
235
+ - Examples for common use cases
236
+
237
+ ## Configuration
238
+
239
+ ### Project-Level Configuration
240
+
241
+ Configure defaults in your project's `project.json` to avoid repeating options:
242
+
243
+ ```json
244
+ {
245
+ "targets": {
246
+ "api": {
247
+ "executor": "nx:run-commands",
248
+ "options": {
249
+ "command": "kosui api:generate --project ${projectName}",
250
+ "host": "http://127.0.0.1:8081",
251
+ "outputPath": "utils",
252
+ "defaultVersion": "v1"
253
+ }
254
+ }
255
+ }
256
+ }
257
+ ```
258
+
259
+ Then run via Nx:
260
+ ```bash
261
+ npx nx run my-project:api
262
+ ```
263
+
264
+ CLI arguments always override project configuration.
265
+
266
+ ### Workspace-Level Configuration
267
+
268
+ For monorepo-wide settings, consider creating a shared configuration file that projects can reference.
269
+
270
+ ## Troubleshooting
271
+
272
+ ### Command Not Found
273
+
274
+ Ensure the package is installed and available in your PATH:
275
+ ```bash
276
+ npm install @kosdev-code/kos-ui-cli
277
+ # or
278
+ npm link # if developing locally
279
+ ```
280
+
281
+ ### OpenAPI Generation Fails
282
+
283
+ **Check device connectivity:**
284
+ ```bash
285
+ curl http://127.0.0.1:8081/api/kos/openapi/api
286
+ ```
287
+
288
+ **Verify project name:**
289
+ ```bash
290
+ npx nx list # List all projects
291
+ ```
292
+
293
+ **Check project.json configuration:**
294
+ - Ensure `sourceRoot` is correctly set
295
+ - Verify target configuration if using `inherit` mode
296
+
297
+ ### Generated Types Have Errors
298
+
299
+ **Regenerate with latest spec:**
300
+ ```bash
301
+ kosui api:generate --project my-project --host http://device.local:8081
302
+ ```
303
+
304
+ **Check for breaking changes in OpenAPI spec:**
305
+ - Compare previous and current OpenAPI specs
306
+ - Update service function signatures as needed
307
+
308
+ ### Version Conflicts
309
+
310
+ When working with multiple API versions:
311
+
312
+ 1. Use `--all-apps-version` to force specific version
313
+ 2. Configure `appVersions` in project.json for per-app versions
314
+ 3. Check `defaultVersion` setting for export aliases
315
+
316
+ ## Development
317
+
318
+ ### Building
319
+
320
+ ```bash
321
+ npx nx run @kosdev-code/kos-ui-cli:build
322
+ ```
323
+
324
+ ### Testing
325
+
326
+ The CLI is tested through manual integration testing:
327
+
328
+ ```bash
329
+ # Link for local development
330
+ npm link
331
+
332
+ # Test commands
333
+ kosui --help
334
+ kosui api:generate --project test-project
335
+ ```
336
+
337
+ ### Contributing
338
+
339
+ See the main [CONTRIBUTING.md](../../../CONTRIBUTING.md) for development guidelines.
340
+
341
+ ## Related Documentation
342
+
343
+ - [KOS UI SDK Documentation](../kos-ui-sdk/README.md)
344
+ - [CODING_STANDARDS.md](../../../CODING_STANDARDS.md)
345
+ - [Workspace Documentation](../../../README.md)
346
+
347
+ ## Support
348
+
349
+ 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.1.23",
3
+ "version": "2.1.26",
4
4
  "bin": {
5
5
  "kosui": "./src/lib/cli.mjs"
6
6
  },
@@ -15,13 +15,14 @@
15
15
  "plop": "^3.1.2",
16
16
  "inquirer-directory": "^2.2.0",
17
17
  "figlet": "^1.6.0",
18
- "create-nx-workspace": "18.0.3"
18
+ "create-nx-workspace": "18.0.3",
19
+ "openapi-typescript": "^7.6.1"
19
20
  },
20
21
  "module": "./src/index.js",
21
22
  "main": "./src/index.js",
22
23
  "kos": {
23
24
  "build": {
24
- "gitHash": "64690ba2c6b001f5fc83da2097ce82acd489f618"
25
+ "gitHash": "5af05d3d902c4ddbee74f34723b5acd86dfbdeb7"
25
26
  }
26
27
  },
27
28
  "publishConfig": {