avil13-co 2.0.0 → 2.1.2
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 +10 -1
- package/dist/ask.d.ts +1 -0
- package/dist/ask.js +20 -2
- package/dist/cli-commands/index.d.ts +3 -1
- package/dist/cli-commands/index.js +14 -2
- package/dist/commands/get-branches.d.ts +6 -1
- package/dist/commands/get-branches.js +15 -3
- package/dist/index.js +8 -1
- package/package.json +1 -1
- package/src/ask.ts +28 -1
- package/src/cli-commands/index.ts +17 -3
- package/src/commands/get-branches.ts +17 -2
- package/src/index.ts +10 -2
package/README.md
CHANGED
package/dist/ask.d.ts
CHANGED
package/dist/ask.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ask = void 0;
|
|
6
|
+
exports.checkItem = exports.ask = void 0;
|
|
7
7
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
8
8
|
inquirer_1.default.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt'));
|
|
9
9
|
const specSymbols = {
|
|
@@ -18,10 +18,28 @@ const ask = async (message, choices) => {
|
|
|
18
18
|
name: 'branch',
|
|
19
19
|
message,
|
|
20
20
|
source(answersSoFar, input = '') {
|
|
21
|
-
|
|
21
|
+
let list = choices.filter(choiceItem => checkItem(choiceItem, input));
|
|
22
|
+
list = list.sort((a, b) => {
|
|
23
|
+
return sortOrder(input, a, b);
|
|
24
|
+
});
|
|
22
25
|
return Promise.resolve(list);
|
|
23
26
|
}
|
|
24
27
|
});
|
|
25
28
|
return prompt;
|
|
26
29
|
};
|
|
27
30
|
exports.ask = ask;
|
|
31
|
+
//
|
|
32
|
+
function checkItem(item, filterString) {
|
|
33
|
+
const reg = getRegExp(filterString);
|
|
34
|
+
return reg.test(item);
|
|
35
|
+
}
|
|
36
|
+
exports.checkItem = checkItem;
|
|
37
|
+
function sortOrder(searchString, name1, name2) {
|
|
38
|
+
if (name2.includes(searchString)) {
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
return 1;
|
|
42
|
+
}
|
|
43
|
+
function getRegExp(filterString) {
|
|
44
|
+
return new RegExp(filterString.split('').map(s => s.trim()).filter(Boolean).join('.*').replace('.*.*', '.*'), 'gi');
|
|
45
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export declare enum Commands {
|
|
2
2
|
Unknown = 0,
|
|
3
3
|
Help = 1,
|
|
4
|
-
DeleteBranch = 2
|
|
4
|
+
DeleteBranch = 2,
|
|
5
|
+
ShowMerged = 3,
|
|
6
|
+
ShowUnMerged = 4
|
|
5
7
|
}
|
|
6
8
|
export declare const getWishOfUser: (firstArg?: string | undefined) => Commands;
|
|
7
9
|
export declare const getHelp: () => string;
|
|
@@ -7,6 +7,8 @@ var Commands;
|
|
|
7
7
|
Commands[Commands["Unknown"] = 0] = "Unknown";
|
|
8
8
|
Commands[Commands["Help"] = 1] = "Help";
|
|
9
9
|
Commands[Commands["DeleteBranch"] = 2] = "DeleteBranch";
|
|
10
|
+
Commands[Commands["ShowMerged"] = 3] = "ShowMerged";
|
|
11
|
+
Commands[Commands["ShowUnMerged"] = 4] = "ShowUnMerged";
|
|
10
12
|
})(Commands = exports.Commands || (exports.Commands = {}));
|
|
11
13
|
;
|
|
12
14
|
const getWishOfUser = (firstArg) => {
|
|
@@ -14,8 +16,12 @@ const getWishOfUser = (firstArg) => {
|
|
|
14
16
|
switch (true) {
|
|
15
17
|
case ['help', '-h', '--h', '--help'].includes(arg):
|
|
16
18
|
return Commands.Help;
|
|
17
|
-
case ['
|
|
19
|
+
case ['-D', 'rm'].includes(arg):
|
|
18
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;
|
|
19
25
|
default:
|
|
20
26
|
return Commands.Unknown;
|
|
21
27
|
}
|
|
@@ -30,7 +36,13 @@ OPTIONS:
|
|
|
30
36
|
help, -h, --h, --help
|
|
31
37
|
Showing this message
|
|
32
38
|
|
|
33
|
-
|
|
39
|
+
m, -m, merged
|
|
40
|
+
Showing merged branches
|
|
41
|
+
|
|
42
|
+
un, -un, --no-merged
|
|
43
|
+
Showing not merged branches
|
|
44
|
+
|
|
45
|
+
-D, rm
|
|
34
46
|
Delete the selected branch
|
|
35
47
|
`;
|
|
36
48
|
};
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBranches = void 0;
|
|
3
|
+
exports.getBranches = exports.BranchesType = void 0;
|
|
4
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
|
+
};
|
|
5
16
|
/**
|
|
6
17
|
* get branch list
|
|
7
18
|
*/
|
|
8
|
-
function getBranches() {
|
|
9
|
-
|
|
19
|
+
function getBranches(type) {
|
|
20
|
+
const command = commandsForGetBranches[type];
|
|
21
|
+
return (0, exec_1.exec)(command)
|
|
10
22
|
.then(parseBranches)
|
|
11
23
|
.then(branches => {
|
|
12
24
|
if (branches.length) {
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,14 @@ const run = async () => {
|
|
|
10
10
|
console.log((0, cli_commands_1.getHelp)());
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
let branchType = commands_1.BranchesType.All;
|
|
14
|
+
if (cli_commands_1.Commands.ShowMerged === userWish) {
|
|
15
|
+
branchType = commands_1.BranchesType.Merged;
|
|
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);
|
|
14
21
|
const { branch } = await (0, ask_1.ask)('Select branch', branches);
|
|
15
22
|
if (cli_commands_1.Commands.DeleteBranch === userWish) {
|
|
16
23
|
(0, delete_barnch_1.deleteBranch)(branch);
|
package/package.json
CHANGED
package/src/ask.ts
CHANGED
|
@@ -18,7 +18,11 @@ export const ask = async (message: string, choices: string[]) => {
|
|
|
18
18
|
name: 'branch',
|
|
19
19
|
message,
|
|
20
20
|
source(answersSoFar, input = '') {
|
|
21
|
-
|
|
21
|
+
let list = choices.filter(choiceItem => checkItem(choiceItem, input));
|
|
22
|
+
|
|
23
|
+
list = list.sort((a, b) => {
|
|
24
|
+
return sortOrder(input, a, b);
|
|
25
|
+
});
|
|
22
26
|
|
|
23
27
|
return Promise.resolve(list);
|
|
24
28
|
}
|
|
@@ -26,3 +30,26 @@ export const ask = async (message: string, choices: string[]) => {
|
|
|
26
30
|
|
|
27
31
|
return prompt;
|
|
28
32
|
};
|
|
33
|
+
|
|
34
|
+
//
|
|
35
|
+
export function checkItem(item: string, filterString: string): boolean {
|
|
36
|
+
const reg = getRegExp(filterString);
|
|
37
|
+
|
|
38
|
+
return reg.test(item);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function sortOrder(searchString: string, name1: string, name2: string): number {
|
|
42
|
+
if (name2.includes(searchString)) {
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return 1;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
function getRegExp(filterString: string) {
|
|
51
|
+
return new RegExp(
|
|
52
|
+
filterString.split('').map(s => s.trim()).filter(Boolean).join('.*').replace('.*.*', '.*'),
|
|
53
|
+
'gi',
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { clc } from '../color';
|
|
2
2
|
|
|
3
3
|
const args = process.argv.slice(2);
|
|
4
4
|
|
|
@@ -6,6 +6,8 @@ export enum Commands {
|
|
|
6
6
|
Unknown,
|
|
7
7
|
Help,
|
|
8
8
|
DeleteBranch,
|
|
9
|
+
ShowMerged,
|
|
10
|
+
ShowUnMerged,
|
|
9
11
|
};
|
|
10
12
|
|
|
11
13
|
export const getWishOfUser = (firstArg?: string): Commands => {
|
|
@@ -15,9 +17,15 @@ export const getWishOfUser = (firstArg?: string): Commands => {
|
|
|
15
17
|
case ['help', '-h', '--h', '--help'].includes(arg):
|
|
16
18
|
return Commands.Help;
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
case ['-D', 'rm'].includes(arg):
|
|
19
21
|
return Commands.DeleteBranch;
|
|
20
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
|
+
|
|
21
29
|
default:
|
|
22
30
|
return Commands.Unknown;
|
|
23
31
|
}
|
|
@@ -33,7 +41,13 @@ OPTIONS:
|
|
|
33
41
|
help, -h, --h, --help
|
|
34
42
|
Showing this message
|
|
35
43
|
|
|
36
|
-
|
|
44
|
+
m, -m, merged
|
|
45
|
+
Showing merged branches
|
|
46
|
+
|
|
47
|
+
un, -un, --no-merged
|
|
48
|
+
Showing not merged branches
|
|
49
|
+
|
|
50
|
+
-D, rm
|
|
37
51
|
Delete the selected branch
|
|
38
52
|
`;
|
|
39
53
|
}
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import { exec } from './exec';
|
|
2
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
|
+
|
|
3
16
|
/**
|
|
4
17
|
* get branch list
|
|
5
18
|
*/
|
|
6
|
-
export function getBranches(): Promise<string[]> {
|
|
7
|
-
|
|
19
|
+
export function getBranches(type: BranchesType): Promise<string[]> {
|
|
20
|
+
const command = commandsForGetBranches[type];
|
|
21
|
+
|
|
22
|
+
return exec(command)
|
|
8
23
|
.then(parseBranches)
|
|
9
24
|
.then(branches => {
|
|
10
25
|
if (branches.length) {
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ask } from './ask';
|
|
2
2
|
import { Commands, getHelp, getWishOfUser } from './cli-commands';
|
|
3
|
-
import { checkoutBranch, getBranches, getCurrentBranchName } from './commands';
|
|
3
|
+
import { BranchesType, checkoutBranch, getBranches, getCurrentBranchName } from './commands';
|
|
4
4
|
import { deleteBranch } from './commands/delete-barnch';
|
|
5
5
|
|
|
6
6
|
const run = async () => {
|
|
@@ -11,7 +11,15 @@ const run = async () => {
|
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
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);
|
|
15
23
|
|
|
16
24
|
const { branch } = await ask('Select branch', branches);
|
|
17
25
|
|