12345678910111213141516171819202122232425262728 |
- const path = require('path');
- const fs = require('fs');
- // 获取当前命令行上下文路径
- const currentDirectory = process.cwd();
- console.log(`----------------------------`)
- console.log(`项目编译打包完成,准备移除非必要的 /dist/plugins 文件夹...`)
- const dist_plugins = path.join(currentDirectory, '/dist/plugins');
- if(fs.existsSync(dist_plugins)) {
- delallfilerid(dist_plugins)
- fs.rmdirSync(dist_plugins)
- console.log(`移除非必要的 /dist/plugins 文件夹成功...`)
- } else {
- console.log(`/dist/plugins 文件夹 不存在,无需移除...`)
- }
- //删除文件夹下的所有文件
- function delallfilerid(fuckpath) {
- fs.readdirSync(fuckpath).forEach((file, index, arr) => {
- if (fs.lstatSync(`${fuckpath}/${file}`).isFile()) {
- fs.unlinkSync(`${fuckpath}/${file}`)
- }else if(fs.lstatSync(`${fuckpath}/${file}`).isDirectory()){
- delallfilerid(`${fuckpath}/${file}`)
- fs.rmdirSync(`${fuckpath}/${file}`)
- }
- })
- }
|