kimu-cli 0.1.1 → 1.0.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +47 -2
  2. package/README.md +18 -7
  3. package/bin/kimu.js +7 -5
  4. package/dist/commands/install.d.ts +3 -0
  5. package/dist/commands/install.d.ts.map +1 -0
  6. package/dist/commands/install.js +58 -0
  7. package/dist/commands/install.js.map +1 -0
  8. package/dist/commands/list.d.ts +3 -0
  9. package/dist/commands/list.d.ts.map +1 -0
  10. package/dist/commands/list.js +167 -0
  11. package/dist/commands/list.js.map +1 -0
  12. package/dist/commands/new.d.ts +16 -0
  13. package/dist/commands/new.d.ts.map +1 -0
  14. package/dist/commands/new.js +316 -0
  15. package/dist/commands/new.js.map +1 -0
  16. package/dist/types/cli-types.d.ts +7 -0
  17. package/dist/types/cli-types.d.ts.map +1 -1
  18. package/dist/utils/module-installer.d.ts +11 -0
  19. package/dist/utils/module-installer.d.ts.map +1 -0
  20. package/dist/utils/module-installer.js +21 -0
  21. package/dist/utils/module-installer.js.map +1 -0
  22. package/dist/utils/registry.d.ts +8 -0
  23. package/dist/utils/registry.d.ts.map +1 -0
  24. package/dist/utils/registry.js +109 -0
  25. package/dist/utils/registry.js.map +1 -0
  26. package/docs/README.md +126 -0
  27. package/docs/command-kimu.md +14 -0
  28. package/docs/commands/create.md +60 -15
  29. package/docs/commands/install.md +52 -8
  30. package/docs/commands/list.md +39 -51
  31. package/docs/commands/new.md +626 -0
  32. package/docs/configuration-files.md +192 -0
  33. package/docs/getting-started.md +386 -0
  34. package/docs/index.md +57 -27
  35. package/docs/intro.md +30 -8
  36. package/docs/quick-reference.md +335 -0
  37. package/package.json +101 -101
  38. package/templates/generators/README.md +76 -0
  39. package/templates/generators/extension/config.json +45 -0
  40. package/templates/generators/extension/templates/component.ts.template +66 -0
  41. package/templates/generators/extension/templates/style.css.template +40 -0
  42. package/templates/generators/extension/templates/view.html.template +9 -0
  43. package/templates/generators/module/config.json +35 -0
  44. package/templates/generators/module/templates/README.md.template +62 -0
  45. package/templates/generators/module/templates/module.ts.template +36 -0
  46. package/templates/generators/module/templates/service.ts.template +41 -0
  47. package/docs/command-kimu-new.md +0 -207
  48. package/docs/command-kimu-old.md +0 -51
@@ -0,0 +1,626 @@
1
+ # kimu new
2
+
3
+ Create a new component from template using the extensible template-based generator system.
4
+
5
+ ## Synopsis
6
+
7
+ ```bash
8
+ kimu new <type> <name> [options]
9
+ kimu new:list
10
+ ```
11
+
12
+ ## Description
13
+
14
+ The `kimu new` command provides an extensible template-based system for generating components in your KIMU project. Similar to Angular CLI's `ng generate`, it creates components with proper structure, files, and registration.
15
+
16
+ ### Key Features
17
+
18
+ - **Template-Based System**: All generators are configured via JSON files in `templates/generators/`
19
+ - **Extensible**: Add new component types without modifying source code
20
+ - **Automatic Registration**: Components are registered in manifest/config files automatically
21
+ - **Placeholder Support**: Rich placeholder system for dynamic content generation
22
+ - **Discovery**: Automatically discovers all available generators
23
+
24
+ ## Available Generators
25
+
26
+ Use `kimu new:list` to see all available component types:
27
+
28
+ ```bash
29
+ $ kimu new:list
30
+
31
+ Available component generators:
32
+
33
+ extension Create a new KIMU extension with component, style, and view files
34
+ module Create a new KIMU module with service and documentation
35
+
36
+ Usage: kimu new <type> <name>
37
+ ```
38
+
39
+ ## Options
40
+
41
+ - `--path <path>` - Custom path for the component (overrides default from config)
42
+ - `--force` - Overwrite if component already exists
43
+ - `--no-register` - Skip registration in manifest/config files
44
+ - `--verbose` - Enable verbose output with detailed logging
45
+
46
+ ## Usage Examples
47
+
48
+ ### Create Extension
49
+
50
+ ```bash
51
+ # Basic usage
52
+ kimu new extension my-dashboard
53
+
54
+ # With custom path
55
+ kimu new extension my-dashboard --path src/custom/extensions/dashboard
56
+
57
+ # Force overwrite existing
58
+ kimu new extension my-dashboard --force
59
+
60
+ # Skip registration
61
+ kimu new extension my-dashboard --no-register
62
+
63
+ # Verbose output
64
+ kimu new extension my-dashboard --verbose
65
+ ```
66
+
67
+ **Generated structure:**
68
+ ```
69
+ src/extensions/my-dashboard/
70
+ ├── component.ts # Component logic with lifecycle methods
71
+ ├── style.css # Component styles
72
+ └── view.html # Component template
73
+ ```
74
+
75
+ **Registration:**
76
+ - Automatically adds entry to `extension-manifest.json`
77
+
78
+ ### Create Module
79
+
80
+ ```bash
81
+ # Basic usage
82
+ kimu new module analytics
83
+
84
+ # With custom path
85
+ kimu new module analytics --path src/custom/modules/analytics
86
+
87
+ # Force overwrite existing
88
+ kimu new module analytics --force
89
+
90
+ # Skip registration
91
+ kimu new module analytics --no-register
92
+ ```
93
+
94
+ **Generated structure:**
95
+ ```
96
+ src/modules/analytics/
97
+ ├── module.ts # Module class
98
+ ├── analytics-service.ts # Service implementation
99
+ └── README.md # Module documentation
100
+ ```
101
+
102
+ **Registration:**
103
+ - Automatically adds to `kimu.config.json` → `modules.installed` array
104
+
105
+ ## Placeholder System
106
+
107
+ Templates use placeholders that are automatically replaced during generation:
108
+
109
+ | Placeholder | Description | Example (for "my-component") |
110
+ |-------------|-------------|------------------------------|
111
+ | `{{name}}` | Original kebab-case name | `my-component` |
112
+ | `{{className}}` | PascalCase name | `MyComponent` |
113
+ | `{{kebabName}}` | Kebab-case (same as name) | `my-component` |
114
+ | `{{camelName}}` | camelCase name | `myComponent` |
115
+ | `{{titleName}}` | Title Case name | `My Component` |
116
+ | `{{snakeName}}` | snake_case name | `my_component` |
117
+ | `{{targetPath}}` | Full target path | `src/extensions/my-component` |
118
+
119
+ ## Creating Custom Generators
120
+
121
+ You can create your own generators by adding new folders in `templates/generators/`:
122
+
123
+ ### 1. Create Generator Directory
124
+
125
+ ```bash
126
+ templates/generators/
127
+ └── my-custom-type/
128
+ ├── config.json
129
+ └── templates/
130
+ ├── file1.template
131
+ └── file2.template
132
+ ```
133
+
134
+ ### 2. Define Configuration
135
+
136
+ Create `config.json`:
137
+
138
+ ```json
139
+ {
140
+ "name": "My Custom Type",
141
+ "description": "Create a custom component type",
142
+ "targetPath": "src/custom/{{name}}",
143
+ "files": [
144
+ {
145
+ "template": "main.ts.template",
146
+ "output": "{{name}}.ts"
147
+ },
148
+ {
149
+ "template": "config.json.template",
150
+ "output": "config.json"
151
+ }
152
+ ],
153
+ "registration": {
154
+ "enabled": true,
155
+ "file": "custom-manifest.json",
156
+ "type": "array",
157
+ "entry": {
158
+ "name": "{{name}}",
159
+ "type": "custom",
160
+ "version": "1.0.0"
161
+ }
162
+ },
163
+ "postCreate": [
164
+ "Edit {{targetPath}}/{{name}}.ts to implement your logic",
165
+ "Configure options in {{targetPath}}/config.json"
166
+ ]
167
+ }
168
+ ```
169
+
170
+ ### 3. Create Templates
171
+
172
+ Templates support full placeholder replacement:
173
+
174
+ ```typescript
175
+ // templates/my-custom-type/templates/main.ts.template
176
+ export class {{className}} {
177
+ constructor(private name: string = '{{name}}') {
178
+ console.log('{{titleName}} created');
179
+ }
180
+
181
+ public greet(): string {
182
+ return `Hello from ${this.name}`;
183
+ }
184
+ }
185
+ ```
186
+
187
+ ### 4. Use Your Generator
188
+
189
+ ```bash
190
+ kimu new my-custom-type my-example
191
+ ```
192
+
193
+ Your generator will automatically appear in `kimu new:list`.
194
+
195
+ ## Configuration Schema
196
+
197
+ ### Generator Config Structure
198
+
199
+ ```typescript
200
+ interface GeneratorConfig {
201
+ name: string; // Display name
202
+ description: string; // Brief description
203
+ targetPath: string; // Output path (supports placeholders)
204
+ files: FileConfig[]; // Template files to process
205
+ registration?: { // Optional auto-registration
206
+ enabled: boolean;
207
+ file: string; // Target config/manifest file
208
+ type: 'array' | 'object';
209
+ path?: string; // Nested path for 'object' type
210
+ entry?: any; // Template for entry (supports placeholders)
211
+ };
212
+ postCreate?: string[]; // Instructions shown after creation
213
+ }
214
+
215
+ interface FileConfig {
216
+ template: string; // Template filename
217
+ output: string; // Output filename (supports placeholders)
218
+ }
219
+ ```
220
+
221
+ ## Validation Rules
222
+
223
+ ### Component Name
224
+
225
+ - Must contain only lowercase letters, numbers, and hyphens
226
+ - Cannot start or end with a hyphen
227
+ - Pattern: `/^[a-z0-9-]+$/`
228
+
229
+ **Valid names:**
230
+ - `my-component`
231
+ - `user-dashboard`
232
+ - `analytics-v2`
233
+
234
+ **Invalid names:**
235
+ - `MyComponent` (uppercase)
236
+ - `my_component` (underscore)
237
+ - `-my-component` (starts with hyphen)
238
+ - `my-component-` (ends with hyphen)
239
+
240
+ ### Project Detection
241
+
242
+ The command must be run from a KIMU project directory (directory containing `kimu.config.json`).
243
+
244
+ ### Type Validation
245
+
246
+ Component type must be one of the discovered generators in `templates/generators/`.
247
+
248
+ ## Exit Codes
249
+
250
+ - `0` - Success
251
+ - `1` - Error (invalid type, invalid name, not in KIMU project, template error)
252
+
253
+ ## Advanced Examples
254
+
255
+ ### Batch Creation with Script
256
+
257
+ ```bash
258
+ #!/bin/bash
259
+ # Create multiple components
260
+
261
+ components=(
262
+ "user-profile"
263
+ "user-settings"
264
+ "user-dashboard"
265
+ )
266
+
267
+ for component in "${components[@]}"; do
268
+ kimu new extension "$component"
269
+ done
270
+ ```
271
+
272
+ ### Custom Path for Organization
273
+
274
+ ```bash
275
+ # Organize by feature
276
+ kimu new extension user-profile --path src/features/user/profile
277
+ kimu new extension user-settings --path src/features/user/settings
278
+
279
+ # Organize by domain
280
+ kimu new module auth --path src/domains/authentication
281
+ kimu new module storage --path src/domains/persistence
282
+ ```
283
+
284
+ ### Template Inspection
285
+
286
+ ```bash
287
+ # View generator configuration
288
+ cat templates/generators/extension/config.json
289
+
290
+ # View template content
291
+ cat templates/generators/extension/templates/component.ts.template
292
+ ```
293
+
294
+ ## Troubleshooting
295
+
296
+ ### Templates Not Found
297
+
298
+ **Error:** `Templates directory not found`
299
+
300
+ **Solution:** Ensure you're running from a directory with `templates/generators/` or the CLI is properly installed.
301
+
302
+ ### Generator Not Found
303
+
304
+ **Error:** `Invalid component type: my-type`
305
+
306
+ **Solution:** Run `kimu new:list` to see available generators. Check that `templates/generators/my-type/config.json` exists.
307
+
308
+ ### Registration Failed
309
+
310
+ **Warning:** `Registration file not found: extension-manifest.json`
311
+
312
+ **Solution:** Create the registration file or use `--no-register` flag.
313
+
314
+ ### Component Already Exists
315
+
316
+ **Error:** `Component already exists: src/extensions/my-component`
317
+
318
+ **Solution:** Use `--force` flag to overwrite or choose a different name.
319
+
320
+ ## Related Commands
321
+
322
+ - [`kimu create`](create.md) - Create a new KIMU project
323
+ - [`kimu build`](build.md) - Build your KIMU project
324
+
325
+ ## See Also
326
+
327
+ - [Quick Reference](../quick-reference.md)
328
+ - [Getting Started Guide](../getting-started.md)
329
+
330
+ Create new components from templates (extensions, modules, etc.) within a KIMU project.
331
+
332
+ ## Syntax
333
+ ```bash
334
+ kimu new <type> <name> [options]
335
+ ```
336
+
337
+ ## Arguments
338
+ - `<type>`: Type of component to create (required)
339
+ - `extension` - Create a new UI extension
340
+ - `module` - Create a new service module
341
+ - `<name>`: Name of the component (required, kebab-case recommended)
342
+
343
+ ## Options
344
+ - `--path <path>`: Custom path for the component (default: auto-detected)
345
+ - `--force`: Overwrite if component already exists
346
+ - `--no-register`: Skip registration in manifest/config files
347
+ - `--verbose`: Enable verbose output
348
+
349
+ ## Examples
350
+
351
+ ### Create a New Extension
352
+ ```bash
353
+ # Basic extension creation
354
+ kimu new extension my-feature
355
+
356
+ # With custom path
357
+ kimu new extension my-feature --path src/extensions/custom
358
+
359
+ # Force overwrite existing
360
+ kimu new extension my-feature --force
361
+
362
+ # Skip registration
363
+ kimu new extension my-feature --no-register
364
+ ```
365
+
366
+ ### Create a New Module
367
+ ```bash
368
+ # Basic module creation
369
+ kimu new module analytics
370
+
371
+ # With custom path
372
+ kimu new module analytics --path src/modules/custom
373
+
374
+ # Force overwrite
375
+ kimu new module analytics --force
376
+ ```
377
+
378
+ ## What It Creates
379
+
380
+ ### For Extensions (`kimu new extension <name>`)
381
+
382
+ Creates a complete extension structure:
383
+
384
+ ```
385
+ src/extensions/<name>/
386
+ ├── component.ts # Extension logic and lifecycle
387
+ ├── style.css # Component styles
388
+ └── view.html # HTML template
389
+ ```
390
+
391
+ **component.ts** includes:
392
+ - `@KimuComponent` decorator with metadata
393
+ - `onInit()` lifecycle hook
394
+ - `getData()` for template binding
395
+ - `onRender()` for DOM manipulation
396
+ - `onDestroy()` for cleanup
397
+ - Event handlers example
398
+
399
+ **style.css** includes:
400
+ - Base component styles
401
+ - Responsive layout
402
+ - Button styles with hover effects
403
+
404
+ **view.html** includes:
405
+ - Template structure
406
+ - Data binding examples
407
+ - Interactive elements
408
+
409
+ **Auto-registration**:
410
+ - Adds entry to `extension-manifest.json`
411
+ - Ready to load with `extensionManager.load('<name>')`
412
+
413
+ ### For Modules (`kimu new module <name>`)
414
+
415
+ Creates a complete module structure:
416
+
417
+ ```
418
+ src/modules/<name>/
419
+ ├── module.ts # Module class
420
+ ├── <name>-service.ts # Service implementation
421
+ └── README.md # Module documentation
422
+ ```
423
+
424
+ **module.ts** includes:
425
+ - Extends `KimuModule`
426
+ - `getService()` method
427
+ - `init()` and `destroy()` lifecycle hooks
428
+
429
+ **<name>-service.ts** includes:
430
+ - Service class implementation
431
+ - Singleton instance export
432
+ - Example methods
433
+ - Initialization logic
434
+
435
+ **README.md** includes:
436
+ - Usage instructions
437
+ - API documentation
438
+ - Examples
439
+
440
+ **Auto-registration**:
441
+ - Adds to `kimu.config.json` modules list
442
+ - Ready to use in your application
443
+
444
+ ## Component Naming Conventions
445
+
446
+ ### Extension Names
447
+ - Use **kebab-case**: `my-feature`, `user-dashboard`
448
+ - Will generate:
449
+ - Class name: `MyFeatureExtension`
450
+ - HTML tag: `my-feature`
451
+ - Path: `src/extensions/my-feature`
452
+
453
+ ### Module Names
454
+ - Use **kebab-case**: `analytics`, `auth-service`
455
+ - Will generate:
456
+ - Class name: `AnalyticsModule`, `AuthServiceModule`
457
+ - Service name: `analyticsService`, `authServiceService`
458
+ - Path: `src/modules/analytics`
459
+
460
+ ## Generated Code Structure
461
+
462
+ ### Extension Component Template
463
+ ```typescript
464
+ import { KimuComponent } from '../../core/kimu-component';
465
+ import { KimuComponentElement } from '../../core/kimu-component-element';
466
+
467
+ @KimuComponent({
468
+ tag: 'my-feature',
469
+ name: 'My Feature',
470
+ version: '1.0.0',
471
+ description: 'Description for my-feature extension',
472
+ author: 'Your Name',
473
+ icon: '🎨',
474
+ internal: false,
475
+ path: 'my-feature',
476
+ dependencies: []
477
+ })
478
+ export class MyFeatureExtension extends KimuComponentElement {
479
+ async onInit(): Promise<void> {
480
+ console.log('MyFeature extension initialized');
481
+ }
482
+
483
+ getData() {
484
+ return {
485
+ title: 'My Feature',
486
+ message: 'Welcome to my-feature extension!'
487
+ };
488
+ }
489
+
490
+ onRender(): void {
491
+ this.setupEventListeners();
492
+ }
493
+
494
+ private setupEventListeners(): void {
495
+ const button = this.$('#actionButton');
496
+ if (button) {
497
+ button.addEventListener('click', () => this.handleAction());
498
+ }
499
+ }
500
+
501
+ private handleAction(): void {
502
+ console.log('Action triggered');
503
+ }
504
+
505
+ onDestroy(): void {
506
+ console.log('MyFeature extension destroyed');
507
+ }
508
+ }
509
+ ```
510
+
511
+ ### Module Template
512
+ ```typescript
513
+ import { KimuModule } from '../../core/kimu-module';
514
+ import { myFeatureService } from './my-feature-service';
515
+
516
+ export default class MyFeatureModule extends KimuModule {
517
+ constructor(name = 'my-feature', version = '1.0.0', options?: any) {
518
+ super(name, version, options);
519
+ }
520
+
521
+ getService() {
522
+ return myFeatureService;
523
+ }
524
+
525
+ async init(): Promise<void> {
526
+ console.log('MyFeatureModule initialized');
527
+ }
528
+
529
+ destroy(): void {
530
+ console.log('MyFeatureModule destroyed');
531
+ }
532
+ }
533
+ ```
534
+
535
+ ## Usage After Creation
536
+
537
+ ### Using Your New Extension
538
+ ```typescript
539
+ // In src/main.ts
540
+ import { KimuExtensionManager } from './core/kimu-extension-manager';
541
+
542
+ const extensionManager = KimuExtensionManager.getInstance();
543
+ await extensionManager.init();
544
+
545
+ // Load your extension
546
+ await extensionManager.load('my-feature');
547
+ ```
548
+
549
+ ### Using Your New Module
550
+ ```typescript
551
+ // In src/main.ts
552
+ import MyFeatureModule from './modules/my-feature/module';
553
+
554
+ const myFeatureModule = new MyFeatureModule();
555
+ await myFeatureModule.init();
556
+
557
+ // Use the service
558
+ const service = myFeatureModule.getService();
559
+ service.doSomething({ data: 'value' });
560
+ ```
561
+
562
+ ## Requirements
563
+
564
+ - Must be run from the root of a KIMU project
565
+ - `kimu.config.json` must exist
566
+ - Component name must match pattern: `/^[a-z0-9-]+$/`
567
+
568
+ ## Next Steps After Creation
569
+
570
+ ### For Extensions
571
+ 1. Edit `src/extensions/<name>/component.ts` to add your logic
572
+ 2. Style your component in `src/extensions/<name>/style.css`
573
+ 3. Update the template in `src/extensions/<name>/view.html`
574
+ 4. Load it in your app with `extensionManager.load('<name>')`
575
+ 5. Test in browser at `http://localhost:5173/`
576
+
577
+ ### For Modules
578
+ 1. Edit `src/modules/<name>/module.ts` to implement module logic
579
+ 2. Create services in `src/modules/<name>/<name>-service.ts`
580
+ 3. Add tests in `src/modules/<name>/<name>.test.ts`
581
+ 4. Import and use in your application
582
+ 5. Document API in the module's README.md
583
+
584
+ ## Notes
585
+
586
+ - Component names must use lowercase letters, numbers, and hyphens only
587
+ - Extensions are automatically registered in `extension-manifest.json`
588
+ - Modules are automatically added to `kimu.config.json`
589
+ - Use `--no-register` to skip automatic registration
590
+ - Use `--force` to overwrite existing components (prompts by default)
591
+ - Generated code includes TypeScript types and JSDoc comments
592
+ - All templates follow KIMU framework best practices
593
+
594
+ ## Tips
595
+
596
+ ### Extension Development
597
+ - Keep extensions focused on a single feature
598
+ - Use dependencies for complex compositions
599
+ - Follow the KIMU component lifecycle
600
+ - Use `this.$()` for DOM queries within your extension
601
+ - Emit events for parent-child communication
602
+
603
+ ### Module Development
604
+ - Export a singleton service instance
605
+ - Keep services stateless when possible
606
+ - Document your API with TypeScript types
607
+ - Add unit tests for all public methods
608
+ - Use async/await for asynchronous operations
609
+
610
+ ## Troubleshooting
611
+
612
+ ### "Not in a KIMU project directory"
613
+ Run the command from the root of a KIMU project where `kimu.config.json` exists.
614
+
615
+ ### "Invalid component name"
616
+ Use only lowercase letters, numbers, and hyphens. Examples: `my-feature`, `user-auth`, `data-table`
617
+
618
+ ### "Component already exists"
619
+ Use `--force` to overwrite, or choose a different name.
620
+
621
+ ## See Also
622
+
623
+ - [Create Command](create.md) - Create new KIMU projects
624
+ - [Extension Development Guide](../getting-started.md#creating-extensions)
625
+ - [Module Development Guide](../intro.md#modules)
626
+ - [KIMU Component API](https://github.com/UnicoVerso/kimu-core)