Skip to content

Commit

Permalink
feat: add clean command (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpselvis committed Feb 13, 2019
1 parent 9819083 commit 632505f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Feflow {
require('../internal/lint')(this);
require('../internal/eject')(this);
require('../internal/deploy')(this);
require('../internal/clean')(this);

// Init client and load external plugins
return Promise.each([
Expand Down
42 changes: 42 additions & 0 deletions lib/internal/clean/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

const fs = require('hexo-fs');
const pathFn = require('path');

const deleteFolderRecursive = function (path) {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach(function (file) {
const curPath = path + '/' + file;
if (fs.lstatSync(curPath).isDirectory()) {
deleteFolderRecursive(curPath);
} else {
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
};

module.exports = function (args) {
const { log, baseDir, pluginDir, logDir } = this;
const packagePath = pathFn.join(baseDir, 'package.json');

// Remove plugin dir
if (fs.existsSync(pluginDir) && fs.lstatSync(pluginDir).isDirectory()) {
deleteFolderRecursive(pluginDir);
}

// Remove log dir
if (fs.existsSync(logDir) && fs.lstatSync(logDir).isDirectory()) {
deleteFolderRecursive(logDir);
}

// Rewrite package.json
fs.writeFileSync(packagePath, JSON.stringify({
'name': 'feflow-home',
'version': '0.0.0',
'private': true
}, null, 4));

log.info('Feflow 重新重新初始化完成');
};
8 changes: 8 additions & 0 deletions lib/internal/clean/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports = function (ctx) {

const cmd = ctx.cmd;

cmd.register('clean', 'Clean feflow folder.', {}, require('./clean'));
};

0 comments on commit 632505f

Please sign in to comment.