@pobuca/xsc
Version:
A cli tool with common git command sets.
74 lines • 3.37 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const semver_1 = require("semver");
const createPR_1 = require("./createPR");
const goToOriginBranch_1 = require("./goToOriginBranch");
const inferProjectDetails_1 = require("./inferProjectDetails");
const updateProjectVersion_1 = require("./updateProjectVersion");
const ProdCommandBaseBranchMap = {
hotfix: 'master',
release: 'develop'
};
const ProdCommandVersionSegmentMap = {
hotfix: 'patch',
release: 'minor'
};
function processProductionCommand(cmd, prodCommand, subCommand) {
return __awaiter(this, void 0, void 0, function* () {
if (subCommand === SubCommand.Finish) {
yield finishCommand(cmd, prodCommand);
}
else if (subCommand === SubCommand.Start) {
yield startCommand(cmd, prodCommand);
}
else {
throw new Error(`Unknown command: ${subCommand}`);
}
});
}
exports.default = processProductionCommand;
var SubCommand;
(function (SubCommand) {
SubCommand["Start"] = "start";
SubCommand["Finish"] = "finish";
})(SubCommand = exports.SubCommand || (exports.SubCommand = {}));
var ProdCommand;
(function (ProdCommand) {
ProdCommand["Hotfix"] = "hotfix";
ProdCommand["Release"] = "release";
})(ProdCommand = exports.ProdCommand || (exports.ProdCommand = {}));
function startCommand(cmd, prodCommand) {
return __awaiter(this, void 0, void 0, function* () {
yield cmd.execSync('git stash');
yield goToOriginBranch_1.default(cmd, ProdCommandBaseBranchMap[prodCommand]);
const { version } = yield inferProjectDetails_1.default(cmd.terminal);
const newVersion = semver_1.inc(version, ProdCommandVersionSegmentMap[prodCommand]);
yield cmd.execSync(`git flow ${prodCommand} start ${newVersion}`);
yield updateProjectVersion_1.default(cmd.terminal, newVersion);
yield cmd.execSync(`git commit -a -m ${newVersion}`);
yield cmd.execSync(`git push --set-upstream origin ${prodCommand}/${newVersion}`);
try {
yield cmd.execSync('git stash pop');
}
catch (e) { }
});
}
function finishCommand(cmd, prodCommand) {
return __awaiter(this, void 0, void 0, function* () {
const { version } = yield inferProjectDetails_1.default(cmd.terminal);
yield createPR_1.default(cmd, `${prodCommand}/${version}`, 'master');
yield createPR_1.default(cmd, `${prodCommand}/${version}`, 'develop');
yield cmd.execSync(`git checkout develop`);
yield cmd.execSync(`git branch -d ${prodCommand}/${version}`);
});
}
//# sourceMappingURL=processProductionCommand.js.map