File size: 609 Bytes
ec675f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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;
}