(node: Protocol, state: GraphState, assetFilesList: string, progressInfo: string)
| 147 | * Components are self-contained UI elements driven by props |
| 148 | */ |
| 149 | export async function generateComponent(node: Protocol, state: GraphState, assetFilesList: string, progressInfo: string): Promise<void> { |
| 150 | const componentName = node.data.componentName || node.data.name || 'UnknownComponent'; |
| 151 | const componentPath = node.data.componentPath || node.data.path || ''; |
| 152 | |
| 153 | logger.printInfoLog(`${progressInfo} 📦 Generating Component: ${componentName}`); |
| 154 | |
| 155 | // Generate prompt |
| 156 | const prompt = generateComponentPrompt({ |
| 157 | componentName, |
| 158 | componentDetails: JSON.stringify(node.data), |
| 159 | styling: JSON.stringify(DEFAULT_STYLING), |
| 160 | assetFiles: assetFilesList, |
| 161 | }); |
| 162 | |
| 163 | // Call AI model |
| 164 | const code = await callModel({ |
| 165 | question: prompt, |
| 166 | imageUrls: state.figmaInfo.thumbnail, |
| 167 | }); |
| 168 | |
| 169 | // Save generated files |
| 170 | const filePath = workspaceManager.resolveAppSrc(state.workspace, workspaceManager.resolveComponentPath(componentPath)); |
| 171 | saveGeneratedCode(code, filePath); |
| 172 | logger.printSuccessLog(`Successfully generated component: ${componentName}`); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Helper function to save generated code (handles both single and multi-file output) |
no test coverage detected