MCPcopy Create free account
hub / github.com/MigoXLab/coderio / processNode

Function processNode

src/nodes/code/utils.ts:19–69  ·  view source on GitHub ↗
(state: GraphState, cache: CodeCache)

Source from the content-addressed store, hash-verified

17 * Uses post-order traversal (children first, then parent)
18 */
19export async function processNode(state: GraphState, cache: CodeCache): Promise<number> {
20 // Read asset files list once for the entire generation run
21 const assetFilesList = getAssetFilesList(state);
22
23 // Flatten tree using post-order traversal (children first, then parent)
24 const flatNodes = flattenPostOrder(state.protocol!);
25 const total = flatNodes.length;
26
27 if (total === 0) {
28 logger.printWarnLog('No components found in structure to generate.');
29 return 0;
30 }
31
32 logger.printInfoLog(`Processing ${total} nodes...`);
33
34 let processedCount = 0;
35 let skippedCount = 0;
36
37 const processSingleNode = async (currentNode: Protocol) => {
38 const componentName = currentNode.data.name || currentNode.data.componentName || 'UnknownComponent';
39 const nodeId = currentNode.id;
40
41 // Check if component is already generated
42 if (isComponentGenerated(cache, nodeId)) {
43 skippedCount++;
44 logger.printInfoLog(`[${processedCount + skippedCount}/${total}] ⏭️ Skipping (cached): ${componentName}`);
45 return;
46 }
47
48 const progressInfo = `[${++processedCount + skippedCount}/${total}]`;
49
50 const isLeaf = !currentNode.children?.length;
51 if (isLeaf) {
52 await generateComponent(currentNode, state, assetFilesList, progressInfo);
53 } else {
54 await generateFrame(currentNode, state, assetFilesList, progressInfo);
55 }
56
57 // Mark component as generated and save immediately to prevent cache loss on interruption
58 saveComponentGenerated(cache, nodeId, state.workspace);
59 };
60
61 // Process nodes with concurrency control
62 await promisePool(flatNodes, processSingleNode);
63
64 if (skippedCount > 0) {
65 logger.printInfoLog(`⏭️ Skipped ${skippedCount} cached components`);
66 }
67 logger.printSuccessLog(`Generated ${processedCount} components`);
68 return processedCount;
69}
70
71/**
72 * Flatten tree into array using post-order traversal

Callers 1

generateCodeFunction · 0.90

Calls 3

promisePoolFunction · 0.90
getAssetFilesListFunction · 0.85
flattenPostOrderFunction · 0.85

Tested by

no test coverage detected