From 63d15a50405a59c6c76dbf2220a3d877edbd2f4a Mon Sep 17 00:00:00 2001 From: Nicholas Wong Date: Fri, 18 Mar 2016 11:03:33 -0400 Subject: [PATCH 01/14] Added babel to the dev-dependencies. --- .babelrc | 1 + package.json | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 .babelrc diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..9d8d516 --- /dev/null +++ b/.babelrc @@ -0,0 +1 @@ +{ "presets": ["es2015"] } diff --git a/package.json b/package.json index 3d4e84d..8f9b02e 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,9 @@ "url": "http://github.com/yahoo/guerilla/issues" }, "scripts": { + "start-master": "babel-node server.js --master", + "start-worker": "babel-node server.js --worker", + "start-redis": "redis-server", "test": "TEST=1 ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- $(find tests -name '*.test.js')", "lint": "./node_modules/.bin/jshint tests" }, @@ -58,10 +61,16 @@ "underscore": "^1.8.3", "yargs": "^3.15.0" }, - "engines": { - "node": ">=0.12" - }, "devDependencies": { + "babel-cli": "^6.6.5", + "babel-eslint": "^5.0.0-beta6", + "babel-loader": "^6.2.1", + "babel-plugin-react-transform": "^2.0.0", + "babel-polyfill": "^6.3.14", + "babel-preset-es2015": "^6.3.13", + "babel-preset-react": "^6.3.13", + "babel-preset-react-hmre": "^1.1.0", + "babel-register": "^6.4.3", "chai": "^3.5.0", "debug": "^2.2.0", "glob": "^7.0.0", From c7da959be6cb4c6ed7f945f9ff8c8d4388432824 Mon Sep 17 00:00:00 2001 From: Nicholas Wong Date: Fri, 18 Mar 2016 11:04:01 -0400 Subject: [PATCH 02/14] Converted utilities to use ES6. --- .gitignore | 6 +++- lib/app.js | 3 +- lib/context.js | 3 +- lib/job-worker.js | 3 +- lib/logger.js | 3 +- lib/mailer.js | 3 +- lib/scheduler.js | 1 - lib/task.js | 3 +- lib/utilities.js | 70 ++++++++++++++++++++----------------------- models/Job.js | 3 +- models/Project.js | 3 +- models/Result.js | 3 +- routes/master/jobs.js | 4 ++- server.js | 2 ++ 14 files changed, 61 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index 986c34e..e867392 100644 --- a/.gitignore +++ b/.gitignore @@ -48,4 +48,8 @@ config/worker/* !config/worker/config.json.sample # intellij Webstorm -.idea/ \ No newline at end of file +.idea/ + +# babel +*-compiled.js +*-compiled.js.map \ No newline at end of file diff --git a/lib/app.js b/lib/app.js index 9c1cee1..431ab7a 100644 --- a/lib/app.js +++ b/lib/app.js @@ -6,6 +6,8 @@ * Sets up middleware, routers, and error handlers for the Express.js application. */ +import utilities from './utilities'; + var fs = require('fs-extra'); var path = require('path'); var morgan = require('morgan'); @@ -16,7 +18,6 @@ var express = require('express'); var less = require('less-middleware'); var browserify = require('browserify-middleware'); var config = require('./config'); -var utilities = require('./utilities'); //setting up app var app = express(); diff --git a/lib/context.js b/lib/context.js index 945e9c9..dddb17c 100644 --- a/lib/context.js +++ b/lib/context.js @@ -6,10 +6,11 @@ * Provides data and functionality to be used by tasks. */ +import utilities from './utilities'; + var path = require('path'); var callsite = require('callsite'); var Task = require('./task'); -var utilities = require('./utilities'); function Context (executor, job, result, device) { var self = this; diff --git a/lib/job-worker.js b/lib/job-worker.js index 7be83ac..11238f5 100644 --- a/lib/job-worker.js +++ b/lib/job-worker.js @@ -6,6 +6,8 @@ * Entry point for a new forked node process to execute a job. */ +import utilities from './utilities'; + require('./globals'); var path = require('path'); @@ -13,7 +15,6 @@ var async = require('async'); var argv = require('yargs').argv; var config = require('./config'); -var utilities = require('./utilities'); var db = require('./db'); var result; diff --git a/lib/logger.js b/lib/logger.js index f31a74d..2b3dfe9 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -6,9 +6,10 @@ * A logger class. */ +import utilities from './utilities'; + var colors = require('colors'); var util = require('util'); -var utilities = require('./utilities'); var argv = require('yargs').argv; function Logger () { diff --git a/lib/mailer.js b/lib/mailer.js index 736d469..15d3b5b 100644 --- a/lib/mailer.js +++ b/lib/mailer.js @@ -6,11 +6,12 @@ * Sends emails for job result status changes. */ +import utilities from './utilities'; + var nodemailer = require('nodemailer'); var fs = require('fs-extra'); var path = require('path'); var ejs = require('ejs'); -var utilities = require('./utilities'); var config = require('./config'); function Mailer () { diff --git a/lib/scheduler.js b/lib/scheduler.js index 6503045..7b5905e 100644 --- a/lib/scheduler.js +++ b/lib/scheduler.js @@ -25,7 +25,6 @@ function isValidCronTime (cronTime) { try { var c = new CronJob(cronTime, function () { c.stop(); - delete c; }); } catch (ex) { diff --git a/lib/task.js b/lib/task.js index eb27911..6130463 100644 --- a/lib/task.js +++ b/lib/task.js @@ -6,9 +6,10 @@ * An abstraction of a task. */ +import utilities from './utilities'; + var path = require('path'); var async = require('async'); -var utilities = require('./utilities'); function Task (params) { this.errors = []; diff --git a/lib/utilities.js b/lib/utilities.js index 18adc04..98ce9b5 100644 --- a/lib/utilities.js +++ b/lib/utilities.js @@ -6,40 +6,36 @@ * Utility and helper functions used across the application. */ -var path = require('path'); -var util = require('util'); - -function Utilities () { -} - -Utilities.prototype.formatMilliseconds = function (ms) { - var secNum = parseInt(ms / 1000, 10); - var hours = Math.floor(secNum / 3600); - var minutes = Math.floor((secNum - (hours * 3600)) / 60); - var seconds = secNum - (hours * 3600) - (minutes * 60); - - if (minutes < 10) - minutes = '0' + minutes; - if (seconds < 10) - seconds = '0' + seconds; - - var time = hours + ':' + minutes + ':' + seconds; - return time; -} - -Utilities.prototype.isDictionary = function (obj) { - return !(!obj || Array.isArray(obj) || obj.constructor != Object); -} - -Utilities.prototype.exists = function (v) { - return !(typeof v == 'undefined' || v == null); -} - -Utilities.prototype.stringify = function (obj) { - if (typeof obj === 'object') - return util.inspect(obj, { showHidden: true, depth: null }); - else - return obj; -} - -module.exports = new Utilities(); +import * as util from 'util'; + +export default class Utilities { + + static formatMilliseconds(ms) { + var secNum = parseInt(ms / 1000, 10); + var hours = Math.floor(secNum / 3600); + var minutes = Math.floor((secNum - (hours * 3600)) / 60); + var seconds = secNum - (hours * 3600) - (minutes * 60); + if (minutes < 10) { + minutes = '0' + minutes; + } + if (seconds < 10) { + seconds = '0' + seconds; + } + return hours + ':' + minutes + ':' + seconds; + } + + static isDictionary(obj) { + return !(!obj || Array.isArray(obj) || obj.constructor != Object); + } + + static exists(v) { + return !(typeof v == 'undefined' || v == null); + } + + static stringify(obj) { + if (typeof obj === 'object') + return util.inspect(obj, {showHidden: true, depth: null}); + else + return obj; + } +} \ No newline at end of file diff --git a/models/Job.js b/models/Job.js index 7b38a82..8984339 100644 --- a/models/Job.js +++ b/models/Job.js @@ -6,12 +6,13 @@ * Models a configured job. */ +import utilities from './utilities'; + var async = require('async'); var path = require('path'); var childProcess = require('child_process'); var config = require(path.join(__rootdir, 'lib', 'config')); var Report = require(path.join(__rootdir, 'lib', 'report')); -var utilities = require(path.join(__rootdir, 'lib', 'utilities')); var Job; diff --git a/models/Project.js b/models/Project.js index 214273a..6f6675c 100644 --- a/models/Project.js +++ b/models/Project.js @@ -6,9 +6,10 @@ * Models a collection of jobs. */ +import utilities from './utilities'; + var async = require('async'); var path = require('path'); -var utilities = require(path.join(__rootdir, 'lib', 'utilities')); var Project; diff --git a/models/Result.js b/models/Result.js index 00ad29c..370acf1 100644 --- a/models/Result.js +++ b/models/Result.js @@ -6,12 +6,13 @@ * Models the results from an individual job run. */ +import utilities from './utilities'; + var moment = require('moment'); var path = require('path'); var util = require('util'); var async = require('async'); var fs = require('fs-extra'); -var utilities = require(path.join(__rootdir, 'lib', 'utilities')); var Result; diff --git a/routes/master/jobs.js b/routes/master/jobs.js index e9a9ad3..0b51442 100644 --- a/routes/master/jobs.js +++ b/routes/master/jobs.js @@ -6,10 +6,12 @@ * Router for all job endpoints. */ +import utilities from '../lib/utilities'; + var router = require('express').Router(); var path = require('path'); var models = require(path.join(__rootdir, 'lib', 'db')).models(); -var utilities = require(path.join(__rootdir, 'lib', 'utilities')); + var Job = models.Job; var ConfigLocation = models.ConfigLocation; diff --git a/server.js b/server.js index 506edbe..dc0201f 100644 --- a/server.js +++ b/server.js @@ -7,6 +7,8 @@ */ var git = require('git-rev'); +var logger = require('./lib/logger'); + git.long(function (str) { require('./lib/globals'); From a19be0e0851002c3e3c8353b0affbf2cb6af4331 Mon Sep 17 00:00:00 2001 From: Nicholas Wong Date: Fri, 18 Mar 2016 11:09:33 -0400 Subject: [PATCH 03/14] Updated launching read me. --- wiki/Launching.md | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/wiki/Launching.md b/wiki/Launching.md index 7dd6387..53f693f 100644 --- a/wiki/Launching.md +++ b/wiki/Launching.md @@ -4,7 +4,11 @@ Navigate to the Guerilla project directory and start the redis server: -`redis-server` +```sh +npm start-redis +# or the following legacy way +# redis-server +``` ### Install NPM Packages @@ -41,6 +45,16 @@ temporary directory. #### Starting syntax -Master: `node server.js --master [--config configFilePath] {--saveTempFiles}` - -Worker: `node server.js --worker [--config configFilePath] {--saveTempFiles}` +Master: +```sh +npm start-master +# or the following legacy way +# node server.js --master [--config configFilePath] {--saveTempFiles}` +``` + +Worker: +```sh +npm start-worker +# or the following legacy way +# node server.js --worker [--config configFilePath] {--saveTempFiles} +``` \ No newline at end of file From 49fc07e05837792aae479a2aec1137374f41a741 Mon Sep 17 00:00:00 2001 From: Nicholas Wong Date: Fri, 18 Mar 2016 11:25:24 -0400 Subject: [PATCH 04/14] Updated launching command. --- package.json | 6 +++--- wiki/Launching.md | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 8f9b02e..a99dee1 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,9 @@ "url": "http://github.com/yahoo/guerilla/issues" }, "scripts": { - "start-master": "babel-node server.js --master", - "start-worker": "babel-node server.js --worker", - "start-redis": "redis-server", + "master": "node ./node_modules/babel-cli/bin/babel-node server.js --master", + "worker": "node ./node_modules/babel-cli/bin/babel-node server.js --worker", + "redis": "redis-server", "test": "TEST=1 ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- $(find tests -name '*.test.js')", "lint": "./node_modules/.bin/jshint tests" }, diff --git a/wiki/Launching.md b/wiki/Launching.md index 53f693f..81a291c 100644 --- a/wiki/Launching.md +++ b/wiki/Launching.md @@ -5,7 +5,7 @@ Navigate to the Guerilla project directory and start the redis server: ```sh -npm start-redis +npm run redis # or the following legacy way # redis-server ``` @@ -47,14 +47,14 @@ temporary directory. Master: ```sh -npm start-master +npm run master # or the following legacy way # node server.js --master [--config configFilePath] {--saveTempFiles}` ``` Worker: ```sh -npm start-worker +npm run worker # or the following legacy way # node server.js --worker [--config configFilePath] {--saveTempFiles} ``` \ No newline at end of file From cd01cbabd38d971ebf202889961105f84d596191 Mon Sep 17 00:00:00 2001 From: Nicholas Wong Date: Fri, 18 Mar 2016 11:28:45 -0400 Subject: [PATCH 05/14] Added back engine. --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index a99dee1..372e461 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,9 @@ "bugs": { "url": "http://github.com/yahoo/guerilla/issues" }, + "engines": { + "node": ">=0.12" + }, "scripts": { "master": "node ./node_modules/babel-cli/bin/babel-node server.js --master", "worker": "node ./node_modules/babel-cli/bin/babel-node server.js --worker", From 23e4d0bf0d308592c47fb90a972fe68e98837345 Mon Sep 17 00:00:00 2001 From: Nicholas Wong Date: Fri, 18 Mar 2016 11:40:47 -0400 Subject: [PATCH 06/14] Updated commands and fixed tests. --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 372e461..1f02995 100644 --- a/package.json +++ b/package.json @@ -25,10 +25,10 @@ "node": ">=0.12" }, "scripts": { - "master": "node ./node_modules/babel-cli/bin/babel-node server.js --master", - "worker": "node ./node_modules/babel-cli/bin/babel-node server.js --worker", + "master": "node ./node_modules/.bin/babel-node server.js --master", + "worker": "node ./node_modules/.bin/babel-node server.js --worker", "redis": "redis-server", - "test": "TEST=1 ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- $(find tests -name '*.test.js')", + "test": "TEST=1 ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- $(find tests -name '*.test.js') --compilers js:babel-core/register", "lint": "./node_modules/.bin/jshint tests" }, "dependencies": { From 457f38fa86b21cc84b718aecd6361f0dab87cbf2 Mon Sep 17 00:00:00 2001 From: Nicholas Wong Date: Mon, 21 Mar 2016 16:59:15 -0400 Subject: [PATCH 07/14] Fixed unit tests. --- models/Job.js | 2 +- models/Project.js | 2 +- models/Result.js | 2 +- package.json | 6 +++--- routes/master/jobs.js | 2 -- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/models/Job.js b/models/Job.js index 8984339..7114363 100644 --- a/models/Job.js +++ b/models/Job.js @@ -6,7 +6,7 @@ * Models a configured job. */ -import utilities from './utilities'; +import utilities from '../lib/utilities'; var async = require('async'); var path = require('path'); diff --git a/models/Project.js b/models/Project.js index 6f6675c..b4a6095 100644 --- a/models/Project.js +++ b/models/Project.js @@ -6,7 +6,7 @@ * Models a collection of jobs. */ -import utilities from './utilities'; +import utilities from '../lib/utilities'; var async = require('async'); var path = require('path'); diff --git a/models/Result.js b/models/Result.js index 370acf1..ad070db 100644 --- a/models/Result.js +++ b/models/Result.js @@ -6,7 +6,7 @@ * Models the results from an individual job run. */ -import utilities from './utilities'; +import utilities from '../lib/utilities'; var moment = require('moment'); var path = require('path'); diff --git a/package.json b/package.json index 1f02995..4fdb99d 100644 --- a/package.json +++ b/package.json @@ -25,10 +25,10 @@ "node": ">=0.12" }, "scripts": { - "master": "node ./node_modules/.bin/babel-node server.js --master", - "worker": "node ./node_modules/.bin/babel-node server.js --worker", + "master": "node_modules/.bin/babel-node server.js --master", + "worker": "node_modules/.bin/babel-node server.js --worker", "redis": "redis-server", - "test": "TEST=1 ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- $(find tests -name '*.test.js') --compilers js:babel-core/register", + "test": "TEST=1 node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- $(find tests -name '*.test.js') --compilers js:babel-core/register", "lint": "./node_modules/.bin/jshint tests" }, "dependencies": { diff --git a/routes/master/jobs.js b/routes/master/jobs.js index 0b51442..6c2da3b 100644 --- a/routes/master/jobs.js +++ b/routes/master/jobs.js @@ -6,8 +6,6 @@ * Router for all job endpoints. */ -import utilities from '../lib/utilities'; - var router = require('express').Router(); var path = require('path'); var models = require(path.join(__rootdir, 'lib', 'db')).models(); From 10b36fffab02992d4cd4b7fcb117080408333028 Mon Sep 17 00:00:00 2001 From: Nicholas Wong Date: Mon, 21 Mar 2016 16:59:41 -0400 Subject: [PATCH 08/14] Reverted changes. --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 4fdb99d..eba500a 100644 --- a/package.json +++ b/package.json @@ -21,9 +21,6 @@ "bugs": { "url": "http://github.com/yahoo/guerilla/issues" }, - "engines": { - "node": ">=0.12" - }, "scripts": { "master": "node_modules/.bin/babel-node server.js --master", "worker": "node_modules/.bin/babel-node server.js --worker", @@ -31,6 +28,9 @@ "test": "TEST=1 node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- $(find tests -name '*.test.js') --compilers js:babel-core/register", "lint": "./node_modules/.bin/jshint tests" }, + "engines": { + "node": ">=0.12" + }, "dependencies": { "async": "^1.0.0", "body-parser": "^1.10.2", From 7fc3f413c218bca475587848417fdad3d577326b Mon Sep 17 00:00:00 2001 From: Nicholas Wong Date: Mon, 21 Mar 2016 17:01:35 -0400 Subject: [PATCH 09/14] Reverted changes. --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index eba500a..b72361a 100644 --- a/package.json +++ b/package.json @@ -28,9 +28,6 @@ "test": "TEST=1 node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- $(find tests -name '*.test.js') --compilers js:babel-core/register", "lint": "./node_modules/.bin/jshint tests" }, - "engines": { - "node": ">=0.12" - }, "dependencies": { "async": "^1.0.0", "body-parser": "^1.10.2", @@ -64,6 +61,9 @@ "underscore": "^1.8.3", "yargs": "^3.15.0" }, + "engines": { + "node": ">=0.12" + }, "devDependencies": { "babel-cli": "^6.6.5", "babel-eslint": "^5.0.0-beta6", From 5f7abf2dbf146e021af484b72ca31caa855a477e Mon Sep 17 00:00:00 2001 From: Nicholas Wong Date: Mon, 21 Mar 2016 17:01:48 -0400 Subject: [PATCH 10/14] Updated code to check existence. --- lib/utilities.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/utilities.js b/lib/utilities.js index 98ce9b5..1eb73c9 100644 --- a/lib/utilities.js +++ b/lib/utilities.js @@ -29,13 +29,14 @@ export default class Utilities { } static exists(v) { - return !(typeof v == 'undefined' || v == null); + return !(v === undefined || v === null); } static stringify(obj) { - if (typeof obj === 'object') + if (typeof obj === 'object') { return util.inspect(obj, {showHidden: true, depth: null}); - else + } else { return obj; + } } } \ No newline at end of file From 25f0213acba0e69b9c7c22142f587c721a6a1859 Mon Sep 17 00:00:00 2001 From: Seye Ojumu Date: Mon, 21 Mar 2016 22:57:09 -0400 Subject: [PATCH 11/14] Updated test + coverage tools to support babeljs. * Bumped istanbul to version 1; supports babel-node + removes unnec. error messages * Bumped test timeouts; transpiling for nodejs v0.12 seems to take a while. * Cosmetic changes to aid testing + coverage. --- lib/cleanup.js | 5 ++++- package.json | 4 ++-- tests/coverage.test.js | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/cleanup.js b/lib/cleanup.js index f5db0de..5461c31 100644 --- a/lib/cleanup.js +++ b/lib/cleanup.js @@ -6,4 +6,7 @@ * Cleans up worker file system of any data from deleted jobs. */ - // TODO: Implement. \ No newline at end of file +// TODO: Implement. +if (require.main === module) { + // do nothing +} \ No newline at end of file diff --git a/package.json b/package.json index b72361a..a0c7b4c 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "master": "node_modules/.bin/babel-node server.js --master", "worker": "node_modules/.bin/babel-node server.js --worker", "redis": "redis-server", - "test": "TEST=1 node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- $(find tests -name '*.test.js') --compilers js:babel-core/register", + "test": "TEST=1 ./node_modules/.bin/babel-node ./node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- --compilers js:babel-core/register --timeout 5000 $(find tests -name '*.test.js') ", "lint": "./node_modules/.bin/jshint tests" }, "dependencies": { @@ -77,7 +77,7 @@ "chai": "^3.5.0", "debug": "^2.2.0", "glob": "^7.0.0", - "istanbul": "^0.4.2", + "istanbul": "^1.0.0-alpha.2", "jshint": "^2.9.1", "lodash": "^4.6.0", "mocha": "^2.4.5", diff --git a/tests/coverage.test.js b/tests/coverage.test.js index 0cc95bb..3bff897 100644 --- a/tests/coverage.test.js +++ b/tests/coverage.test.js @@ -139,6 +139,8 @@ describe('Coverage baseline', function () { }); mockery.registerSubstitute('./logger', path.join(__ROOTDIR, 'tests', 'mocks', 'logger')); + mockery.registerSubstitute('./lib/logger', + path.join(__ROOTDIR, 'tests', 'mocks', 'logger')); mockery.registerSubstitute('git-rev', path.join(__ROOTDIR, 'tests', 'mocks', 'git-rev')); mockery.registerSubstitute('fs-extra', From 2d5846f0def7804bc8c76cae4caf85682d754501 Mon Sep 17 00:00:00 2001 From: Seye Ojumu Date: Mon, 21 Mar 2016 23:13:43 -0400 Subject: [PATCH 12/14] Removed unnecessary ```--compilers js:babel-core/register``` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a0c7b4c..5c1f107 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "master": "node_modules/.bin/babel-node server.js --master", "worker": "node_modules/.bin/babel-node server.js --worker", "redis": "redis-server", - "test": "TEST=1 ./node_modules/.bin/babel-node ./node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- --compilers js:babel-core/register --timeout 5000 $(find tests -name '*.test.js') ", + "test": "TEST=1 ./node_modules/.bin/babel-node ./node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- --timeout 5000 $(find tests -name '*.test.js') ", "lint": "./node_modules/.bin/jshint tests" }, "dependencies": { From c649097b32ea0b42447de876ace113c26a21418c Mon Sep 17 00:00:00 2001 From: Nicholas Wong Date: Tue, 22 Mar 2016 09:43:18 -0400 Subject: [PATCH 13/14] Updated utilities file. --- lib/app.js | 2 +- lib/context.js | 2 +- lib/job-worker.js | 2 +- lib/logger.js | 2 +- lib/mailer.js | 2 +- lib/task.js | 2 +- lib/utilities.js | 49 ++++++++++++++++++++++------------------------- models/Job.js | 2 +- models/Project.js | 2 +- models/Result.js | 2 +- 10 files changed, 32 insertions(+), 35 deletions(-) diff --git a/lib/app.js b/lib/app.js index 431ab7a..7998a62 100644 --- a/lib/app.js +++ b/lib/app.js @@ -6,7 +6,7 @@ * Sets up middleware, routers, and error handlers for the Express.js application. */ -import utilities from './utilities'; +import * as utilities from './utilities'; var fs = require('fs-extra'); var path = require('path'); diff --git a/lib/context.js b/lib/context.js index dddb17c..848d89f 100644 --- a/lib/context.js +++ b/lib/context.js @@ -6,7 +6,7 @@ * Provides data and functionality to be used by tasks. */ -import utilities from './utilities'; +import * as utilities from './utilities'; var path = require('path'); var callsite = require('callsite'); diff --git a/lib/job-worker.js b/lib/job-worker.js index 11238f5..add320f 100644 --- a/lib/job-worker.js +++ b/lib/job-worker.js @@ -6,7 +6,7 @@ * Entry point for a new forked node process to execute a job. */ -import utilities from './utilities'; +import * as utilities from './utilities'; require('./globals'); diff --git a/lib/logger.js b/lib/logger.js index 2b3dfe9..7e54d96 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -6,7 +6,7 @@ * A logger class. */ -import utilities from './utilities'; +import * as utilities from './utilities'; var colors = require('colors'); var util = require('util'); diff --git a/lib/mailer.js b/lib/mailer.js index 15d3b5b..0e4e4c4 100644 --- a/lib/mailer.js +++ b/lib/mailer.js @@ -6,7 +6,7 @@ * Sends emails for job result status changes. */ -import utilities from './utilities'; +import * as utilities from './utilities'; var nodemailer = require('nodemailer'); var fs = require('fs-extra'); diff --git a/lib/task.js b/lib/task.js index 6130463..3138825 100644 --- a/lib/task.js +++ b/lib/task.js @@ -6,7 +6,7 @@ * An abstraction of a task. */ -import utilities from './utilities'; +import * as utilities from './utilities'; var path = require('path'); var async = require('async'); diff --git a/lib/utilities.js b/lib/utilities.js index 1eb73c9..f1440ae 100644 --- a/lib/utilities.js +++ b/lib/utilities.js @@ -8,35 +8,32 @@ import * as util from 'util'; -export default class Utilities { - - static formatMilliseconds(ms) { - var secNum = parseInt(ms / 1000, 10); - var hours = Math.floor(secNum / 3600); - var minutes = Math.floor((secNum - (hours * 3600)) / 60); - var seconds = secNum - (hours * 3600) - (minutes * 60); - if (minutes < 10) { - minutes = '0' + minutes; - } - if (seconds < 10) { - seconds = '0' + seconds; - } - return hours + ':' + minutes + ':' + seconds; +export function formatMilliseconds(ms) { + var secNum = parseInt(ms / 1000, 10); + var hours = Math.floor(secNum / 3600); + var minutes = Math.floor((secNum - (hours * 3600)) / 60); + var seconds = secNum - (hours * 3600) - (minutes * 60); + if (minutes < 10) { + minutes = '0' + minutes; } - - static isDictionary(obj) { - return !(!obj || Array.isArray(obj) || obj.constructor != Object); + if (seconds < 10) { + seconds = '0' + seconds; } + return hours + ':' + minutes + ':' + seconds; +} - static exists(v) { - return !(v === undefined || v === null); - } +export function isDictionary(obj) { + return !(!obj || Array.isArray(obj) || obj.constructor != Object); +} + +export function exists(v) { + return !(v === undefined || v === null); +} - static stringify(obj) { - if (typeof obj === 'object') { - return util.inspect(obj, {showHidden: true, depth: null}); - } else { - return obj; - } +export function stringify(obj) { + if (typeof obj === 'object') { + return util.inspect(obj, {showHidden: true, depth: null}); + } else { + return obj; } } \ No newline at end of file diff --git a/models/Job.js b/models/Job.js index 7114363..263e961 100644 --- a/models/Job.js +++ b/models/Job.js @@ -6,7 +6,7 @@ * Models a configured job. */ -import utilities from '../lib/utilities'; +import * as utilities from '../lib/utilities'; var async = require('async'); var path = require('path'); diff --git a/models/Project.js b/models/Project.js index b4a6095..616f831 100644 --- a/models/Project.js +++ b/models/Project.js @@ -6,7 +6,7 @@ * Models a collection of jobs. */ -import utilities from '../lib/utilities'; +import * as utilities from '../lib/utilities'; var async = require('async'); var path = require('path'); diff --git a/models/Result.js b/models/Result.js index ad070db..7ace9e7 100644 --- a/models/Result.js +++ b/models/Result.js @@ -6,7 +6,7 @@ * Models the results from an individual job run. */ -import utilities from '../lib/utilities'; +import * as utilities from '../lib/utilities'; var moment = require('moment'); var path = require('path'); From c572581e5bddf2d9416a27e52e8d87e6741a75d4 Mon Sep 17 00:00:00 2001 From: Nicholas Wong Date: Tue, 22 Mar 2016 09:44:26 -0400 Subject: [PATCH 14/14] Reverted changes. --- server.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/server.js b/server.js index dc0201f..506edbe 100644 --- a/server.js +++ b/server.js @@ -7,8 +7,6 @@ */ var git = require('git-rev'); -var logger = require('./lib/logger'); - git.long(function (str) { require('./lib/globals');