2021-02-18 19:40:44 +01:00
|
|
|
import * as fsWithCallbacks from 'fs'
|
2020-07-05 15:48:51 +02:00
|
|
|
import path from 'path'
|
|
|
|
|
2021-02-18 19:40:44 +01:00
|
|
|
const fs = fsWithCallbacks.promises
|
|
|
|
|
|
|
|
async function copyDirectory (source: string, destination: string): Promise<void> {
|
|
|
|
const filesToCreate = await fs.readdir(source)
|
|
|
|
for (let file of filesToCreate) {
|
|
|
|
const originalFilePath = path.join(source, file)
|
|
|
|
const stats = await fs.stat(originalFilePath)
|
|
|
|
if (stats.isFile()) {
|
|
|
|
const writePath = path.join(destination, file)
|
|
|
|
await fs.copyFile(originalFilePath, writePath)
|
|
|
|
} else if (stats.isDirectory()) {
|
|
|
|
await fs.mkdir(path.join(destination, file))
|
|
|
|
await copyDirectory(path.join(source, file), path.join(destination, file))
|
|
|
|
}
|
|
|
|
}
|
2020-07-05 15:48:51 +02:00
|
|
|
}
|
|
|
|
|
2021-02-18 19:40:44 +01:00
|
|
|
export default copyDirectory
|