Skip to content

Commit cbbc298

Browse files
committed
implements @n8rzz/branches and removes git branch logics
* restructures app file layout in favor of single file
1 parent c2dac78 commit cbbc298

File tree

7 files changed

+111
-156
lines changed

7 files changed

+111
-156
lines changed

bin/gbdm.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

bin/gbrdm.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
3+
require('../index');

index.js

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

lib/extractBranchList.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

lib/gbdm.js

Lines changed: 0 additions & 78 deletions
This file was deleted.

package-lock.json

Lines changed: 40 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)