Skip to content

Commit

Permalink
feat: umi plugin list (umijs#157)
Browse files Browse the repository at this point in the history
* support command:plugin

* bugfix:presets未定义时,UMI_PRESETS为undefined

* code formatting

* filter plugin.ts

* pnpm format
  • Loading branch information
siyi98 authored Nov 4, 2021
1 parent 001593e commit d256466
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
8 changes: 6 additions & 2 deletions examples/boilerplate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"scripts": {
"dev": "../../packages/umi/bin/umi.js dev"
"start": "pnpm run dev",
"dev": "umi dev",
"plugin": "umi plugin"
},
"devDependencies": {}
"devDependencies": {
"umi": "workspace:*"
}
}
33 changes: 33 additions & 0 deletions packages/preset-built-in/src/commands/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { IApi } from '../types';

export default (api: IApi) => {
api.registerCommand({
name: 'plugin',
description: 'inspect umi plugins',
fn({ args }) {
const command = args._[0];
console.log('command', command);

if (!command) {
throw new Error(`
Sub command not found: umi plugin
Did you mean:
umi plugin list
`);
}
switch (command) {
case 'list':
getPluginList();
break;
default:
throw new Error(`Unsupported sub command ${command} for umi plugin.`);
}
function getPluginList() {
Object.keys(api.service.plugins).forEach((pluginId: string) => {
const plugin = api.service.plugins[pluginId];
console.info(`- ${plugin.id}`);
});
}
},
});
};
1 change: 1 addition & 0 deletions packages/preset-built-in/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default () => {
require.resolve('./commands/setup'),
require.resolve('./commands/version'),
require.resolve('./commands/generate/generate'),
require.resolve('./commands/plugin'),
],
};
};
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d256466

Please sign in to comment.