index.ts
1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import fs from 'node:fs';
import path from 'node:path';
import { logger } from '../../utils/logger';
import { GraphState } from '../../state';
import { writeScaffold } from './scaffold';
/**
* 'initial' node: initialize the empty project scaffold.
*
* The scaffold is deterministic (React V18 + TS + Vite + TailwindCSS V4 + Less),
* so we generate it directly instead of driving an LLM agent. This is instant,
* reproducible, and keeps the model out of the critical path — the previous
* agent-based approach could hang indefinitely against some OpenAI-compatible
* endpoints (e.g. Aliyun MAAS Qwen) due to an unbounded agent loop.
*/
export const initialProject = async (state: GraphState) => {
logger.printInfoLog('Initializing project...');
const appPath = state.workspace.app;
const appName = state.urlInfo.name || 'my-app';
if (!appPath) {
throw new Error('Workspace application path is not defined.');
}
fs.mkdirSync(appPath, { recursive: true });
writeScaffold(appPath, appName);
// Validate that essential files/directories were created.
const essentialFiles = ['package.json', 'src', 'vite.config.ts', 'tsconfig.json', 'index.html', 'src/main.tsx', 'src/App.tsx'];
for (const file of essentialFiles) {
const fullPath = path.join(appPath, file);
if (!fs.existsSync(fullPath)) {
throw new Error(`Critical file/directory missing: "${file}". The project scaffolding may have failed.`);
}
}
logger.printSuccessLog(`Scaffold created at ${appPath}`);
return {};
};