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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user