-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 add clean_node_modules script
add clean_node_modules script
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |