@kosdev-code/kos-nx-plugin 2.0.33 → 2.0.35

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 (85) hide show
  1. package/package.json +2 -2
  2. package/src/generators/kos-component/README.md +453 -0
  3. package/src/generators/kos-component/generator_refactored.d.ts +8 -0
  4. package/src/generators/kos-component/generator_refactored.d.ts.map +1 -0
  5. package/src/generators/kos-component/generator_refactored.js +96 -0
  6. package/src/generators/kos-component/generator_refactored.js.map +1 -0
  7. package/src/generators/kos-component/index.d.ts +5 -0
  8. package/src/generators/kos-component/index.d.ts.map +1 -0
  9. package/src/generators/kos-component/index.js +12 -0
  10. package/src/generators/kos-component/index.js.map +1 -0
  11. package/src/generators/kos-component/plugin-handlers/base.d.ts +47 -0
  12. package/src/generators/kos-component/plugin-handlers/base.d.ts.map +1 -0
  13. package/src/generators/kos-component/plugin-handlers/base.js +42 -0
  14. package/src/generators/kos-component/plugin-handlers/base.js.map +1 -0
  15. package/src/generators/kos-component/plugin-handlers/control-pour-handler.d.ts +9 -0
  16. package/src/generators/kos-component/plugin-handlers/control-pour-handler.d.ts.map +1 -0
  17. package/src/generators/kos-component/plugin-handlers/control-pour-handler.js +31 -0
  18. package/src/generators/kos-component/plugin-handlers/control-pour-handler.js.map +1 -0
  19. package/src/generators/kos-component/plugin-handlers/cui-handler.d.ts +9 -0
  20. package/src/generators/kos-component/plugin-handlers/cui-handler.d.ts.map +1 -0
  21. package/src/generators/kos-component/plugin-handlers/cui-handler.js +31 -0
  22. package/src/generators/kos-component/plugin-handlers/cui-handler.js.map +1 -0
  23. package/src/generators/kos-component/plugin-handlers/default-handler.d.ts +14 -0
  24. package/src/generators/kos-component/plugin-handlers/default-handler.d.ts.map +1 -0
  25. package/src/generators/kos-component/plugin-handlers/default-handler.js +37 -0
  26. package/src/generators/kos-component/plugin-handlers/default-handler.js.map +1 -0
  27. package/src/generators/kos-component/plugin-handlers/factory.d.ts +10 -0
  28. package/src/generators/kos-component/plugin-handlers/factory.d.ts.map +1 -0
  29. package/src/generators/kos-component/plugin-handlers/factory.js +42 -0
  30. package/src/generators/kos-component/plugin-handlers/factory.js.map +1 -0
  31. package/src/generators/kos-component/plugin-handlers/nav-handler.d.ts +9 -0
  32. package/src/generators/kos-component/plugin-handlers/nav-handler.d.ts.map +1 -0
  33. package/src/generators/kos-component/plugin-handlers/nav-handler.js +32 -0
  34. package/src/generators/kos-component/plugin-handlers/nav-handler.js.map +1 -0
  35. package/src/generators/kos-component/plugin-handlers/setting-handler.d.ts +9 -0
  36. package/src/generators/kos-component/plugin-handlers/setting-handler.d.ts.map +1 -0
  37. package/src/generators/kos-component/plugin-handlers/setting-handler.js +32 -0
  38. package/src/generators/kos-component/plugin-handlers/setting-handler.js.map +1 -0
  39. package/src/generators/kos-component/plugin-handlers/setup-handler.d.ts +9 -0
  40. package/src/generators/kos-component/plugin-handlers/setup-handler.d.ts.map +1 -0
  41. package/src/generators/kos-component/plugin-handlers/setup-handler.js +32 -0
  42. package/src/generators/kos-component/plugin-handlers/setup-handler.js.map +1 -0
  43. package/src/generators/kos-component/plugin-handlers/trouble-action-handler.d.ts +9 -0
  44. package/src/generators/kos-component/plugin-handlers/trouble-action-handler.d.ts.map +1 -0
  45. package/src/generators/kos-component/plugin-handlers/trouble-action-handler.js +32 -0
  46. package/src/generators/kos-component/plugin-handlers/trouble-action-handler.js.map +1 -0
  47. package/src/generators/kos-component/plugin-handlers/utility-handler.d.ts +9 -0
  48. package/src/generators/kos-component/plugin-handlers/utility-handler.d.ts.map +1 -0
  49. package/src/generators/kos-component/plugin-handlers/utility-handler.js +32 -0
  50. package/src/generators/kos-component/plugin-handlers/utility-handler.js.map +1 -0
  51. package/src/generators/kos-component/types.d.ts +53 -0
  52. package/src/generators/kos-component/types.d.ts.map +1 -0
  53. package/src/generators/kos-component/types.js +45 -0
  54. package/src/generators/kos-component/types.js.map +1 -0
  55. package/src/generators/kos-component/utils/file-generator.d.ts +7 -0
  56. package/src/generators/kos-component/utils/file-generator.d.ts.map +1 -0
  57. package/src/generators/kos-component/utils/file-generator.js +26 -0
  58. package/src/generators/kos-component/utils/file-generator.js.map +1 -0
  59. package/src/generators/kos-component/utils/kos-config-builder.d.ts +27 -0
  60. package/src/generators/kos-component/utils/kos-config-builder.d.ts.map +1 -0
  61. package/src/generators/kos-component/utils/kos-config-builder.js +82 -0
  62. package/src/generators/kos-component/utils/kos-config-builder.js.map +1 -0
  63. package/src/generators/kos-component/utils/localization.d.ts +7 -0
  64. package/src/generators/kos-component/utils/localization.d.ts.map +1 -0
  65. package/src/generators/kos-component/utils/localization.js +29 -0
  66. package/src/generators/kos-component/utils/localization.js.map +1 -0
  67. package/src/generators/kos-component/utils/validation.d.ts +18 -0
  68. package/src/generators/kos-component/utils/validation.d.ts.map +1 -0
  69. package/src/generators/kos-component/utils/validation.js +65 -0
  70. package/src/generators/kos-component/utils/validation.js.map +1 -0
  71. package/src/generators/kos-container-model/files/services/__modelNameDashCase__-services.ts.template +3 -9
  72. package/src/generators/kos-i18n-project/files/.kos.json.template +4 -1
  73. package/src/generators/kos-model/files/services/__nameDashCase__-services.ts.template +3 -9
  74. package/src/generators/kos-plugin-project/files/.kos.json.template +2 -1
  75. package/src/generators/kos-splash-project/files/project/.kos.json.template +8 -0
  76. package/src/generators/kos-theme-project/files/.kos.json.template +4 -1
  77. package/src/generators/kos-ui-project/files/.kos.json.template +4 -1
  78. package/src/generators/preset/api/utils/service.ts.template +7 -2
  79. package/src/generators/preset/files/.kos.json.template +4 -1
  80. package/src/generators/preset/generator.d.ts.map +1 -1
  81. package/src/generators/preset/generator.js +6 -0
  82. package/src/generators/preset/generator.js.map +1 -1
  83. package/src/generators/preset/model/.kos.json.template +15 -0
  84. package/src/generators/preset/model-components/.kos.json.template +8 -0
  85. package/src/generators/preset/root/.kos.json.template +10 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kosdev-code/kos-nx-plugin",
3
- "version": "2.0.33",
3
+ "version": "2.0.35",
4
4
  "type": "commonjs",
5
5
  "generators": "./generators.json",
6
6
  "publishConfig": {
@@ -19,7 +19,7 @@
19
19
  "main": "./src/index.js",
20
20
  "kos": {
21
21
  "build": {
22
- "gitHash": "f20219f379424dadeb9920b5996c2acdb8840dfa"
22
+ "gitHash": "bd22a54c89e11ae8a92541407b2bcea0ec90723b"
23
23
  }
24
24
  }
25
25
  }
@@ -0,0 +1,453 @@
1
+ # Adding New Plugin Component Types
2
+
3
+ This guide explains how to extend the KOS component generator to support new plugin types for KOS UI applications.
4
+
5
+ ## Overview
6
+
7
+ The KOS component generator uses a modular architecture where each plugin type is handled by a dedicated handler class. This makes it easy to add new plugin types without modifying the core generator logic.
8
+
9
+ ## Architecture
10
+
11
+ ```
12
+ kos-component/
13
+ ├── generator.ts # Main generator (orchestrates the process)
14
+ ├── types.ts # Type definitions and constants
15
+ ├── plugin-handlers/ # Plugin-specific logic
16
+ │ ├── base.ts # Base handler interface and common functionality
17
+ │ ├── [type]-handler.ts # Individual plugin handlers
18
+ │ └── factory.ts # Handler factory and registry
19
+ └── utils/ # Shared utilities
20
+ ├── file-generator.ts # File generation logic
21
+ ├── localization.ts # i18n updates
22
+ ├── kos-config-builder.ts # .kos.json configuration builder
23
+ └── validation.ts # Input validation
24
+ ```
25
+
26
+ ## Step-by-Step Guide
27
+
28
+ ### 1. Define Plugin Type Constants
29
+
30
+ Add your new plugin type to `types.ts`:
31
+
32
+ ```typescript
33
+ // types.ts
34
+ export const PLUGIN_TYPES = {
35
+ // ... existing types
36
+ MY_NEW_PLUGIN: 'myNewPlugin',
37
+ } as const;
38
+
39
+ export const CONTRIBUTION_TYPE_MAP: Record<string, string> = {
40
+ // ... existing mappings
41
+ [PLUGIN_TYPES.MY_NEW_PLUGIN]: 'my-new-contribution',
42
+ };
43
+
44
+ // Add to localized types if your plugin needs i18n
45
+ export const LOCALIZED_PLUGIN_TYPES: ReadonlySet<string> = new Set([
46
+ // ... existing types
47
+ PLUGIN_TYPES.MY_NEW_PLUGIN, // if localization is needed
48
+ ]);
49
+ ```
50
+
51
+ ### 2. Create Plugin Handler
52
+
53
+ Create a new handler file `plugin-handlers/my-new-plugin-handler.ts`:
54
+
55
+ ```typescript
56
+ import { NormalizedOptions, PluginConfiguration, PLUGIN_TYPES } from '../types';
57
+ import { BasePluginHandler } from './base';
58
+
59
+ export class MyNewPluginHandler extends BasePluginHandler {
60
+ protected pluginType = PLUGIN_TYPES.MY_NEW_PLUGIN;
61
+ protected contributionKey = 'my-new-contribution';
62
+ protected requiresI18n = true; // or false if no localization needed
63
+
64
+ createConfiguration(options: NormalizedOptions): PluginConfiguration {
65
+ const configPrefix = this.getConfigPrefix(options);
66
+ const experienceId = `${configPrefix}.myNewPlugin.experience`;
67
+
68
+ const contribution = {
69
+ id: `${configPrefix}.myNewPlugin`,
70
+ title: `${configPrefix}.myNewPlugin.title`,
71
+ namespace: options.appProject,
72
+ // Add plugin-specific properties here
73
+ myCustomProperty: options.nameCamelCase,
74
+ experienceId,
75
+ };
76
+
77
+ const experience = this.createExperience(options, experienceId);
78
+
79
+ return {
80
+ contributions: {
81
+ myNewContributions: [contribution], // Use appropriate contribution key
82
+ },
83
+ experiences: {
84
+ [experienceId]: experience,
85
+ },
86
+ };
87
+ }
88
+ }
89
+ ```
90
+
91
+ #### Handler Customization Options
92
+
93
+ **Override template path** if your plugin uses custom templates:
94
+ ```typescript
95
+ getTemplatePath(): string {
96
+ return 'my-custom-template-folder';
97
+ }
98
+ ```
99
+
100
+ **Custom component path** if needed:
101
+ ```typescript
102
+ protected getComponentPath(options: NormalizedOptions): string {
103
+ return `${options.appDirectory}/custom-path/${options.nameDashCase}/${options.nameDashCase}.tsx`;
104
+ }
105
+ ```
106
+
107
+ ### 3. Register Handler in Factory
108
+
109
+ Update `plugin-handlers/factory.ts`:
110
+
111
+ ```typescript
112
+ // Add import
113
+ import { MyNewPluginHandler } from './my-new-plugin-handler';
114
+
115
+ // Add to handlers map
116
+ private static handlers: Map<string, new () => PluginHandler> = new Map<
117
+ string,
118
+ new () => PluginHandler
119
+ >([
120
+ // ... existing handlers
121
+ [PLUGIN_TYPES.MY_NEW_PLUGIN, MyNewPluginHandler],
122
+ ]);
123
+ ```
124
+
125
+ ### 4. Register CLI Command (Required for kosui plugin:* syntax)
126
+
127
+ To make your plugin available via `kosui plugin:myNewPlugin`, update the CLI metadata in `/packages/sdk/kos-ui-cli/src/lib/generators/plugin/index.mjs`:
128
+
129
+ ```javascript
130
+ export const metadata = [
131
+ // ... existing metadata
132
+ {
133
+ key: "plugin:myNewPlugin",
134
+ name: "KOS UI Plugin My New Plugin",
135
+ namedArguments: {
136
+ name: "componentName",
137
+ componentName: "componentName",
138
+ project: "componentProject",
139
+ componentProject: "componentProject",
140
+ // Add any plugin-specific arguments
141
+ customOption: "customOption"
142
+ }
143
+ },
144
+ ];
145
+
146
+ // Add to pluginTypes array
147
+ const pluginTypes = [
148
+ // ... existing types
149
+ { key: "plugin:myNewPlugin", name: "myNewPlugin" },
150
+ ];
151
+ ```
152
+
153
+ **Important:** The `name` field in pluginTypes must match the `pluginType` value used in the NX generator!
154
+
155
+ ### 5. Create Template Files (Optional)
156
+
157
+ If your plugin needs custom templates, create a template directory:
158
+
159
+ ```
160
+ kos-component/
161
+ └── my-new-contribution/ # Template folder (matches contributionKey)
162
+ ├── __nameDashCase__.tsx__template__
163
+ ├── __nameDashCase__.stories.tsx__template__
164
+ ├── index.ts__template__
165
+ └── __nameDashCase__.css__template__ (optional)
166
+ ```
167
+
168
+ **Component Template** (`__nameDashCase__.tsx__template__`):
169
+ ```typescript
170
+ import React from 'react';
171
+
172
+ interface <%= namePascalCase %>Props {
173
+ // Add your plugin-specific props
174
+ }
175
+
176
+ export const <%= namePascalCase %>: React.FC<<%= namePascalCase %>Props> = (props) => {
177
+ return (
178
+ <div className="<%= nameDashCase %>">
179
+ <h2><%= namePascalCase %> Plugin</h2>
180
+ {/* Your plugin-specific UI */}
181
+ </div>
182
+ );
183
+ };
184
+
185
+ export default <%= namePascalCase %>;
186
+ ```
187
+
188
+ **Storybook Template** (`__nameDashCase__.stories.tsx__template__`):
189
+ ```typescript
190
+ /**
191
+ * Note: The plugin project Storybook configuration requires that the Studio
192
+ * Simulator is running in order to retrieve model data...
193
+ */
194
+ import { MyNewPluginStoryContainer } from "@kosdev-code/kos-ui-plugin/dev";
195
+ import type { Meta, StoryObj } from "@storybook/react";
196
+ import { <%= namePascalCase %> } from "./<%= nameDashCase %>";
197
+
198
+ const meta: Meta<typeof <%= namePascalCase %>> = {
199
+ args: {},
200
+ component: <%= namePascalCase %>,
201
+ decorators: [
202
+ (Story, context) => (
203
+ <MyNewPluginStoryContainer>
204
+ <Story args={{ ...context.args }} />
205
+ </MyNewPluginStoryContainer>
206
+ ),
207
+ ],
208
+ tags: ["!autodocs"],
209
+ title: "my-new-plugin/<%= namePascalCase %>",
210
+ };
211
+
212
+ export default meta;
213
+
214
+ type Story = StoryObj<typeof <%= namePascalCase %>>;
215
+
216
+ export const Default: Story = {
217
+ render: (props) => <<%= namePascalCase %> {...props} />,
218
+ };
219
+ ```
220
+
221
+ **Available Story Containers:**
222
+ - `CUIStoryContainer` - For CUI plugins
223
+ - `UtilityStoryContainer` - For utility plugins
224
+ - `SetupStoryContainer` - For setup plugins
225
+ - `SettingStoryContainer` - For setting plugins
226
+ - `NavStoryContainer` - For navigation plugins
227
+ - `ControlPourStoryContainer` - For control pour plugins
228
+ - `TroubleActionStoryContainer` - For trouble action plugins
229
+
230
+ ### 6. Add Schema Support (Optional)
231
+
232
+ If your plugin needs additional CLI parameters, update `schema.json`:
233
+
234
+ ```json
235
+ {
236
+ "properties": {
237
+ "myCustomOption": {
238
+ "type": "string",
239
+ "description": "Custom option for my new plugin type"
240
+ }
241
+ }
242
+ }
243
+ ```
244
+
245
+ And update `schema.d.ts`:
246
+ ```typescript
247
+ export interface KosComponentGeneratorSchema {
248
+ // ... existing properties
249
+ myCustomOption?: string;
250
+ }
251
+ ```
252
+
253
+ ### 7. Add Validation (Optional)
254
+
255
+ If your plugin has specific validation requirements, update `utils/validation.ts`:
256
+
257
+ ```typescript
258
+ export function validateOptions(
259
+ tree: Tree,
260
+ options: KosComponentGeneratorSchema
261
+ ): void {
262
+ // ... existing validation
263
+
264
+ // Add custom validation for your plugin
265
+ if (options.pluginType === 'myNewPlugin' && !options.myCustomOption) {
266
+ throw new ValidationError(
267
+ 'myCustomOption is required for myNewPlugin type'
268
+ );
269
+ }
270
+ }
271
+ ```
272
+
273
+ ## Testing Your New Plugin Type
274
+
275
+ ### 1. Build the Plugin
276
+ ```bash
277
+ nx build kos-nx-plugin
278
+ ```
279
+
280
+ ### 2. Test Generation
281
+ ```bash
282
+ # Test your new plugin type using the specific plugin generator
283
+ kosui plugin:myNewPlugin --name test-component --project my-test-project
284
+
285
+ # Or use the generic pluginComponent generator
286
+ kosui pluginComponent --name test-component --project my-test-project
287
+ # (This will prompt you to select from existing plugin types)
288
+ ```
289
+
290
+ ### 3. Verify Output
291
+ Check that the generated files include:
292
+ - Component files in the correct location (`.tsx`)
293
+ - Storybook stories (`.stories.tsx`)
294
+ - Index files (`index.ts`)
295
+ - Updated .kos.json with your contribution
296
+ - Localization entries (if applicable)
297
+ - Proper template rendering with correct variable substitution
298
+
299
+ ## Best Practices
300
+
301
+ ### 1. **Naming Conventions**
302
+ - Plugin type: `camelCase` (e.g., `myNewPlugin`)
303
+ - Contribution key: `kebab-case` (e.g., `my-new-contribution`)
304
+ - Handler class: `PascalCase` + `Handler` (e.g., `MyNewPluginHandler`)
305
+
306
+ ### 2. **Configuration Structure**
307
+ Follow existing patterns for contribution objects:
308
+ ```typescript
309
+ {
310
+ id: `${configPrefix}.${pluginType}`,
311
+ title: `${configPrefix}.${pluginType}.title`,
312
+ namespace: options.appProject,
313
+ experienceId, // if using experiences
314
+ // Plugin-specific properties
315
+ }
316
+ ```
317
+
318
+ ### 3. **Template Organization**
319
+ - Use meaningful template folder names
320
+ - Include index.ts for clean imports
321
+ - Follow existing template variable patterns
322
+
323
+ ### 4. **Documentation**
324
+ - Update CLI help text if needed
325
+ - Add examples to this README
326
+ - Document any special requirements
327
+
328
+ ## Extending Base Functionality
329
+
330
+ ### Custom Experience Creation
331
+ ```typescript
332
+ protected createExperience(
333
+ options: NormalizedOptions,
334
+ experienceId: string
335
+ ): ExperienceConfig {
336
+ const compPath = this.getCustomComponentPath(options);
337
+
338
+ return {
339
+ id: experienceId,
340
+ component: options.namePascalCase,
341
+ location: `./src/${compPath}`,
342
+ // Add custom experience properties
343
+ customProperty: 'value',
344
+ };
345
+ }
346
+ ```
347
+
348
+ ### Custom Contribution Logic
349
+ ```typescript
350
+ createConfiguration(options: NormalizedOptions): PluginConfiguration {
351
+ // Create multiple contributions if needed
352
+ const contributions = this.createMultipleContributions(options);
353
+
354
+ return {
355
+ contributions: {
356
+ contribution1: contributions.first,
357
+ contribution2: contributions.second,
358
+ },
359
+ experiences: { /* ... */ },
360
+ };
361
+ }
362
+ ```
363
+
364
+ ## Example: Complete Plugin Implementation
365
+
366
+ Here's a complete example for a "dashboard" plugin type:
367
+
368
+ ```typescript
369
+ // plugin-handlers/dashboard-handler.ts
370
+ export class DashboardPluginHandler extends BasePluginHandler {
371
+ protected pluginType = PLUGIN_TYPES.DASHBOARD;
372
+ protected contributionKey = 'dashboard';
373
+ protected requiresI18n = true;
374
+
375
+ createConfiguration(options: NormalizedOptions): PluginConfiguration {
376
+ const configPrefix = this.getConfigPrefix(options);
377
+ const experienceId = `${configPrefix}.dashboard.experience`;
378
+
379
+ const contribution = {
380
+ id: `${configPrefix}.dashboard`,
381
+ title: `${configPrefix}.dashboard.title`,
382
+ namespace: options.appProject,
383
+ dashboardType: options.nameCamelCase,
384
+ layout: 'grid', // Dashboard-specific property
385
+ experienceId,
386
+ };
387
+
388
+ const experience = this.createExperience(options, experienceId);
389
+
390
+ return {
391
+ contributions: {
392
+ dashboards: [contribution],
393
+ },
394
+ experiences: {
395
+ [experienceId]: experience,
396
+ },
397
+ };
398
+ }
399
+ }
400
+ ```
401
+
402
+ ## CLI Usage
403
+
404
+ Once implemented, your new plugin type will be available via the CLI:
405
+
406
+ ```bash
407
+ # Generate utility plugin component using specific plugin generator
408
+ kosui plugin:utility --name data-export --project admin-ui
409
+
410
+ # Generate setting plugin with additional group option
411
+ kosui plugin:setting --name user-preferences --project admin-ui --group appearance
412
+
413
+ # Generate navigation plugin
414
+ kosui plugin:nav --name system-status --project admin-ui
415
+
416
+ # Alternative: Using generic plugin component generator
417
+ kosui pluginComponent --name data-export --project admin-ui
418
+ # (Will prompt to select from: cui, setup, utility, setting, nav, controlPour)
419
+ ```
420
+
421
+ ## Troubleshooting
422
+
423
+ **Plugin not recognized:**
424
+ - Verify handler is registered in factory.ts
425
+ - Check PLUGIN_TYPES constant is exported
426
+ - Ensure plugin type matches exactly
427
+
428
+ **Template not found:**
429
+ - Check template folder name matches contributionKey
430
+ - Verify template files exist and have correct extensions
431
+ - Use `getTemplatePath()` if using custom path
432
+
433
+ **Configuration not applied:**
434
+ - Check .kos.json structure matches expected format
435
+ - Verify contribution keys are correct
436
+ - Test KosConfigBuilder logic with debug output
437
+
438
+ **Localization not working:**
439
+ - Ensure plugin type is in LOCALIZED_PLUGIN_TYPES
440
+ - Check locale file exists at expected path
441
+ - Verify updateLocalization is called for your handler
442
+
443
+ ## Contributing
444
+
445
+ When contributing new plugin types to the KOS framework:
446
+
447
+ 1. Follow this guide for implementation
448
+ 2. Add comprehensive tests
449
+ 3. Update documentation
450
+ 4. Submit PR with clear description of the plugin's purpose
451
+ 5. Include usage examples
452
+
453
+ For questions or support, refer to the KOS development team or create an issue in the project repository.
@@ -0,0 +1,8 @@
1
+ import { Tree } from "@nx/devkit";
2
+ import { KosComponentGeneratorSchema } from "./schema";
3
+ /**
4
+ * Refactored KOS Component Generator
5
+ */
6
+ export declare function kosComponentGenerator(tree: Tree, options: KosComponentGeneratorSchema): Promise<void>;
7
+ export default kosComponentGenerator;
8
+ //# sourceMappingURL=generator_refactored.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator_refactored.d.ts","sourceRoot":"","sources":["../../../../../../../packages/plugins/kos-nx-plugin/src/generators/kos-component/generator_refactored.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,IAAI,EAAE,MAAM,YAAY,CAAC;AAIzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAQvD;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,2BAA2B,iBAiCrC;AAuFD,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.kosComponentGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const path = require("path");
6
+ const project_utils_1 = require("../../utils/project-utils");
7
+ const normalize_options_1 = require("../kos-model/lib/normalize-options");
8
+ const types_1 = require("./types");
9
+ const factory_1 = require("./plugin-handlers/factory");
10
+ const file_generator_1 = require("./utils/file-generator");
11
+ const localization_1 = require("./utils/localization");
12
+ const kos_config_builder_1 = require("./utils/kos-config-builder");
13
+ const validation_1 = require("./utils/validation");
14
+ /**
15
+ * Refactored KOS Component Generator
16
+ */
17
+ async function kosComponentGenerator(tree, options) {
18
+ try {
19
+ // Step 1: Validate options
20
+ (0, validation_1.validateOptions)(tree, options);
21
+ // Step 2: Normalize options
22
+ const normalized = await prepareOptions(tree, options);
23
+ // Step 3: Get project configuration
24
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, normalized.appProject);
25
+ const projectRoot = projectConfig.sourceRoot;
26
+ if (!projectRoot) {
27
+ throw new Error(`No source root found for project ${normalized.appProject}`);
28
+ }
29
+ // Step 4: Generate component files
30
+ await generateFiles(tree, projectRoot, normalized);
31
+ // Step 5: Update plugin configuration if needed
32
+ if (options.pluginType) {
33
+ await updatePluginConfiguration(tree, projectConfig, normalized);
34
+ }
35
+ // Step 6: Format files
36
+ await (0, devkit_1.formatFiles)(tree);
37
+ }
38
+ catch (error) {
39
+ console.error("Error in kosComponentGenerator:", error);
40
+ throw error;
41
+ }
42
+ }
43
+ exports.kosComponentGenerator = kosComponentGenerator;
44
+ /**
45
+ * Prepares and normalizes options
46
+ */
47
+ async function prepareOptions(tree, options) {
48
+ const normalized = (0, normalize_options_1.normalizeOptions)(tree, {
49
+ ...options,
50
+ modelProject: "__NONE__",
51
+ });
52
+ // Get KOS configuration for component location
53
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, normalized.appProject);
54
+ const kosConfig = (0, project_utils_1.getKosProjectConfiguration)(tree, projectConfig.name);
55
+ const componentLocation = kosConfig?.generator?.defaults?.component?.folder || "";
56
+ // Set component directory and type
57
+ normalized.appDirectory = options.appDirectory || componentLocation;
58
+ normalized.type =
59
+ types_1.CONTRIBUTION_TYPE_MAP[options.pluginType || ""] || options.type;
60
+ return normalized;
61
+ }
62
+ /**
63
+ * Generates component files from templates
64
+ */
65
+ async function generateFiles(tree, projectRoot, options) {
66
+ // Get appropriate handler
67
+ const handler = factory_1.PluginHandlerFactory.createHandler(options.pluginType);
68
+ const templatePath = handler.getTemplatePath();
69
+ // Determine target path
70
+ const targetPath = path.join(projectRoot, options.appDirectory, options.type, options.nameDashCase);
71
+ // Generate files
72
+ (0, file_generator_1.generateComponentFiles)(tree, templatePath, targetPath, options);
73
+ }
74
+ /**
75
+ * Updates plugin configuration in .kos.json
76
+ */
77
+ async function updatePluginConfiguration(tree, projectConfig, options) {
78
+ const kosConfigPath = path.join(projectConfig.root, ".kos.json");
79
+ if (!tree.exists(kosConfigPath)) {
80
+ console.warn(`No .kos.json found at ${kosConfigPath}`);
81
+ return;
82
+ }
83
+ // Get handler and create configuration
84
+ const handler = factory_1.PluginHandlerFactory.createHandler(options.pluginType);
85
+ const pluginConfig = handler.createConfiguration(options);
86
+ // Update .kos.json using builder
87
+ const builder = kos_config_builder_1.KosConfigBuilder.create();
88
+ builder.addPluginConfiguration(pluginConfig);
89
+ builder.applyToFile(tree, kosConfigPath);
90
+ // Update localization if needed
91
+ if (handler.requiresLocalization() && projectConfig.sourceRoot) {
92
+ (0, localization_1.updateLocalization)(tree, projectConfig.sourceRoot, options, handler.getContributionKey());
93
+ }
94
+ }
95
+ exports.default = kosComponentGenerator;
96
+ //# sourceMappingURL=generator_refactored.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator_refactored.js","sourceRoot":"","sources":["../../../../../../../packages/plugins/kos-nx-plugin/src/generators/kos-component/generator_refactored.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,5 @@
1
+ export { kosComponentGenerator as default, kosComponentGenerator, } from "./generator_refactored";
2
+ export { PluginHandler } from "./plugin-handlers/base";
3
+ export { PluginHandlerFactory } from "./plugin-handlers/factory";
4
+ export * from "./types";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../packages/plugins/kos-nx-plugin/src/generators/kos-component/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,IAAI,OAAO,EAChC,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,cAAc,SAAS,CAAC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PluginHandlerFactory = exports.kosComponentGenerator = exports.default = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // Main export - use the refactored generator
6
+ var generator_refactored_1 = require("./generator_refactored");
7
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return generator_refactored_1.kosComponentGenerator; } });
8
+ Object.defineProperty(exports, "kosComponentGenerator", { enumerable: true, get: function () { return generator_refactored_1.kosComponentGenerator; } });
9
+ var factory_1 = require("./plugin-handlers/factory");
10
+ Object.defineProperty(exports, "PluginHandlerFactory", { enumerable: true, get: function () { return factory_1.PluginHandlerFactory; } });
11
+ tslib_1.__exportStar(require("./types"), exports);
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/plugins/kos-nx-plugin/src/generators/kos-component/index.ts"],"names":[],"mappings":";;;;AAAA,6CAA6C;AAC7C,+DAGgC;AAF9B,+GAAA,qBAAqB,OAAW;AAChC,6HAAA,qBAAqB,OAAA;AAKvB,qDAAiE;AAAxD,+GAAA,oBAAoB,OAAA;AAC7B,kDAAwB"}
@@ -0,0 +1,47 @@
1
+ import { ExperienceConfig, NormalizedOptions, PluginConfiguration } from "../types";
2
+ /**
3
+ * Base interface for plugin-specific handlers
4
+ */
5
+ export interface PluginHandler {
6
+ /**
7
+ * Creates the plugin-specific configuration
8
+ */
9
+ createConfiguration(options: NormalizedOptions): PluginConfiguration;
10
+ /**
11
+ * Returns the contribution key for this plugin type
12
+ */
13
+ getContributionKey(): string;
14
+ /**
15
+ * Checks if this plugin type requires localization
16
+ */
17
+ requiresLocalization(): boolean;
18
+ /**
19
+ * Gets the template source path for this plugin type
20
+ */
21
+ getTemplatePath(): string;
22
+ }
23
+ /**
24
+ * Base implementation with common functionality
25
+ */
26
+ export declare abstract class BasePluginHandler implements PluginHandler {
27
+ protected abstract pluginType: string;
28
+ protected abstract contributionKey: string;
29
+ protected abstract requiresI18n: boolean;
30
+ abstract createConfiguration(options: NormalizedOptions): PluginConfiguration;
31
+ getContributionKey(): string;
32
+ requiresLocalization(): boolean;
33
+ getTemplatePath(): string;
34
+ /**
35
+ * Helper to create experience configuration
36
+ */
37
+ protected createExperience(options: NormalizedOptions, experienceId: string): ExperienceConfig;
38
+ /**
39
+ * Helper to get component path
40
+ */
41
+ protected getComponentPath(options: NormalizedOptions): string;
42
+ /**
43
+ * Helper to create config prefix
44
+ */
45
+ protected getConfigPrefix(options: NormalizedOptions): string;
46
+ }
47
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/plugins/kos-nx-plugin/src/generators/kos-component/plugin-handlers/base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EAEpB,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,GAAG,mBAAmB,CAAC;IAErE;;OAEG;IACH,kBAAkB,IAAI,MAAM,CAAC;IAE7B;;OAEG;IACH,oBAAoB,IAAI,OAAO,CAAC;IAEhC;;OAEG;IACH,eAAe,IAAI,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,8BAAsB,iBAAkB,YAAW,aAAa;IAC9D,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IACtC,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAC3C,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAEzC,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,GAAG,mBAAmB;IAE7E,kBAAkB,IAAI,MAAM;IAI5B,oBAAoB,IAAI,OAAO;IAI/B,eAAe,IAAI,MAAM;IAIzB;;OAEG;IACH,SAAS,CAAC,gBAAgB,CACxB,OAAO,EAAE,iBAAiB,EAC1B,YAAY,EAAE,MAAM,GACnB,gBAAgB;IAUnB;;OAEG;IACH,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM;IAI9D;;OAEG;IACH,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM;CAG9D"}