singleCopy.js 770 B

12345678910111213141516171819202122232425262728
  1. const path = require('path')
  2. const fs = require('fs')
  3. const ora = require('ora')
  4. const rm = require('rimraf')
  5. const copy = require('copy')
  6. const chalk = require('chalk')
  7. const rootPath = path.resolve(__dirname, '../')
  8. new Promise(() => {
  9. // 替换单模块文件
  10. let copying = ora('copying...')
  11. copying.start()
  12. rm('*.js', err => {
  13. if (err) throw (err)
  14. let folderList = fs.readdirSync(path.resolve(rootPath, 'babelLib'))
  15. folderList.forEach((item, index) => {
  16. copy(`babelLib/${item}/*.js`, rootPath, function (err, files) {
  17. if (err) throw err;
  18. if (index === folderList.length - 1) {
  19. console.log(chalk.cyan(' Copy complete.\n'))
  20. copying.stop()
  21. }
  22. })
  23. })
  24. })
  25. }).catch((err) => {
  26. throw err
  27. })