Skip to content

Commit

Permalink
Bug fixes everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
lazamar committed Mar 26, 2016
1 parent 91693bb commit 3fc9e33
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"object-shorthand": 0,
"block-spacing": [2, "always"],
"prefer-template": 0,
"func-names": 0
"func-names": 0,
"prefer-rest-params": 0
}
}
43 changes: 43 additions & 0 deletions npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs', '/usr/local/bin/npm', 'start' ]
2 info using npm@3.3.12
3 info using node@v4.4.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle home-ci@1.0.0~prestart: home-ci@1.0.0
6 silly lifecycle home-ci@1.0.0~prestart: no script for prestart, continuing
7 info lifecycle home-ci@1.0.0~start: home-ci@1.0.0
8 verbose lifecycle home-ci@1.0.0~start: unsafe-perm in lifecycle true
9 verbose lifecycle home-ci@1.0.0~start: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/home/marcelo/Documents/Projects/home-ci/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$ANDROID_HOME/tools:$JAVA_HOME/bin:$ANDROID_HOME/platform-tools
10 verbose lifecycle home-ci@1.0.0~start: CWD: /home/marcelo/Documents/Projects/home-ci
11 silly lifecycle home-ci@1.0.0~start: Args: [ '-c', 'node src/js/router.js' ]
12 silly lifecycle home-ci@1.0.0~start: Returned: code: 1 signal: null
13 info lifecycle home-ci@1.0.0~start: Failed to exec start script
14 verbose stack Error: home-ci@1.0.0 start: `node src/js/router.js`
14 verbose stack Exit status 1
14 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:232:16)
14 verbose stack at emitTwo (events.js:87:13)
14 verbose stack at EventEmitter.emit (events.js:172:7)
14 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14)
14 verbose stack at emitTwo (events.js:87:13)
14 verbose stack at ChildProcess.emit (events.js:172:7)
14 verbose stack at maybeClose (internal/child_process.js:827:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
15 verbose pkgid home-ci@1.0.0
16 verbose cwd /home/marcelo/Documents/Projects/home-ci
17 error Linux 3.19.0-56-generic
18 error argv "/usr/bin/nodejs" "/usr/local/bin/npm" "start"
19 error node v4.4.0
20 error npm v3.3.12
21 error code ELIFECYCLE
22 error home-ci@1.0.0 start: `node src/js/router.js`
22 error Exit status 1
23 error Failed at the home-ci@1.0.0 start script 'node src/js/router.js'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the home-ci package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error node src/js/router.js
23 error You can get their info via:
23 error npm owner ls home-ci
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
4 changes: 4 additions & 0 deletions public/font-awesome.min.css

Large diffs are not rendered by default.

Binary file added public/fontawesome-webfont.eot
Binary file not shown.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Home-CI</title>
<link rel="icon" href="/s/home-ci.ico" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="/s/main.css"></link>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link rel="stylesheet" href="/s/font-awesome.min.css">
<style>
pre {
line-height: 70%;
Expand Down
17 changes: 8 additions & 9 deletions public/repo.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//This will be sent by the server
var STATUS = {
success: true,

//Possible values: ['cloning', 'installing', 'pulling', 'testing', 'free'],
availability: 'free',
};
// //This will be sent by the server
// var STATUS = {
// success: true,
//
// //Possible values: ['cloning', 'installing', 'pulling', 'testing', 'free'],
// state: 'free',
// };

(function (stats) {
'use strict';
Expand All @@ -13,7 +13,7 @@ var STATUS = {
var dividingBar = document.querySelector('.dividing-bar');
if (!statusIcon || !dividingBar) {
console.error('No status icon or loading bar found.');
} else if (stats.availability !== 'free') {
} else if (stats.state !== 'free') {
statusIcon.classList.add('fa-cog');
statusIcon.classList.add('spinning');
statusIcon.classList.add('warning-yellow');
Expand All @@ -26,5 +26,4 @@ var STATUS = {
statusIcon.classList.add('fail-red');
dividingBar.classList.add('failure');
}

}(STATUS));
2 changes: 1 addition & 1 deletion src/html/project_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Home-CLI</title>
<link rel="icon" href="/s/home-ci.ico" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="/s/main.css"></link>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link rel="stylesheet" href="/s/font-awesome.min.css">
<style>
pre {
line-height: 70%;
Expand Down
17 changes: 9 additions & 8 deletions src/js/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function Controller() {
*/
this.getRepoPage = function getRepoPage(user, repoName) {
var repo;
var rawPage = new Promise(function (resolve, reject) {
return new Promise(function (resolve, reject) {
var err = validateUserAndRepo(user, repoName);
if (err) {
reject(err);
Expand All @@ -63,32 +63,33 @@ function Controller() {
}

repo = repoFound;
if (!repo.isFree()) { return null; }
if (!repo.isFree()) { return Promise.reject('Busy'); }

return repo.tests.getLastLog();
})
.then(function (log) {
if (!log) {
// test log not found, so let's run a test and update the state.
repo.test();
return 'Log not found'; // Remove this after loading client-side script has been done.
}

return log; // Return log for page to be constructed or null.
})
.catch(function (err) {
console.error(err);
return { content: err, success: false };
});
return { output: err, success: false };
})

// Now we just build the page and return it
return rawPage.then(function (retrievedLog) {
.then(function (retrievedLog) {
var log = retrievedLog || {};
return utils.buildTemplate({
username: user,
repo: repoName,
code: '',
content: log.output,
success: log.success,
script: '',
content: log.output || '',
success: !!log.success,
state: repo ? repo.getState() : null,
});
});
Expand Down
6 changes: 3 additions & 3 deletions src/js/repo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ RepoTests.prototype.getFileNames = function getFileNames() {
* @return {Promise} Will resolve into a log object or rejected
*/
RepoTests.prototype.getLogFromFile = function getLogFromFile(fileName) {
if (!fileName) { return Promise.reject(null); }
if (!fileName) { return Promise.resolve(null); }

var logsFolder = this.repo.logsFolder;
var testPath = path.format({ dir: logsFolder, base: fileName });

return utils.readFile(testPath)
.then(function (jsonString) {
return JSON.stringify(jsonString);
return JSON.parse(jsonString);
})
.catch(function () { return null; });
};
Expand Down Expand Up @@ -152,7 +152,7 @@ RepoTests.prototype.saveTest = function saveTest(content, exitStatus) {

// Write log to file
var logsFolder = this.repo.logsFolder;
var testName = 'test-' + newTestNo + '.log';
var testName = 'test-' + newTestNo + '.json';
var fullPath = path.format({ dir: logsFolder, base: testName });

utils.writeFile(fullPath, log);
Expand Down
8 changes: 5 additions & 3 deletions src/js/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ Repository.prototype.deleteFiles = function () {
* log or an error message.
*/
Repository.prototype.test = function test() {
if (!this.isFree()) { return Promise.resolve('Busy'); }

var _this = this;
var output = '';
var exitStatus = 0;
Expand All @@ -214,21 +216,21 @@ Repository.prototype.test = function test() {
.then(function (res) {
output += '\n' + res.output;
exitStatus += res.exitStatus;
if (exitStatus > 0) { return Promise.reject(); }
if (exitStatus > 0) { return Promise.reject(res.output); }

return _this.install();
})
.then(function (res) {
output += '\n' + res.output;
exitStatus += res.exitStatus;
if (exitStatus > 0) { return Promise.reject(); }
if (exitStatus > 0) { return Promise.reject(res.output); }

return _this.tests.run();
})
.then(function (res) {
output += '\n' + res.output;
exitStatus += res.exitStatus;
if (exitStatus > 0) { return Promise.reject(); }
if (exitStatus > 0) { return Promise.reject(res.output); }

return Promise.resolve();
})
Expand Down
45 changes: 26 additions & 19 deletions src/js/utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
var fs = require('fs');
var mkdirp = require('mkdirp');
var Promise = require('promise'); //jshint ignore:line
var ansi_up = require('ansi_up'); //ANSI to coloured HTML
var Promise = require('promise');
var ansiUp = require('ansi_up'); // ANSI to coloured HTML
var rimraf = require('rimraf');
var Path = require('path');

module.exports = (function utils() {
'use strict';

var parse = (function () {
var validateRegex = /^(\/)([\w-]+)(?:(\/)([\w-]+))?/;
return {
Expand All @@ -26,7 +24,7 @@ module.exports = (function utils() {
// TODO: Make readfile functions return null if an error happens
function readFile(fileName) {
return new Promise(function (resolve, reject) {
fs.readFile(fileName, function (err, data) {
fs.readFile(fileName, 'utf8', function (err, data) {
if (err) {
reject('File not found:' + fileName);
} else {
Expand Down Expand Up @@ -60,15 +58,15 @@ module.exports = (function utils() {

function terminalToHTML(text) {
var withLineBreaks = text.replace(/\n/g, '\n<br/> ');
return ansi_up.ansi_to_html(withLineBreaks);
return ansiUp.ansi_to_html(withLineBreaks);
}

var ansi = {
green: '\x1B[32m',
red: '\x1B[31m',
yellow: '\x1B[33m',
blue: '\x1b[34m',
none: '\x1B[0m'
none: '\x1B[0m',
};

function ansiColorise(color, str) {
Expand Down Expand Up @@ -96,11 +94,12 @@ module.exports = (function utils() {
try {
if (what === 'file') {
return fs.statSync(path).isFile();
} else if (what === 'directory') {
}
if (what === 'directory') {
return fs.statSync(path).isDirectory();
} else {
throw new Error('Unexpected parameter value in utils.checkExistsSync.');
}

throw new Error('Unexpected parameter value in utils.checkExistsSync.');
} catch (e) {
// no such file or directory. File really does not exist
if (e.code === 'ENOENT') { return false; }
Expand Down Expand Up @@ -154,27 +153,35 @@ module.exports = (function utils() {
return 'Error building Template \n';
}

template = template.toString();
template = template.replace('$$REPO$$', fields.repo);
template = template.replace('$$USERNAME$$', fields.username);
template = template.replace('$$CONTENT$$', fields.content);
template = template.replace('$$SCRIPT$$', fields.script);
var statusObj = {
success: fields.success,
state: fields.state,
};
var script = 'var STATUS = ' + JSON.stringify(statusObj);
script += '\n' + (fields.script || '');

template = template.toString(); // eslint-disable-line no-param-reassign, max-len
template = template.replace('$$REPO$$', fields.repo); // eslint-disable-line no-param-reassign, max-len
template = template.replace('$$USERNAME$$', fields.username); // eslint-disable-line no-param-reassign, max-len
template = template.replace('$$CONTENT$$', fields.content); // eslint-disable-line no-param-reassign, max-len
template = template.replace('$$SCRIPT$$', script); // eslint-disable-line no-param-reassign, max-len

return template;
});
}

//get number of files like test10.log and test11.log
// get number of files like test10.log and test11.log
function getFileNumber(fileName) {
if (!fileName) { return null; }

var match = fileName.match(/([0-9]+)\.[^0-9]+$/) || [];
var fileNo = parseInt(match[1]);
var fileNo = parseInt(match[1], 10);
return fileNo || null;
}

//Compares names like test10.log and test11.log
// Compares names like test10.log and test11.log
function compareFileNames(f1, f2) {
//Make number an int or NaN if no number was matched.
// Make number an int or NaN if no number was matched.
var f1No = getFileNumber(f1);
var f2No = getFileNumber(f2);

Expand Down

0 comments on commit 3fc9e33

Please sign in to comment.