ogit
Version:
A lazy developer's Git CLI made simple. Makes using git on cloud IDEs (i.e. C9) a walk in the park.
115 lines (114 loc) • 5.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const Constants_1 = require("./../utils/Constants");
const AbstractBranchCommand_1 = require("../abstracts/AbstractBranchCommand");
require("reflect-metadata");
const git_1 = require("../wrapper/git");
const command_1 = require("@oclif/command");
const inquirer = require("inquirer");
const chalk = require('chalk');
class CreateGitFlowCommand extends AbstractBranchCommand_1.default {
run() {
const _super = name => super[name];
return tslib_1.__awaiter(this, void 0, void 0, function* () {
this.config[Constants_1.FEATURE_BRNACH_NAME] = yield git_1.GitFacade.getConfigDataFromAnyWhere(Constants_1.FEATURE_BRNACH_NAME);
this.config[Constants_1.RELEASE_BRANCH_NAME] = yield git_1.GitFacade.getConfigDataFromAnyWhere(Constants_1.RELEASE_BRANCH_NAME);
this.config[Constants_1.HOTFIX_BRANCH_NAME] = yield git_1.GitFacade.getConfigDataFromAnyWhere(Constants_1.HOTFIX_BRANCH_NAME);
this.config[Constants_1.NEXT_RELEASE_BRANCH] = yield git_1.GitFacade.getConfigDataFromAnyWhere(Constants_1.NEXT_RELEASE_BRANCH);
yield _super("runHelper").call(this);
});
}
getBranchNamePrefix(type, config) {
switch (type) {
case 'feature':
return config[Constants_1.FEATURE_BRNACH_NAME];
case 'release':
return config[Constants_1.RELEASE_BRANCH_NAME];
case 'hotfix':
return config[Constants_1.HOTFIX_BRANCH_NAME];
default:
return '';
}
}
getSelectedBranch() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const localBranches = this.localBranches;
const { flags } = this.parse(CreateGitFlowCommand);
const prompts = [];
let localBranchName, brnachType;
let answers = {};
if (!flags.type) {
prompts.push({
message: 'What type of git flow do you want to start?',
type: 'list',
name: 'type',
choices: ['feature', 'release', 'hotfix']
});
answers = yield inquirer.prompt(prompts).then((answers) => {
return inquirer.prompt({
message: 'Local branch name',
type: 'input',
name: 'localBranchName',
validate: (branchName) => {
brnachType = answers.type;
if (branchName) {
const branchToSearch = `${this.getBranchNamePrefix(answers.type, this.config)}/${branchName}`;
if (localBranches.indexOf(branchToSearch) > -1) {
return `A local branch named ${chalk.green(branchToSearch)} already exists`;
}
return true;
}
return false;
}
});
});
localBranchName = `${this.getBranchNamePrefix(brnachType, this.config)}/${answers.localBranchName}`;
}
else {
prompts.push({
message: 'Local branch name',
type: 'input',
name: 'localBranchName',
validate: (branchName) => {
if (branchName) {
const branchToSearch = `${this.getBranchNamePrefix(flags.type, this.config)}/${branchName}`;
if (localBranches.indexOf(branchToSearch) > -1) {
return `A local branch named ${chalk.green(branchToSearch)} already exists`;
}
else {
return true;
}
}
return false;
}
});
answers = yield inquirer.prompt(prompts);
localBranchName = `${this.getBranchNamePrefix(flags.type, this.config)}/${answers.localBranchName}`;
brnachType = flags.type;
}
// console.log(`this.config = ${JSON.stringify(this.config)}`);
const productionReleaseBranch = this.config[Constants_1.PRODUCTION_RELEASE_BRANCH];
const nextReleaseBranch = this.config[Constants_1.NEXT_RELEASE_BRANCH];
return {
branchNameA: localBranchName,
branchNameB: brnachType === 'hotfix' ? productionReleaseBranch : nextReleaseBranch
};
});
}
preformBranchOperation(branchInfo) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
// console.log(`preformBranchOperation - ${JSON.stringify(branchInfo)}`);
yield git_1.GitFacade.createBranch(branchInfo.branchNameA, branchInfo.branchNameB);
});
}
}
CreateGitFlowCommand.description = 'Starts GitFlow branching model workflow';
CreateGitFlowCommand.flags = {
// branch type: --type or -t
type: command_1.flags.string({
char: 't',
description: 'type of branching'
})
};
exports.default = CreateGitFlowCommand;