diff --git a/packages/feflow-cli/src/core/native/help.ts b/packages/feflow-cli/src/core/native/help.ts index bc09fe22..8a746c26 100644 --- a/packages/feflow-cli/src/core/native/help.ts +++ b/packages/feflow-cli/src/core/native/help.ts @@ -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. `); diff --git a/packages/feflow-cli/src/core/native/list.ts b/packages/feflow-cli/src/core/native/list.ts new file mode 100644 index 00000000..fa93aa17 --- /dev/null +++ b/packages/feflow-cli/src/core/native/list.ts @@ -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)); + } + }); + }); +}; +