Fix scaffold copy and better error handling for create app (#202)

I was over-eager in https://github.com/dyad-sh/dyad/pull/200 and removed
copyDirectoryRecursive which is actually needed to copy the scaffold
out.
This commit is contained in:
Will Chen
2025-05-19 17:58:49 -07:00
committed by GitHub
parent b4b9556e2c
commit 4d2b4783bc
3 changed files with 60 additions and 42 deletions

View File

@@ -1,4 +1,5 @@
import fs from "node:fs";
import { promises as fsPromises } from "node:fs";
import path from "node:path";
/**
@@ -31,3 +32,22 @@ export function getFilesRecursively(dir: string, baseDir: string): string[] {
return files;
}
export async function copyDirectoryRecursive(
source: string,
destination: string,
) {
await fsPromises.mkdir(destination, { recursive: true });
const entries = await fsPromises.readdir(source, { withFileTypes: true });
for (const entry of entries) {
const srcPath = path.join(source, entry.name);
const destPath = path.join(destination, entry.name);
if (entry.isDirectory()) {
await copyDirectoryRecursive(srcPath, destPath);
} else {
await fsPromises.copyFile(srcPath, destPath);
}
}
}