1.0.0 • Published 3 years ago
@lmdwjs/command-core v1.0.0
command-hook-core
cli脚手架中的插件 基于插件的生命周期 和 内核hook 1. 加载插件 添加到 内存中 核心 默认: package.json mdw-cli 中配置的 plugins插件 -> node_modules中寻找并加载 npmPlugin 平台插件: 重写 loadPlatformPlugin 调用loadRelativePlugin方法 IPluginInstance
--》(this.core.addPlugin(TestPlugin);)
--》 cli.loadRelativePlugin( relative(process.cwd(), resolve(__dirname, './plugins')), 'no-provider.ts' );
ready准备 加载 npm lifecycle 加载 instance IPluginInstance 加载 npmPlugin string -> 对象 --》 addPlugin --》 instance 加载 loadUserLifecycleExtends mdw-integration:lifecycle --> userLifecycle
invoke调用 --》输入参数 --》 展示帮助 --》 获取命令
{ commandName: command, command: cmdObj, usage, parentCommandList, }
--> loadLifecycle 加载生命周期钩子
--》 invoke 方法入口
--》 执行生命周期钩子
使用文档
默认插件
class Test {
constructor() {
this.commands = {
${pluginName}: {
lifecycleEvents: ['main'],
options: {
mwtest123: {
usage: 'xxx'
}
}
}
};
}
};
exports.Test = Test;
平台插件:
provider
command
hooks
lifecycleEvents
noLifecycleEvents
class Plugin extends BasePlugin {
provider = 'test';
commands = {
invoke: {
usage: 'test provider invoke',
lifecycleEvents: ['one', 'two'],
options: {
function: {
usage: 'function name',
shortcut: 'f',
},
},
},
};
hooks = {
'before:invoke:one': () => {
this.core.cli.log('before:invoke:one');
},
'invoke:one': async () => {
this.core.cli.log('invoke:one');
},
'after:invoke:one': () => {
this.core.cli.log('after:invoke:one');
},
'before:invoke:two': async () => {
this.core.cli.log('before:invoke:two');
},
'invoke:two': () => {
this.core.cli.log('invoke:two');
},
'after:invoke:two': async () => {
this.core.cli.log('after:invoke:two');
},
};
}
npm 插件
{
"mdw-integration": {
"lifecycle": {
"before:invoke:one": "node ./index.js"
}
}
}
nodejs 性能测试 benchmark
1.0.0
3 years ago