| 4 | import { ensureDirectoryExists } from '@code-pushup/test-utils'; |
| 5 | |
| 6 | export async function materializeTree(tree: Tree, targetFolder: string) { |
| 7 | const changes = tree.listChanges(); |
| 8 | await Promise.all( |
| 9 | changes.map(async change => { |
| 10 | const filePath = path.join(targetFolder, change.path); |
| 11 | |
| 12 | if (change.type === 'CREATE' || change.type === 'UPDATE') { |
| 13 | try { |
| 14 | await ensureDirectoryExists(path.dirname(filePath)); |
| 15 | await writeFile(filePath, change.content?.toString() ?? ''); |
| 16 | } catch (error) { |
| 17 | console.error(`Failed to process file ${filePath}:`, error); |
| 18 | } |
| 19 | } |
| 20 | }), |
| 21 | ); |
| 22 | } |