Pluggable micro application framework.
基于webpack多入口的多仓库业务模块开发的插件应用框架脚手架.
yarn add @micro-app/clior
npm install -D @micro-app/clinpx micro-app initmodule.exports={name: '@micro-app/demo',description: '',version: '0.0.1',type: '',// types 类型staticPath: [],// String | Arrayentry: {// 入口main: './test/index.js',},htmls: [// 输出模版配置{template: './test/index.js',},],alias: {// 别名配置api: '',config: {link: '',description: '配置',},service: {link: '',description: '接口',type: 'server',},},strict: true,// 严格强依赖模式micros: ['test'],// 被注册的容器// 服务配置server: {hooks: '',entry: '',// 服务端入口port: 8088,// 服务端口号},plugins: [// 自定义插件// [{// id: 'test',// description: '这是test',// link: __dirname + '/test/testPlugin',// }, {// a: 1,// }],],};"dependencies": {
"@micro-app/test": "git+ssh://git@github.com/micro-app.git#test"
},npx micro-app serveor
npx micro-app-devnpx micro-app startor
npx micro-app-startconstapi=require('@micro-demo/api');plugins: [[// 1{id: 'test',// 插件 iddescription: '这是test',// 插件描述link: __dirname+'/test/testPlugin.js',// 插件地址},{// 注册入的 optsa: 1,}],],文件必须返回一个方法.
module.exports=function(api,opts){console.log(opts);api.onInitDone(item=>{console.log('init Done',item);});api.onInitDone(()=>{console.log('init Done2',api.getState('webpackConfig'));});api.onPluginInitDone(item=>{console.log('onPluginInitDone',item);});};可通过如下命令进行动态查看
npxmicro-appshowmethods以提供的方法如下, System Build-in 为内置方法
╰─➤npxmicro-appshowmethodsPluginMethods:
*onPluginInitDone(SystemBuild-in)*beforeMergeConfig(SystemBuild-in)*afterMergeConfig(SystemBuild-in)*modifyDefaultServerConfig(SystemBuild-in)*onInitWillDone(SystemBuild-in)*onInitDone(SystemBuild-in)*modifyCommand(SystemBuild-in)*onRunCommand(SystemBuild-in)*modifyCommandHelp(SystemBuild-in)*modifyWebpackConfig(合并之后提供webpackconfig进行再次修改事件)*onServerInit(服务初始化时事件)*onServerInitWillDone(服务初始化即将完成事件)*onServerInitDone(服务初始化完成事件)*onServerRunSuccess(服务运行启动成功时事件)*onServerRunFail(服务运行启动失败时事件)*beforeServerEntry(服务进入业务逻辑前事件)*afterServerEntry(服务从业务逻辑出来后事件)*beforeDevServer(开发服务创建前事件)*afterDevServer(开发服务创建后事件)*onBuildSuccess(构建成功时事件)*onBuildFail(构建失败时事件)*beforeBuild(开始构建前事件)*afterBuild(构建结束后事件)*beforeCommandUpdate(开始更新前事件)*afterCommandUpdate(更新完毕后事件)*beforeCommandDeploy(发布前事件)*afterCommandDeploy(发布后事件)*modifyCommandDeployMessage(发布消息二次编辑事件)// 以下为针对 vusion 类型的方法*modifyVusionConfig(对服务启动前对vusionconfig进行修改,需要返回所有参数)*modifyVusionWebpackConfig(对服务启动前对vusionwebpackConfig进行修改,需要返回所有参数)*modifyDefaultVusionConfig(初始化修改通用vusion.config.js,需要返回所有参数)可参考以下插件, 如:
// 注册一个方法api.registerMethod('beforeCommandUpdate',{type: api.API_TYPE.EVENT,description: '开始更新前事件',});// 注册一个终端命令api.registerCommand('update',{description: 'update package.json',usage: 'micro-app update [options]',options: {'--all': 'update all.','-n <name>': 'only update <name>.',},details: `Examples:${chalk.gray('# update all')} micro-app update --all${chalk.gray('# only update <name>')} micro-app update -name <name> `.trim(),},args=>{constname=args.name;returnupdateMicro(api,name);});// 对外触发已注册的方法.api.applyPluginHooks('beforeCommandUpdate',{ name, logger, microsConfig });其它插件使用 beforeCommandUpdate 方法, 如下:
api.beforeCommandUpdate(item=>{console.log('beforeCommandUpdate',item);});╰─➤npxmicro-apphelp
Usage: micro-app<command>[options]Commands:
*show(showalias&sharedlist,etc.)*check(checkalldependencies.)*version(showversion)*start(runsserverforproduction)*serve(runsserverfordevelopment)*build(buildforproduction)*update(updatepackage.json)*deploy(synccommitstatus.)runmicro-apphelp[command]forusageofaspecificcommand.npxmicro-appshowmicrosnpxmicro-appshowaliasnpxmicro-appshowsharednpxmicro-app-dev--progress