1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-11-09 22:08:58 +01:00
programming-challenges/scripts/utils/copyDirPromise.ts
2020-07-05 15:48:51 +02:00

27 lines
796 B
TypeScript

import fs from 'fs'
import path from 'path'
function copyDirPromise (source: string, destination: string) {
return new Promise(next => {
const filesToCreate = fs.readdirSync(source)
filesToCreate.forEach(async file => {
const originalFilePath = path.join(source, file)
const stats = fs.statSync(originalFilePath)
if (stats.isFile()) {
if (file === '.npmignore') file = '.gitignore'
const writePath = path.join(destination, file)
fs.copyFileSync(originalFilePath, writePath)
} else if (stats.isDirectory()) {
fs.mkdirSync(path.join(destination, file))
await copyDirPromise(
path.join(source, file),
path.join(destination, file)
)
}
})
next()
})
}
export default copyDirPromise