Skip to content

Commit abc2bd4

Browse files
committed
✨ 增加 api.onServerInitWillDone 方法, 优化调整调用顺序.
1 parent 69ebaa1 commit abc2bd4

File tree

8 files changed

+43
-60
lines changed

8 files changed

+43
-60
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ npx micro-app show methods
215215
* modifyChainWebpcakConfig ( 合并之后提供 webpack-chain 进行再次修改事件 )
216216
* onChainWebpcakConfig ( 修改之后提供 webpack-chain 进行查看事件 )
217217
* onServerInit ( 服务初始化时事件 )
218+
* onServerInitWillDone ( 服务初始化即将完成事件 )
218219
* onServerInitDone ( 服务初始化完成事件 )
219220
* onServerRunSuccess ( 服务运行启动成功时事件 )
220221
* onServerRunFail ( 服务运行启动失败时事件 )

micro-app.config.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ module.exports = {
4545

4646
strict: true,
4747

48-
// micros: [ 'test' ], // 被注册的容器
49-
// micros$$test: { // 单独配置
50-
// disabled: true, // 禁用入口
51-
// link: '', // 本地路径, 进行本地开发使用的软链接.
52-
// },
48+
micros: [ 'test' ], // 被注册的容器
5349

5450
// 服务配置
5551
server: {
@@ -60,13 +56,13 @@ module.exports = {
6056
},
6157
},
6258

63-
// plugins: [
64-
// [{
65-
// id: 'test',
66-
// description: '这是test',
67-
// link: __dirname + '/test/testPlugin',
68-
// }, {
69-
// a: 1,
70-
// }],
71-
// ],
59+
plugins: [
60+
[{
61+
id: 'test',
62+
description: '这是test',
63+
link: __dirname + '/test/testPlugin',
64+
}, {
65+
a: 1,
66+
}],
67+
],
7268
};

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@micro-app/cli",
3-
"version": "0.2.0-beta.1",
3+
"version": "0.2.0-beta.2",
44
"description": "[CLI] Pluggable micro application framework.",
55
"bin": {
66
"micro-app": "./bin/micro-app.js",
@@ -35,10 +35,9 @@
3535
},
3636
"license": "MIT",
3737
"devDependencies": {
38-
"@micro-app/core": "^0.1.7",
38+
"@micro-app/core": "^0.2.0-beta.1",
3939
"@micro-app/plugin-koa-static-server": "^0.0.1",
40-
"@micro-app/plugin-koa-webpack-middleware": "^0.0.2",
41-
"@micro-app/plugin-webpack-adapter": "^0.0.5",
40+
"@micro-app/plugin-koa-webpack-middleware": "^0.0.3",
4241
"@types/jest": "^24.0.18",
4342
"babel-eslint": "^10.0.3",
4443
"coveralls": "^3.0.6",
@@ -48,8 +47,7 @@
4847
"webpack": "^4.39.2"
4948
},
5049
"peerDependencies": {
51-
"@micro-app/core": ">=0.1.7",
52-
"@micro-app/plugin-webpack-adapter": "^0.0.5"
50+
"@micro-app/core": ">=0.2.0"
5351
},
5452
"dependencies": {
5553
"koa": "^2.8.1",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ describe('Command serve', () => {
5656
expect(app).not.toBeUndefined();
5757
expect(app).not.toBeNull();
5858
});
59+
plugin._api.onServerInitWillDone(({ args, app }) => {
60+
expect(args).not.toBeUndefined();
61+
expect(args).not.toBeNull();
62+
expect(app).not.toBeUndefined();
63+
expect(app).not.toBeNull();
64+
});
5965
plugin._api.onServerInitDone(({ args, app }) => {
6066
expect(args).not.toBeUndefined();
6167
expect(args).not.toBeNull();

plugins/commands/start/methods.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ module.exports = api => {
1111
type: api.API_TYPE.EVENT,
1212
description: '服务初始化时事件',
1313
});
14+
api.registerMethod('onServerInitWillDone', {
15+
type: api.API_TYPE.EVENT,
16+
description: '服务初始化即将完成事件',
17+
});
1418
api.registerMethod('onServerInitDone', {
1519
type: api.API_TYPE.EVENT,
1620
description: '服务初始化完成事件',

plugins/commands/start/start.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ describe('Command start', () => {
6262
expect(app).not.toBeUndefined();
6363
expect(app).not.toBeNull();
6464
});
65+
plugin._api.onServerInitWillDone(({ args, app }) => {
66+
expect(args).not.toBeUndefined();
67+
expect(args).not.toBeNull();
68+
expect(app).not.toBeUndefined();
69+
expect(app).not.toBeNull();
70+
});
71+
6572
plugin._api.onServerRunSuccess(({ args, host, port }) => {
6673
expect(args).not.toBeUndefined();
6774
expect(args).not.toBeNull();

src/server/createServer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ module.exports = function(api, args = {}) {
4646
api.applyPluginHooks('afterServerEntry', { app, args });
4747
applyHooks(_HookEvent, 'after');
4848

49+
api.applyPluginHooks('onServerInitWillDone', { app, args });
50+
4951
api.applyPluginHooks('onServerInitDone', { app, args });
5052
applyHooks(_HookEvent, 'done');
5153

@@ -59,7 +61,7 @@ module.exports = function(api, args = {}) {
5961
reject(err);
6062
return;
6163
}
62-
console.log('\n');
64+
console.log('\r\n');
6365
logger.success(`Server running... listen on ${port}, host: ${host}`);
6466

6567
api.applyPluginHooks('onServerRunSuccess', { host, port, args });

yarn.lock

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,10 @@
379379
"@types/istanbul-reports" "^1.1.1"
380380
"@types/yargs" "^13.0.0"
381381

382-
"@micro-app/core@^0.1.7":
383-
version "0.1.7"
384-
resolved "https://registry.yarnpkg.com/@micro-app/core/-/core-0.1.7.tgz#8081614e9c8f32f1db611d3040e670126469529c"
385-
integrity sha512-YLEwXFXh+xbbc74nm//jTdOtkZunHnPT058sJEphujAlrW6+4KhtgCgFOg1G7ivWAhJw8hv+IzDKGlkOQRlX3Q==
382+
"@micro-app/core@^0.2.0-beta.1":
383+
version "0.2.0-beta.1"
384+
resolved "https://registry.yarnpkg.com/@micro-app/core/-/core-0.2.0-beta.1.tgz#898ee980d4a93e505e39d5d38f3b371bac82ec97"
385+
integrity sha512-U59cWYS7XgDlrWnRjdHC/LCTIOhvORi/4T/OXltjr73JyQx4CJUOuH5ufVzdPRPASEbPQeeOOVKfGegMVjsCGA==
386386
dependencies:
387387
ajv "^6.10.2"
388388
ajv-keywords "^3.4.1"
@@ -391,7 +391,6 @@
391391
cheerio "^1.0.0-rc.3"
392392
dotenv "^8.1.0"
393393
lodash "^4.17.15"
394-
module-alias "^2.2.1"
395394
ora "^3.4.0"
396395
semver "^6.3.0"
397396
semver-regex "^3.1.0"
@@ -406,21 +405,14 @@
406405
dependencies:
407406
koa-static "^5.0.0"
408407

409-
"@micro-app/plugin-koa-webpack-middleware@^0.0.2":
410-
version "0.0.2"
411-
resolved "https://registry.yarnpkg.com/@micro-app/plugin-koa-webpack-middleware/-/plugin-koa-webpack-middleware-0.0.2.tgz#5e59b2464e691ce361c54e8c9082e14a1289b584"
412-
integrity sha512-u/bMTagxNDnWKdPS97hgxrNnZoMzhiLKTkqeHAhrMGRqpRdbQYGJSJkwEFhXBq0RutkomgHOKg5Y6sFfdoMH2w==
408+
"@micro-app/plugin-koa-webpack-middleware@^0.0.3":
409+
version "0.0.3"
410+
resolved "https://registry.yarnpkg.com/@micro-app/plugin-koa-webpack-middleware/-/plugin-koa-webpack-middleware-0.0.3.tgz#d84d5f96d271510fc4437a8415d7a15288830075"
411+
integrity sha512-aRSb7JZleFksSVHjxs6iL5ibq3mDmUR/vA2HBUaviqE+wFPhwDtz78RWaPrtlhF79lPTd60H5zRvTmG8nObEoA==
413412
dependencies:
414413
webpack-dev-middleware "^2.0.6"
415414
webpack-hot-middleware "^2.25.0"
416415

417-
"@micro-app/plugin-webpack-adapter@^0.0.5":
418-
version "0.0.5"
419-
resolved "https://registry.yarnpkg.com/@micro-app/plugin-webpack-adapter/-/plugin-webpack-adapter-0.0.5.tgz#5321b1d0db06a6328c5cef6c5b19879ea16f2b45"
420-
integrity sha512-YoWlXE9TTGnKiOpMYblN1dFDo5GMsoHzoTJQZkVIQII9RDlFJXEItyTa0qjMmrHSPGugt0nHZuZqwIli1ujh3g==
421-
dependencies:
422-
webpack-chain "^6.0.0"
423-
424416
"@sindresorhus/is@^0.14.0":
425417
version "0.14.0"
426418
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea"
@@ -1836,11 +1828,6 @@ deep-is@~0.1.3:
18361828
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
18371829
integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=
18381830

1839-
deepmerge@^1.5.2:
1840-
version "1.5.2"
1841-
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-1.5.2.tgz#10499d868844cdad4fee0842df8c7f6f0c95a753"
1842-
integrity sha512-95k0GDqvBjZavkuvzx/YqVLv/6YYa17fz6ILMSf7neqQITCPbnfEnQvEgMPNjH4kgobe7+WIL0yJEHku+H3qtQ==
1843-
18441831
defaults@^1.0.3:
18451832
version "1.0.3"
18461833
resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d"
@@ -3464,11 +3451,6 @@ istanbul-reports@^2.2.6:
34643451
dependencies:
34653452
handlebars "^4.1.2"
34663453

3467-
javascript-stringify@^2.0.0:
3468-
version "2.0.0"
3469-
resolved "https://registry.yarnpkg.com/javascript-stringify/-/javascript-stringify-2.0.0.tgz#ef750216ae66504ffd670b68c8b8aa07bdf7b588"
3470-
integrity sha512-zzK8+ByrzvOL6N92hRewwUKL0wN0TOaIuUjX0Jj8lraxWvr5wHYs2YTjaj2lstF+8qMv5cmPPef47va8NT8lDw==
3471-
34723454
jest-changed-files@^24.9.0:
34733455
version "24.9.0"
34743456
resolved "https://registry.yarnpkg.com/jest-changed-files/-/jest-changed-files-24.9.0.tgz#08d8c15eb79a7fa3fc98269bc14b451ee82f8039"
@@ -4412,11 +4394,6 @@ mkdirp@^0.5.0, mkdirp@^0.5.1:
44124394
dependencies:
44134395
minimist "0.0.8"
44144396

4415-
module-alias@^2.2.1:
4416-
version "2.2.1"
4417-
resolved "https://registry.yarnpkg.com/module-alias/-/module-alias-2.2.1.tgz#553aea9dc7f99cd45fd75e34a574960dc46550da"
4418-
integrity sha512-LTez0Eo+YtfUhgzhu/LqxkUzOpD+k5C0wXBLun0L1qE2BhHf6l09dqam8e7BnoMYA6mAlP0vSsGFQ8QHhGN/aQ==
4419-
44204397
move-concurrently@^1.0.1:
44214398
version "1.0.1"
44224399
resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"
@@ -6511,14 +6488,6 @@ webidl-conversions@^4.0.2:
65116488
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"
65126489
integrity sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==
65136490

6514-
webpack-chain@^6.0.0:
6515-
version "6.0.0"
6516-
resolved "https://registry.yarnpkg.com/webpack-chain/-/webpack-chain-6.0.0.tgz#9c36525a1271a54e7bfd1791199b395f400ae4f1"
6517-
integrity sha512-NK62XgJOOSmYs4kaXFIKKeClpuOVHY7m6e4XwxbVX/2HAUboH6xFCTVXMVv8+jB6K8o/UGjlo1Cv3XXOyNAAGw==
6518-
dependencies:
6519-
deepmerge "^1.5.2"
6520-
javascript-stringify "^2.0.0"
6521-
65226491
webpack-dev-middleware@^2.0.6:
65236492
version "2.0.6"
65246493
resolved "https://registry.yarnpkg.com/webpack-dev-middleware/-/webpack-dev-middleware-2.0.6.tgz#a51692801e8310844ef3e3790e1eacfe52326fd4"

0 commit comments

Comments
 (0)