Skip to content

Commit

Permalink
feat: list plugins and generators (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
shanshandev authored and cpselvis committed Apr 15, 2019
1 parent 981e329 commit 984d62b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/internal/console/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ module.exports = function (ctx) {
cmd.register('help', 'Get help on a command.', {}, require('./help'));

cmd.register('version', 'Display version information.', {}, require('./version'));

cmd.register('list', 'Show all plugins installed.', {}, require('./list'));
};
45 changes: 45 additions & 0 deletions lib/internal/console/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* @Description: display all plugins installed
* @Author: salomezhang
* @Date: 2019-04-15
*/

const pathFn = require('path');
const fs = require('fs');
const chalk = require('chalk');

function loadModuleList(ctx) {
const packagePath = pathFn.join(ctx.baseDir, 'package.json');
const pluginDir = ctx.pluginDir;
const extend = function (target, source) {
for (var obj in source) {
target[obj] = source[obj];
}
return target;
};
if (fs.existsSync(packagePath)) {
let content = fs.readFileSync(packagePath, 'utf8');
const json = JSON.parse(content);
const deps = extend(json.dependencies || {}, json.devDependencies || {});
let keys = Object.keys(deps);
let list = keys.filter(function (name) {
if (!/^feflow-plugin-|^@[^/]+\/feflow-plugin-|generator-|^@[^/]+\/generator-/.test(name)) return false;
const path = pathFn.join(pluginDir, name);
return fs.existsSync(path);
});
return list;
} else {
return [];
}
}

module.exports = function () {
const ctx = this;
const list = loadModuleList(ctx);

console.log('Below are all installed generators and plugins:');
console.log('===============================================');
list.map(function (name) {
console.log(chalk.magenta(name));
})
};

0 comments on commit 984d62b

Please sign in to comment.