@specverse/engines 4.1.5 → 4.1.7

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 (122) hide show
  1. package/dist/libs/instance-factories/applications/templates/generic/backend-env-generator.js +22 -0
  2. package/dist/libs/instance-factories/applications/templates/generic/backend-package-json-generator.js +66 -0
  3. package/dist/libs/instance-factories/applications/templates/generic/backend-tsconfig-generator.js +54 -0
  4. package/dist/libs/instance-factories/applications/templates/generic/main-generator.js +290 -0
  5. package/dist/libs/instance-factories/applications/templates/react/_view-components-source.js +530 -0
  6. package/dist/libs/instance-factories/applications/templates/react/api-client-generator.js +437 -0
  7. package/dist/libs/instance-factories/applications/templates/react/api-types-generator.js +146 -0
  8. package/dist/libs/instance-factories/applications/templates/react/app-tsx-generator.js +73 -0
  9. package/dist/libs/instance-factories/applications/templates/react/env-example-generator.js +18 -0
  10. package/dist/libs/instance-factories/applications/templates/react/field-helpers-generator.js +99 -0
  11. package/dist/libs/instance-factories/applications/templates/react/gitignore-generator.js +35 -0
  12. package/dist/libs/instance-factories/applications/templates/react/index-css-generator.js +9 -0
  13. package/dist/libs/instance-factories/applications/templates/react/index-html-generator.js +23 -0
  14. package/dist/libs/instance-factories/applications/templates/react/main-tsx-generator.js +29 -0
  15. package/dist/libs/instance-factories/applications/templates/react/package-json-generator.js +49 -0
  16. package/dist/libs/instance-factories/applications/templates/react/pattern-adapter-generator.js +156 -0
  17. package/dist/libs/instance-factories/applications/templates/react/react-pattern-adapter.js +935 -0
  18. package/dist/libs/instance-factories/applications/templates/react/relationship-field-generator.js +143 -0
  19. package/dist/libs/instance-factories/applications/templates/react/runtime-app-tsx-generator.js +101 -0
  20. package/dist/libs/instance-factories/applications/templates/react/runtime-package-json-generator.js +50 -0
  21. package/dist/libs/instance-factories/applications/templates/react/tailwind-adapter-generator.js +646 -0
  22. package/dist/libs/instance-factories/applications/templates/react/tailwind-adapter-wrapper-generator.js +65 -0
  23. package/dist/libs/instance-factories/applications/templates/react/tsconfig-generator.js +28 -0
  24. package/dist/libs/instance-factories/applications/templates/react/use-api-hooks-generator.js +132 -0
  25. package/dist/libs/instance-factories/applications/templates/react/view-dashboard-generator.js +143 -0
  26. package/dist/libs/instance-factories/applications/templates/react/view-detail-generator.js +143 -0
  27. package/dist/libs/instance-factories/applications/templates/react/view-form-generator.js +355 -0
  28. package/dist/libs/instance-factories/applications/templates/react/view-list-generator.js +91 -0
  29. package/dist/libs/instance-factories/applications/templates/react/view-router-generator.js +79 -0
  30. package/dist/libs/instance-factories/applications/templates/react/vite-config-generator.js +42 -0
  31. package/dist/libs/instance-factories/cli/templates/commander/cli-bin-wrapper-generator.js +11 -0
  32. package/dist/libs/instance-factories/cli/templates/commander/cli-entry-generator.js +111 -0
  33. package/dist/libs/instance-factories/cli/templates/commander/command-generator.js +928 -0
  34. package/dist/libs/instance-factories/communication/templates/eventemitter/bus-generator.js +83 -0
  35. package/dist/libs/instance-factories/communication/templates/eventemitter/publisher-generator.js +91 -0
  36. package/dist/libs/instance-factories/communication/templates/eventemitter/subscriber-generator.js +86 -0
  37. package/dist/libs/instance-factories/controllers/templates/fastify/meta-routes-generator.js +93 -0
  38. package/dist/libs/instance-factories/controllers/templates/fastify/routes-generator.js +280 -0
  39. package/dist/libs/instance-factories/controllers/templates/fastify/server-generator.js +125 -0
  40. package/dist/libs/instance-factories/infrastructure/templates/docker-k8s/infrastructure-generator.js +25 -0
  41. package/dist/libs/instance-factories/orms/templates/prisma/schema-generator.js +371 -0
  42. package/dist/libs/instance-factories/orms/templates/prisma/services-generator.js +266 -0
  43. package/dist/libs/instance-factories/scaffolding/templates/generic/env-example-generator.js +51 -0
  44. package/dist/libs/instance-factories/scaffolding/templates/generic/env-generator.js +61 -0
  45. package/dist/libs/instance-factories/scaffolding/templates/generic/gitignore-generator.js +59 -0
  46. package/dist/libs/instance-factories/scaffolding/templates/generic/package-json-generator.js +126 -0
  47. package/dist/libs/instance-factories/scaffolding/templates/generic/readme-generator.js +159 -0
  48. package/dist/libs/instance-factories/scaffolding/templates/generic/tsconfig-generator.js +56 -0
  49. package/dist/libs/instance-factories/scaffolding/templates/generic/tsconfig-react-generator.js +37 -0
  50. package/dist/libs/instance-factories/sdks/templates/python/sdk-generator.js +29 -0
  51. package/dist/libs/instance-factories/sdks/templates/typescript/sdk-generator.js +28 -0
  52. package/dist/libs/instance-factories/services/templates/memory/generate-interpreter.js +14 -0
  53. package/dist/libs/instance-factories/services/templates/memory/step-conventions-memory.js +415 -0
  54. package/dist/libs/instance-factories/services/templates/prisma/behavior-generator.js +177 -0
  55. package/dist/libs/instance-factories/services/templates/prisma/controller-generator.js +413 -0
  56. package/dist/libs/instance-factories/services/templates/prisma/service-generator.js +243 -0
  57. package/dist/libs/instance-factories/services/templates/prisma/step-conventions.js +264 -0
  58. package/dist/libs/instance-factories/services/templates/shared-patterns.js +24 -0
  59. package/dist/libs/instance-factories/shared/path-resolver.js +59 -0
  60. package/dist/libs/instance-factories/storage/templates/mongodb/config-generator.js +13 -0
  61. package/dist/libs/instance-factories/storage/templates/mongodb/docker-generator.js +16 -0
  62. package/dist/libs/instance-factories/storage/templates/postgresql/config-generator.js +45 -0
  63. package/dist/libs/instance-factories/storage/templates/postgresql/docker-generator.js +46 -0
  64. package/dist/libs/instance-factories/storage/templates/redis/config-generator.js +14 -0
  65. package/dist/libs/instance-factories/storage/templates/redis/docker-generator.js +16 -0
  66. package/dist/libs/instance-factories/test-generation.js +145 -0
  67. package/dist/libs/instance-factories/testing/templates/vitest/tests-generator.js +30 -0
  68. package/dist/libs/instance-factories/tools/templates/mcp/mcp-server-generator.js +149 -0
  69. package/dist/libs/instance-factories/tools/templates/mcp/static/src/controllers/MCPServerController.js +232 -0
  70. package/dist/libs/instance-factories/tools/templates/mcp/static/src/events/EventEmitter.js +49 -0
  71. package/dist/libs/instance-factories/tools/templates/mcp/static/src/index.js +18 -0
  72. package/dist/libs/instance-factories/tools/templates/mcp/static/src/interfaces/ResourceProvider.js +0 -0
  73. package/dist/libs/instance-factories/tools/templates/mcp/static/src/models/LibrarySuggestion.js +97 -0
  74. package/dist/libs/instance-factories/tools/templates/mcp/static/src/models/SpecVerseResource.js +64 -0
  75. package/dist/libs/instance-factories/tools/templates/mcp/static/src/server/mcp-server.js +182 -0
  76. package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/CLIProxyService.js +1210 -0
  77. package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/EmbeddedResourcesAdapter.js +172 -0
  78. package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/EntityModuleService.js +240 -0
  79. package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/HybridResourcesProvider.js +147 -0
  80. package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/LibraryToolsService.js +281 -0
  81. package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/OrchestratorBridge.js +409 -0
  82. package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/OrchestratorToolsService.js +414 -0
  83. package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/PromptToolsService.js +467 -0
  84. package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/ResourcesProviderService.js +135 -0
  85. package/dist/libs/instance-factories/tools/templates/mcp/static/src/types/index.js +0 -0
  86. package/dist/libs/instance-factories/tools/templates/vscode/static/extension.js +965 -0
  87. package/dist/libs/instance-factories/tools/templates/vscode/vscode-extension-generator.js +238 -0
  88. package/dist/libs/instance-factories/validation/templates/zod/validation-generator.js +25 -0
  89. package/dist/libs/instance-factories/views/index.js +48 -0
  90. package/dist/libs/instance-factories/views/templates/react/adapters/antd-adapter.js +742 -0
  91. package/dist/libs/instance-factories/views/templates/react/adapters/mui-adapter.js +824 -0
  92. package/dist/libs/instance-factories/views/templates/react/adapters/shadcn-adapter.js +719 -0
  93. package/dist/libs/instance-factories/views/templates/react/app-generator.js +45 -0
  94. package/dist/libs/instance-factories/views/templates/react/components-generator.js +779 -0
  95. package/dist/libs/instance-factories/views/templates/react/forms-generator.js +285 -0
  96. package/dist/libs/instance-factories/views/templates/react/frontend-package-json-generator.js +46 -0
  97. package/dist/libs/instance-factories/views/templates/react/hooks-generator.js +111 -0
  98. package/dist/libs/instance-factories/views/templates/react/index-css-generator.js +9 -0
  99. package/dist/libs/instance-factories/views/templates/react/index-html-generator.js +23 -0
  100. package/dist/libs/instance-factories/views/templates/react/main-tsx-generator.js +21 -0
  101. package/dist/libs/instance-factories/views/templates/react/react-component-generator.js +299 -0
  102. package/dist/libs/instance-factories/views/templates/react/router-generator.js +136 -0
  103. package/dist/libs/instance-factories/views/templates/react/router-generic-generator.js +107 -0
  104. package/dist/libs/instance-factories/views/templates/react/shared-utils-generator.js +179 -0
  105. package/dist/libs/instance-factories/views/templates/react/spec-json-generator.js +7 -0
  106. package/dist/libs/instance-factories/views/templates/react/types-generator.js +56 -0
  107. package/dist/libs/instance-factories/views/templates/react/views-metadata-generator.js +27 -0
  108. package/dist/libs/instance-factories/views/templates/react/vite-config-generator.js +29 -0
  109. package/dist/libs/instance-factories/views/templates/runtime/runtime-view-renderer.js +261 -0
  110. package/dist/libs/instance-factories/views/templates/shared/adapter-types.js +34 -0
  111. package/dist/libs/instance-factories/views/templates/shared/atomic-components-registry.js +800 -0
  112. package/dist/libs/instance-factories/views/templates/shared/base-generator.js +305 -0
  113. package/dist/libs/instance-factories/views/templates/shared/component-metadata.js +517 -0
  114. package/dist/libs/instance-factories/views/templates/shared/composite-pattern-types.js +0 -0
  115. package/dist/libs/instance-factories/views/templates/shared/composite-patterns.js +445 -0
  116. package/dist/libs/instance-factories/views/templates/shared/index.js +80 -0
  117. package/dist/libs/instance-factories/views/templates/shared/pattern-validator.js +210 -0
  118. package/dist/libs/instance-factories/views/templates/shared/property-mapper.js +492 -0
  119. package/dist/libs/instance-factories/views/templates/shared/syntax-mapper.js +321 -0
  120. package/dist/realize/index.js +36 -12
  121. package/dist/realize/index.js.map +1 -1
  122. package/package.json +3 -2
@@ -0,0 +1,299 @@
1
+ import {
2
+ BaseComponentGenerator
3
+ } from "../shared/base-generator.js";
4
+ import { getSyntaxPattern } from "../shared/syntax-mapper.js";
5
+ import { extractComponentTypes } from "../shared/base-generator.js";
6
+ class ReactComponentGenerator extends BaseComponentGenerator {
7
+ reactConfig;
8
+ constructor(adapter, config) {
9
+ super(adapter, config);
10
+ this.reactConfig = config;
11
+ }
12
+ // ============================================================================
13
+ // Abstract Method Implementations
14
+ // ============================================================================
15
+ /**
16
+ * Generate React imports
17
+ */
18
+ generateImports(viewSpec) {
19
+ const imports = [];
20
+ const reactImports = this.getReactCoreImports(viewSpec);
21
+ if (reactImports) {
22
+ imports.push(reactImports);
23
+ }
24
+ const componentTypes = extractComponentTypes(viewSpec.components);
25
+ const componentImports = this.getComponentImports(componentTypes);
26
+ imports.push(...componentImports);
27
+ return imports.join("\n");
28
+ }
29
+ /**
30
+ * Generate complete React component
31
+ */
32
+ generateComponent(parts) {
33
+ const lines = [];
34
+ if (this.reactConfig.includeComments) {
35
+ lines.push(`/**`);
36
+ lines.push(` * ${parts.name} Component`);
37
+ lines.push(` * Generated by SpecVerse`);
38
+ lines.push(` */`);
39
+ lines.push("");
40
+ }
41
+ lines.push(parts.imports);
42
+ lines.push("");
43
+ const propsInterface = this.generatePropsInterface(parts.name);
44
+ if (propsInterface) {
45
+ lines.push(propsInterface);
46
+ lines.push("");
47
+ }
48
+ lines.push(this.generateComponentFunction(parts));
49
+ return lines.join("\n");
50
+ }
51
+ /**
52
+ * Generate state declarations using React hooks
53
+ */
54
+ generateState(state) {
55
+ const stateDeclarations = [];
56
+ for (const [name, def] of Object.entries(state)) {
57
+ const declaration = getSyntaxPattern("stateDeclaration", "react", {
58
+ name,
59
+ Name: this.capitalize(name),
60
+ type: def.type,
61
+ initial: JSON.stringify(def.initial)
62
+ });
63
+ if (this.reactConfig.includeComments && def.description) {
64
+ stateDeclarations.push(` // ${def.description}`);
65
+ }
66
+ stateDeclarations.push(` ${declaration}`);
67
+ }
68
+ return stateDeclarations.join("\n");
69
+ }
70
+ /**
71
+ * Generate event handlers
72
+ */
73
+ generateEvents(events) {
74
+ const eventHandlers = [];
75
+ for (const [name, def] of Object.entries(events)) {
76
+ const handler = getSyntaxPattern("eventHandler", "react", {
77
+ Name: this.capitalize(name),
78
+ params: def.params || "",
79
+ body: def.body
80
+ });
81
+ if (this.reactConfig.includeComments && def.description) {
82
+ eventHandlers.push(` // ${def.description}`);
83
+ }
84
+ eventHandlers.push(` ${handler}`);
85
+ }
86
+ return eventHandlers.join("\n\n");
87
+ }
88
+ /**
89
+ * Get file extension (.tsx for React/TypeScript)
90
+ */
91
+ getFileExtension() {
92
+ return this.reactConfig.typescript ? ".tsx" : ".jsx";
93
+ }
94
+ /**
95
+ * Get additional files (styles, types, etc.)
96
+ */
97
+ getAdditionalFiles(viewSpec) {
98
+ const files = {};
99
+ if (this.reactConfig.typescript && this.reactConfig.strictMode) {
100
+ files[`${viewSpec.name}.types.ts`] = this.generateTypesFile(viewSpec);
101
+ }
102
+ return files;
103
+ }
104
+ // ============================================================================
105
+ // React-Specific Helper Methods
106
+ // ============================================================================
107
+ /**
108
+ * Get React core imports (useState, useEffect, etc.)
109
+ */
110
+ getReactCoreImports(viewSpec) {
111
+ const hooks = [];
112
+ if (viewSpec.state && Object.keys(viewSpec.state).length > 0) {
113
+ hooks.push("useState");
114
+ }
115
+ if (this.needsUseEffect(viewSpec)) {
116
+ hooks.push("useEffect");
117
+ }
118
+ if (hooks.length > 0) {
119
+ return `import React, { ${hooks.join(", ")} } from 'react';`;
120
+ }
121
+ return `import React from 'react';`;
122
+ }
123
+ /**
124
+ * Get component library imports
125
+ */
126
+ getComponentImports(componentTypes) {
127
+ const imports = [];
128
+ const importMap = /* @__PURE__ */ new Map();
129
+ for (const type of componentTypes) {
130
+ const adapterComponent = this.adapter.components[type];
131
+ if (adapterComponent && adapterComponent.import) {
132
+ const importMatch = adapterComponent.import.match(/from ['"](.+)['"]/);
133
+ if (importMatch) {
134
+ const source = importMatch[1];
135
+ const componentMatch = adapterComponent.import.match(/import \{ (.+) \}/);
136
+ if (componentMatch) {
137
+ const componentName = componentMatch[1];
138
+ if (!importMap.has(source)) {
139
+ importMap.set(source, []);
140
+ }
141
+ importMap.get(source).push(componentName);
142
+ }
143
+ }
144
+ }
145
+ }
146
+ for (const [source, components] of importMap) {
147
+ imports.push(getSyntaxPattern("libraryImport", "react", {
148
+ exports: components.join(", "),
149
+ library: source
150
+ }));
151
+ }
152
+ return imports;
153
+ }
154
+ /**
155
+ * Generate props interface for TypeScript
156
+ */
157
+ generatePropsInterface(componentName) {
158
+ if (!this.reactConfig.typescript) {
159
+ return null;
160
+ }
161
+ const lines = [];
162
+ if (this.reactConfig.includeComments) {
163
+ lines.push(`/**`);
164
+ lines.push(` * Props for ${componentName} component`);
165
+ lines.push(` */`);
166
+ }
167
+ lines.push(`interface ${componentName}Props {`);
168
+ lines.push(` // Component props will be added here`);
169
+ lines.push(`}`);
170
+ return lines.join("\n");
171
+ }
172
+ /**
173
+ * Generate main component function
174
+ */
175
+ generateComponentFunction(parts) {
176
+ const lines = [];
177
+ const propsParam = this.reactConfig.typescript ? `props: ${parts.name}Props` : "props";
178
+ lines.push(`export function ${parts.name}(${propsParam}) {`);
179
+ if (parts.state) {
180
+ lines.push(parts.state);
181
+ lines.push("");
182
+ }
183
+ if (parts.events) {
184
+ lines.push(parts.events);
185
+ lines.push("");
186
+ }
187
+ lines.push(" return (");
188
+ lines.push(' <div className="specverse-view">');
189
+ const indentedComponents = parts.components.split("\n").map((line) => line ? ` ${line}` : "").join("\n");
190
+ lines.push(indentedComponents);
191
+ lines.push(" </div>");
192
+ lines.push(" );");
193
+ lines.push("}");
194
+ return lines.join("\n");
195
+ }
196
+ /**
197
+ * Generate separate types file
198
+ */
199
+ generateTypesFile(viewSpec) {
200
+ const lines = [];
201
+ lines.push(`/**`);
202
+ lines.push(` * Type definitions for ${viewSpec.name}`);
203
+ lines.push(` * Generated by SpecVerse`);
204
+ lines.push(` */`);
205
+ lines.push("");
206
+ if (viewSpec.state) {
207
+ lines.push(`export interface ${viewSpec.name}State {`);
208
+ for (const [name, def] of Object.entries(viewSpec.state)) {
209
+ if (def.description) {
210
+ lines.push(` /** ${def.description} */`);
211
+ }
212
+ lines.push(` ${name}: ${def.type};`);
213
+ }
214
+ lines.push(`}`);
215
+ lines.push("");
216
+ }
217
+ if (viewSpec.events) {
218
+ for (const [name, def] of Object.entries(viewSpec.events)) {
219
+ const handlerName = `${this.capitalize(name)}Handler`;
220
+ const params = def.params || "";
221
+ if (def.description) {
222
+ lines.push(`/** ${def.description} */`);
223
+ }
224
+ lines.push(`export type ${handlerName} = (${params}) => void;`);
225
+ lines.push("");
226
+ }
227
+ }
228
+ return lines.join("\n");
229
+ }
230
+ /**
231
+ * Check if component needs useEffect hook
232
+ */
233
+ needsUseEffect(viewSpec) {
234
+ if (viewSpec.events) {
235
+ const eventNames = Object.keys(viewSpec.events).map((e) => e.toLowerCase());
236
+ return eventNames.some(
237
+ (name) => name.includes("mount") || name.includes("init") || name.includes("load")
238
+ );
239
+ }
240
+ return false;
241
+ }
242
+ /**
243
+ * Capitalize first letter of string
244
+ */
245
+ capitalize(str) {
246
+ return str.charAt(0).toUpperCase() + str.slice(1);
247
+ }
248
+ // ============================================================================
249
+ // React-Specific Component Rendering
250
+ // ============================================================================
251
+ /**
252
+ * Override to add React-specific rendering hints
253
+ */
254
+ renderAdapterComponent(type, properties, children, context) {
255
+ if (!properties.className && type !== "container") {
256
+ properties.className = `specverse-${type}`;
257
+ }
258
+ return super.renderAdapterComponent(type, properties, children, context);
259
+ }
260
+ }
261
+ function createReactGenerator(adapter, config) {
262
+ const defaultConfig = {
263
+ framework: "react",
264
+ target: "shadcn",
265
+ typescript: true,
266
+ strictMode: false,
267
+ includeComments: true,
268
+ maxDepth: 3,
269
+ enableWarnings: true
270
+ };
271
+ const finalConfig = { ...defaultConfig, ...config };
272
+ return new ReactComponentGenerator(adapter, finalConfig);
273
+ }
274
+ function generateReactComponent(viewSpec, adapter, options) {
275
+ const generator = createReactGenerator(adapter, options);
276
+ const result = generator.generate(viewSpec);
277
+ if (result.warnings.length > 0) {
278
+ console.warn("Generation warnings:", result.warnings);
279
+ }
280
+ return result.code;
281
+ }
282
+ function generateReactComponentFiles(viewSpec, adapter, options) {
283
+ const generator = createReactGenerator(adapter, options);
284
+ const result = generator.generate(viewSpec);
285
+ const files = /* @__PURE__ */ new Map();
286
+ const ext = generator.getFileExtension();
287
+ files.set(`${viewSpec.name}${ext}`, result.code);
288
+ const additionalFiles = generator.getAdditionalFiles(viewSpec);
289
+ for (const [filename, content] of Object.entries(additionalFiles)) {
290
+ files.set(filename, content);
291
+ }
292
+ return files;
293
+ }
294
+ export {
295
+ ReactComponentGenerator,
296
+ createReactGenerator,
297
+ generateReactComponent,
298
+ generateReactComponentFiles
299
+ };
@@ -0,0 +1,136 @@
1
+ function generateRouter(context) {
2
+ const { spec, models = [], views = [] } = context;
3
+ const specViews = views.length > 0 ? views : spec?.views ? Object.entries(spec.views) : [];
4
+ const imports = [];
5
+ const routes = [];
6
+ routes.push(` {
7
+ path: '/',
8
+ element: <div className="home-page">
9
+ <h1>Welcome</h1>
10
+ <nav>
11
+ <ul>
12
+ ${generateHomeLinks(specViews, models)}
13
+ </ul>
14
+ </nav>
15
+ </div>
16
+ }`);
17
+ const usedPaths = /* @__PURE__ */ new Set();
18
+ specViews.forEach((viewEntry) => {
19
+ const [viewName, viewDef] = Array.isArray(viewEntry) ? viewEntry : [viewEntry.name, viewEntry];
20
+ const viewType = viewDef?.type || "list";
21
+ const model = Array.isArray(viewDef?.model) ? viewDef.model[0] : viewDef?.model;
22
+ if (!model) return;
23
+ const modelLower = model.toLowerCase();
24
+ const modelPlural = modelLower + "s";
25
+ imports.push(`import ${viewName} from './components/${viewName}';`);
26
+ const basePath = `/${modelPlural}`;
27
+ switch (viewType) {
28
+ case "list":
29
+ const listPath = usedPaths.has(basePath) ? `${basePath}/${viewName.toLowerCase().replace(/view$/, "")}` : basePath;
30
+ if (!usedPaths.has(listPath)) {
31
+ routes.push(` {
32
+ path: '${listPath}',
33
+ element: <${viewName} />
34
+ }`);
35
+ usedPaths.add(listPath);
36
+ }
37
+ break;
38
+ case "detail":
39
+ const detailPath = `${basePath}/:id`;
40
+ if (!usedPaths.has(detailPath)) {
41
+ routes.push(` {
42
+ path: '${detailPath}',
43
+ element: <${viewName} />
44
+ }`);
45
+ usedPaths.add(detailPath);
46
+ }
47
+ break;
48
+ case "form":
49
+ const newPath = `${basePath}/new`;
50
+ const editPath = `${basePath}/:id/edit`;
51
+ if (!usedPaths.has(newPath)) {
52
+ routes.push(` {
53
+ path: '${newPath}',
54
+ element: <${viewName} />
55
+ }`);
56
+ usedPaths.add(newPath);
57
+ }
58
+ if (!usedPaths.has(editPath)) {
59
+ routes.push(` {
60
+ path: '${editPath}',
61
+ element: <${viewName} />
62
+ }`);
63
+ usedPaths.add(editPath);
64
+ }
65
+ break;
66
+ case "dashboard":
67
+ const dashPath = modelLower === "author" || modelLower === "user" ? "/dashboard" : `/dashboard/${modelLower}`;
68
+ if (!usedPaths.has(dashPath)) {
69
+ routes.push(` {
70
+ path: '${dashPath}',
71
+ element: <${viewName} />
72
+ }`);
73
+ usedPaths.add(dashPath);
74
+ }
75
+ break;
76
+ }
77
+ });
78
+ return `/**
79
+ * React Router Configuration
80
+ * Auto-generated by SpecVerse
81
+ */
82
+
83
+ import { createBrowserRouter } from 'react-router-dom';
84
+ ${imports.join("\n")}
85
+
86
+ /**
87
+ * Application Router
88
+ */
89
+ export const router = createBrowserRouter([
90
+ ${routes.join(",\n")}
91
+ ]);
92
+ `;
93
+ }
94
+ function generateHomeLinks(views, models) {
95
+ const links = [];
96
+ const usedPaths = /* @__PURE__ */ new Set();
97
+ views.forEach((viewEntry) => {
98
+ const [viewName, viewDef] = Array.isArray(viewEntry) ? viewEntry : [viewEntry.name, viewEntry];
99
+ const viewType = viewDef?.type || "list";
100
+ const model = Array.isArray(viewDef?.model) ? viewDef.model[0] : viewDef?.model;
101
+ if (!model) return;
102
+ const modelLower = model.toLowerCase();
103
+ const modelPlural = modelLower + "s";
104
+ const basePath = `/${modelPlural}`;
105
+ const viewLabel = viewName.replace(/View$/, "").replace(/([A-Z])/g, " $1").trim();
106
+ switch (viewType) {
107
+ case "list":
108
+ const listPath = usedPaths.has(basePath) ? `${basePath}/${viewName.toLowerCase().replace(/view$/, "")}` : basePath;
109
+ if (!usedPaths.has(listPath)) {
110
+ links.push(` <li><a href="${listPath}">${viewLabel}</a></li>`);
111
+ usedPaths.add(listPath);
112
+ }
113
+ break;
114
+ case "form":
115
+ const formPath = `${basePath}/new`;
116
+ if (!usedPaths.has(formPath)) {
117
+ links.push(` <li><a href="${formPath}">Create ${model}</a></li>`);
118
+ usedPaths.add(formPath);
119
+ }
120
+ break;
121
+ case "dashboard":
122
+ const dashPath = modelLower === "author" || modelLower === "user" ? "/dashboard" : `/dashboard/${modelLower}`;
123
+ if (!usedPaths.has(dashPath)) {
124
+ links.push(` <li><a href="${dashPath}">${viewLabel}</a></li>`);
125
+ usedPaths.add(dashPath);
126
+ }
127
+ break;
128
+ case "detail":
129
+ break;
130
+ }
131
+ });
132
+ return links.join("\n");
133
+ }
134
+ export {
135
+ generateRouter as default
136
+ };
@@ -0,0 +1,107 @@
1
+ function generateRouter(context) {
2
+ const { spec, models = [], views = [] } = context;
3
+ const specViews = views.length > 0 ? views : spec?.views || [];
4
+ const viewsArray = Array.isArray(specViews) ? specViews : Object.values(specViews);
5
+ const modelViews = /* @__PURE__ */ new Map();
6
+ const viewImports = [];
7
+ const routeEntries = [];
8
+ viewsArray.forEach((viewDef) => {
9
+ const viewName = viewDef.name;
10
+ if (!viewName) return;
11
+ const model = Array.isArray(viewDef.model) ? viewDef.model[0] : viewDef.model;
12
+ if (!model) return;
13
+ const viewType = viewDef.type || "list";
14
+ const modelLower = model.toLowerCase();
15
+ const path = `/${modelLower}${viewType}`;
16
+ viewImports.push(`import ${viewName} from './components/${viewName}';`);
17
+ routeEntries.push(` <Route path="${path}" element={<${viewName} />} />`);
18
+ if (!modelViews.has(model)) modelViews.set(model, []);
19
+ modelViews.get(model).push({ name: viewName, type: viewType, path });
20
+ });
21
+ const appName = spec?.componentName || spec?.metadata?.component || spec?.name || "App";
22
+ const sidebarSections = Array.from(modelViews.entries()).map(([model, views2]) => {
23
+ const lower = model.toLowerCase();
24
+ const listView = views2.find((v) => v.type === "list");
25
+ const formView = views2.find((v) => v.type === "form");
26
+ const specialistViews = views2.filter((v) => !["list", "detail", "form"].includes(v.type));
27
+ const specialistLinks = specialistViews.map((v) => {
28
+ const label = v.type.charAt(0).toUpperCase() + v.type.slice(1);
29
+ const icon = v.type === "board" ? "\u25A6" : v.type === "timeline" ? "\u23F1" : v.type === "calendar" ? "\u{1F4C5}" : v.type === "dashboard" ? "\u{1F4CA}" : v.type === "analytics" ? "\u{1F4C8}" : "\u25C6";
30
+ return ` <Link to="${v.path}" className={\`flex items-center gap-2 px-2 py-1.5 rounded text-sm transition-all \${location.pathname === '${v.path}' ? 'bg-blue-50 text-blue-700 font-medium border border-blue-200' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900 border border-transparent'}\`}>
31
+ <span className="text-xs">${icon}</span> ${label}
32
+ </Link>`;
33
+ }).join("\n");
34
+ return ` {/* ${model} */}
35
+ <div>
36
+ <h3 className="px-2 text-xs font-semibold text-gray-400 uppercase tracking-wider mb-1">${model}s</h3>
37
+ <div className="space-y-0.5">
38
+ ${listView ? ` <Link to="${listView.path}" className={\`flex items-center gap-2 px-2 py-1.5 rounded text-sm transition-all \${location.pathname === '${listView.path}' ? 'bg-blue-50 text-blue-700 font-medium border border-blue-200' : 'text-gray-700 hover:bg-gray-50 border border-transparent'}\`}>
39
+ <span className="text-xs">\u2630</span> Browse
40
+ </Link>` : ""}
41
+ ${formView ? ` <Link to="${formView.path}" className={\`flex items-center gap-2 px-2 py-1.5 rounded text-sm transition-all \${location.pathname === '${formView.path}' ? 'bg-blue-50 text-blue-700 font-medium border border-blue-200' : 'text-gray-700 hover:bg-gray-50 border border-transparent'}\`}>
42
+ <span className="text-xs">\uFF0B</span> New
43
+ </Link>` : ""}
44
+ ${specialistLinks}
45
+ </div>
46
+ </div>`;
47
+ }).join("\n\n");
48
+ const firstModel = Array.from(modelViews.keys())[0]?.toLowerCase() || "unknown";
49
+ const hasDashboard = viewsArray.some((v) => v.type === "dashboard");
50
+ const defaultElement = hasDashboard ? viewsArray.find((v) => v.type === "dashboard")?.name || `${Array.from(modelViews.keys())[0]}ListView` : `${Array.from(modelViews.keys())[0] || "Unknown"}ListView`;
51
+ return `import { BrowserRouter as Router, Routes, Route, Link, useLocation } from 'react-router-dom';
52
+ ${viewImports.join("\n")}
53
+
54
+ function Sidebar() {
55
+ const location = useLocation();
56
+ return (
57
+ <aside className="w-60 bg-white border-r border-gray-200 flex flex-col">
58
+ {/* App Header */}
59
+ <div className="px-4 py-5 border-b border-gray-100">
60
+ <h1 className="text-lg font-bold text-gray-900">${appName}</h1>
61
+ <p className="text-xs text-gray-400 mt-0.5">Generated from specification</p>
62
+ </div>
63
+
64
+ {/* Navigation */}
65
+ <nav className="flex-1 overflow-y-auto px-3 py-4 space-y-5">
66
+ ${sidebarSections}
67
+ </nav>
68
+
69
+ {/* Footer */}
70
+ <div className="px-4 py-3 border-t border-gray-100 text-xs text-gray-400">
71
+ Powered by SpecVerse
72
+ </div>
73
+ </aside>
74
+ );
75
+ }
76
+
77
+ function App() {
78
+ return (
79
+ <Router>
80
+ <div className="flex h-screen bg-gray-50 overflow-hidden">
81
+ <Sidebar />
82
+ <main className="flex-1 overflow-y-auto">
83
+ <Routes>
84
+ <Route path="/" element={<${defaultElement} />} />
85
+ ${routeEntries.join("\n")}
86
+ <Route path="*" element={
87
+ <div className="flex items-center justify-center h-full">
88
+ <div className="text-center">
89
+ <h1 className="text-4xl font-bold text-gray-300 mb-2">404</h1>
90
+ <p className="text-gray-500">Page not found</p>
91
+ <Link to="/" className="mt-4 inline-block text-blue-600 hover:text-blue-700 text-sm">\u2190 Back to home</Link>
92
+ </div>
93
+ </div>
94
+ } />
95
+ </Routes>
96
+ </main>
97
+ </div>
98
+ </Router>
99
+ );
100
+ }
101
+
102
+ export default App;
103
+ `;
104
+ }
105
+ export {
106
+ generateRouter as default
107
+ };