Skip to content

Commit b792f31

Browse files
committed
:fix: 修复bug
1 parent 528015f commit b792f31

File tree

5 files changed

+13
-21
lines changed

5 files changed

+13
-21
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@micro-app/plugin-deploy",
3-
"version": "0.0.1",
3+
"version": "0.0.3",
44
"description": "[Plugin] auto deploy plugin.",
55
"main": "src/index.js",
66
"scripts": {

src/commands/deploy/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@ module.exports = function(api, opts = {}) {
1313
'--message': 'git commit message.',
1414
'--name': 'git commit user name.',
1515
'--email': 'git commit user email.',
16-
'--hooks': 'git commit hooks.',
1716
'--config <config>': '指定配置文件路径, 相对于根路径. 默认为根目录下的: "micro-app.deploy.config.js"',
1817
},
1918
details: `
2019
Examples:
2120
${chalk.gray('# deploy')}
2221
micro-app deploy
23-
${chalk.gray('# git hooks')}
24-
micro-app deploy --hooks
2522
${chalk.gray('# config file')}
2623
micro-app deploy --config micro-app.deploy.config.js
2724

src/commands/git/index.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const path = require('path');
44
const { fs, _, chalk, Env } = require('@micro-app/shared-utils');
55
const CONSTANTS = require('../../constants');
6-
const { execGit, execGitSync, getCurrBranch, getGitBranch, getGitUser } = require('./utils');
6+
const { execGit, execGitSync, getCurrBranch, getGitBranch, getGitUser, getCommitHash } = require('./utils');
77

88
function createCNAMEFile({ deployConfig, deployDir }) {
99
const cname = deployConfig.cname;
@@ -61,16 +61,6 @@ function gitPush(api, { args, deployConfig, deployDir, gitURL, gitBranch, commit
6161
return chain;
6262
}
6363

64-
function getCommitHash(api, { currBranch, isHooks }) {
65-
let commitHash = '';
66-
if (isHooks) {
67-
commitHash = execGitSync([ 'rev-parse', '--verify', 'HEAD' ]);
68-
} else {
69-
commitHash = execGitSync([ 'rev-parse', `origin/${currBranch}` ]);
70-
}
71-
return commitHash;
72-
}
73-
7464
function getGitMessage(api, { deployConfig, commitHash }) {
7565
let gitMessage = deployConfig.message && ` | ${deployConfig.message}` || '';
7666
if (!gitMessage) {
@@ -138,8 +128,7 @@ module.exports = async function deployCommit(api, args, deployConfigs) {
138128
logger.throw('Sorry, this script requires git');
139129
}
140130

141-
const isHooks = args.hooks;
142-
131+
// TODO 迁移到外部,且不中断
143132
return Promise.all(deployConfigs.map(async (deployConfig, index) => {
144133

145134
const gitURL = deployConfig.url || '';
@@ -156,7 +145,7 @@ module.exports = async function deployCommit(api, args, deployConfigs) {
156145

157146
const currBranch = getCurrBranch(deployConfig);
158147

159-
const commitHash = getCommitHash(api, { currBranch, isHooks });
148+
const commitHash = getCommitHash();
160149
if (_.isEmpty(commitHash)) {
161150
logger.warn('Not Found commit Hash!');
162151
return;

src/commands/git/utils.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const TIMEOUT = 1000 * 60 * 3;
77
module.exports = {
88
execGit,
99
execGitSync,
10+
getCommitHash,
1011
getCurrBranch,
1112
getGitBranch,
1213
getGitUser,
@@ -27,10 +28,15 @@ function execGitSync(args, options = {}) {
2728
const cmd = [ 'git' ].concat(args).join(' ');
2829
const { stdout, code, stderr } = shell.exec(cmd, Object.assign({ stdio: 'ignore', timeout: TIMEOUT, silent: true }, options));
2930
if (code === 0) { return (stdout || '').trim(); }
30-
logger.warn('[execGitSync]', stderr || stdout);
31+
logger.warn('[execGitSync]', cmd, stderr || stdout);
3132
return '';
3233
}
3334

35+
function getCommitHash() {
36+
const commitHash = execGitSync([ 'rev-parse', '--verify', 'HEAD' ]);
37+
return commitHash;
38+
}
39+
3440
function getCurrBranch(deployConfig) {
3541
if (deployConfig && deployConfig.baseBranch) {
3642
return deployConfig.baseBranch;

src/index.js

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

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

5-
api.assertVersion('>=0.2.2');
5+
api.assertVersion('>=0.3.0');
66

77
// methods
88
require('./methods')(api, opts);
@@ -13,5 +13,5 @@ module.exports = function DeployCommand(api, opts = {}) {
1313
};
1414

1515
module.exports.configuration = {
16-
description: '强制发布更新当前提交信息到指定 git 中命令行',
16+
description: '自动发布更新命令行',
1717
};

0 commit comments

Comments
 (0)