Skip to content

Commit

Permalink
feat: 🎸 add clean_node_modules script
Browse files Browse the repository at this point in the history
add clean_node_modules script
  • Loading branch information
lgf-136 committed Sep 27, 2022
1 parent 00c2e09 commit b5de14c
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions clean_node_modules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

const fs = require('fs');

const delTargetDir = 'node_modules';

const enterTargetDir = '.';

function deleteFolder(path) {
let files = [];
if (fs.existsSync(path)) {
files = fs.readdirSync(path);
files.forEach(file => {
const curPath = `${path}/${file}`;
// 本来网上是statSync 我给改成了 lstatSync
if (fs.lstatSync(curPath).isDirectory()) {
deleteFolder(curPath);
} else {
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
}

function deleteTargetFolder(path, target) {
let files = [];
if (fs.existsSync(path)) {
files = fs.readdirSync(path);
files.forEach(file => {
const curPath = `${path}/${file}`;
if (fs.lstatSync(curPath).isDirectory()) {
// 同下边 都改成lstatSync
if (file === target) {
deleteFolder(curPath);
} else {
deleteTargetFolder(curPath, target);
}
}
});
}
}

deleteTargetFolder(enterTargetDir, delTargetDir);

0 comments on commit b5de14c

Please sign in to comment.