Skip to content

Commit

Permalink
feat: add list command (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
shanshandev authored and cpselvis committed Nov 21, 2019
1 parent aa0e020 commit 1b8bcc0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/feflow-cli/src/core/native/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = (ctx: any) => {
Options:
--version, -[v] Print version and exit successfully.
--help, -[h] Print this help and exit successfully.
--list, -[l] Print all all plugins installed.
Report bugs to https://github.com/Tencent/feflow.
`);

Expand Down
52 changes: 52 additions & 0 deletions packages/feflow-cli/src/core/native/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

import path from 'path';
import fs from 'fs';
import chalk from 'chalk'

function loadModuleList(ctx: any) {
const packagePath = ctx.rootPkg;
const pluginDir = path.join(ctx.root, 'node_modules');
const extend = function (target:any, source:any) {
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 pluginPath = path.join(pluginDir, name);
return fs.existsSync(pluginPath);
});
return list;
} else {
return [];
}
}


module.exports = (ctx: any) => {
ctx.commander.register('list', 'Show all plugins installed.', () => {
const list = loadModuleList(ctx);

console.log('You can search more templates or plugins through https://feflowjs.com/encology/');
console.log('===============================================');
console.log('templates');
list.map(function (name) {
if (!/generator-|^@[^/]+\/generator-/.test(name)){
console.log(chalk.magenta(name));
}
});
console.log('plugins');
list.map(function (name) {
if (!/^feflow-plugin-|^@[^/]+\/feflow-plugin-/.test(name)) {
console.log(chalk.magenta(name));
}
});
});
};

0 comments on commit 1b8bcc0

Please sign in to comment.