-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
63 lines (52 loc) · 1.51 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const { exec } = require('child_process');
const { prompt } = require('inquirer');
const chalk = require('chalk');
const branches = require('@n8rzz/branches');
function _buildCheckboxList(branchList) {
const questions = [
{
name: 'branchesToDelete',
type: 'checkbox',
message: 'Select branches to delete',
choices: branchList
}
];
prompt(questions)
.then((answers) => {
_confirmBranchesToDelete(answers.branchesToDelete);
});
}
function _confirmBranchesToDelete(branchList) {
prompt({
name: 'confirm',
type: 'confirm',
message: `Are you sure you want to delete these branches: ${branchList.join(', ')}?`
}).then((answers) => {
if (!answers.confirm) {
console.log(chalk.red('Aborting delete. Whew!'));
return;
}
_deleteBranchList(branchList);
});
}
function _deleteBranchList(branchList) {
for (let i = 0; i < branchList.length; i++) {
const branchName = branchList[i];
try {
_deleteSingleBranch(branchName);
} catch (error) {
throw error;
}
}
}
function _deleteSingleBranch(branchName) {
exec(`git branch -D ${branchName}`, (err, stdout, stderr) => {
if (err) {
throw err;
}
console.log(chalk.yellow(`Deleted branch: ${branchName}`));
});
}
(function () {
return branches().then((branchList) => _buildCheckboxList(branchList));
})();