Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/compatible no develop branch #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 47 additions & 33 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* @Author: fei
* @Date: 2018-08-23 17:50:31
* @Last Modified by: fei
* @Last Modified time: 2018-08-28 15:47:34
* @Last Modified by: atever
* @Last Modified time: 2019-05-21 15:40:00
*/
'use strict';

Expand Down Expand Up @@ -65,7 +65,9 @@ async function _choreVersionCommit(dir, version) {
async function resolveFeat(dir) {
const remote = 'origin';
const developBranch = 'develop';
const remoteDevelopBranch = 'remotes/origin/develop'
const masterBranch = 'master';
let previousVersion, currentVersion;

console.log(chalk.green('>> 开始'));

Expand All @@ -77,29 +79,37 @@ async function resolveFeat(dir) {
}

const git = simpleGit(dir);

// develop 分支拉取代码 --> 升级版本号 --> 推送到远程 develop 分支
console.log(chalk.green(`>> 切换分支到: ${developBranch}`));
await git.checkout(developBranch);

console.log(chalk.green(`>> 拉取远程分支: git pull ${remote} ${developBranch}`));
await git.pull(remote, developBranch);

const [previousVersion, currentVersion] = await _updatePackageVersion(dir, 'develop');
console.log(chalk.green(`>> 更新版本号,旧版本号: ${previousVersion},新版本号: ${currentVersion}`));

console.log(chalk.green(`>> 提交版本更新 commit: chore(package.json): bump version to: ${currentVersion}`));
await _choreVersionCommit(dir, currentVersion);

console.log(chalk.green(`>> 推送到远程分支: git push ${remote} ${developBranch}`));
await git.push(remote, developBranch);

// master 分支合并 develop 分支 --> 打 tag --> 推送到远程分支
console.log(chalk.green(`>> 切换分支到: ${masterBranch}`));
await git.checkout(masterBranch);

console.log(chalk.green(`>> 合并 ${developBranch}`));
await git.mergeFromTo(developBranch, masterBranch);
const gitBranch = await git.branch();
if(gitBranch.branches[remoteDevelopBranch]) {
// develop 分支拉取代码 --> 升级版本号 --> 推送到远程 develop 分支
console.log(chalk.green(`>> 切换分支到: ${developBranch}`));
await git.checkout(developBranch);

console.log(chalk.green(`>> 拉取远程分支: git pull ${remote} ${developBranch}`));
await git.pull(remote, developBranch);

[previousVersion, currentVersion] = await _updatePackageVersion(dir, 'develop');
console.log(chalk.green(`>> 更新版本号,旧版本号: ${previousVersion},新版本号: ${currentVersion}`));

console.log(chalk.green(`>> 提交版本更新 commit: chore(package.json): bump version to: ${currentVersion}`));
await _choreVersionCommit(dir, currentVersion);

console.log(chalk.green(`>> 推送到远程分支: git push ${remote} ${developBranch}`));
await git.push(remote, developBranch);

// master 分支合并 develop 分支 --> 打 tag --> 推送到远程分支
console.log(chalk.green(`>> 切换分支到: ${masterBranch}`));
await git.checkout(masterBranch);

console.log(chalk.green(`>> 合并 ${developBranch}`));
await git.mergeFromTo(developBranch, masterBranch);
} else {
[previousVersion, currentVersion] = await _updatePackageVersion(dir, 'notExistDevelop');
console.log(chalk.green(`>> 更新版本号,旧版本号: ${previousVersion},新版本号: ${currentVersion}`));

console.log(chalk.green(`>> 提交版本更新 commit: chore(package.json): bump version to: ${currentVersion}`));
await _choreVersionCommit(dir, currentVersion);
}

console.log(chalk.green(`>> tag: ${currentVersion}`));
const answer = await insquirer.prompt([{
Expand All @@ -123,6 +133,7 @@ async function resolveFeat(dir) {
async function resolveFix(dir) {
const remote = 'origin';
const developBranch = 'develop';
const remoteDevelopBranch = 'remotes/origin/develop'
const masterBranch = 'master';

console.log(chalk.green('>> 开始'));
Expand Down Expand Up @@ -158,17 +169,20 @@ async function resolveFix(dir) {
await git.addAnnotatedTag(currentVersion, answer.tagMessage);

console.log(chalk.green(`>> 推送到远程分支: git push ${remote} ${masterBranch} --tags`));
await git .push(remote, masterBranch, { '--tags': true });
await git.push(remote, masterBranch, { '--tags': true });

// develop 分支合并 master 分支 --> 推送到远程分支
console.log(chalk.green(`>> 切换分支到: ${developBranch}`));
await git.checkout(developBranch);
const gitBranch = await git.branch();
if(gitBranch.branches[remoteDevelopBranch]) {
// develop 分支合并 master 分支 --> 推送到远程分支
console.log(chalk.green(`>> 切换分支到: ${developBranch}`));
await git.checkout(developBranch);

console.log(chalk.green(`>> 合并 ${masterBranch}`));
await git.mergeFromTo(masterBranch, developBranch);
console.log(chalk.green(`>> 合并 ${masterBranch}`));
await git.mergeFromTo(masterBranch, developBranch);

console.log(chalk.green(`>> 推送到远程分支: git push ${remote} ${developBranch}`));
await git.push(remote, developBranch);
console.log(chalk.green(`>> 推送到远程分支: git push ${remote} ${developBranch}`));
await git.push(remote, developBranch);
}

// 回复当前分支修改的代码 git stash pop
if (currentStatus.changed) {
Expand Down