clean.js 903 B

123456789101112131415161718192021222324252627282930313233
  1. const fs = require('fs');
  2. const path = require('path');
  3. function deleteFolderRecursive(directoryPath) {
  4. if (fs.existsSync(directoryPath)) {
  5. fs.readdirSync(directoryPath).forEach((file) => {
  6. const curPath = path.join(directoryPath, file);
  7. if (fs.lstatSync(curPath).isDirectory()) {
  8. deleteFolderRecursive(curPath);
  9. } else {
  10. try {
  11. fs.unlinkSync(curPath);
  12. } catch (err) {
  13. console.log(`无法删除文件 ${curPath}: ${err.message}`);
  14. }
  15. }
  16. });
  17. try {
  18. fs.rmdirSync(directoryPath);
  19. } catch (err) {
  20. console.log(`无法删除目录 ${directoryPath}: ${err.message}`);
  21. }
  22. }
  23. }
  24. const buildDir = path.join(__dirname, '..', 'electron-build');
  25. try {
  26. deleteFolderRecursive(buildDir);
  27. console.log('清理完成');
  28. } catch (err) {
  29. console.error('清理过程中发生错误:', err);
  30. process.exit(1);
  31. }