(state: GraphState)
| 8 | * Generates React components from the page structure tree |
| 9 | */ |
| 10 | export async function generateCode(state: GraphState) { |
| 11 | try { |
| 12 | logger.printInfoLog('🚀 Starting Code Generation...'); |
| 13 | |
| 14 | // Validate required state fields |
| 15 | if (!state.protocol) { |
| 16 | throw new Error('No protocol data found'); |
| 17 | } |
| 18 | |
| 19 | // Load code cache |
| 20 | const cache = loadCodeCache(state.workspace); |
| 21 | |
| 22 | // Process the entire node tree (cache is saved incrementally after each component) |
| 23 | const totalComponents = await processNode(state, cache); |
| 24 | |
| 25 | // Inject root component to App.tsx (cache is saved after injection) |
| 26 | await injectRootComponentToApp(state, cache); |
| 27 | |
| 28 | logger.printSuccessLog(`✨ Code generation completed! Generated ${totalComponents} components`); |
| 29 | } catch (error) { |
| 30 | const errorMessage = error instanceof Error ? error.message : String(error); |
| 31 | throw new Error(`Code generation failed: ${errorMessage}`); |
| 32 | } |
| 33 | } |
no test coverage detected