|
2 | 2 |
|
3 | 3 | module.exports = function(api, opts = {}) { |
4 | 4 |
|
5 | | - const chalk = require('chalk'); |
| 5 | + const { chalk } = require('@micro-app/shared-utils'); |
6 | 6 |
|
7 | 7 | api.registerCommand('deploy', { |
8 | 8 | description: 'sync commit status.', |
9 | 9 | usage: 'micro-app deploy [options]', |
10 | 10 | options: { |
11 | 11 | '-': 'deploy last commit', |
12 | | - '--type': '部署方式类型. (default: github)', |
| 12 | + '--type': '部署方式类型. (default: git)', |
13 | 13 | '--message': 'git commit message.', |
14 | 14 | '--name': 'git commit user name.', |
15 | 15 | '--email': 'git commit user email.', |
@@ -60,30 +60,30 @@ Config: |
60 | 60 | return; |
61 | 61 | } |
62 | 62 |
|
63 | | - // default: github |
| 63 | + const deployCmds = [ |
| 64 | + { |
| 65 | + type: 'git', |
| 66 | + run: require('../git'), |
| 67 | + }, |
| 68 | + ].concat(api.applyPluginHooks('addCommandDeployType', []) || []); |
| 69 | + |
| 70 | + // default: git |
64 | 71 | args.type = args.type || 'git'; |
65 | 72 |
|
66 | 73 | let chain = Promise.resolve(); |
67 | 74 |
|
68 | 75 | chain = chain.then(() => api.applyPluginHooks('beforeCommandDeploy', { args, config: deployConfig })); |
69 | 76 |
|
70 | 77 | const type = args.type; |
71 | | - switch (type) { |
72 | | - case 'git': |
73 | | - case 'github': |
74 | | - { |
75 | | - const gitCMD = require('../git'); |
76 | | - chain = chain.then(() => gitCMD(api, args, deployConfig)); |
77 | | - break; |
78 | | - } |
79 | | - default: |
80 | | - chain = chain.then(() => { |
81 | | - logger.warn('[Deploy]', `Not Found type: ${type}!`); |
82 | | - // TODO others type |
83 | | - }); |
84 | | - break; |
| 78 | + const allCmds = deployCmds.filter(item => item.type === type); |
| 79 | + if (allCmds.length > 0) { |
| 80 | + allCmds.forEach(item => { |
| 81 | + const run = item.run; |
| 82 | + chain = chain.then(() => run(api, args, deployConfig)); |
| 83 | + }); |
| 84 | + } else { |
| 85 | + chain = chain.then(() => logger.warn('[Deploy]', `Not Found type: ${type}!`)); |
85 | 86 | } |
86 | | - |
87 | 87 | chain = chain.then(() => api.applyPluginHooks('afterCommandDeploy', { args, config: deployConfig })); |
88 | 88 |
|
89 | 89 | return chain; |
|
0 commit comments