ogit
Version:
A lazy developer's Git CLI made simple. Makes using git on cloud IDEs (i.e. C9) a walk in the park.
159 lines (158 loc) • 6.09 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const Constants_1 = require("./../utils/Constants");
require("reflect-metadata");
const git_1 = require("../wrapper/git");
const command_1 = require("@oclif/command");
const inquirer = require("inquirer");
class SetupGitFlowCommand extends command_1.Command {
constructor() {
super(...arguments);
this.searchBranch = (branches) => {
return (answers, input) => {
const searchResults = branches.filter(branch => branch.indexOf(input) > -1);
return Promise.resolve(searchResults ? searchResults : answers);
};
};
}
run() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield git_1.GitFacade.syncRemoteBranches();
const branchesList = yield git_1.GitFacade.listBranches();
const remoteBranches = [];
for (let branch of branchesList) {
if (!branch.isLocal) {
remoteBranches.push(branch.name);
}
}
// console.log(remoteBranches);
inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt'));
const { flags } = this.parse(SetupGitFlowCommand);
const prompts = [];
let answers = {};
if (!flags.global) {
prompts.push({
message: 'Setting up GitFlow globaly?',
type: 'confirm',
name: 'global',
default: false
});
}
if (!flags.production) {
prompts.push({
message: 'Name of the production release branch to create local from',
type: 'autocomplete',
source: this.searchBranch(remoteBranches),
name: 'production',
validate(choices) {
return choices.length > 0;
}
});
}
if (!flags.next) {
prompts.push({
message: 'Name of the next release branch to create local from',
type: 'autocomplete',
source: this.searchBranch(remoteBranches),
name: 'next',
validate(choices) {
return choices.length > 0;
}
});
}
if (!flags.feature) {
prompts.push({
message: 'Feature branch prefix',
type: 'input',
default: 'feature',
name: 'feature',
validate(name) {
return name !== '';
}
});
}
if (!flags.release) {
prompts.push({
message: 'Release branch prefix',
type: 'input',
default: 'release',
name: 'release',
validate(name) {
return name !== '';
}
});
}
if (!flags.hotfix) {
prompts.push({
message: 'Hotfix branch prefix',
type: 'input',
default: 'hotfix',
name: 'hotfix',
validate(name) {
return name !== '';
}
});
}
if (!flags.tag) {
prompts.push({
message: 'Version tag prefix',
type: 'input',
name: 'tag',
validate(name) {
return name !== '';
}
});
}
if (prompts.length > 0) {
answers = yield inquirer.prompt(prompts);
}
const options = Object.assign({}, flags, answers);
yield git_1.GitFacade.setConfigData(Constants_1.PRODUCTION_RELEASE_BRANCH, options.production, options.global);
yield git_1.GitFacade.setConfigData(Constants_1.NEXT_RELEASE_BRANCH, options.next, options.global);
yield git_1.GitFacade.setConfigData(Constants_1.FEATURE_BRNACH_NAME, options.feature, options.global);
yield git_1.GitFacade.setConfigData(Constants_1.RELEASE_BRANCH_NAME, options.release, options.global);
yield git_1.GitFacade.setConfigData(Constants_1.HOTFIX_BRANCH_NAME, options.hotfix, options.global);
yield git_1.GitFacade.setConfigData(Constants_1.VERSION_TAG_PREFIX, options.tag, options.global);
});
}
}
SetupGitFlowCommand.description = 'Sets up GitFlow branching model workflow';
SetupGitFlowCommand.flags = {
// global setting: --global or -g
global: command_1.flags.string({
char: 'g',
description: 'setup flow config globally'
}),
//production release branch: --production or -p
production: command_1.flags.string({
char: 'p',
description: 'name of the production release branch'
}),
//next release branch: --next or -n
next: command_1.flags.string({
char: 'n',
description: 'name of the next release branch'
}),
//feature branch name: --feature or -f
feature: command_1.flags.string({
char: 'f',
description: 'name of the feature branch'
}),
//release branch name: --release or -r
release: command_1.flags.string({
char: 'r',
description: 'name of the release branch'
}),
//hotfix branch: --hotfix or -h
hotfix: command_1.flags.string({
char: 'h',
description: 'name of the hotfix branch'
}),
//version tag prefix: --tag or -t
tag: command_1.flags.string({
char: 't',
description: 'version tag prefix'
})
};
exports.default = SetupGitFlowCommand;