Skip to content

Instantly share code, notes, and snippets.

@manabuyasuda
Last active October 13, 2021 10:04
Show Gist options
  • Select an option

  • Save manabuyasuda/82c8b4f4c08562dcd210323d5220bbd1 to your computer and use it in GitHub Desktop.

Select an option

Save manabuyasuda/82c8b4f4c08562dcd210323d5220bbd1 to your computer and use it in GitHub Desktop.
あるディレクトリ内のファイルすべてを複製する
// package.jsonの`scripts`に以下のように指定する
// "duplicateFiles": "node scripts/duplicateFiles.js"
const fs = require('fs-extra')
// 複製元のパス
const src = './src/'
// 複製先のパス
const dest = './public/'
// `dest`をフォルダごと、すべて削除する
try {
fs.removeSync(dest)
console.log(`✨ Deleted "${dest}"`)
} catch(err) {
console.error(err)
}
// `src`を`dest`に複製する
try {
fs.copySync(src, dest)
console.log(`✨ Duplicate "${src}" to "${dest}"`)
console.log(`👏 Completed successfully!`)
} catch(err) {
console.error(err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment