@pobuca/xsc
Version:
A cli tool with common git command sets.
132 lines • 5.26 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 chalk_1 = require("chalk");
const Command_1 = require("../classes/Command");
const { green, red } = chalk_1.default;
class XSCCommand extends Command_1.default {
invoke(subCommand) {
return __awaiter(this, void 0, void 0, function* () {
if (subCommand === SubCommand.Init) {
yield this.initializeRepo();
}
else {
yield this.statusCommand();
}
});
}
statusCommand() {
return __awaiter(this, void 0, void 0, function* () {
for (const line of XSCCommand.asciiLogo) {
this.emit('raw', line);
}
yield this.verifyCommand('git', 'git --version', [
'Download from https://git-scm.com/downloads',
'Verify it is in your PATH by running `git`'
]);
yield this.verifyCommand('git flow', 'git flow version', [
'Update or install git (https://git-scm.com/downloads)',
'Verify by running `git flow --version`'
]);
yield this.verifyCommand('hub', 'hub --version', [
'Download the latest hub release (https://github.com/github/hub/releases)',
'Add binary to your PATH',
'Verify by running `hub --version`'
]);
yield this.verifyCommand('az', 'az --version', [
'Download & install (https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest)',
'Verify it is in your PATH',
'Log in by running `az login`'
]);
yield this.verifyCommand('az devops', 'az devops -h', [
'Install or update your Azure CLI (https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest)',
'Run `az extension add --name azure-devops`',
'Log in by running `az login`'
]);
});
}
verifyCommand(commandName, command, fixSteps) {
return __awaiter(this, void 0, void 0, function* () {
const indentation = ' '.repeat(4);
try {
yield this.execSync(command, { stdio: 'ignore' }, true);
this.emit('raw', `${indentation}${green('√')} ${commandName}`);
}
catch (e) {
this.emit('raw', `${indentation}${red('x')} ${commandName}`);
let count = 1;
for (const step of fixSteps) {
this.emit('raw', `${indentation.repeat(2)}${red(`${count}. ${step}`)}`);
count++;
}
}
});
}
initializeRepo() {
return __awaiter(this, void 0, void 0, function* () {
try {
yield this.execSync('git status');
}
catch (e) {
yield this.execSync('git init');
yield this.execSync('git add . && git commit -m "Initial commit"');
}
this.initializeGitFlow();
});
}
initializeGitFlow() {
return __awaiter(this, void 0, void 0, function* () {
const gitConfigFilePath = '.git/config';
let gitConfigFile = this.terminal.readFileSync(gitConfigFilePath).toString();
if (!this.containsGitFlowOptions(gitConfigFile)) {
gitConfigFile += XSCCommand.defaultGitFlowConfig;
this.terminal.writeFileSync(gitConfigFilePath, gitConfigFile);
}
});
}
containsGitFlowOptions(configFile) {
const lines = configFile.split('\n');
for (const line of lines) {
if (line.match(/^\[gitflow /)) {
return true;
}
}
return false;
}
}
exports.default = XSCCommand;
XSCCommand.command = 'xsc';
XSCCommand.defaultGitFlowConfig = [
'',
'[gitflow "branch"]',
'\tmaster = master',
'\tdevelop = develop',
'[gitflow "prefix"]',
'\tfeature = feature/',
'\tbugfix = ',
'\trelease = release/',
'\thotfix = hotfix/',
'\tsupport = ',
'\tversiontag = '
].join('\n');
XSCCommand.asciiLogo = [
' _ _ ___ ___ ',
'( \\/ )/ __) / __)',
' ) ( \\__ \\( (__ ',
`(_/\\_)(___/ \\___) v${require('../../package').version}`,
' by Pobuca',
''
];
var SubCommand;
(function (SubCommand) {
SubCommand["Init"] = "init";
})(SubCommand || (SubCommand = {}));
//# sourceMappingURL=xsc.js.map