index.ts
1.68 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
41
42
43
import fs from 'node:fs';
import path from 'node:path';
import { logger } from '../../utils/logger';
import { GraphState } from '../../state';
import { writeScaffold, getScaffoldEssentialFiles } from './scaffold';
import { getProjectProfile } from '../../utils/project-profile';
/**
* '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.reportPhase('初始化项目', 8);
logger.printInfoLog('正在初始化项目…');
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 });
const profile = getProjectProfile();
writeScaffold(appPath, appName, profile);
// Validate that essential files/directories were created (framework-specific).
const essentialFiles = getScaffoldEssentialFiles(profile);
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(`脚手架已生成于 ${appPath}`);
return {};
};