1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-07-18 02:20:12 +02:00
programming-challenges/scripts/utils/copyDirPromise.ts

22 lines
716 B
TypeScript
Raw Normal View History

import * as fsWithCallbacks from 'fs'
2020-07-05 15:48:51 +02:00
import path from 'path'
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
}
export default copyDirectory