2023-10-23 23:16:24 +02:00
|
|
|
import fs from "node:fs"
|
|
|
|
import path from "node:path"
|
2021-06-09 20:31:45 +02:00
|
|
|
|
2022-09-22 16:16:21 +02:00
|
|
|
export const copyDirectory = async (
|
2021-06-09 20:31:45 +02:00
|
|
|
source: string,
|
2023-10-23 23:16:24 +02:00
|
|
|
destination: string,
|
2022-09-22 16:16:21 +02:00
|
|
|
): Promise<void> => {
|
2021-06-09 20:31:45 +02:00
|
|
|
const filesToCreate = await fs.promises.readdir(source)
|
|
|
|
for (const file of filesToCreate) {
|
|
|
|
const originalFilePath = path.join(source, file)
|
|
|
|
const stats = await fs.promises.stat(originalFilePath)
|
|
|
|
if (stats.isFile()) {
|
|
|
|
const writePath = path.join(destination, file)
|
|
|
|
await fs.promises.copyFile(originalFilePath, writePath)
|
|
|
|
} else if (stats.isDirectory()) {
|
|
|
|
await fs.promises.mkdir(path.join(destination, file), { recursive: true })
|
|
|
|
await copyDirectory(path.join(source, file), path.join(destination, file))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|