-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: list plugins and generators (#88)
- Loading branch information
1 parent
981e329
commit 984d62b
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}) | ||
}; |