Skip to content

Commit 8f91fc9

Browse files
authored
CIO-65 Broken Promises (#105)
* CIO-65 Update unhandled error catchall. Begin rewriting promises * CIO-65 Remove unecessary condition from prompt * CIO-65 Remove async function. Rewrite refreshTable with better promise use * CIO-65 Remove async await from git utils * CIO-65 Remove async await from utils * CIO-65 SF * CIO-65 Move getRemoteTabs into promise resolution * CIO-65 Refactor select promise logic and formatting * CIO-65 Return execGit as promise. * CIO-65 SF * CIO-65 Update documentation and formatting * CIO-65 Add error handle function * CIO-65 Handle detatched head method * CIO-65 add type constants for success messages * CIO-65 Add create constant * CIO-65 Move confirmation question data into handleDetatchedHead * CIO-65 Add dev dependencies * CIO-65 Remove create branch on remote * CIO-65 Remove create branch export * CIO-65 Update git checkout options * CIO-65 SF * CIO-65 Add babel * CIO-65 Add babelrc * CIO-65 Add src dir for babel * CIO-65 Add version flag check * CIO-65 Add lib dir for prod files * CIO-65 Update git promise * CIO-65 Change vars to let with introduction of babel * CIO-65 Destructure git methods * CIO-65 Remove handle success * CIO-65 Update Git promise * CIO-65 Rebuild * CIO-65 Update index js to remove anti pipe msg * CIO-65 appjs SF * CIO-65 SF * CIO-65 Update babel presets * CIO-65 Add reject to refresh. Update docheckout method. Change getRefs to getRefsArray * CIO-65 Add gulp task runner * CIO-65 Update gulp file * CIO-65 Move readError to utils. Change exports to es6 * CIO-65 Update git utils to es6 exports. Update readError method * CIO-65 Update readerror * CIO-65 Update build and format list promises * CIO-65 Rebuild * CIO-65 Update gulpfile err logs * CIO-65 Update selected line assignments * CIO-65 Rebuild * CIO-65 SF * CIO-65 Rebuild * CIO-65 Update npm watch * CIO-65 Cannot refresh error * CIO-65 Rebuild
1 parent dde0b43 commit 8f91fc9

19 files changed

+6283
-449
lines changed

.babelrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"presets": [
3+
["env", {
4+
"targets": {
5+
"node": "current"
6+
}
7+
}]
8+
]
9+
}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
README.html
2-
node_modules/
2+
node_modules/

gulpfile.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var babel = require('gulp-babel');
2+
var chalk = require('chalk');
3+
var gulp = require('gulp');
4+
5+
gulp.task('build', function() {
6+
return gulp
7+
.src('src/**/*.js')
8+
.pipe(babel())
9+
.on('error', function (error) {
10+
process.stderr.write(chalk.red.bold('Build failed.') + '\n');
11+
process.stderr.write(error.fileName + '\n');
12+
process.stderr.write(error.stack + '\n');
13+
14+
this.emit('end');
15+
})
16+
.pipe(gulp.dest('lib'));
17+
});
18+
19+
gulp.task('watch', function() {
20+
gulp.watch('src/**/*.js', ['build']);
21+
})

index.js

Lines changed: 2 additions & 233 deletions
Original file line numberDiff line numberDiff line change
@@ -1,236 +1,5 @@
11
#!/usr/bin/env node
22

3-
'use strict';
3+
const app = require('./lib/app');
44

5-
const chalk = require('chalk');
6-
const path = require('path');
7-
const program = require('commander');
8-
const updateNotifier = require('update-notifier');
9-
10-
const git = require(path.resolve(__dirname, 'utils/git'));
11-
const dialogue = require(path.resolve(__dirname, 'utils/interface'));
12-
const { getRemoteTabs } = require(path.resolve(__dirname, 'utils/utils'));
13-
14-
// Checks for available update and returns an instance
15-
const pkg = require(path.resolve(__dirname, 'package.json'));
16-
const notifier = updateNotifier({ pkg });
17-
18-
program.version('0.6.1', '-v, --version');
19-
20-
program.parse(process.argv);
21-
22-
if (notifier.update) {
23-
notifier.notify();
24-
}
25-
26-
if (!process.argv.slice(2).length) {
27-
const screen = dialogue.screen();
28-
29-
const branchTable = dialogue.branchTable();
30-
const statusBarText = dialogue.statusBarText();
31-
const helpDialogue = dialogue.helpDialogue();
32-
const question = dialogue.question();
33-
const statusBar = dialogue.statusBar();
34-
const statusHelpText = dialogue.statusHelpText();
35-
36-
var currentRemote = 'local';
37-
var remoteList = [];
38-
39-
const toggleHelp = () => {
40-
helpDialogue.toggle();
41-
screen.render();
42-
};
43-
44-
/**
45-
* @todo: Build a keyMap utility
46-
* @body: Add left and right functionality to change remote. Add getUniqueRemotes method here.
47-
*/
48-
screen.key('?', toggleHelp);
49-
screen.key(['escape', 'q', 'C-c'], () => process.exit(0));
50-
screen.key('r', () => {
51-
branchTable.clearItems();
52-
53-
git.doFetchBranches().then(() => refreshTable(currentRemote));
54-
});
55-
56-
screen.append(branchTable);
57-
screen.append(statusBar);
58-
screen.append(helpDialogue);
59-
60-
statusBar.append(statusBarText);
61-
statusBar.append(statusHelpText);
62-
63-
process.on('SIGWINCH', () => {
64-
screen.emit('resize');
65-
});
66-
67-
/**
68-
* Trim and remove whitespace from selected line.
69-
*
70-
* @param {String} selectedLine String representation of selected line.
71-
* @return {Array} Array of selected line.
72-
*/
73-
const parseSelection = selectedLine => {
74-
const selection = selectedLine.split(/\s*\s/).map(column => {
75-
return column === 'local' ? '' : column;
76-
});
77-
78-
return selection;
79-
};
80-
81-
branchTable.on('select', async selectedLine => {
82-
const selection = parseSelection(selectedLine.content);
83-
84-
const gitBranch = selection[2];
85-
const gitRemote = selection[1];
86-
87-
/**
88-
* @todo: Identify and handle unhandledRejections
89-
* @body: Some errors are not handled and the following rejection is passed is the workaround
90-
*/
91-
process.on('unhandledRejection', reason => {
92-
console.log(chalk.yellow('[LOG] ') + reason);
93-
});
94-
95-
// If selection is a remote, prompt if new branch is to be created.
96-
if (gitRemote) {
97-
question.setData([
98-
[
99-
'Create local branch named: ' +
100-
chalk.white.bold(`${gitBranch}`) +
101-
'?',
102-
],
103-
['Yes'],
104-
['No'],
105-
]);
106-
107-
screen.append(question);
108-
question.focus();
109-
screen.render();
110-
111-
question.on('select', async (val, key) => {
112-
const answer = val.content.trim();
113-
114-
if (answer === 'Yes') {
115-
await git
116-
.doCheckoutBranch(gitBranch, gitRemote)
117-
.then(git.doCreateBranch(gitBranch))
118-
.then(screen.destroy());
119-
} else if (answer === 'No') {
120-
await git
121-
.doCheckoutBranch(gitBranch, gitRemote)
122-
.then(screen.destroy());
123-
}
124-
});
125-
} else {
126-
await git.doCheckoutBranch(gitBranch, gitRemote).then(screen.destroy());
127-
}
128-
});
129-
130-
/**
131-
* @todo: Build a keybind utility
132-
*/
133-
branchTable.key(['left', 'h'], () => {
134-
currentRemote = getPrevRemote(currentRemote, remoteList);
135-
});
136-
137-
branchTable.key(['right', 'l'], () => {
138-
currentRemote = getNextRemote(currentRemote, remoteList);
139-
});
140-
141-
branchTable.key('j', () => {
142-
branchTable.down();
143-
144-
screen.render();
145-
});
146-
147-
branchTable.key('k', () => {
148-
branchTable.up();
149-
150-
screen.render();
151-
});
152-
153-
branchTable.key('space', function() {
154-
const selection = parseSelection(this.items[this.selected].content);
155-
156-
const gitBranch = selection[2];
157-
const gitRemote = selection[1];
158-
159-
var args = [];
160-
161-
if (gitRemote) {
162-
args.push(gitRemote);
163-
}
164-
165-
args.push(gitBranch);
166-
167-
if (args.length > 1) {
168-
args = args.join('/');
169-
}
170-
171-
screen.spawn('git', ['log', args, '--color=always']);
172-
});
173-
174-
branchTable.focus();
175-
176-
/**
177-
* Cycle to previous remote
178-
*
179-
* @param currentRemote {String} Current displayed remote
180-
* @param remoteList {Array} Unique remotes for current project
181-
* @return {String}
182-
*/
183-
function getPrevRemote(currentRemote, remoteList) {
184-
var currIndex = remoteList.indexOf(currentRemote);
185-
186-
if (currIndex > 0) {
187-
currIndex -= 1;
188-
}
189-
190-
currentRemote = remoteList[currIndex];
191-
192-
refreshTable(currentRemote);
193-
194-
return currentRemote;
195-
}
196-
197-
/**
198-
* Cycle to next remote
199-
*
200-
* @param currentRemote {String} Current displayed remote
201-
* @param remoteList {Array} Unique remotes for current project
202-
* @return {String}
203-
*/
204-
function getNextRemote(currentRemote, remoteList) {
205-
var currIndex = remoteList.indexOf(currentRemote);
206-
207-
if (currIndex < remoteList.length - 1) {
208-
currIndex += 1;
209-
}
210-
211-
currentRemote = remoteList[currIndex];
212-
213-
refreshTable(currentRemote);
214-
215-
return currentRemote;
216-
}
217-
218-
/**
219-
* Build array of branches for main interface
220-
*
221-
* @param {String} currentRemote Current displayed remote
222-
*/
223-
async function refreshTable(currentRemote) {
224-
const results = await git.buildListArray(currentRemote);
225-
226-
branchTable.setData([['', 'Remote', 'Branch Name', 'Path'], ...results]);
227-
228-
remoteList = await git.buildRemoteList();
229-
230-
statusBarText.content = getRemoteTabs(remoteList, currentRemote);
231-
232-
screen.render();
233-
}
234-
235-
refreshTable(currentRemote);
236-
}
5+
app.start(process.argv.slice(2));

0 commit comments

Comments
 (0)