zhangdocs
Version:
Simple document generation tool. Dependence Node.js run.
39 lines (35 loc) • 1.24 kB
JavaScript
var fs = require('fs');
var file = require('./file');
var log = console.log;
var color = require('colors-cli');
var shell = require('shelljs');
// var exec = require('child_process').exec
module.exports = clean
function clean(commander){
var url = process.cwd();
var arr = fs.readdirSync(url);
arr.forEach(function(item) {
var fullPath = url + '/' + item;
if (file.isDir(fullPath) && (item === 'html' || item === 'static')) {
shell.rm('-rf', fullPath);
log(color.green('delete "/') + item + color.green('" Success !'));
} else if (file.isFile(fullPath) && item === 'index.html') {
shell.rm(fullPath);
log(color.green('delete "/') + item + color.green('" Success !'));
}
});
}
// 使用递归删除文件
function deleteFolderRecursive(path) {
if(fs.existsSync(path)) {
fs.readdirSync(path).forEach(function(file){
var curPath = path + "/" + file;
if(fs.statSync(curPath).isDirectory()) {
deleteFolderRecursive(curPath);
} else {
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
}