Skip to content

Commit 75ee403

Browse files
committed
:fix: fixed some bugs
1 parent 5c062b9 commit 75ee403

File tree

5 files changed

+32
-32
lines changed

5 files changed

+32
-32
lines changed

micro-app.deploy.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ module.exports = {
99
},
1010
message: 'AUTO TEST',
1111
user: {
12-
name: '',
13-
email: '',
12+
name: 'Zyao89',
13+
1414
},
1515
dest: 'test/gitinfo',
1616
// cname: 'www.2o3t.cn',

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@
3535
},
3636
"devDependencies": {
3737
"@micro-app/cli": "^0.3.0-alpha.3",
38+
"@micro-app/shared-utils": "^0.1.13",
3839
"@types/jest": "^24.0.25",
3940
"babel-eslint": "^10.0.3",
4041
"eslint": "^5.16.0",
4142
"eslint-config-2o3t": "^1.1.17",
4243
"jest": "^24.9.0"
43-
},
44-
"dependencies": {
45-
"@micro-app/shared-utils": "^0.1.11"
4644
}
4745
}

src/commands/deploy/index.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
module.exports = function(api, opts = {}) {
44

5-
const chalk = require('chalk');
5+
const { chalk } = require('@micro-app/shared-utils');
66

77
api.registerCommand('deploy', {
88
description: 'sync commit status.',
99
usage: 'micro-app deploy [options]',
1010
options: {
1111
'-': 'deploy last commit',
12-
'--type': '部署方式类型. (default: github)',
12+
'--type': '部署方式类型. (default: git)',
1313
'--message': 'git commit message.',
1414
'--name': 'git commit user name.',
1515
'--email': 'git commit user email.',
@@ -60,30 +60,30 @@ Config:
6060
return;
6161
}
6262

63-
// default: github
63+
const deployCmds = [
64+
{
65+
type: 'git',
66+
run: require('../git'),
67+
},
68+
].concat(api.applyPluginHooks('addCommandDeployType', []) || []);
69+
70+
// default: git
6471
args.type = args.type || 'git';
6572

6673
let chain = Promise.resolve();
6774

6875
chain = chain.then(() => api.applyPluginHooks('beforeCommandDeploy', { args, config: deployConfig }));
6976

7077
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}!`));
8586
}
86-
8787
chain = chain.then(() => api.applyPluginHooks('afterCommandDeploy', { args, config: deployConfig }));
8888

8989
return chain;

src/commands/git/utils.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { logger, execa } = require('@micro-app/shared-utils');
3+
const { logger, execa, shell } = require('@micro-app/shared-utils');
44

55
const TIMEOUT = 1000 * 60 * 3;
66

@@ -24,13 +24,11 @@ function execGit(args, options = {}) {
2424
}
2525

2626
function execGitSync(args, options = {}) {
27-
try {
28-
const { stdout, exitCode } = execa.sync('git', args, Object.assign({ stdio: 'ignore', timeout: TIMEOUT }, options));
29-
return exitCode === 0 ? (stdout || '').trim() : '';
30-
} catch (error) {
31-
logger.warn('[execGitSync]', error.message);
32-
return '';
33-
}
27+
const cmd = [ 'git' ].concat(args).join(' ');
28+
const { stdout, code, stderr } = shell.exec(cmd, Object.assign({ stdio: 'ignore', timeout: TIMEOUT, silent: true }, options));
29+
if (code === 0) { return (stdout || '').trim(); }
30+
logger.warn('[execGitSync]', stderr || stdout);
31+
return '';
3432
}
3533

3634
function getCurrBranch() {

src/methods/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@ module.exports = function registerMethods(api, opts = {}) {
1515
description: '发布消息二次编辑事件',
1616
});
1717

18-
// TODO others type
18+
// others type
19+
api.registerMethod('addCommandDeployType', {
20+
type: api.API_TYPE.ADD,
21+
description: '添加其它类型的发布事件',
22+
});
1923
};

0 commit comments

Comments
 (0)