123456789101112131415161718192021222324252627282930313233 |
- const fs = require('fs');
- const path = require('path');
- function deleteFolderRecursive(directoryPath) {
- if (fs.existsSync(directoryPath)) {
- fs.readdirSync(directoryPath).forEach((file) => {
- const curPath = path.join(directoryPath, file);
- if (fs.lstatSync(curPath).isDirectory()) {
- deleteFolderRecursive(curPath);
- } else {
- try {
- fs.unlinkSync(curPath);
- } catch (err) {
- console.log(`无法删除文件 ${curPath}: ${err.message}`);
- }
- }
- });
- try {
- fs.rmdirSync(directoryPath);
- } catch (err) {
- console.log(`无法删除目录 ${directoryPath}: ${err.message}`);
- }
- }
- }
- const buildDir = path.join(__dirname, '..', 'electron-build');
- try {
- deleteFolderRecursive(buildDir);
- console.log('清理完成');
- } catch (err) {
- console.error('清理过程中发生错误:', err);
- process.exit(1);
- }
|