restore.js 768 B

12345678910111213141516171819202122
  1. const path = require('path');
  2. const fs = require('fs');
  3. // 获取当前命令行上下文路径
  4. const currentDirectory = process.cwd();
  5. console.log(`----------------------------`)
  6. console.log(`项目编译打包完成,准备恢复配置文件...`)
  7. // 获取缓存文件
  8. console.log(`获取配置缓存文件...`)
  9. const cacheJsonPath = path.join(currentDirectory, 'scripts/cache.json');
  10. const cacheJsonContent = fs.readFileSync(cacheJsonPath, 'utf8');
  11. // 恢复配置文件
  12. console.log(`正在恢复为编译前的配置文件...`)
  13. const indexJsonPath = path.join(currentDirectory, 'src/config/index.json');
  14. fs.writeFileSync(indexJsonPath, cacheJsonContent, 'utf8');
  15. // 删除缓存文件
  16. console.log(`删除配置缓存文件...`)
  17. fs.unlinkSync(cacheJsonPath);