avil13-co 1.1.5 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -2
- package/dist/ask.d.ts +3 -1
- package/dist/ask.js +19 -53
- package/dist/cli-commands/index.d.ts +9 -0
- package/dist/cli-commands/index.js +49 -0
- package/dist/color.d.ts +27 -0
- package/dist/color.js +30 -75
- package/dist/commands/checkout-branch.d.ts +1 -0
- package/dist/commands/checkout-branch.js +16 -0
- package/dist/commands/delete-barnch.d.ts +1 -0
- package/dist/commands/delete-barnch.js +30 -0
- package/dist/commands/exec.d.ts +1 -0
- package/dist/commands/exec.js +8 -0
- package/dist/commands/get-branches.d.ts +9 -0
- package/dist/commands/get-branches.js +47 -0
- package/dist/commands/get-current-branch-name.d.ts +1 -0
- package/dist/commands/get-current-branch-name.js +10 -0
- package/dist/commands/index.d.ts +3 -0
- package/dist/commands/index.js +19 -0
- package/dist/index.js +26 -66
- package/package.json +10 -9
- package/src/ask.ts +2 -1
- package/src/cli-commands/index.ts +53 -0
- package/src/color.ts +2 -2
- package/src/commands/checkout-branch.ts +16 -0
- package/src/commands/delete-barnch.ts +31 -0
- package/src/commands/exec.ts +9 -0
- package/src/commands/get-branches.ts +50 -0
- package/src/commands/get-current-branch-name.ts +9 -0
- package/src/commands/index.ts +3 -0
- package/src/index.ts +26 -12
- package/dist/commands.d.ts +0 -6
- package/dist/commands.js +0 -114
- package/src/commands.ts +0 -68
package/README.md
CHANGED
|
@@ -6,8 +6,35 @@
|
|
|
6
6
|
|
|
7
7
|
Install:
|
|
8
8
|
|
|
9
|
-
```
|
|
9
|
+
```sh
|
|
10
10
|
npm install -g avil13-co
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Type alias "`co`" for switch branch.
|
|
13
|
+
Type alias "`co`" for switch branch.
|
|
14
|
+
|
|
15
|
+
# Usage
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
# Shows a list of branches that can be switched to
|
|
19
|
+
co
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
# Shows help message
|
|
24
|
+
co -h
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
# Showing merged branches
|
|
29
|
+
co m
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
# Showing not merged branches
|
|
34
|
+
co un
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
# Choosing a branch to delete
|
|
39
|
+
co -D
|
|
40
|
+
```
|
package/dist/ask.d.ts
CHANGED
package/dist/ask.js
CHANGED
|
@@ -1,61 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
4
|
};
|
|
38
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
6
|
+
exports.ask = void 0;
|
|
7
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
8
|
+
inquirer_1.default.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt'));
|
|
9
|
+
const specSymbols = {
|
|
42
10
|
_saveCursor: '\x1b7',
|
|
43
11
|
_restoreCursor: '\x1b8',
|
|
44
12
|
_clear: '\x1b[H\x1b[2J',
|
|
45
13
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return Promise.resolve(list);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
return [2 /*return*/, prompt];
|
|
14
|
+
const ask = async (message, choices) => {
|
|
15
|
+
const prompt = inquirer_1.default.prompt({
|
|
16
|
+
//@ts-ignore
|
|
17
|
+
type: 'autocomplete',
|
|
18
|
+
name: 'branch',
|
|
19
|
+
message,
|
|
20
|
+
source(answersSoFar, input = '') {
|
|
21
|
+
const list = choices.filter(str => str.indexOf(input) > -1);
|
|
22
|
+
return Promise.resolve(list);
|
|
23
|
+
}
|
|
60
24
|
});
|
|
61
|
-
|
|
25
|
+
return prompt;
|
|
26
|
+
};
|
|
27
|
+
exports.ask = ask;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHelp = exports.getWishOfUser = exports.Commands = void 0;
|
|
4
|
+
const args = process.argv.slice(2);
|
|
5
|
+
var Commands;
|
|
6
|
+
(function (Commands) {
|
|
7
|
+
Commands[Commands["Unknown"] = 0] = "Unknown";
|
|
8
|
+
Commands[Commands["Help"] = 1] = "Help";
|
|
9
|
+
Commands[Commands["DeleteBranch"] = 2] = "DeleteBranch";
|
|
10
|
+
Commands[Commands["ShowMerged"] = 3] = "ShowMerged";
|
|
11
|
+
Commands[Commands["ShowUnMerged"] = 4] = "ShowUnMerged";
|
|
12
|
+
})(Commands = exports.Commands || (exports.Commands = {}));
|
|
13
|
+
;
|
|
14
|
+
const getWishOfUser = (firstArg) => {
|
|
15
|
+
const arg = firstArg || args[0];
|
|
16
|
+
switch (true) {
|
|
17
|
+
case ['help', '-h', '--h', '--help'].includes(arg):
|
|
18
|
+
return Commands.Help;
|
|
19
|
+
case ['-D', 'rm'].includes(arg):
|
|
20
|
+
return Commands.DeleteBranch;
|
|
21
|
+
case ['m', '-m', 'merged'].includes(arg):
|
|
22
|
+
return Commands.ShowMerged;
|
|
23
|
+
case ['un', '--no-merged'].includes(arg):
|
|
24
|
+
return Commands.ShowUnMerged;
|
|
25
|
+
default:
|
|
26
|
+
return Commands.Unknown;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.getWishOfUser = getWishOfUser;
|
|
30
|
+
const getHelp = () => {
|
|
31
|
+
return `
|
|
32
|
+
DESCRIPTION:
|
|
33
|
+
A console program for quickly switching between branches
|
|
34
|
+
|
|
35
|
+
OPTIONS:
|
|
36
|
+
help, -h, --h, --help
|
|
37
|
+
Showing this message
|
|
38
|
+
|
|
39
|
+
m, -m, merged
|
|
40
|
+
Showing merged branches
|
|
41
|
+
|
|
42
|
+
un, -un, --no-merged
|
|
43
|
+
Showing not merged branches
|
|
44
|
+
|
|
45
|
+
-D, rm
|
|
46
|
+
Delete the selected branch
|
|
47
|
+
`;
|
|
48
|
+
};
|
|
49
|
+
exports.getHelp = getHelp;
|
package/dist/color.d.ts
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const clc: {
|
|
2
|
+
_red: string;
|
|
3
|
+
_green: string;
|
|
4
|
+
_yellow: string;
|
|
5
|
+
_blue: string;
|
|
6
|
+
_greenBg: string;
|
|
7
|
+
_redBg: string;
|
|
8
|
+
_blueBg: string;
|
|
9
|
+
_cyan: string;
|
|
10
|
+
_white: string;
|
|
11
|
+
_gray: string;
|
|
12
|
+
_right: string;
|
|
13
|
+
_off: string;
|
|
14
|
+
color(...args: any[]): string;
|
|
15
|
+
greenOrRed(isVal: any, ...strList: any[]): string;
|
|
16
|
+
greenOrRedBg(isVal: any, ...strList: any): string;
|
|
17
|
+
greenBg(str1: any, str2: any): string;
|
|
18
|
+
redBg(str1: any, str2: any): string;
|
|
19
|
+
blueBg(str1: any, str2: any): string;
|
|
20
|
+
green(...args: any[]): string;
|
|
21
|
+
red(...args: any[]): string;
|
|
22
|
+
yellow(...args: any[]): string;
|
|
23
|
+
blue(...args: any[]): string;
|
|
24
|
+
cyan(...args: any[]): string;
|
|
25
|
+
white(...args: any[]): string;
|
|
26
|
+
gray(...args: any[]): string;
|
|
27
|
+
};
|
package/dist/color.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
6
|
-
r[k] = a[j];
|
|
7
|
-
return r;
|
|
8
|
-
};
|
|
9
|
-
module.exports = {
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clc = void 0;
|
|
4
|
+
exports.clc = {
|
|
10
5
|
_red: '\x1b[31m',
|
|
11
6
|
_green: '\x1b[32m',
|
|
12
7
|
_yellow: '\x1b[33m',
|
|
@@ -19,102 +14,62 @@ module.exports = {
|
|
|
19
14
|
_gray: '\x1b[0;90m',
|
|
20
15
|
_right: '\x1b[46G',
|
|
21
16
|
_off: '\x1b[0m',
|
|
22
|
-
color
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
var color = args[0];
|
|
28
|
-
var str = args[1];
|
|
29
|
-
var left = args.splice(2);
|
|
30
|
-
return ("" + color + str + this._off + (left.length ? ' ' + left.join(' ') : ''));
|
|
17
|
+
color(...args) {
|
|
18
|
+
const color = args[0];
|
|
19
|
+
const str = args[1];
|
|
20
|
+
const left = args.splice(2);
|
|
21
|
+
return (`${color}${str}${this._off}` + (left.length ? ' ' + left.join(' ') : ''));
|
|
31
22
|
},
|
|
32
|
-
greenOrRed
|
|
33
|
-
var strList = [];
|
|
34
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
35
|
-
strList[_i - 1] = arguments[_i];
|
|
36
|
-
}
|
|
23
|
+
greenOrRed(isVal, ...strList) {
|
|
37
24
|
return isVal === true
|
|
38
25
|
? this.green.apply(this, strList)
|
|
39
26
|
: this.red.apply(this, strList);
|
|
40
27
|
},
|
|
41
|
-
greenOrRedBg
|
|
42
|
-
var strList = [];
|
|
43
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
44
|
-
strList[_i - 1] = arguments[_i];
|
|
45
|
-
}
|
|
28
|
+
greenOrRedBg(isVal, ...strList) {
|
|
46
29
|
return isVal === true
|
|
47
30
|
? this.greenBg.apply(this, strList)
|
|
48
31
|
: this.redBg.apply(this, strList);
|
|
49
32
|
},
|
|
50
|
-
greenBg
|
|
51
|
-
|
|
33
|
+
greenBg(str1, str2) {
|
|
34
|
+
let str = this.color(this._greenBg, ` ${str1} `);
|
|
52
35
|
if (str2) {
|
|
53
36
|
str += ' ' + this.color(this._green, str2);
|
|
54
37
|
}
|
|
55
38
|
return str;
|
|
56
39
|
},
|
|
57
|
-
redBg
|
|
58
|
-
|
|
40
|
+
redBg(str1, str2) {
|
|
41
|
+
let str = this.color(this._redBg, ` ${str1} `);
|
|
59
42
|
if (str2) {
|
|
60
43
|
str += ' ' + this.color(this._red, str2);
|
|
61
44
|
}
|
|
62
45
|
return str;
|
|
63
46
|
},
|
|
64
|
-
blueBg
|
|
65
|
-
|
|
47
|
+
blueBg(str1, str2) {
|
|
48
|
+
let str = this.color(this._blueBg, ` ${str1} `);
|
|
66
49
|
if (str2) {
|
|
67
50
|
str += ' ' + this.color(this._blue, str2);
|
|
68
51
|
}
|
|
69
52
|
return str;
|
|
70
53
|
},
|
|
71
|
-
green
|
|
72
|
-
|
|
73
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
74
|
-
args[_i] = arguments[_i];
|
|
75
|
-
}
|
|
76
|
-
return this.color.apply(this, __spreadArrays([this._green], args));
|
|
54
|
+
green(...args) {
|
|
55
|
+
return this.color.apply(this, [this._green, ...args]);
|
|
77
56
|
},
|
|
78
|
-
red
|
|
79
|
-
|
|
80
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
81
|
-
args[_i] = arguments[_i];
|
|
82
|
-
}
|
|
83
|
-
return this.color.apply(this, __spreadArrays([this._red], args));
|
|
57
|
+
red(...args) {
|
|
58
|
+
return this.color.apply(this, [this._red, ...args]);
|
|
84
59
|
},
|
|
85
|
-
yellow
|
|
86
|
-
|
|
87
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
88
|
-
args[_i] = arguments[_i];
|
|
89
|
-
}
|
|
90
|
-
return this.color.apply(this, __spreadArrays([this._yellow], args));
|
|
60
|
+
yellow(...args) {
|
|
61
|
+
return this.color.apply(this, [this._yellow, ...args]);
|
|
91
62
|
},
|
|
92
|
-
blue
|
|
93
|
-
|
|
94
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
95
|
-
args[_i] = arguments[_i];
|
|
96
|
-
}
|
|
97
|
-
return this.color.apply(this, __spreadArrays([this._blue], args));
|
|
63
|
+
blue(...args) {
|
|
64
|
+
return this.color.apply(this, [this._blue, ...args]);
|
|
98
65
|
},
|
|
99
|
-
cyan
|
|
100
|
-
|
|
101
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
102
|
-
args[_i] = arguments[_i];
|
|
103
|
-
}
|
|
104
|
-
return this.color.apply(this, __spreadArrays([this._cyan], args));
|
|
66
|
+
cyan(...args) {
|
|
67
|
+
return this.color.apply(this, [this._cyan, ...args]);
|
|
105
68
|
},
|
|
106
|
-
white
|
|
107
|
-
|
|
108
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
109
|
-
args[_i] = arguments[_i];
|
|
110
|
-
}
|
|
111
|
-
return this.color.apply(this, __spreadArrays([this._white], args));
|
|
69
|
+
white(...args) {
|
|
70
|
+
return this.color.apply(this, [this._white, ...args]);
|
|
112
71
|
},
|
|
113
|
-
gray
|
|
114
|
-
|
|
115
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
116
|
-
args[_i] = arguments[_i];
|
|
117
|
-
}
|
|
118
|
-
return this.color.apply(this, __spreadArrays([this._gray], args));
|
|
72
|
+
gray(...args) {
|
|
73
|
+
return this.color.apply(this, [this._gray, ...args]);
|
|
119
74
|
},
|
|
120
75
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function checkoutBranch(branchName: string): Promise<void>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkoutBranch = void 0;
|
|
4
|
+
const exec_1 = require("./exec");
|
|
5
|
+
const color_1 = require("../color");
|
|
6
|
+
//
|
|
7
|
+
async function checkoutBranch(branchName) {
|
|
8
|
+
if (!branchName) {
|
|
9
|
+
throw new Error('No branch...');
|
|
10
|
+
}
|
|
11
|
+
const checkoutCommand = `git checkout ${branchName}`;
|
|
12
|
+
console.log(' ' + color_1.clc.green('git checkout', branchName) + '\n');
|
|
13
|
+
const checkoutCommandResult = await (0, exec_1.exec)(checkoutCommand);
|
|
14
|
+
console.log(checkoutCommandResult);
|
|
15
|
+
}
|
|
16
|
+
exports.checkoutBranch = checkoutBranch;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function deleteBranch(branchName: string): Promise<void>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.deleteBranch = void 0;
|
|
7
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
8
|
+
const exec_1 = require("./exec");
|
|
9
|
+
const color_1 = require("../color");
|
|
10
|
+
async function deleteBranch(branchName) {
|
|
11
|
+
if (!branchName) {
|
|
12
|
+
throw new Error('No branch...');
|
|
13
|
+
}
|
|
14
|
+
const res = await inquirer_1.default.prompt({
|
|
15
|
+
type: 'confirm',
|
|
16
|
+
name: 'answer',
|
|
17
|
+
message: color_1.clc.yellow('Are you sure you want to delete the branch "') + color_1.clc.red(branchName) + color_1.clc.yellow('"?'),
|
|
18
|
+
default: false,
|
|
19
|
+
});
|
|
20
|
+
if (res.answer === true) {
|
|
21
|
+
const command = `git branch -D ${branchName}`;
|
|
22
|
+
console.log(' ' + color_1.clc.redBg(`git branch -D ${branchName}`, '') + '\n');
|
|
23
|
+
const checkoutCommandResult = await (0, exec_1.exec)(command);
|
|
24
|
+
console.log(checkoutCommandResult);
|
|
25
|
+
console.log(color_1.clc.yellow('Branch'), color_1.clc.red(branchName), color_1.clc.yellow('has been deleted'));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
console.log(color_1.clc.yellow('The branch was not deleted'));
|
|
29
|
+
}
|
|
30
|
+
exports.deleteBranch = deleteBranch;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function exec(command: any): Promise<string>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exec = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
function exec(command) {
|
|
6
|
+
return new Promise((resolve, reject) => (0, child_process_1.exec)(command, (err, stdout) => err ? reject(err) : resolve(stdout)));
|
|
7
|
+
}
|
|
8
|
+
exports.exec = exec;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBranches = exports.BranchesType = void 0;
|
|
4
|
+
const exec_1 = require("./exec");
|
|
5
|
+
var BranchesType;
|
|
6
|
+
(function (BranchesType) {
|
|
7
|
+
BranchesType[BranchesType["All"] = 0] = "All";
|
|
8
|
+
BranchesType[BranchesType["Merged"] = 1] = "Merged";
|
|
9
|
+
BranchesType[BranchesType["NotMerged"] = 2] = "NotMerged";
|
|
10
|
+
})(BranchesType = exports.BranchesType || (exports.BranchesType = {}));
|
|
11
|
+
const commandsForGetBranches = {
|
|
12
|
+
[BranchesType.All]: 'git branch --all',
|
|
13
|
+
[BranchesType.Merged]: 'git branch --all --merged',
|
|
14
|
+
[BranchesType.NotMerged]: 'git branch --all --no-merged',
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* get branch list
|
|
18
|
+
*/
|
|
19
|
+
function getBranches(type) {
|
|
20
|
+
const command = commandsForGetBranches[type];
|
|
21
|
+
return (0, exec_1.exec)(command)
|
|
22
|
+
.then(parseBranches)
|
|
23
|
+
.then(branches => {
|
|
24
|
+
if (branches.length) {
|
|
25
|
+
return branches;
|
|
26
|
+
}
|
|
27
|
+
throw new Error('No branches found...');
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
exports.getBranches = getBranches;
|
|
31
|
+
function parseBranches(stdout) {
|
|
32
|
+
return stdout
|
|
33
|
+
.split('\n')
|
|
34
|
+
.filter(s => !/\s->\s/.test(s))
|
|
35
|
+
.map(cleanBranchName)
|
|
36
|
+
.filter(Boolean)
|
|
37
|
+
.filter(onlyUnique);
|
|
38
|
+
}
|
|
39
|
+
function cleanBranchName(name) {
|
|
40
|
+
return name
|
|
41
|
+
.replace(/^\*/, '')
|
|
42
|
+
.replace(/remotes\/origin\//, '')
|
|
43
|
+
.trim();
|
|
44
|
+
}
|
|
45
|
+
function onlyUnique(value, index, self) {
|
|
46
|
+
return self.indexOf(value) === index;
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getCurrentBranchName(): Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCurrentBranchName = void 0;
|
|
4
|
+
const exec_1 = require("./exec");
|
|
5
|
+
async function getCurrentBranchName() {
|
|
6
|
+
const currentBranchName = `git rev-parse --abbrev-ref HEAD`;
|
|
7
|
+
const stdout = await (0, exec_1.exec)(currentBranchName);
|
|
8
|
+
console.log(stdout);
|
|
9
|
+
}
|
|
10
|
+
exports.getCurrentBranchName = getCurrentBranchName;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./checkout-branch"), exports);
|
|
18
|
+
__exportStar(require("./get-branches"), exports);
|
|
19
|
+
__exportStar(require("./get-current-branch-name"), exports);
|
package/dist/index.js
CHANGED
|
@@ -1,69 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ask_1 = require("./ask");
|
|
4
|
+
const cli_commands_1 = require("./cli-commands");
|
|
5
|
+
const commands_1 = require("./commands");
|
|
6
|
+
const delete_barnch_1 = require("./commands/delete-barnch");
|
|
7
|
+
const run = async () => {
|
|
8
|
+
const userWish = (0, cli_commands_1.getWishOfUser)();
|
|
9
|
+
if (cli_commands_1.Commands.Help === userWish) {
|
|
10
|
+
console.log((0, cli_commands_1.getHelp)());
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
let branchType = commands_1.BranchesType.All;
|
|
14
|
+
if (cli_commands_1.Commands.ShowMerged === userWish) {
|
|
15
|
+
branchType = commands_1.BranchesType.Merged;
|
|
36
16
|
}
|
|
17
|
+
else if (cli_commands_1.Commands.ShowUnMerged === userWish) {
|
|
18
|
+
branchType = commands_1.BranchesType.NotMerged;
|
|
19
|
+
}
|
|
20
|
+
const branches = await (0, commands_1.getBranches)(branchType);
|
|
21
|
+
const { branch } = await (0, ask_1.ask)('Select branch', branches);
|
|
22
|
+
if (cli_commands_1.Commands.DeleteBranch === userWish) {
|
|
23
|
+
(0, delete_barnch_1.deleteBranch)(branch);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
await (0, commands_1.checkoutBranch)(branch);
|
|
27
|
+
await (0, commands_1.getCurrentBranchName)();
|
|
37
28
|
};
|
|
38
|
-
|
|
39
|
-
var commands_1 = require("./commands");
|
|
40
|
-
var ask_1 = require("./ask");
|
|
41
|
-
var run = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
42
|
-
var branches, branch, stdout;
|
|
43
|
-
return __generator(this, function (_a) {
|
|
44
|
-
switch (_a.label) {
|
|
45
|
-
case 0: return [4 /*yield*/, commands_1.getBranches()];
|
|
46
|
-
case 1:
|
|
47
|
-
branches = _a.sent();
|
|
48
|
-
return [4 /*yield*/, ask_1.ask('Select branch', branches)];
|
|
49
|
-
case 2:
|
|
50
|
-
branch = (_a.sent()).branch;
|
|
51
|
-
stdout = '';
|
|
52
|
-
return [4 /*yield*/, commands_1.checkoutBranch(branch)];
|
|
53
|
-
case 3:
|
|
54
|
-
stdout = _a.sent();
|
|
55
|
-
console.log(stdout);
|
|
56
|
-
return [4 /*yield*/, commands_1.getCurrentBranchName()];
|
|
57
|
-
case 4:
|
|
58
|
-
stdout = _a.sent();
|
|
59
|
-
console.log(stdout);
|
|
60
|
-
return [2 /*return*/];
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}); };
|
|
64
|
-
try {
|
|
65
|
-
run();
|
|
66
|
-
}
|
|
67
|
-
catch (err) {
|
|
68
|
-
console.log(err);
|
|
69
|
-
}
|
|
29
|
+
run();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "avil13-co",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"public": true,
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
"assets"
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
|
-
"
|
|
17
|
+
"prepublishOnly": "npm run build",
|
|
18
18
|
"start": "npm run build && node dist/index.js",
|
|
19
19
|
"dev": "ts-node --project tsconfig.json src/index.ts",
|
|
20
20
|
"dev:watch": "nodemon",
|
|
21
21
|
"lint:fix": "eslint --fix --ext .js,.ts .",
|
|
22
|
-
"test": "
|
|
23
|
-
"test:watch": "
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest",
|
|
24
24
|
"type-check": "tsc -p . --noEmit",
|
|
25
25
|
"type-check:watch": "npm run type-check -- --watch",
|
|
26
26
|
"build": "rm -rf ./dist && tsc -p ."
|
|
@@ -37,12 +37,13 @@
|
|
|
37
37
|
"url": "git@github.com:avil13/avil13-git-co.git"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"inquirer": "^
|
|
41
|
-
"inquirer-autocomplete-prompt": "^
|
|
40
|
+
"inquirer": "^8.2.2",
|
|
41
|
+
"inquirer-autocomplete-prompt": "^2.0.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@types/
|
|
45
|
-
"
|
|
46
|
-
"
|
|
44
|
+
"@types/inquirer": "^8.2.1",
|
|
45
|
+
"@types/node": "^17.0.23",
|
|
46
|
+
"ts-node": "^10.7.0",
|
|
47
|
+
"typescript": "^4.6.3"
|
|
47
48
|
}
|
|
48
49
|
}
|
package/src/ask.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
2
|
|
|
3
3
|
inquirer.registerPrompt(
|
|
4
4
|
'autocomplete',
|
|
@@ -13,6 +13,7 @@ const specSymbols = {
|
|
|
13
13
|
|
|
14
14
|
export const ask = async (message: string, choices: string[]) => {
|
|
15
15
|
const prompt = inquirer.prompt({
|
|
16
|
+
//@ts-ignore
|
|
16
17
|
type: 'autocomplete',
|
|
17
18
|
name: 'branch',
|
|
18
19
|
message,
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { clc } from '../color';
|
|
2
|
+
|
|
3
|
+
const args = process.argv.slice(2);
|
|
4
|
+
|
|
5
|
+
export enum Commands {
|
|
6
|
+
Unknown,
|
|
7
|
+
Help,
|
|
8
|
+
DeleteBranch,
|
|
9
|
+
ShowMerged,
|
|
10
|
+
ShowUnMerged,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const getWishOfUser = (firstArg?: string): Commands => {
|
|
14
|
+
const arg: string = firstArg || args[0];
|
|
15
|
+
|
|
16
|
+
switch (true) {
|
|
17
|
+
case ['help', '-h', '--h', '--help'].includes(arg):
|
|
18
|
+
return Commands.Help;
|
|
19
|
+
|
|
20
|
+
case ['-D', 'rm'].includes(arg):
|
|
21
|
+
return Commands.DeleteBranch;
|
|
22
|
+
|
|
23
|
+
case ['m', '-m', 'merged'].includes(arg):
|
|
24
|
+
return Commands.ShowMerged;
|
|
25
|
+
|
|
26
|
+
case ['un', '--no-merged'].includes(arg):
|
|
27
|
+
return Commands.ShowUnMerged;
|
|
28
|
+
|
|
29
|
+
default:
|
|
30
|
+
return Commands.Unknown;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export const getHelp = (): string => {
|
|
36
|
+
return `
|
|
37
|
+
DESCRIPTION:
|
|
38
|
+
A console program for quickly switching between branches
|
|
39
|
+
|
|
40
|
+
OPTIONS:
|
|
41
|
+
help, -h, --h, --help
|
|
42
|
+
Showing this message
|
|
43
|
+
|
|
44
|
+
m, -m, merged
|
|
45
|
+
Showing merged branches
|
|
46
|
+
|
|
47
|
+
un, -un, --no-merged
|
|
48
|
+
Showing not merged branches
|
|
49
|
+
|
|
50
|
+
-D, rm
|
|
51
|
+
Delete the selected branch
|
|
52
|
+
`;
|
|
53
|
+
}
|
package/src/color.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export const clc = {
|
|
2
2
|
_red: '\x1b[31m',
|
|
3
3
|
_green: '\x1b[32m',
|
|
4
4
|
_yellow: '\x1b[33m',
|
|
@@ -27,7 +27,7 @@ module.exports = {
|
|
|
27
27
|
? this.green.apply(this, strList)
|
|
28
28
|
: this.red.apply(this, strList);
|
|
29
29
|
},
|
|
30
|
-
greenOrRedBg(isVal, ...strList) {
|
|
30
|
+
greenOrRedBg(isVal, ...strList: any) {
|
|
31
31
|
return isVal === true
|
|
32
32
|
? this.greenBg.apply(this, strList)
|
|
33
33
|
: this.redBg.apply(this, strList);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { exec } from './exec';
|
|
2
|
+
import { clc } from '../color';
|
|
3
|
+
|
|
4
|
+
//
|
|
5
|
+
export async function checkoutBranch(branchName: string) {
|
|
6
|
+
if (!branchName) {
|
|
7
|
+
throw new Error('No branch...');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const checkoutCommand = `git checkout ${branchName}`;
|
|
11
|
+
|
|
12
|
+
console.log(' ' + clc.green('git checkout', branchName) + '\n');
|
|
13
|
+
|
|
14
|
+
const checkoutCommandResult = await exec(checkoutCommand);
|
|
15
|
+
console.log(checkoutCommandResult);
|
|
16
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import { exec } from './exec';
|
|
3
|
+
import { clc } from '../color';
|
|
4
|
+
|
|
5
|
+
export async function deleteBranch(branchName: string) {
|
|
6
|
+
if (!branchName) {
|
|
7
|
+
throw new Error('No branch...');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const res = await inquirer.prompt({
|
|
11
|
+
type: 'confirm',
|
|
12
|
+
name: 'answer',
|
|
13
|
+
message: clc.yellow('Are you sure you want to delete the branch "') + clc.red(branchName) + clc.yellow('"?'),
|
|
14
|
+
default: false,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
if (res.answer === true) {
|
|
18
|
+
const command = `git branch -D ${branchName}`;
|
|
19
|
+
|
|
20
|
+
console.log(' ' + clc.redBg(`git branch -D ${branchName}`, '') + '\n');
|
|
21
|
+
|
|
22
|
+
const checkoutCommandResult = await exec(command);
|
|
23
|
+
|
|
24
|
+
console.log(checkoutCommandResult);
|
|
25
|
+
console.log(clc.yellow('Branch'), clc.red(branchName), clc.yellow('has been deleted'));
|
|
26
|
+
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
console.log(clc.yellow('The branch was not deleted'));
|
|
31
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { exec } from './exec';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export enum BranchesType {
|
|
5
|
+
All,
|
|
6
|
+
Merged,
|
|
7
|
+
NotMerged,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const commandsForGetBranches = {
|
|
11
|
+
[BranchesType.All]: 'git branch --all',
|
|
12
|
+
[BranchesType.Merged]: 'git branch --all --merged',
|
|
13
|
+
[BranchesType.NotMerged]: 'git branch --all --no-merged',
|
|
14
|
+
} as const;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* get branch list
|
|
18
|
+
*/
|
|
19
|
+
export function getBranches(type: BranchesType): Promise<string[]> {
|
|
20
|
+
const command = commandsForGetBranches[type];
|
|
21
|
+
|
|
22
|
+
return exec(command)
|
|
23
|
+
.then(parseBranches)
|
|
24
|
+
.then(branches => {
|
|
25
|
+
if (branches.length) {
|
|
26
|
+
return branches;
|
|
27
|
+
}
|
|
28
|
+
throw new Error('No branches found...');
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function parseBranches(stdout) {
|
|
33
|
+
return stdout
|
|
34
|
+
.split('\n')
|
|
35
|
+
.filter(s => !/\s->\s/.test(s))
|
|
36
|
+
.map(cleanBranchName)
|
|
37
|
+
.filter(Boolean)
|
|
38
|
+
.filter(onlyUnique);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function cleanBranchName(name) {
|
|
42
|
+
return name
|
|
43
|
+
.replace(/^\*/, '')
|
|
44
|
+
.replace(/remotes\/origin\//, '')
|
|
45
|
+
.trim();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function onlyUnique(value, index, self) {
|
|
49
|
+
return self.indexOf(value) === index;
|
|
50
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,22 +1,36 @@
|
|
|
1
|
-
import { getBranches, checkoutBranch, getCurrentBranchName } from './commands';
|
|
2
1
|
import { ask } from './ask';
|
|
2
|
+
import { Commands, getHelp, getWishOfUser } from './cli-commands';
|
|
3
|
+
import { BranchesType, checkoutBranch, getBranches, getCurrentBranchName } from './commands';
|
|
4
|
+
import { deleteBranch } from './commands/delete-barnch';
|
|
3
5
|
|
|
4
6
|
const run = async () => {
|
|
5
|
-
const
|
|
7
|
+
const userWish = getWishOfUser();
|
|
8
|
+
|
|
9
|
+
if (Commands.Help === userWish) {
|
|
10
|
+
console.log(getHelp());
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let branchType: BranchesType = BranchesType.All;
|
|
15
|
+
|
|
16
|
+
if (Commands.ShowMerged === userWish) {
|
|
17
|
+
branchType = BranchesType.Merged;
|
|
18
|
+
} else if (Commands.ShowUnMerged === userWish) {
|
|
19
|
+
branchType = BranchesType.NotMerged;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const branches = await getBranches(branchType);
|
|
6
23
|
|
|
7
24
|
const { branch } = await ask('Select branch', branches);
|
|
8
25
|
|
|
9
|
-
|
|
26
|
+
if (Commands.DeleteBranch === userWish) {
|
|
27
|
+
deleteBranch(branch);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
10
30
|
|
|
11
|
-
|
|
12
|
-
console.log(stdout);
|
|
31
|
+
await checkoutBranch(branch);
|
|
13
32
|
|
|
14
|
-
|
|
15
|
-
console.log(stdout);
|
|
33
|
+
await getCurrentBranchName()
|
|
16
34
|
};
|
|
17
35
|
|
|
18
|
-
|
|
19
|
-
run();
|
|
20
|
-
} catch (err) {
|
|
21
|
-
console.log(err);
|
|
22
|
-
}
|
|
36
|
+
run();
|
package/dist/commands.d.ts
DELETED
package/dist/commands.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var child_process = require('child_process');
|
|
40
|
-
var clc = require('./color');
|
|
41
|
-
function exec(command) {
|
|
42
|
-
return new Promise(function (resolve, reject) {
|
|
43
|
-
return child_process.exec(command, function (err, stdout) {
|
|
44
|
-
return err ? reject(err) : resolve(stdout);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* get branch list
|
|
50
|
-
*/
|
|
51
|
-
function getBranches() {
|
|
52
|
-
return exec('git branch --all')
|
|
53
|
-
.then(parseBranches)
|
|
54
|
-
.then(function (branches) {
|
|
55
|
-
if (branches.length) {
|
|
56
|
-
return branches;
|
|
57
|
-
}
|
|
58
|
-
throw new Error('No branches found...');
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
exports.getBranches = getBranches;
|
|
62
|
-
function parseBranches(stdout) {
|
|
63
|
-
return stdout
|
|
64
|
-
.split('\n')
|
|
65
|
-
.filter(function (s) { return !/\s->\s/.test(s); })
|
|
66
|
-
.map(cleanBranchName)
|
|
67
|
-
.filter(Boolean)
|
|
68
|
-
.filter(onlyUnique);
|
|
69
|
-
}
|
|
70
|
-
function cleanBranchName(name) {
|
|
71
|
-
return name
|
|
72
|
-
.replace(/^\*/, '')
|
|
73
|
-
.replace(/remotes\/origin\//, '')
|
|
74
|
-
.trim();
|
|
75
|
-
}
|
|
76
|
-
function onlyUnique(value, index, self) {
|
|
77
|
-
return self.indexOf(value) === index;
|
|
78
|
-
}
|
|
79
|
-
function checkoutBranch(branchName) {
|
|
80
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
-
var stdoutStrings, checkoutCommand, checkoutCommandResult;
|
|
82
|
-
return __generator(this, function (_a) {
|
|
83
|
-
switch (_a.label) {
|
|
84
|
-
case 0:
|
|
85
|
-
if (!branchName) {
|
|
86
|
-
throw new Error('No branch...');
|
|
87
|
-
}
|
|
88
|
-
stdoutStrings = [];
|
|
89
|
-
checkoutCommand = "git checkout " + branchName;
|
|
90
|
-
stdoutStrings.push(' ' + clc.green('git checkout', branchName) + '\n');
|
|
91
|
-
return [4 /*yield*/, exec(checkoutCommand)];
|
|
92
|
-
case 1:
|
|
93
|
-
checkoutCommandResult = _a.sent();
|
|
94
|
-
stdoutStrings.push(checkoutCommandResult);
|
|
95
|
-
return [2 /*return*/, stdoutStrings.join('\n')];
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
exports.checkoutBranch = checkoutBranch;
|
|
101
|
-
function getCurrentBranchName() {
|
|
102
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
103
|
-
var currentBranchName;
|
|
104
|
-
return __generator(this, function (_a) {
|
|
105
|
-
switch (_a.label) {
|
|
106
|
-
case 0:
|
|
107
|
-
currentBranchName = "git rev-parse --abbrev-ref HEAD";
|
|
108
|
-
return [4 /*yield*/, exec(currentBranchName)];
|
|
109
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
exports.getCurrentBranchName = getCurrentBranchName;
|
package/src/commands.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const child_process = require('child_process');
|
|
2
|
-
const clc = require('./color');
|
|
3
|
-
|
|
4
|
-
function exec(command): Promise<string> {
|
|
5
|
-
return new Promise((resolve, reject) =>
|
|
6
|
-
child_process.exec(command, (err, stdout) =>
|
|
7
|
-
err ? reject(err) : resolve(stdout)
|
|
8
|
-
)
|
|
9
|
-
);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* get branch list
|
|
14
|
-
*/
|
|
15
|
-
export function getBranches(): Promise<string[]> {
|
|
16
|
-
return exec('git branch --all')
|
|
17
|
-
.then(parseBranches)
|
|
18
|
-
.then(branches => {
|
|
19
|
-
if (branches.length) {
|
|
20
|
-
return branches;
|
|
21
|
-
}
|
|
22
|
-
throw new Error('No branches found...');
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function parseBranches(stdout) {
|
|
27
|
-
return stdout
|
|
28
|
-
.split('\n')
|
|
29
|
-
.filter(s => !/\s->\s/.test(s))
|
|
30
|
-
.map(cleanBranchName)
|
|
31
|
-
.filter(Boolean)
|
|
32
|
-
.filter(onlyUnique);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function cleanBranchName(name) {
|
|
36
|
-
return name
|
|
37
|
-
.replace(/^\*/, '')
|
|
38
|
-
.replace(/remotes\/origin\//, '')
|
|
39
|
-
.trim();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function onlyUnique(value, index, self) {
|
|
43
|
-
return self.indexOf(value) === index;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export async function checkoutBranch(branchName: string): Promise<string> {
|
|
47
|
-
if (!branchName) {
|
|
48
|
-
throw new Error('No branch...');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const stdoutStrings: string[] = [];
|
|
52
|
-
const checkoutCommand = `git checkout ${branchName}`;
|
|
53
|
-
|
|
54
|
-
stdoutStrings.push(' ' + clc.green('git checkout', branchName) + '\n');
|
|
55
|
-
|
|
56
|
-
const checkoutCommandResult = await exec(checkoutCommand);
|
|
57
|
-
stdoutStrings.push(checkoutCommandResult);
|
|
58
|
-
|
|
59
|
-
return stdoutStrings.join('\n');
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
export async function getCurrentBranchName(): Promise<string> {
|
|
64
|
-
const currentBranchName = `git rev-parse --abbrev-ref HEAD`;
|
|
65
|
-
|
|
66
|
-
return await exec(currentBranchName);
|
|
67
|
-
}
|
|
68
|
-
|