website-builde / lib /file-parser.ts
Daviddolor's picture
Single-process Chromium, fixed visual-polish prompt, Docker config for HF Space
ec675f2
Raw
History Blame Contribute Delete
609 Bytes
export interface GeneratedFile {
path: string;
content: string;
}
// Parses model output formatted as:
// ### FILE: app/page.tsx
// ```tsx
// ...content...
// ```
export function parseGeneratedFiles(raw: string): GeneratedFile[] {
const files: GeneratedFile[] = [];
const fileBlockRegex = /### FILE:\s*(.+?)\s*\n```[a-zA-Z]*\n([\s\S]*?)```/g;
let match: RegExpExecArray | null;
while ((match = fileBlockRegex.exec(raw)) !== null) {
const filePath = match[1].trim();
const content = match[2].replace(/\s+$/, "") + "\n";
files.push({ path: filePath, content });
}
return files;
}