MCPcopy Index your code
hub / github.com/MigoXLab/coderio / design2code

Function design2code

src/graph.ts:13–72  ·  view source on GitHub ↗
(url: string, mode?: ValidationMode)

Source from the content-addressed store, hash-verified

11import { logger } from './utils/logger';
12
13export async function design2code(url: string, mode?: ValidationMode): Promise<void> {
14 const urlInfo = parseFigmaUrl(url);
15 const threadId = urlInfo.projectName!;
16 const workspace = workspaceManager.initWorkspace(threadId);
17
18 // Initialize SqliteSaver with the database path
19 const checkpointer = initializeSqliteSaver(workspace.db);
20 const resume = await promptCheckpointChoice(checkpointer, threadId);
21
22 logger.printInfoLog(`Starting design-to-code process for: ${urlInfo.projectName}`);
23
24 // If not resuming, delete workspace and reinitialize checkpointer
25 if (resume !== true) {
26 // Preserve only the database file to avoid EBUSY error on Windows (SQLite lock)
27 workspaceManager.deleteWorkspace(workspace, [
28 'checkpoint/coderio-cli.db',
29 'checkpoint/coderio-cli.db-shm',
30 'checkpoint/coderio-cli.db-wal',
31 ]);
32 logger.printInfoLog('Starting fresh...');
33
34 // Clear existing checkpoints for this thread instead of deleting the file
35 await clearThreadCheckpoint(checkpointer, threadId);
36 } else {
37 logger.printInfoLog('Resuming from cache...');
38 }
39
40 // Compile graph with checkpointer (after potential reinitialization)
41 const graph = new StateGraph(GraphStateAnnotation)
42 .addNode(GraphNode.INITIAL, initialProject)
43 .addNode(GraphNode.PROCESS, generateProtocol)
44 .addNode(GraphNode.CODE, generateCode)
45 .addNode(GraphNode.VALIDATION, runValidation)
46 .addEdge(START, GraphNode.INITIAL)
47 .addEdge(GraphNode.INITIAL, GraphNode.PROCESS)
48 .addEdge(GraphNode.PROCESS, GraphNode.CODE)
49 .addEdge(GraphNode.CODE, GraphNode.VALIDATION)
50 .addEdge(GraphNode.VALIDATION, END)
51 .compile({ checkpointer });
52
53 const config = { configurable: { thread_id: threadId } };
54
55 // If resuming from checkpoint, pass null to let LangGraph resume from saved state
56 // Otherwise, pass initial state to start fresh
57 const validationMode: ValidationMode = mode ?? ValidationMode.Full;
58 const state =
59 resume === true
60 ? null
61 : {
62 messages: [],
63 urlInfo,
64 workspace,
65 config: {
66 validationMode,
67 },
68 };
69 await graph.invoke(state, config);
70

Callers 1

registerD2CCommandFunction · 0.90

Calls 6

parseFigmaUrlFunction · 0.90
initializeSqliteSaverFunction · 0.90
promptCheckpointChoiceFunction · 0.90
clearThreadCheckpointFunction · 0.90
initWorkspaceMethod · 0.80
deleteWorkspaceMethod · 0.80

Tested by

no test coverage detected