UNPKG

1.93 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 return new (P || (P = Promise))(function (resolve, reject) {
4 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7 step((generator = generator.apply(thisArg, _arguments || [])).next());
8 });
9};
10Object.defineProperty(exports, "__esModule", { value: true });
11const fs = require("fs");
12const lodash_1 = require("lodash");
13const utils_1 = require("./utils");
14const github_1 = require("./github");
15const validations_1 = require("./validations");
16const commands = [
17 [{ cmd: 'gh', cmd_gh: 'setup' }, github_1.setup],
18 [{ cmd: 'gh', cmd_gh: 'feature' }, github_1.startWorkOnFeature],
19 [{ cmd: 'gh', cmd_gh: 'pr' }, github_1.createPullRequest],
20 [{ cmd: 'gh', cmd_gh: 'commit' }, github_1.makeCommit],
21 [{ cmd: 'gh', cmd_gh: 'open' }, github_1.openPullRequestOnGitHub]
22];
23function main() {
24 return __awaiter(this, void 0, void 0, function* () {
25 const hophopDir = utils_1.getHophopDir();
26 !fs.existsSync(hophopDir) && fs.mkdirSync(hophopDir);
27 yield utils_1.checkForUpdates();
28 validations_1.default();
29 const args = utils_1.parseArgs();
30 const pickedArgs = lodash_1.pick(args, ['cmd', 'cmd_gh', 'cmd_toggl']);
31 const command = lodash_1.find(commands, c => lodash_1.isEqual(c[0], pickedArgs));
32 yield command[1](args);
33 });
34}
35main().catch(e => {
36 if (e instanceof utils_1.HophopError) {
37 e.message && utils_1.error('\n', e.message, '\n');
38 }
39 else {
40 utils_1.error('\n', e.stack, '\n');
41 }
42 process.exit(0);
43});