From bf60c5bce2e4e429074f2255aaba2c730eb30337 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 14:46:45 +1100 Subject: [PATCH 01/39] Add linting to the npm test script. --- package.json | 8 +++++--- test/jshint.js | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 test/jshint.js diff --git a/package.json b/package.json index 202ec1b..f904efb 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "babel" ], "scripts": { - "test": "node node_modules/jasmine-node/bin/jasmine-node --verbose --captureExceptions test/specs" + "test": "npm run lint && node node_modules/jasmine-node/bin/jasmine-node --verbose --captureExceptions test/specs", + "lint": "gulp lint --gulpfile ./test/jshint.js" }, "contributors": [ "bholloway", @@ -106,8 +107,9 @@ "yargs": "latest" }, "devDependencies": { + "jasmine-diff-matchers": "~2.0.0", "jasmine-node": "2.0.0-beta4", - "ncp": "~2.0.0", - "jasmine-diff-matchers": "~2.0.0" + "jshint-stylish": "^1.0.1", + "ncp": "~2.0.0" } } diff --git a/test/jshint.js b/test/jshint.js new file mode 100644 index 0000000..ef05c68 --- /dev/null +++ b/test/jshint.js @@ -0,0 +1,18 @@ +'use strict'; +var jshint = require('gulp-jshint'); +var gulp = require('gulp'); +var path = require('path'); +var cwd = path.resolve(process.cwd(), '..'); +var config = path.resolve(cwd, '.jshintrc'); +var stylish = require('jshint-stylish'); + +gulp.task('lint', function() { + return gulp.src([ + 'lib/**/*.js', + 'tasks/**/*.js', + 'bin/**/*.js', + 'test/specs/**/*.js' + ], {cwd:cwd}) + .pipe(jshint(config)) + .pipe(jshint.reporter(stylish)); +}); \ No newline at end of file From d306d0640bf42045f562439aa88d25508af36ddf Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 14:49:15 +1100 Subject: [PATCH 02/39] jshint fixes cli.js. --- bin/cli.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 552d36f..2634c6d 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -9,13 +9,11 @@ var path = require('path'), gulp = require('gulp'), gutil = require('gulp-util'), wordwrap = require('wordwrap'), - runSequence = require('run-sequence'), chalk = require('chalk'), prettyTime = require('pretty-hrtime'), yargs = require('yargs'); -var taskYargs = require('../lib/util/task-yargs'), - taskYargsRun = require('../lib/util/task-yargs-run'); +var taskYargsRun = require('../lib/util/task-yargs-run'); // TODO @bholloway menus // var mainMenu = require('../lib/cli/mainMenu'); @@ -51,8 +49,8 @@ var defaultYargsInstance = yargs ].join('\n'))) // .example('angularity', 'Interactive menu') //TODO reinstate when interactive menu is reinstated .example('angularity -v', 'Display the version of angularity') - .example('angularity \ -h', 'Get help on a particular task') - .example('angularity \', 'Run the given task') + .example('angularity -h', 'Get help on a particular task') + .example('angularity ', 'Run the given task') .option('version', { describe: 'Display the curent version', alias: ['v'], From 643164a94857f47885f41845c4c4bbd7579423a0 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:06:46 +1100 Subject: [PATCH 03/39] jshint fixes build.js. --- tasks/build.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tasks/build.js b/tasks/build.js index d70e885..4e35be3 100644 --- a/tasks/build.js +++ b/tasks/build.js @@ -9,27 +9,24 @@ function setUpTaskBuild(tyRun) { options: [], onInit: function onBuildTask(yargsInstance) { var gulp = require('gulp'), - wordwrap = require('wordwrap'), runSequence = require('run-sequence'); - var taskYargs = require('../lib/util/task-yargs'), - hr = require('../lib/util/hr'); + var hr = require('../lib/util/hr'); - var cliArgs = yargsInstance + yargsInstance .strict() - .wrap(80) - .argv; + .wrap(80); gulp.task('build', function (done) { console.log(hr('-', 80, 'build')); runSequence('javascript', 'css', 'html', done); }); }, - onRun: function onBuildTask(yargsInstance) { + onRun: function onBuildTask() { var runSequence = require('run-sequence'); runSequence(taskDefinition.name); } - } + }; tyRun.taskYargs.register(taskDefinition); } From fe25ca8dbfd980271d3b0072e50609c5601877e5 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:07:03 +1100 Subject: [PATCH 04/39] jshint fixes css.js. --- tasks/css.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tasks/css.js b/tasks/css.js index 6d45050..f0ce11e 100644 --- a/tasks/css.js +++ b/tasks/css.js @@ -10,19 +10,15 @@ function setUpTaskCss(tyRun) { onInit: function onInitCssTask(yargsInstance) { var gulp = require('gulp'), rimraf = require('gulp-rimraf'), - runSequence = require('run-sequence'), - wordwrap = require('wordwrap'), - path = require('path'); + runSequence = require('run-sequence'); var nodeSass = require('../lib/build/node-sass'), - taskYargs = require('../lib/util/task-yargs'), hr = require('../lib/util/hr'), streams = require('../lib/config/streams'); - var cliArgs = yargsInstance + yargsInstance .strict() - .wrap(80) - .argv; + .wrap(80); gulp.task('css', function (done) { console.log(hr('-', 80, 'css')); @@ -46,7 +42,7 @@ function setUpTaskCss(tyRun) { .pipe(gulp.dest(streams.BUILD)); }); }, - onRun: function onRunCssTask(yargsInstance) { + onRun: function onRunCssTask() { var runSequence = require('run-sequence'); runSequence(taskDefinition.name); } From cc1ac80c63665ea73a9c9f8059e8b586e499fa72 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:07:21 +1100 Subject: [PATCH 05/39] jshint fixes html.js. --- tasks/html.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tasks/html.js b/tasks/html.js index 6357370..404df39 100644 --- a/tasks/html.js +++ b/tasks/html.js @@ -10,26 +10,22 @@ function setUpTaskHtml(tyRun) { options: [], onInit: function onInitHtmlTask(yargsInstance) { var gulp = require('gulp'), - concat = require('gulp-concat'), inject = require('gulp-inject'), plumber = require('gulp-plumber'), rimraf = require('gulp-rimraf'), - runSequence = require('run-sequence'), - wordwrap = require('wordwrap'); + runSequence = require('run-sequence'); var injectAdjacent = require('../lib/inject/adjacent-files'), bowerFiles = require('../lib/inject/bower-files'), - taskYargs = require('../lib/util/task-yargs'), hr = require('../lib/util/hr'), streams = require('../lib/config/streams'); - var cliArgs = yargsInstance + yargsInstance .strict() - .wrap(80) - .argv; + .wrap(80); // `cliArgs` are available within gulp tasks by means of closure, - // as they are only called after `onRun` has been invoked, and they have been passeds + // as they are only called after `onRun` has been invoked, and they have been passed gulp.task('html', function (done) { console.log(hr('-', 80, 'html')); runSequence( @@ -65,7 +61,7 @@ function setUpTaskHtml(tyRun) { .pipe(gulp.dest(streams.BUILD)); }); }, - onRun: function onRunHtmlTask(yargsInstance) { + onRun: function onRunHtmlTask() { var runSequence = require('run-sequence'); runSequence(taskDefinition.name); } From bb05a6d084b46c4cfb76e031a457c4cb5943cdee Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:07:37 +1100 Subject: [PATCH 06/39] jshint fixes init.js. --- tasks/init.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/tasks/init.js b/tasks/init.js index 1d3c26e..9fd7c1d 100644 --- a/tasks/init.js +++ b/tasks/init.js @@ -191,7 +191,7 @@ function setUpInitTask(tyRun) { 'If a package.json is present initialisation will occur in the current directory. Otherwise a sub-directory is' + 'created per the project name', '', - 'Where run on an exising project existing files will not be altered, delete existing files in order to change ' + + 'Where run on an existing project existing files will not be altered, delete existing files in order to change ' + 'properties.', '', 'Both the npm and bower packages are initially set private which you will need to clear in order to publish.', @@ -206,7 +206,6 @@ function setUpInitTask(tyRun) { onInit: function onInitInitTask(yargsInstance) { var gulp = require('gulp'), gutil = require('gulp-util'), - wordwrap = require('wordwrap'), runSequence = require('run-sequence'), path = require('path'), fs = require('fs'), @@ -310,12 +309,6 @@ function setUpInitTask(tyRun) { copyTemplateSync('.editorconfig'); }); - function padded(length) { - return function(text) { - return (text + (new Array(length)).join(' ')).slice(0, length); - } - } - function mkdirIfNotExisting(projectRelativePath) { var absolute = path.resolve(projectRelativePath); var exists = fs.existsSync(absolute); @@ -362,7 +355,7 @@ function setUpInitTask(tyRun) { } } }, - onRun: function onRunInitTask(yargsInstance) { + onRun: function onRunInitTask() { var runSequence = require('run-sequence'); runSequence(taskDefinition.name); } From a88d5776397bc2b4c394ffa753f7ec844d2b43ea Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:07:48 +1100 Subject: [PATCH 07/39] jshint fixes javascript.js. --- tasks/javascript.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tasks/javascript.js b/tasks/javascript.js index ddf50b0..1b74efe 100644 --- a/tasks/javascript.js +++ b/tasks/javascript.js @@ -7,8 +7,8 @@ function setUpTaskJavascript(tyRun) { var optionDefinitionJsHintReporter = { key: 'jshint-reporter', value: { - describe: 'Specify a custom JsHint reporter to use. Either a locally npm installed module, or the absolute path ' + - 'to one.', + describe: 'Specify a custom JsHint reporter to use. Either a locally npm installed module,' + + ' or the absolute path to one.', alias: ['j'], //TODO @bguiz get this from config default: 'angularity-jshint-reporter', @@ -98,9 +98,6 @@ function setUpTaskJavascript(tyRun) { checkKarmaReporter ], onInit: function onInitJavascriptTask(yargsInstance) { - var path = require('path'), - fs = require('fs'); - var gulp = require('gulp'), jshint = require('gulp-jshint'), rimraf = require('gulp-rimraf'), @@ -109,12 +106,10 @@ function setUpTaskJavascript(tyRun) { combined = require('combined-stream'), to5ify = require('6to5ify'), stringify = require('stringify'), - wordwrap = require('wordwrap'), ngAnnotate = require('browserify-ngannotate'); var karma = require('../lib/test/karma'), browserify = require('../lib/build/browserify'), - taskYargs = require('../lib/util/task-yargs'), hr = require('../lib/util/hr'), streams = require('../lib/config/streams'), jshintReporter = require('../lib/util/jshint-reporter'); @@ -162,7 +157,7 @@ function setUpTaskJavascript(tyRun) { }); // clean javascript from the test directory - // don't remove the karma conf or Webstorm ide will have problems + // don't remove the karma conf or WebStorm ide will have problems gulp.task('javascript:cleanunit', function () { return gulp .src([streams.TEST + '/**/*.js*', '!**/karma.conf.js'], {read: false}) // keep configuration @@ -192,7 +187,7 @@ function setUpTaskJavascript(tyRun) { ) .pipe(semiflat(process.cwd())) .pipe(karma.createConfig(reporters)) - .pipe(gulp.dest(streams.TEST)) + .pipe(gulp.dest(streams.TEST)); }); /** @@ -210,10 +205,10 @@ function setUpTaskJavascript(tyRun) { } // Augment exported function with utility functions because - // dependant tasks would liek to share this + // dependant tasks would like to share this setUpTaskJavascript.getTransforms = getTransforms; }, - onRun: function onRunJavascriptTask(yargsInstance) { + onRun: function onRunJavascriptTask() { console.log('onRunJavascriptTask'); var runSequence = require('run-sequence'); runSequence(taskDefinition.name); From 691962269eda2acfeb0c475afdb49d0897e77cf9 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:07:56 +1100 Subject: [PATCH 08/39] jshint fixes release.js. --- tasks/release.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tasks/release.js b/tasks/release.js index 4b559b5..cebcf47 100644 --- a/tasks/release.js +++ b/tasks/release.js @@ -8,10 +8,8 @@ function setUpTaskRelease(tyRun) { prerequisiteTasks: ['help', 'build'], checks: [], options: [], - onInit: function onInitReleaseTask(yargsInstance) { + onInit: function onInitReleaseTask() { var gulp = require('gulp'), - concat = require('gulp-concat'), - wrap = require('gulp-wrap'), inject = require('gulp-inject'), plumber = require('gulp-plumber'), rimraf = require('gulp-rimraf'), @@ -22,15 +20,13 @@ function setUpTaskRelease(tyRun) { var injectAdjacent = require('../lib/inject/adjacent-files'), injectTransform = require('../lib/inject/relative-transform'), bowerFiles = require('../lib/inject/bower-files'), - versionDirectory = require('../lib/release/version-directory'), taskYargs = require('../lib/util/task-yargs'), hr = require('../lib/util/hr'), - jshintReporter = require('../lib/util/jshint-reporter'), streams = require('../lib/config/streams'); taskYargs.register('release', { - description: (wordwrap(2, 80)('The "release" task performs a single build and exports the build files along with bower ' + - 'components to a release directory.')), + description: (wordwrap(2, 80)('The "release" task performs a single build and exports the build ' + + 'files along with bower components to a release directory.')), prerequisiteTasks: ['help', 'build'], checks: [], options: [] @@ -80,19 +76,19 @@ function setUpTaskRelease(tyRun) { }); // version the release app directory - /* TODO resolve versioning and CDN release + /* TODO resolve visioning and CDN release gulp.task('release:versionapp', function () { return gulp.src(streams.RELEASE_APP + '/**') .pipe(versionDirectory('$', true)); }); */ }, - onRun: function onRunReleaseTask(yargsInstance) { + onRun: function onRunReleaseTask() { var runSequence = require('run-sequence'); runSequence(taskDefinition.name); } - } + }; tyRun.taskYargs.register(taskDefinition); -}; +} module.exports = setUpTaskRelease; From a620ee80c7cc4719c17595f55309f4a430589f48 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:08:09 +1100 Subject: [PATCH 09/39] jshint fixes server.js. --- tasks/server.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tasks/server.js b/tasks/server.js index 6c14886..20a28f4 100644 --- a/tasks/server.js +++ b/tasks/server.js @@ -40,12 +40,9 @@ function setUpTaskServer(tyRun) { onInit: function onInitServerTask(yargsInstance) { var gulp = require('gulp'), gutil = require('gulp-util'), - wordwrap = require('wordwrap'), browserSync = require('browser-sync'); - var taskYargs = require('../lib/util/task-yargs'), - hr = require('../lib/util/hr'), - jshintReporter = require('../lib/util/jshint-reporter'), + var hr = require('../lib/util/hr'), streams = require('../lib/config/streams'); var cliArgs; @@ -78,7 +75,7 @@ function setUpTaskServer(tyRun) { browserSync.reload(); }); }, - onRun: function onRunServerTask(yargsInstance) { + onRun: function onRunServerTask() { var runSequence = require('run-sequence'); runSequence(taskDefinition.name); } From 81767c732edcdcdd65a03a18a7845c2683839c02 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:08:22 +1100 Subject: [PATCH 10/39] jshint fixes test.js. --- tasks/test.js | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/tasks/test.js b/tasks/test.js index 07d097d..23f911c 100644 --- a/tasks/test.js +++ b/tasks/test.js @@ -13,25 +13,11 @@ function setUpTaskTest(tyRun) { options: [], checks: [], onInit: function onInitTestTask(yargsInstance) { - var path = require('path'), - fs = require('fs'); - - var gulp = require('gulp'), - jshint = require('gulp-jshint'), - rimraf = require('gulp-rimraf'), - runSequence = require('run-sequence'), - combined = require('combined-stream'), - to5ify = require('6to5ify'), - stringify = require('stringify'), - wordwrap = require('wordwrap'), - ngAnnotate = require('browserify-ngannotate'); + var gulp = require('gulp'); var karma = require('../lib/test/karma'), - browserify = require('../lib/build/browserify'), - taskYargs = require('../lib/util/task-yargs'), hr = require('../lib/util/hr'), - streams = require('../lib/config/streams'), - jshintReporter = require('../lib/util/jshint-reporter'); + streams = require('../lib/config/streams'); var cliArgs; cliArgs = yargsInstance @@ -39,7 +25,7 @@ function setUpTaskTest(tyRun) { .wrap(80) .argv; - gulp.task('test', ['javascript'], function (done) { + gulp.task('test', ['javascript'], function () { console.log(hr('-', 80, 'test')); gulp @@ -47,7 +33,7 @@ function setUpTaskTest(tyRun) { .pipe(karma.run()); }); }, - onRun: function onRunTestTask(yargsInstance) { + onRun: function onRunTestTask() { var runSequence = require('run-sequence'); runSequence(taskDefinition.name); } From e72a4ebd7cb97d4ab11f925f384eeffd238587ff Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:08:33 +1100 Subject: [PATCH 11/39] jshint fixes watch.js. --- tasks/watch.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tasks/watch.js b/tasks/watch.js index 94e6463..fe25291 100644 --- a/tasks/watch.js +++ b/tasks/watch.js @@ -3,7 +3,7 @@ function setUpTaskWatch(tyRun) { var defaults = require('../lib/config/defaults'); - var config = defaults.getInstance() + defaults.getInstance() .file('angularity.json') .defaults({ port: 55555 @@ -17,16 +17,12 @@ function setUpTaskWatch(tyRun) { prerequisiteTasks: ['help', 'server'], checks: [], options: [], - onInit: function onInitWatchTask(yargsInstance) { + onInit: function onInitWatchTask() { var gulp = require('gulp'), watch = require('gulp-watch'), - wordwrap = require('wordwrap'), watchSequence = require('gulp-watch-sequence'); - var defaults = require('../lib/config/defaults'), - hr = require('../lib/util/hr'), - karma = require('../lib/test/karma'), - jshintReporter = require('../lib/util/jshint-reporter'), + var hr = require('../lib/util/hr'), streams = require('../lib/config/streams'); gulp.task('watch', ['server'], function () { @@ -48,19 +44,20 @@ function setUpTaskWatch(tyRun) { emitOnGlob: false }, queue.getHandler('css', 'html', 'reload')); // html will be needed in case previous injection failed - watch([streams.APP + '/**/*.html', streams.BOWER + '/**/*', '!**/*.js', '!**/*.scss'], { // don't conflict JS or CSS + // don't conflict JS or CSS + watch([streams.APP + '/**/*.html', streams.BOWER + '/**/*', '!**/*.js', '!**/*.scss'], { name : 'INJECT', emitOnGlob: false }, queue.getHandler('html', 'reload')); }); }, - onRun: function onRunWatchTask(yargsInstance) { + onRun: function onRunWatchTask() { var runSequence = require('run-sequence'); runSequence(taskDefinition.name); } }; tyRun.taskYargs.register(taskDefinition); -}; +} module.exports = setUpTaskWatch; From e234c83b3ba9512b4e4abd4db8a8c3baaba4547a Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:08:57 +1100 Subject: [PATCH 12/39] jshint fixe webstorm.js. --- tasks/webstorm.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/webstorm.js b/tasks/webstorm.js index 560d1b5..b0d2953 100644 --- a/tasks/webstorm.js +++ b/tasks/webstorm.js @@ -1,6 +1,6 @@ 'use strict'; -function setUpWebstormTask(tyRun) { +function setUpWebStormTask(tyRun) { var fs = require('fs'), path = require('path'), ideTemplate = require('ide-template'), @@ -369,4 +369,4 @@ function setUpWebstormTask(tyRun) { return result; } } -module.exports = setUpWebstormTask; +module.exports = setUpWebStormTask; From 9a62230168ec8ab48da1cd114c6ede3bffab6964 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:09:45 +1100 Subject: [PATCH 13/39] Adjust jshint configuration to allow javascript url syntax that conflicts with gulp task definitions. --- .jshintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.jshintrc b/.jshintrc index 6305ee1..52deba6 100644 --- a/.jshintrc +++ b/.jshintrc @@ -21,6 +21,7 @@ "maxparams": 20, "maxdepth": 5, "maxlen": 120, + "scripturl": true, "node": true, "jasmine": true } \ No newline at end of file From 86f46b393a1e79fb32c4574410a4ed9fb2f4c4f1 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:42:58 +1100 Subject: [PATCH 14/39] jshint fixes for specs. --- test/specs/tasks/css-task.js | 3 ++- test/specs/tasks/init.spec.js | 3 ++- test/specs/tasks/javascript-task.js | 6 ++++-- test/specs/tasks/release.spec.js | 6 ++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/test/specs/tasks/css-task.js b/test/specs/tasks/css-task.js index b66a74b..cef881a 100644 --- a/test/specs/tasks/css-task.js +++ b/test/specs/tasks/css-task.js @@ -13,7 +13,8 @@ function expectations(testCase) { expect(testCase.stdout).toBeTask('css'); expect(testCase.cwd).toHaveExpectedCssExcept(); expect(workingBuildFile('index.css')).diffFilePatch(sourceBuildFile('index.css')); -// expect(workingBuildFile('index.css.map')).diffFilePatch(sourceBuildFile('index.css.map')); // TODO @bholloway solve repeatability of .map files +// expect(workingBuildFile('index.css.map')).diffFilePatch(sourceBuildFile('index.css.map')); +// TODO @bholloway solve repeatability of .map files } function customMatchers() { diff --git a/test/specs/tasks/init.spec.js b/test/specs/tasks/init.spec.js index 419ba78..31fd4a6 100644 --- a/test/specs/tasks/init.spec.js +++ b/test/specs/tasks/init.spec.js @@ -115,7 +115,8 @@ describe('The Angularity init task', function () { helper.runner.create() .addParameters({ version: '1.2.3' }) .addParameters({ version: '4.6.6-rc2A' }) -// .addParameters({ version: '"non semver string"', illegal: true }) // TODO @bholloway doesn't invoke correctly on windows +// .addParameters({ version: '"non semver string"', illegal: true }) +// TODO @bholloway doesn't invoke correctly on windows .addInvocation('init --version {version}') .addInvocation('init -v {version}') .forEach(slowIt(expectations)) diff --git a/test/specs/tasks/javascript-task.js b/test/specs/tasks/javascript-task.js index 9fa7ad2..7079760 100644 --- a/test/specs/tasks/javascript-task.js +++ b/test/specs/tasks/javascript-task.js @@ -20,11 +20,13 @@ function expectations(testCase) { // build output expect(workingBuildFile('index.js')).diffFilePatch(sourceBuildFile('index.js')); -// expect(workingBuildFile('index.js.map' )).diffFilePatch(sourceBuildFile('index.js.map')); // TODO @bholloway solve repeatability of .map files +// expect(workingBuildFile('index.js.map' )).diffFilePatch(sourceBuildFile('index.js.map')); +// TODO @bholloway solve repeatability of .map files // test output expect(workingTestFile('index.js')).diffFilePatch(sourceTestFile('index.js')); -// expect(workingTestFile('index.js.map')).diffFilePatch(sourceTestFile('index.js.map')); // TODO @bholloway solve repeatability of .map files +// expect(workingTestFile('index.js.map')).diffFilePatch(sourceTestFile('index.js.map')); +// TODO @bholloway solve repeatability of .map files } function customMatchers() { diff --git a/test/specs/tasks/release.spec.js b/test/specs/tasks/release.spec.js index 588f407..424a90d 100644 --- a/test/specs/tasks/release.spec.js +++ b/test/specs/tasks/release.spec.js @@ -80,8 +80,10 @@ function expectations(testCase) { expect(workingReleaseFile('index.html')).diffFilePatch(sourceReleaseFile('index.html')); expect(workingReleaseFile('index.js')).diffFilePatch(sourceReleaseFile('index.js')); expect(workingReleaseFile('index.css')).diffFilePatch(sourceReleaseFile('index.css')); -// expect(workingReleaseFile('index.js.map' )).diffFilePatch(sourceReleaseFile('index.js.map')); // TODO @bholloway solve repeatability of .map files -// expect(workingReleaseFile('index.css.map')).diffFilePatch(sourceReleaseFile('index.css.map')); // TODO @bholloway solve repeatability of .map files +// expect(workingReleaseFile('index.js.map' )).diffFilePatch(sourceReleaseFile('index.js.map')); +// TODO @bholloway solve repeatability of .map files +// expect(workingReleaseFile('index.css.map')).diffFilePatch(sourceReleaseFile('index.css.map')); +// TODO @bholloway solve repeatability of .map files // vendor files expect(workingVendorFile('manifest.json')).diffFilePatch(sourceVendorFile('manifest.json')); From 41c66f02a708b8c2126ab5165d37ba2549d6021f Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:43:25 +1100 Subject: [PATCH 15/39] jshint fixes for browserify.js. --- lib/build/browserify.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/build/browserify.js b/lib/build/browserify.js index 5559f1d..7192f27 100644 --- a/lib/build/browserify.js +++ b/lib/build/browserify.js @@ -22,7 +22,7 @@ var fs = require('fs'), function isLiteralAST(node) { var candidates = Array.prototype.slice.call(arguments, 1); return (node) && (node.type === 'Literal') && candidates.some(function (candidate) { - return (node.value === candidate) + return (node.value === candidate); }); } @@ -130,7 +130,7 @@ function compile(bannerWidth, transforms) { var BOWER = path.relative(process.cwd(), bowerDir.sync()); return transformTools.makeRequireTransform('requireTransform', null, function (args, opts, done) { - // transform the original path where relevent + // transform the original path where relevant var original = args[0]; var split = original.split(/[\\\/]/g); // keep delimiters var firstTerm = split.splice(0, 1)[0]; // remove the first term from the split @@ -258,7 +258,7 @@ function compile(bannerWidth, transforms) { uglify : { compress: { // anything that changes semicolons to commas will cause debugger problems sequences: false, - join_vars: false + join_vars: false // jshint ignore:line }, mangle : { toplevel: true From 80d3093e4f75772c53db6a667181946dbed1b8c4 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:43:46 +1100 Subject: [PATCH 16/39] jshint fixes for node-sass.js. --- lib/build/node-sass.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/build/node-sass.js b/lib/build/node-sass.js index 8d64606..3e5d0e5 100644 --- a/lib/build/node-sass.js +++ b/lib/build/node-sass.js @@ -109,7 +109,7 @@ module.exports = function (bannerWidth, libraryPaths) { /** * Push file contents to the output stream. - * @param {string} ext The extention for the file, including dot + * @param {string} ext The extension for the file, including dot * @param {string|object?} contents The contents for the file or fields to assign to it * @return {vinyl.File} The file that has been pushed to the stream */ @@ -136,7 +136,7 @@ module.exports = function (bannerWidth, libraryPaths) { function reworkPlugin(stylesheet) { // visit each node (selector) in the stylesheet recursively using the official utility method - visit(stylesheet, function (declarations, node) { + visit(stylesheet, function (declarations) { // each node may have multiple declarations declarations.forEach(function (declaration) { From 22b6b4b949d1c9622e4002465b6fd9a2bc8c3c08 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:44:02 +1100 Subject: [PATCH 17/39] jshint fixes for defaults.js. --- lib/config/defaults.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/defaults.js b/lib/config/defaults.js index dfd6d5b..2f1dbf7 100755 --- a/lib/config/defaults.js +++ b/lib/config/defaults.js @@ -145,7 +145,7 @@ function readFile(filePath, field) { if (filePath && fs.existsSync(filePath)) { var data = fs.readFileSync(filePath).toString(); try { - var json = JSON.parse(data) + var json = JSON.parse(data); return field ? (json[field] || {}) : json; } catch(error) { throw new Error('Unparsable json file: ' + filePath); From 726701b2d93c8c3d6c6241a1aa8f58ecdf143702 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:44:15 +1100 Subject: [PATCH 18/39] jshint fixes for platform.js. --- lib/config/platform.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/platform.js b/lib/config/platform.js index e0f9e37..8ddfcff 100644 --- a/lib/config/platform.js +++ b/lib/config/platform.js @@ -45,4 +45,4 @@ module.exports = { isMacOS : isMacOS, isUnix : isUnix, userHomeDirectory: userHomeDirectory -} +}; From 7d8bd06370ba48a25bd017fa0b57edf0b98fdde8 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:44:28 +1100 Subject: [PATCH 19/39] jshint fixes for streams.js. --- lib/config/streams.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/streams.js b/lib/config/streams.js index a8d401f..7c87fc0 100644 --- a/lib/config/streams.js +++ b/lib/config/streams.js @@ -38,7 +38,7 @@ function getLocalLibGlob() { return function() { return flatten(Array.prototype.slice.call(arguments)) .concat(excludes); // important - excludes must come after includes - } + }; } function mapRoutes(result, path) { From 1cae44a1d2a277f7eb2c78463bfb6c612e4a2821 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:44:47 +1100 Subject: [PATCH 20/39] jshint fixes for adjacent-files.js. --- lib/inject/adjacent-files.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/inject/adjacent-files.js b/lib/inject/adjacent-files.js index 8736f7a..53ad06c 100644 --- a/lib/inject/adjacent-files.js +++ b/lib/inject/adjacent-files.js @@ -61,4 +61,4 @@ module.exports = function (extension, opts, recurse) { done(); }); }); -} \ No newline at end of file +}; \ No newline at end of file From caf812f7da6ebdad1dabc1bf7cfb03c0bd460b89 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:45:03 +1100 Subject: [PATCH 21/39] jshint fixes for brower-files.js. --- lib/inject/bower-files.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/inject/bower-files.js b/lib/inject/bower-files.js index 3e0b6a6..fdcdad5 100644 --- a/lib/inject/bower-files.js +++ b/lib/inject/bower-files.js @@ -5,7 +5,7 @@ var combined = require('combined-stream'), gutil = require('gulp-util'), spigot = require('stream-spigot'), defaults = require('lodash.defaults'), - flatten = require("lodash.flatten"), + flatten = require('lodash.flatten'), through = require('through2'), path = require('path'), fs = require('fs'); @@ -21,7 +21,7 @@ function json(includeDev) { try { return fs.existsSync(filename) && require(path.resolve(filename)); } catch(error) { - gutil.log('Error parsing bower.json at ' + filename) + gutil.log('Error parsing bower.json at ' + filename); } } var bower = read('bower.json'); @@ -178,4 +178,4 @@ module.exports = function () { src: src }; return self; -} \ No newline at end of file +}; \ No newline at end of file From 7826432cb5a2612807040c59ae410d48f86cc325 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:45:20 +1100 Subject: [PATCH 22/39] jshint fixes for karma.js. --- lib/test/karma.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/test/karma.js b/lib/test/karma.js index d7f64c4..9decb84 100644 --- a/lib/test/karma.js +++ b/lib/test/karma.js @@ -8,9 +8,7 @@ var path = require('path'), lodashMerge = require('lodash.merge'), childProcess = require('child_process'); -var yargs = require('../util/yargs'), - streams = require('../config/streams'), - platform = require('../config/platform'); +var platform = require('../config/platform'); //TODO @bguiz get this from config var defaultReporterName = 'karma-angularity-reporter'; @@ -100,7 +98,7 @@ function getKarmaReporterName(reporterName) { * Expects all the `*.js` files to be included as the files list in the karma conf * Creates a new karma config file, based on the karma config file name found in * the local project root, and augments its file list by replacing - * `ANGULARITY_FILE_LIST` in ablock comment with the actual array of files. + * `ANGULARITY_FILE_LIST` in a block comment with the actual array of files. * The new karma config file is added to the stream, * All input `*.js` files are filtered out of the stream * From e0c0c3ff49493938a8fb12e1a359221d1afbfbab Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:45:30 +1100 Subject: [PATCH 23/39] jshint fixes for hr.js. --- lib/util/hr.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util/hr.js b/lib/util/hr.js index 82f8eef..1a10fe2 100644 --- a/lib/util/hr.js +++ b/lib/util/hr.js @@ -13,6 +13,6 @@ function hr(char, length, title) { text = char + text + char; // centre title between the given character } return text.slice(0, length); // enforce length, left justified -}; +} module.exports = hr; \ No newline at end of file From 23275a175044c65853a063f833ec6f352db6cade Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:45:51 +1100 Subject: [PATCH 24/39] jshint fixes for jshint-reporter.js. --- lib/util/jshint-reporter.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/util/jshint-reporter.js b/lib/util/jshint-reporter.js index 3b90d99..a716cae 100644 --- a/lib/util/jshint-reporter.js +++ b/lib/util/jshint-reporter.js @@ -4,8 +4,6 @@ var path = require('path'); var gulpJshint = require('gulp-jshint'); -var yargs = require('./yargs'); - //TODO @bguiz get this from config var defaultReporterName = 'angularity-jshint-reporter'; From 18bd5da351156ec043b3c2b9cdf40927f527dabe Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:46:08 +1100 Subject: [PATCH 25/39] jshint fixes for task-yargs-run.js. --- lib/util/task-yargs-run.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/util/task-yargs-run.js b/lib/util/task-yargs-run.js index 7cd465a..8fe6ebe 100644 --- a/lib/util/task-yargs-run.js +++ b/lib/util/task-yargs-run.js @@ -19,7 +19,7 @@ function checkFlagMissing(opt, key, value) { } } -function checkFlagType(opt, ket, value) { +function checkFlagType(opt, key, value) { var valueType = (typeof value); var typeIsOk = false; var validTypes = ['string', 'boolean', 'number'] @@ -51,7 +51,7 @@ function checkFlagType(opt, ket, value) { if (!typeIsOk) { var expectedType = JSON.stringify(validTypes); if (opt.value.isMultiple) { - expectedType = 'Array<' + expectedType + '>' + expectedType = 'Array<' + expectedType + '>'; } throw new Error('' + key + ' is expected to be of types ' + expectedType + ' but a ' + (typeof value) + ' was provided instead.'); From 31be93ec489620fc46bf92900d5af59a87bc4cd2 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:46:22 +1100 Subject: [PATCH 26/39] jshint fixes for task-yargs.js. --- lib/util/task-yargs.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/util/task-yargs.js b/lib/util/task-yargs.js index ac6ba97..fbdb3f9 100644 --- a/lib/util/task-yargs.js +++ b/lib/util/task-yargs.js @@ -19,7 +19,7 @@ function checkFlagMissing(opt, key, value) { } } -function checkFlagType(opt, ket, value) { +function checkFlagType(opt, key, value) { var valueType = (typeof value); var typeIsOk = false; var validTypes = ['string', 'boolean', 'number'] @@ -51,7 +51,7 @@ function checkFlagType(opt, ket, value) { if (!typeIsOk) { var expectedType = JSON.stringify(validTypes); if (opt.value.isMultiple) { - expectedType = 'Array<' + expectedType + '>' + expectedType = 'Array<' + expectedType + '>'; } throw new Error('' + key + ' is expected to be of types ' + expectedType + ' but a ' + (typeof value) + ' was provided instead.'); From baadcec9057f5bb51502c9aa001923691b261561 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:46:39 +1100 Subject: [PATCH 27/39] jshint fixes for yargs.js. --- lib/util/yargs.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/util/yargs.js b/lib/util/yargs.js index 869689a..61b8f5c 100644 --- a/lib/util/yargs.js +++ b/lib/util/yargs.js @@ -46,17 +46,17 @@ function listTasks() { } /** - * Check that any additional arugments are only the subcommand + * Check that any additional arguments are only the sub command * @param {Object} argv parsed argv hash * @param {Array} options options and their aliases * @throws Error where task is improperly specified */ -function subCommandCheck(argv, options) { +function subCommandCheck(argv) { var bareArguments = argv._; if (bareArguments) { if (bareArguments.length > 1) { throw new Error('Too many tasks specified: '+ bareArguments.slice(1)); - } else if ((bareArguments.length == 1) && listTasks().indexOf(bareArguments[0]) < 0) { + } else if ((bareArguments.length === 1) && listTasks().indexOf(bareArguments[0]) < 0) { throw new Error('Unknown task: ' + bareArguments[0]); } } @@ -102,7 +102,7 @@ function singleDashCheck(argv, options) { // error message if (pending.length) { - throw new Error('Superfluous arguments: ' + pending.join(', ')) + throw new Error('Superfluous arguments: ' + pending.join(', ')); } } @@ -131,7 +131,7 @@ function createCheck() { commit: function() { return getCheck(elements); // lock in the current instance state } - } + }; // the implementation of the yargs check method function getCheck(elements) { From 4300cc112878021b0cbe5abfb77eb941e038aaa1 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Thu, 19 Mar 2015 15:47:53 +1100 Subject: [PATCH 28/39] Remove interactive menus, they maybe reimplemented in a future version. --- lib/cli/MenuPrompt.js | 51 -------------- lib/cli/generatorMenu.js | 144 -------------------------------------- lib/cli/initialiseMenu.js | 63 ----------------- lib/cli/installMenu.js | 103 --------------------------- lib/cli/mainMenu.js | 86 ----------------------- 5 files changed, 447 deletions(-) delete mode 100644 lib/cli/MenuPrompt.js delete mode 100644 lib/cli/generatorMenu.js delete mode 100755 lib/cli/initialiseMenu.js delete mode 100755 lib/cli/installMenu.js delete mode 100644 lib/cli/mainMenu.js diff --git a/lib/cli/MenuPrompt.js b/lib/cli/MenuPrompt.js deleted file mode 100644 index 2b1fe22..0000000 --- a/lib/cli/MenuPrompt.js +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Utility to more easily write the cli options through asks npm. - * - * See the usage in the initialiseMenu.js. - */ -'use strict'; - -var Q = require('q'), - asks = require('asks'); - -var QuestionType = { - INPUT: 'input', - LIST : 'list' -}; - -function Menu() { - this.questions = []; -} - -Menu.prototype.askText = function (name, message, defaultValue, validate, filter) { - this.addQuesitonType(name, message, null, defaultValue, validate, filter, QuestionType.INPUT); -}; - -Menu.prototype.askList = function (name, message, choices, defaultValue, validate, filter) { - this.addQuesitonType(name, message, choices, defaultValue, validate, filter, QuestionType.LIST); -}; - -Menu.prototype.addQuesitonType = function(name, message, choices, defaultValue, validate, filter, type) { - var question = {}; - question.name = name; - question.choices = choices; - question.message = message; - question.default = defaultValue; - question.type = type; - question.filter = filter; - question.validate = validate; - - this.questions.push(question); -}; - -Menu.prototype.run = function () { - var deferred = Q.defer(); - - asks.prompt(this.questions, function (result) { - deferred.resolve(result); - }); - - return deferred.promise; -}; - -module.exports = Menu; \ No newline at end of file diff --git a/lib/cli/generatorMenu.js b/lib/cli/generatorMenu.js deleted file mode 100644 index 36bb6af..0000000 --- a/lib/cli/generatorMenu.js +++ /dev/null @@ -1,144 +0,0 @@ -'use strict'; - -var inquirer = require('inquirer'), - fs = require('fs'), - gulp = require('gulp'), - gulpUtil = require('gulp-util'); - -var generator = require('../generator/generator'); -var generatorUtil = generator.util; - -function prompt() { - var choices = [new inquirer.Separator()] - .concat(generatorUtil.listProjects()) - .concat('cancel'); - var menuPrompt = { - type : 'list', - name : 'choice', - message: 'Choose a project to generate', - choices: choices, - filter : function (value) { - return value.toLowerCase().replace(' ', '_'); - } - }; - function handleMenu(answer) { - if (answer.choice !== 'cancel') { - createGenerator(answer.choice); - } - } - inquirer.prompt(menuPrompt, handleMenu); -} - -function promptProjectName(project) { - var menuPrompt = { - type : 'input', - name : 'name', - default: project.projectName, - message: 'What is the name of your new project?' - }; - function handleMenu(answer) { - project.setProjectName(answer.name); - promptProjectDestination(project); - } - inquirer.prompt(menuPrompt, handleMenu); -} - -function promptProjectDestination(project) { - var message, choices; - - if (generatorUtil.validateExistingProject(process.cwd())) { - choices = ['Enter a Location', 'continue', 'cancel']; - message = [ - 'Warning your current working directory already has a project.', - 'You must enter a new location to generate a project.' - ].join('\n'); - - } else if (fs.exists(project.destination)) { - choices = ['Enter a Location', 'replace', 'cancel']; - message = 'There is already a folder at the destination'; - - } else { - choices = ['y', 'Enter a Location', 'cancel']; - message = [ - 'Do you want to create a project in the directory?', - gulpUtil.colors.red(project.destination) - ].join('\n'); - } - var menuPrompt = { - type : 'list', - name : 'choice', - message: message, - choices: choices, - filter : function (value) { - return value.toLowerCase(); - } - }; - function handleMenu(answer) { - switch(answer.choice) { - case 'y': - case 'continue': - gulp.start(project.projectType); - break; - case 'enter a location': - promptProjectLocation(project); - break; - case 'cancel': - break; - default: - throw new Error('Unrecognised choice: ' + answer.choice) - } - } - inquirer.prompt(menuPrompt, handleMenu); -} - -function createGenerator(type) { - var project = generator.createProject(type); - generator.currentProject = project; - promptProjectName(project); -} - -function promptProjectLocation(project) { - var menuPrompt = { - type : 'input', - name : 'choice', - message: 'Enter a local absolute path you wish to create this project.', - filter : function (value) { - return value; - } - }; - function handleMenu(answer) { - project.destination = answer.choice; - if (fs.existsSync(answer.choice)) { - gulp.start(project.projectType); - } else { - promptConfirmNewDestination(project); - } - } - inquirer.prompt(menuPrompt, handleMenu); -} - -function promptConfirmNewDestination(project) { - var menuPrompt = { - type : 'list', - name : 'choice', - message: [ - 'The location', - project.destination , - 'does not exist, are you sure you want it created?' - ].join('\n'), - choices: ['y', 'cancel'], - filter : function (value) { - return value.toLowerCase(); - } - }; - function handleMenu(answer) { - if (answer.choice === 'y') { - gulp.start(project.projectType); - } - } - inquirer.prompt(menuPrompt, handleMenu); -} - -module.exports = { - prompt: prompt -}; \ No newline at end of file diff --git a/lib/cli/initialiseMenu.js b/lib/cli/initialiseMenu.js deleted file mode 100755 index 0e06461..0000000 --- a/lib/cli/initialiseMenu.js +++ /dev/null @@ -1,63 +0,0 @@ -'use strict'; - -var fs = require('fs'), - path = require('path'); - -var generatorUtil = require('../generator/generator').util, - Menu = require('./MenuPrompt'), - generatorMenu = require('./generatorMenu'), - configDefaults = require('../config/defaults'), - compileTargets = configDefaults.compileTargets, - projectConfig = configDefaults.projectConfig; - -var initDirectory; - -function prompt() { - initialise(process.cwd()) -} - -function initialise(directory) { - initDirectory = directory; - - if (generatorUtil.validateExistingProject(directory)) { - console.error('It appears you already have an angularity project in this directory', directory); - - } else if (!generatorUtil.validateProjectDirectories(directory)) { - console.log('There is no project in your current working directory, here are the projects you can generate.'); - generatorMenu.prompt(); - - } else if (!generatorUtil.validateConfigExists(directory)) { - console.log('It appears that you are missing an angularity.json, lets generate one.', directory); - initialiseMenu.promptConfig(initialiseConfig); - } -} - -function promptConfig(callback) { - var PORT = Math.floor(Math.random() * 9000) + 1000; - var ITEMS = [ - ['name', 'What is the name of your project?', projectConfig.name], - ['version', 'Do you want to specify a different version than..?', projectConfig.version], - ['author', 'Who is the author of this project?', 'Bob'], - ['description', 'Do you want to specify a short description of this project?'], - ['javascriptVersion', 'What version of JavaScript do you want to use?',[compileTargets.ES6, compileTargets.ES5]], - ['serverHttpPort', 'What http port do you want for the local development server?', PORT] - ]; - - var menu = new Menu(); - ITEMS.forEach(function(item) { - menu.askText.apply(menu, item); // @impaler - if this is the only use of Menu should we not inline this call? - }); - menu.run() - .then(callback); -} - -function initialiseConfig(config) { - generatorUtil.createAngularityProjectConfig(initDirectory, config); -} - -module.exports = { - prompt: prompt, - initialise: initialise, - promptConfig: promptConfig, - initialiseConfig: initialiseConfig -}; \ No newline at end of file diff --git a/lib/cli/installMenu.js b/lib/cli/installMenu.js deleted file mode 100755 index 8862dc0..0000000 --- a/lib/cli/installMenu.js +++ /dev/null @@ -1,103 +0,0 @@ -//'use strict'; -// -//var inquirer = require('inquirer'), -// path = require('path'), -// fs = require('fs'); -// -//var ideTemplate = require('ide-template'), -// webStorm = require('../../templates/angularity/webStorm'); -// -//require('shelljs/global'); -// -//function prompt() { -// var menuPrompt = { -// type : 'list', -// name : 'choice', -// choices: ['External Tools', 'File Templates'], -// message: 'Choose which WebStorm settings to install.', -// filter : function (value) { -// return value.toLowerCase(); -// } -// }; -// function handleMenu(answer) { -// switch (answer.choice) { -// case 'external tools': -// promptExternalTools(); -// break; -// case 'file templates': -// promptFileTemplates(); -// break; -// default: -// throw new Error('Unrecognised choice: ' + answer.choice) -// } -// } -// inquirer.prompt(menuPrompt, handleMenu); -//} -// -//function promptFileTemplates() { -// var menuPrompt = { -// type : 'list', -// name : 'choice', -// choices: ['es5', 'es6'], -// message: 'What Javascript version of the File Templates do you want to install?', -// filter : function (value) { -// return value.toLowerCase(); -// } -// }; -// -// function handleMenu(answer) { -// var templateFolder = webStorm.copyFileTemplates(answer.choice); -// console.log([ -// '', -// 'Copied file templates to ' + templateFolder, -// 'In WebStorm you will have angularity templates in menu File->New.' -// ].join('\n')); -// } -// inquirer.prompt(menuPrompt, handleMenu); -//} -// -//function promptExternalTools() { -// var externalToolPath = path.join(ideTemplate.webStorm.userPreferences(), 'tools', 'Angularity.xml'); -// var hasExisting = fs.existsSync(externalToolPath); -// var message = hasExisting ? -// 'You already have an External Tool setup for Angularity.' : -// 'Setup will install External tools for running Angularity in WebStorm.'; -// var choices = hasExisting ? ['overwrite','cancel'] : ['continue', 'cancel']; -// var menuPrompt = { -// type : 'list', -// name : 'choice', -// choices: choices, -// message: message, -// filter : function (value) { -// return value.toLowerCase(); -// } -// }; -// -// function handleMenu(answer) { -// console.log('If you have WebStorm open, please restart it.'); -// switch(answer.choice) { -// case 'continue': -// webStorm.generateAngularityWebStormTools(); -// break; -// case 'overwrite': -// console.log('overriding exiting Angularity.xml'); -// rm(externalToolPath); -// webStorm.generateAngularityWebStormTools(); -// console.log([ -// '', -// 'Wrote WebStorm to ' + externalToolPath + '.', -// 'In Webstorm you can launch Angularity builds in menu Tools->Angularity.' -// ].join('\n')); -// break; -// case 'cancel': -// break; -// default: -// throw new Error('Unrecognised choice: ' + answer.choice) -// } -// } -// inquirer.prompt(menuPrompt, handleMenu); -//} -// -//module.exports = { -// prompt: prompt -//}; \ No newline at end of file diff --git a/lib/cli/mainMenu.js b/lib/cli/mainMenu.js deleted file mode 100644 index 6e3d576..0000000 --- a/lib/cli/mainMenu.js +++ /dev/null @@ -1,86 +0,0 @@ -/** - * The main prompts for Angularity's command line interface. - */ -'use strict'; - -var inquirer = require('inquirer'), - gulp = require('gulp'), - gulpUtil = require('gulp-util'), - fs = require('fs'); - -var generatorUtil = require('../generator/generator').util, - initialiseMenu = require('./initialiseMenu'), - generatorMenu = require('./generatorMenu'), - installMenu = require('./installMenu'); - -require('shelljs/global'); - -function prompt() { - var GULP_TASKS = ['build', 'test', 'watch', 'release']; - var hasExisting = generatorUtil.validateExistingProject(process.cwd()); - - // banner - var version = require('../../package.json').version; - var art = '\n' + - ' █████╗ ███╗ ██╗ ██████╗ ██╗ ██╗██╗ █████╗ ██████╗ ██╗████████╗██╗ ██╗\n' + - '██╔══██╗████╗ ██║██╔════╝ ██║ ██║██║ ██╔══██╗██╔══██╗██║╚══██╔══╝╚██╗ ██╔╝\n' + - '███████║██╔██╗ ██║██║ ███╗██║ ██║██║ ███████║██████╔╝██║ ██║ ╚████╔╝\n' + - '██╔══██║██║╚██╗██║██║ ██║██║ ██║██║ ██╔══██║██╔══██╗██║ ██║ ╚██╔╝\n' + - '██║ ██║██║ ╚████║╚██████╔╝╚██████╔╝███████╗██║ ██║██║ ██║██║ ██║ ██║\n' + - '╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝\n' + - 'Version ' + version + ', visit angularity.github.io for documentation and resources\n'; - console.log(art); - - // menu - var choices = (hasExisting ? [new inquirer.Separator('Build Options')].concat(GULP_TASKS) : [ ]) - .concat([ - new inquirer.Separator(), - 'Generate Project', - new inquirer.Separator(), - 'Install WebStorm Tools' - ]); - var message = (hasExisting ? [ - 'Angularity Project', - ' ' + config.projectConfig.name, - ' v.' + config.projectConfig.version, - '' - ] : [ - 'Welcome to Angularity', - gulpUtil.colors.red(' No project was found in your current working directory.'), - '' - ]).join('\n'); - var menuPrompt = { - type : 'list', - name : 'choice', - message: message, - choices: choices, - filter : function (value) { - return value.toLowerCase(); - } - }; - function handleMenu(answer) { - var isTask = (GULP_TASKS.indexOf(answer.choice) >= 0); - if (isTask) { - gulp.start(answer.choice); - } else { - switch (answer.choice) { - case 'generate project': - generatorMenu.prompt(); - break; - case 'install webstorm tools': - installMenu.prompt(); - break; - case 'initialise angularity': - initialiseMenu.prompt(); - break; - default: - throw new Error('Unrecognised task: ' + answer.choice) - } - } - } - inquirer.prompt(menuPrompt, handleMenu); -} - -module.exports = { - prompt: prompt -}; \ No newline at end of file From 79847c6e3a37f347ee641f53da2903c76ff7b5e5 Mon Sep 17 00:00:00 2001 From: Brendan Graetz Date: Thu, 19 Mar 2015 16:42:02 +1100 Subject: [PATCH 29/39] =BG= fixing/ ignoring misc jshint violations --- lib/test/karma.js | 5 +- lib/util/yargs.js | 173 ---------------------------------------------- 2 files changed, 4 insertions(+), 174 deletions(-) delete mode 100644 lib/util/yargs.js diff --git a/lib/test/karma.js b/lib/test/karma.js index 9decb84..69e1d5c 100644 --- a/lib/test/karma.js +++ b/lib/test/karma.js @@ -144,12 +144,15 @@ function karmaCreateConfig(reporters, configFileName) { } var filePath = path.resolve(configFileName); if (fs.existsSync(filePath)) { + // Can safely ignore JsHint warnign here because through2 sets the value of + // `this` to the file stream + var stream = this; // jshint ignore:line var contents = fs.readFileSync(filePath).toString() .replace(basePathRegex, encode(process.cwd())) .replace(filesAppendRegex, encode(files.concat(additional))) .replace(reportersAppendRegex, encode(reporters.map(getKarmaReporterName))) .replace(pluginsAppendRegex, '[\n' + reporters.map(requirePlugins).join(',\n') + '\n]'); - this.push(new gutil.File({ + stream.push(new gutil.File({ path : filePath, contents: new Buffer(contents) })); diff --git a/lib/util/yargs.js b/lib/util/yargs.js deleted file mode 100644 index 61b8f5c..0000000 --- a/lib/util/yargs.js +++ /dev/null @@ -1,173 +0,0 @@ -'use strict'; - -var yargs = require('yargs'); - - -var instances = { }; - -/** - * Retrieve a sub-command (task) that may be independently described - * @param {string} taskName The name of the sub-command or null for the overall command - * @returns {yargs} The same yargs instance for each unique taskName - */ -function getInstance(taskName) { - var lowercase = (typeof taskName === 'string') ? taskName.toLowerCase() : ''; // allow zero length - instances[lowercase] = instances[lowercase] || yargs(process.argv.slice(2)); - instances[lowercase].argv; // must access argv to avoid runtime error later - return instances[lowercase]; -} - -/** - * Retrieve the argv for the yargs instance that is implied by the given sub-command. - * Non-zero length of argv._ indicates superfluous arguments. - * @returns {object} A yargs.argv object - */ -function resolveArgv() { - var instance = instances['']; - var argv = instance ? instance.argv : {}; - var taskName = argv._ && argv._[0] && argv._[0].toLowerCase(); - if (taskName && (taskName in instances)) { - instance = instances[taskName]; - argv = instance.argv; - argv.taskName = argv._.shift(); - } - return argv; -} - -/** - * Retrieve a sorted list of sub-command (tas) names - * @returns {Array} A list of tasks sorted alphabetically - */ -function listTasks() { - return Object - .getOwnPropertyNames(instances) - .filter(Boolean) - .sort(); -} - -/** - * Check that any additional arguments are only the sub command - * @param {Object} argv parsed argv hash - * @param {Array} options options and their aliases - * @throws Error where task is improperly specified - */ -function subCommandCheck(argv) { - var bareArguments = argv._; - if (bareArguments) { - if (bareArguments.length > 1) { - throw new Error('Too many tasks specified: '+ bareArguments.slice(1)); - } else if ((bareArguments.length === 1) && listTasks().indexOf(bareArguments[0]) < 0) { - throw new Error('Unknown task: ' + bareArguments[0]); - } - } -} - -/** -* A strict checking function that allows long options to be specified with a single dash -* @param {Object} argv parsed argv hash -* @param {Array} options options and their aliases -* @throws Error where there are superfluous arguments -*/ -function singleDashCheck(argv, options) { - - // get all argv fields - var pending = Object.keys(argv) - .filter(function removeSpecialKeys(key) { - return (['_', '$0'].indexOf(key) < 0); - }); - - // convenience to remove an element from the pending list - function removeElement(element) { - var index = pending.indexOf(element); - if (index >= 0) { - pending.splice(index, 1); - } - } - - // for each key - for (var key in options) { - - // remove this key - removeElement(key); - - // for each alias, remove the characters between their matching substring - // i.e. -version|-v => remove: e, r, s, i, o, n - (options[key] || []).forEach(function eachAlias(alias) { - var comparable = alias.slice(0, key.length); - if (comparable === key) { - alias.slice(key.length).split('').forEach(removeElement); - } - }); - } - - // error message - if (pending.length) { - throw new Error('Superfluous arguments: ' + pending.join(', ')); - } -} - -/** - * Given an object of field:fn will apply each fn to the value of the same fields. - * Where the given methods return a string, that will be used to raise an error. - */ -function createCheck() { - var NONE = 0, - GATE_METHOD = 1, - TEST_METHOD = 2, - TEST_OBJECT = 3; - - // instance methods - var elements = [ ]; - var self = { - withGate: function(element) { - elements.push(element, GATE_METHOD); - return self; - }, - withTest: function(element) { - var type = (typeof element === 'function') ? TEST_METHOD : (typeof element === 'object') ? TEST_OBJECT : NONE; - elements.push(element, type); - return self; - }, - commit: function() { - return getCheck(elements); // lock in the current instance state - } - }; - - // the implementation of the yargs check method - function getCheck(elements) { - function throwString(value) { - if (typeof value === 'string') { - throw new Error(value); - } - } - return function check(argv) { - for (var i = 0; i < elements.length; i += 2) { - var element = elements[i]; - var type = elements[i + 1]; - if (type === GATE_METHOD) { - if (!element(argv)) break; - } else if (type === TEST_METHOD) { - throwString(element(argv)); - } else if (type === TEST_OBJECT) { - for (var key in element) { - if (key in argv) { - throwString(element[key](argv[key])); - } - } - } - } - }; - } - - // complete - return self; -} - -module.exports = { - getInstance : getInstance, - resolveArgv : resolveArgv, - listTasks : listTasks, - subCommandCheck: subCommandCheck, - singleDashCheck: singleDashCheck, - createCheck : createCheck -}; From 177bbb73974a46b8ed2cc386b614fd3ac1b9368a Mon Sep 17 00:00:00 2001 From: Brendan Graetz Date: Thu, 19 Mar 2015 17:04:40 +1100 Subject: [PATCH 30/39] =BG= clean up extraneous yargs instance usages in individual tasks - also added a new npm run task for `testonly` that doesn't run lint, and isn't verbose --- package.json | 1 + tasks/build.js | 6 +----- tasks/css.js | 6 +----- tasks/html.js | 6 +----- tasks/init.js | 6 +++--- tasks/javascript.js | 6 +++--- tasks/watch.js | 8 -------- 7 files changed, 10 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index f904efb..64f9b8b 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ ], "scripts": { "test": "npm run lint && node node_modules/jasmine-node/bin/jasmine-node --verbose --captureExceptions test/specs", + "testonly": "node node_modules/jasmine-node/bin/jasmine-node --captureExceptions test/specs", "lint": "gulp lint --gulpfile ./test/jshint.js" }, "contributors": [ diff --git a/tasks/build.js b/tasks/build.js index 4e35be3..cb13d2c 100644 --- a/tasks/build.js +++ b/tasks/build.js @@ -7,16 +7,12 @@ function setUpTaskBuild(tyRun) { prerequisiteTasks: ['help', 'javascript', 'css', 'html'], checks: [], options: [], - onInit: function onBuildTask(yargsInstance) { + onInit: function onBuildTask() { var gulp = require('gulp'), runSequence = require('run-sequence'); var hr = require('../lib/util/hr'); - yargsInstance - .strict() - .wrap(80); - gulp.task('build', function (done) { console.log(hr('-', 80, 'build')); runSequence('javascript', 'css', 'html', done); diff --git a/tasks/css.js b/tasks/css.js index f0ce11e..37679c3 100644 --- a/tasks/css.js +++ b/tasks/css.js @@ -7,7 +7,7 @@ function setUpTaskCss(tyRun) { prerequisiteTasks: ['help'], checks: [], options: [], - onInit: function onInitCssTask(yargsInstance) { + onInit: function onInitCssTask() { var gulp = require('gulp'), rimraf = require('gulp-rimraf'), runSequence = require('run-sequence'); @@ -16,10 +16,6 @@ function setUpTaskCss(tyRun) { hr = require('../lib/util/hr'), streams = require('../lib/config/streams'); - yargsInstance - .strict() - .wrap(80); - gulp.task('css', function (done) { console.log(hr('-', 80, 'css')); runSequence( diff --git a/tasks/html.js b/tasks/html.js index 404df39..f6b40c5 100644 --- a/tasks/html.js +++ b/tasks/html.js @@ -8,7 +8,7 @@ function setUpTaskHtml(tyRun) { prerequisiteTasks: ['help'], checks: [], options: [], - onInit: function onInitHtmlTask(yargsInstance) { + onInit: function onInitHtmlTask() { var gulp = require('gulp'), inject = require('gulp-inject'), plumber = require('gulp-plumber'), @@ -20,10 +20,6 @@ function setUpTaskHtml(tyRun) { hr = require('../lib/util/hr'), streams = require('../lib/config/streams'); - yargsInstance - .strict() - .wrap(80); - // `cliArgs` are available within gulp tasks by means of closure, // as they are only called after `onRun` has been invoked, and they have been passed gulp.task('html', function (done) { diff --git a/tasks/init.js b/tasks/init.js index 9fd7c1d..76cd867 100644 --- a/tasks/init.js +++ b/tasks/init.js @@ -220,10 +220,10 @@ function setUpInitTask(tyRun) { var cliArgs; var templateParams; - yargsInstance + cliArgs = yargsInstance .strict() - .wrap(80); - cliArgs = yargsInstance.argv; + .wrap(80) + .argv; gulp.task('init', function (done) { console.log(hr('-', 80, 'init')); diff --git a/tasks/javascript.js b/tasks/javascript.js index 1b74efe..3adcdde 100644 --- a/tasks/javascript.js +++ b/tasks/javascript.js @@ -116,9 +116,9 @@ function setUpTaskJavascript(tyRun) { var cliArgs; cliArgs = yargsInstance - .strict() - .wrap(80) - .argv; + .strict() + .wrap(80) + .argv; gulp.task('javascript', function (done) { console.log(hr('-', 80, 'javascript')); diff --git a/tasks/watch.js b/tasks/watch.js index fe25291..ff459da 100644 --- a/tasks/watch.js +++ b/tasks/watch.js @@ -1,14 +1,6 @@ 'use strict'; function setUpTaskWatch(tyRun) { - var defaults = require('../lib/config/defaults'); - - defaults.getInstance() - .file('angularity.json') - .defaults({ - port: 55555 - }); - var taskDefinition = { name: 'watch', description: ('The "watch" task performs an initial build and then serves the application on localhost at ' + From 63c451d2f24a4c22893b827345c46e6280bec568 Mon Sep 17 00:00:00 2001 From: Brendan Graetz Date: Thu, 19 Mar 2015 17:28:21 +1100 Subject: [PATCH 31/39] =BG= experimental commit to test if local jasmine installation works for jasmine --- .travis.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 60c1be4..e10484e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,11 +10,9 @@ matrix: fast_finish: true before_install: - npm install -g npm@2.1.7 - - npm i -g - - npm i -g jasmine-node - node -v - npm -v - - jasmine-node --version script: - pwd && ls - - jasmine-node --verbose --test-dir /home/travis/build/angularity/node-angularity/test \ No newline at end of file + - node node_modules/jasmine-node/bin/jasmine-node --version + - node node_modules/jasmine-node/bin/jasmine-node --captureExceptions --test-dir /home/travis/build/angularity/node-angularity/test From 2802f26e679ae0294e8b0787e48003074c08eaea Mon Sep 17 00:00:00 2001 From: Brendan Graetz Date: Thu, 19 Mar 2015 17:33:27 +1100 Subject: [PATCH 32/39] =BG= update test directory fro jasmine-node --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e10484e..f7c2f1d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,4 +15,4 @@ before_install: script: - pwd && ls - node node_modules/jasmine-node/bin/jasmine-node --version - - node node_modules/jasmine-node/bin/jasmine-node --captureExceptions --test-dir /home/travis/build/angularity/node-angularity/test + - node node_modules/jasmine-node/bin/jasmine-node --captureExceptions test/specs From fe25d1e76625c50f810e718673b484c9b2563ea8 Mon Sep 17 00:00:00 2001 From: Brendan Graetz Date: Thu, 19 Mar 2015 17:36:53 +1100 Subject: [PATCH 33/39] =BG= try npm run test instead --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f7c2f1d..019a30a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,4 +15,4 @@ before_install: script: - pwd && ls - node node_modules/jasmine-node/bin/jasmine-node --version - - node node_modules/jasmine-node/bin/jasmine-node --captureExceptions test/specs + - npm run test From e38025e0f46a5025a8b420ad44a8a75759123354 Mon Sep 17 00:00:00 2001 From: Brendan Graetz Date: Thu, 19 Mar 2015 17:45:16 +1100 Subject: [PATCH 34/39] =BG= reinstate global install --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 019a30a..fd84b08 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ matrix: fast_finish: true before_install: - npm install -g npm@2.1.7 + - npm install -g - node -v - npm -v script: From 5485ce9eb636fc93eae13187155a3a74146bf43e Mon Sep 17 00:00:00 2001 From: benholloway Date: Thu, 19 Mar 2015 18:06:46 +1100 Subject: [PATCH 35/39] removed dependency on global gulp --- package.json | 2 +- test/helpers/helper.js | 165 ---------------------------------------- test/jshint.js | 26 +++---- test/rebuildExpected.js | 18 ----- 4 files changed, 14 insertions(+), 197 deletions(-) delete mode 100755 test/helpers/helper.js delete mode 100644 test/rebuildExpected.js diff --git a/package.json b/package.json index 64f9b8b..6bf28de 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "scripts": { "test": "npm run lint && node node_modules/jasmine-node/bin/jasmine-node --verbose --captureExceptions test/specs", "testonly": "node node_modules/jasmine-node/bin/jasmine-node --captureExceptions test/specs", - "lint": "gulp lint --gulpfile ./test/jshint.js" + "lint": "node ./test/jshint.js" }, "contributors": [ "bholloway", diff --git a/test/helpers/helper.js b/test/helpers/helper.js deleted file mode 100755 index 84dbc0e..0000000 --- a/test/helpers/helper.js +++ /dev/null @@ -1,165 +0,0 @@ -'use strict'; -var Q = require('q'), - path = require('path'), - fs = require('fs'), - rimraf = require('rimraf'), - cp = require('shelljs').cp, - childProcess = require('child_process'); - -/** - * Shortcut to a temporary absolute path to perform integration tests. - * @type {*|String} - */ -var testPath = path.resolve(__dirname, '..', 'test-temp'); - -/** - * Shortcut to resolve the absolute path to the expected files for integration tests. - * @param folderName - * @returns {*} - */ -function expectedFolder(folderName) { - var folderPath = path.resolve(__dirname, '..', 'expected', folderName); - - if (!fs.existsSync(folderPath)) { - console.error('helper.folderPath() the folderName', folderName, 'is not located in', folderPath); - } - - return folderPath; -} - -/** - * Shortcut to create a temporary test path based on name. - * @param folderName - * @returns {*|string} - */ -function resolveTestTempPath(folderName) { - var testTempPath = path.join(testPath, String(folderName)); - - if (!fs.existsSync(testPath)) { - fs.mkdirSync(testPath); - } - - if (!fs.existsSync(testTempPath)) { - fs.mkdirSync(testTempPath); - } - - return testTempPath; -} - -/** - * Shortcut to delete all the content of the testPath folder. - */ -function cleanTestTemp(done) { - rimraf(testPath, function () { - done(); - }); -} - -/** - * Shortcut to run multiple global angularity commands, - * given multiple argument arrays, multiple processes will run in parallel. - * The resolve value of the promise is an array of the process result objects. - * @example helper.runAngularityAlias(['-h', '--help']) - * @param aliases - * @param config - * @returns {promise} - */ -function runAngularityAlias(aliases, config) { - var deferred = Q.defer(); - - var aliased = []; - aliases.forEach(function (args) { - aliased.push(runAngularity(args, config)); - }); - - Q.all(aliased) - .then(function (results) { - deferred.resolve(results); - }); - - return deferred.promise; -} - -/** - * Shortcut to run the global angularity command. - * The promise will resolve with an object containing the - * process exit code, stdout, stderr. - * @example helper.runAngularity('build') - * @param args - * @param config - * @returns {promise} - */ -function runAngularity(args, config) { - var deferred = Q.defer(); - - runAngularityProcess(args, config, processCallback); - - function processCallback(error, stdout, stderr) { - var code; - if (error === null) { - code = 0; - } else { - code = error.code; - } - - var result = { - args : args, - code : code, - stdout: stdout, - stderr: stderr - }; - - deferred.resolve(result); - } - - return deferred.promise; -} - -/** - * Shortcut to run the global angularity command. - * Specify an array of strings or a singular string - * for the arguments of the process. - * @param args - * @param config - * @returns {*} - */ -function runAngularityProcess(args, config, callback) { - config = config || {}; - args = args || []; - if (typeof args === 'string') { - args = [args]; - } - - var command = 'angularity ' + args.join(' '); - - childProcess.exec(command, config, callback); -} - -/** - * Shortcut to copy the expected project recursively and remove a specific folder recursivley - * Workarounds with rimraf async were necessary for windows. - * //TODO Ideally we want to reduce these dependencies while still being cross platform. - * - * @param done callback for when the rimraf is completed - * @param sourceFolder the expected target folder to copy - * @param targetFolder the target folder to remove - * @param destinationPath the destination path for the project to be copied to - */ -function prepareExpectedDir(done, souceFolder, targetFolder, destinationPath) { - rimraf(path.join(souceFolder, targetFolder), function () { - cp('-Rf', destinationPath + '/*', souceFolder); - rimraf(path.join(souceFolder, targetFolder), function () { - done(); - }); - }); -} - -module.exports = { - testPath : testPath, - cleanTestTemp : cleanTestTemp, - prepareExpectedDir : prepareExpectedDir, - expectedFolder : expectedFolder, - resolveTestTempPath: resolveTestTempPath, - runAngularity : runAngularity, - runAngularityAlias : runAngularityAlias -}; \ No newline at end of file diff --git a/test/jshint.js b/test/jshint.js index ef05c68..dd4fe56 100644 --- a/test/jshint.js +++ b/test/jshint.js @@ -1,18 +1,18 @@ +#!/usr/bin/env node 'use strict'; -var jshint = require('gulp-jshint'); -var gulp = require('gulp'); -var path = require('path'); -var cwd = path.resolve(process.cwd(), '..'); -var config = path.resolve(cwd, '.jshintrc'); -var stylish = require('jshint-stylish'); + +var jshint = require('gulp-jshint'), + gulp = require('gulp'), + path = require('path'), + stylish = require('jshint-stylish'); gulp.task('lint', function() { - return gulp.src([ - 'lib/**/*.js', - 'tasks/**/*.js', - 'bin/**/*.js', - 'test/specs/**/*.js' - ], {cwd:cwd}) + var cwd = path.resolve(__dirname, '..'), + config = path.resolve(cwd, '.jshintrc'), + glob = ['lib/**/*.js', 'tasks/**/*.js', 'bin/**/*.js', 'test/specs/**/*.js']; + return gulp.src(glob, {cwd: cwd}) .pipe(jshint(config)) .pipe(jshint.reporter(stylish)); -}); \ No newline at end of file +}); + +gulp.start('lint'); diff --git a/test/rebuildExpected.js b/test/rebuildExpected.js deleted file mode 100644 index 7f6d187..0000000 --- a/test/rebuildExpected.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Shortcut utiltiy to build the expected project files for the integration tests. - * @type {exports} - */ - -var helper = require('./helpers/helper'); -var minimalEs5 = helper.expectedFolder('minimal-es5'); -rebuildExpectedProject(minimalEs5); - -function rebuildExpectedProject(location) { - 'use strict'; - process.chdir(location); - - helper.runAngularityAlias(['build', 'test', 'release']) - .then(function(){ - console.log('expected project in ' + location + ' is rebuilt.'); - }); -} \ No newline at end of file From ddaac53b502af86360592f3192c0cee14b130445 Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Fri, 20 Mar 2015 08:48:59 +1100 Subject: [PATCH 36/39] fail the build on lint error. --- test/jshint.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/jshint.js b/test/jshint.js index dd4fe56..a2f1809 100644 --- a/test/jshint.js +++ b/test/jshint.js @@ -12,7 +12,8 @@ gulp.task('lint', function() { glob = ['lib/**/*.js', 'tasks/**/*.js', 'bin/**/*.js', 'test/specs/**/*.js']; return gulp.src(glob, {cwd: cwd}) .pipe(jshint(config)) - .pipe(jshint.reporter(stylish)); + .pipe(jshint.reporter(stylish)) + .pipe(jshint.reporter('fail')); }); gulp.start('lint'); From 5f6e1940752086585995095598974a70328c8263 Mon Sep 17 00:00:00 2001 From: benholloway Date: Fri, 20 Mar 2015 09:04:44 +1100 Subject: [PATCH 37/39] fixed jshint warnings, most were valid only a couple are spurious --- lib/build/browserify.js | 91 ++++++++++++++++++++---------------- lib/build/node-sass.js | 58 +++++++++++++---------- lib/config/defaults.js | 16 +++++-- lib/inject/adjacent-files.js | 11 +++-- lib/inject/bower-files.js | 6 ++- test/jshint.js | 2 +- 6 files changed, 108 insertions(+), 76 deletions(-) diff --git a/lib/build/browserify.js b/lib/build/browserify.js index 7192f27..6bc7b83 100644 --- a/lib/build/browserify.js +++ b/lib/build/browserify.js @@ -112,11 +112,11 @@ function compile(bannerWidth, transforms) { * @return {string} The transformed file path */ function rootRelative(filePath, i, array) { - var rootRelative = slash(path.relative(process.cwd(), path.resolve(filePath))); // resolve relative references - var isProject = (rootRelative.slice(0, 2) !== '..'); - var result = [ + var rootRelPath = slash(path.relative(process.cwd(), path.resolve(filePath))); // resolve relative references + var isProject = (rootRelPath.slice(0, 2) !== '..'); + var result = [ sourceMapBase || '', - isProject ? rootRelative : path.basename(rootRelative) + isProject ? rootRelPath : path.basename(rootRelPath) ].join(path.sep); if ((typeof i === 'number') && (typeof array === 'object')) { array[i] = result; @@ -179,43 +179,52 @@ function compile(bannerWidth, transforms) { var timeout; function errorHandler(error) { var text = error.toString(); - var analysis; - var message; - - // SyntaxError: ::: - if (analysis = /^\s*SyntaxError\:\s*([^:]*)\s*\:\s*([^(]*)\s*\((\d+:\d+)\)\s*\n/.exec(text)) { - message = [analysis[1], analysis[3], analysis[2]].join(':') + '\n'; - - // Error: SyntaxError: while parsing json file - } else if (analysis = /^\s*Error: SyntaxError\:\s*(.*)\s*while parsing json file\s*([^]*)/.exec(text)) { - message = [analysis[2], '0', '0', ' ' + analysis[1]].join(':') + '\n'; - - // Line : : - } else if (analysis = /Line\s*(\d+)\s*\:\s*([^:]*)\s*:\s*(.*)\s*/.exec(text)) { - message = [analysis[3], analysis[1], 0, ' ' + analysis[2]].join(':') + '\n'; - - // Error: Cannot find module '' from '' - // find the first text match for any text quoted in - } else if (analysis = /^\s*Error\: Cannot find module '(.*)\'\s*from\s*\'(.*)\'\s*$/.exec(text)) { - var filename = fs.readdirSync(analysis[2]) - .filter(RegExp.prototype.test.bind(/\.js$/i)) - .filter(function (jsFilename) { - var fullPath = path.join(analysis[2], jsFilename); - var fileText = fs.readFileSync(fullPath).toString(); - return (new RegExp('[\'"]' + analysis[1] + '[\'"]')).test(fileText); - }) - .shift(); - message = path.join(analysis[2], filename) + ':0:0: Cannot find import ' + analysis[1] + '\n'; - - // Unknown - } else { - message = 'TODO parse this error\n' + text + '\n'; - } - - // add unique - if (output.indexOf(message) < 0) { - output.push(message); - } + [ + // SyntaxError: ::: + function() { + var analysis = /^\s*SyntaxError\:\s*([^:]*)\s*\:\s*([^(]*)\s*\((\d+:\d+)\)\s*\n/.exec(text); + return analysis && ([analysis[1], analysis[3], analysis[2]].join(':') + '\n'); + }, + // Error: SyntaxError: while parsing json file + function() { + var analysis = /^\s*Error: SyntaxError\:\s*(.*)\s*while parsing json file\s*([^]*)/.exec(text); + return analysis && ([analysis[2], '0', '0', ' ' + analysis[1]].join(':') + '\n'); + }, + // Line : : + function() { + var analysis = /Line\s*(\d+)\s*\:\s*([^:]*)\s*:\s*(.*)\s*/.exec(text); + return analysis && ([analysis[3], analysis[1], 0, ' ' + analysis[2]].join(':') + '\n'); + }, + // Error: Cannot find module '' from '' + // find the first text match for any text quoted in + function() { + var analysis = /^\s*Error\: Cannot find module '(.*)\'\s*from\s*\'(.*)\'\s*$/.exec(text); + if (analysis) { + var filename = fs.readdirSync(analysis[2]) + .filter(RegExp.prototype.test.bind(/\.js$/i)) + .filter(function (jsFilename) { + var fullPath = path.join(analysis[2], jsFilename); + var fileText = fs.readFileSync(fullPath).toString(); + return (new RegExp('[\'"]' + analysis[1] + '[\'"]')).test(fileText); + }) + .shift(); + return path.join(analysis[2], filename) + ':0:0: Cannot find import ' + analysis[1] + '\n'; + } + }, + // Unknown + function() { + return 'TODO parse this error\n' + text + '\n'; + } + ] + .map(function(method) { + return method(); + }) + .filter(Boolean) + .forEach(function addUnique(message) { + if (output.indexOf(message) < 0) { + output.push(message); + } + }); // complete overall only once there are no further errors clearTimeout(timeout); diff --git a/lib/build/node-sass.js b/lib/build/node-sass.js index 3e5d0e5..7b50310 100644 --- a/lib/build/node-sass.js +++ b/lib/build/node-sass.js @@ -28,7 +28,32 @@ function encodeRelativeURL(startPath, uri) { */ function notPackage(absolutePath) { return ['package.json', 'bower.json'].every(function fileNotFound(file) { - return !(fs.existsSync(path.resolve(absolutePath, file))); + return !(fs.existsSync(path.resolve(absolutePath, file))); + }); + } + + /** + * Enqueue subdirectories that are not packages and are not in the root path + * @param {Array} queue The queue to add to + * @param {string} basePath The path to consider + */ + function enqueue(queue, basePath) { + fs.readdirSync(basePath) + .filter(function notHidden(filename) { + return (filename.charAt(0) !== '.'); + }) + .map(function toAbsolute(filename) { + return path.join(basePath, filename); + }) + .filter(function directoriesOnly(absolutePath) { + return fs.statSync(absolutePath).isDirectory(); + }) + .filter(function notInRootPath(absolutePath) { + return (pathToRoot.indexOf(absolutePath) < 0); + }) + .filter(notPackage) + .forEach(function enqueue(absolutePath) { + queue.push(absolutePath); }); } @@ -37,12 +62,13 @@ function encodeRelativeURL(startPath, uri) { if (absoluteStart) { // find path to the root, stopping at cwd, package.json or bower.json - var pathToRoot = [ ]; - do { + var pathToRoot = []; + var isWorking = true; + while (isWorking) { pathToRoot.push(absoluteStart); - var isWorking = (absoluteStart !== process.cwd()) && notPackage(absoluteStart); + isWorking = (absoluteStart !== process.cwd()) && notPackage(absoluteStart); absoluteStart = path.resolve(absoluteStart, '..'); - } while (isWorking); + } // start a queue with the path to the root var queue = pathToRoot.concat(); @@ -57,30 +83,14 @@ function encodeRelativeURL(startPath, uri) { // file exists so convert to a dataURI and end if (fs.existsSync(fullPath)) { - var type = mime.lookup(fullPath); + var type = mime.lookup(fullPath); var contents = fs.readFileSync(fullPath); - var base64 = new Buffer(contents).toString('base64'); + var base64 = new Buffer(contents).toString('base64'); return 'url(data:' + type + ';base64,' + base64 + ')'; } // enqueue subdirectories that are not packages and are not in the root path else { - fs.readdirSync(basePath) - .filter(function notHidden(filename) { - return (filename.charAt(0) !== '.'); - }) - .map(function toAbsolute(filename) { - return path.join(basePath, filename); - }) - .filter(function directoriesOnly(absolutePath) { - return fs.statSync(absolutePath).isDirectory(); - }) - .filter(function notInRootPath(absolutePath) { - return (pathToRoot.indexOf(absolutePath) < 0); - }) - .filter(notPackage) - .forEach(function enqueue(absolutePath) { - queue.push(absolutePath); - }); + enqueue(queue, basePath); } } } diff --git a/lib/config/defaults.js b/lib/config/defaults.js index 2f1dbf7..6be7e98 100755 --- a/lib/config/defaults.js +++ b/lib/config/defaults.js @@ -12,7 +12,8 @@ var instances = { }; * @returns {{file: Function, defaults: Function, get: Function}} */ function getInstance(key) { - return instances[key] = instances[key] || new Defaults(key); + var result = instances[key] = instances[key] || new Defaults(key); + return result; } /** @@ -39,10 +40,11 @@ function Defaults(key) { * @return {Defaults} the current instance */ function file() { - var file = this.file_ = path.resolve(path.join.apply(path, arguments)); - if (file && fs.existsSync(file)) { + /* jshint validthis:true */ + var filePath = this.file_ = path.resolve(path.join.apply(path, arguments)); + if (filePath && fs.existsSync(filePath)) { var existing = this.values_; - this.values_ = readFile(file, this.key_) || {}; + this.values_ = readFile(filePath, this.key_) || {}; this.set(existing); } return this; @@ -54,6 +56,7 @@ function file() { * @return {Defaults} the current instance */ function defaults(parameters) { + /* jshint validthis:true */ this.defaults_ = (typeof parameters === 'object') ? parameters : {}; return this; } @@ -64,6 +67,7 @@ function defaults(parameters) { * @return {*} the resolved value of that field */ function get(field) { + /* jshint validthis:true */ if (field) { return (field in this.values_) ? this.values_[field] : this.defaults_[field]; } else { @@ -76,6 +80,7 @@ function get(field) { * @returns {Array.} List of changed fields, possible empty */ function changeList() { + /* jshint validthis:true */ return Object.keys(this.values_); } @@ -86,6 +91,7 @@ function changeList() { * @return {Defaults} the current instance */ function set(objectOrField, value) { + /* jshint validthis:true */ // enumerable object mode if (typeof objectOrField === 'object') { @@ -115,6 +121,7 @@ function set(objectOrField, value) { * Clear any overrides */ function revert() { + /* jshint validthis:true */ this.values_ = {}; return this; } @@ -124,6 +131,7 @@ function revert() { * @return {string} the full path to the file that was written */ function commit() { + /* jshint validthis:true */ var pending; if (this.key_) { pending = readFile(this.file_) || {}; diff --git a/lib/inject/adjacent-files.js b/lib/inject/adjacent-files.js index 53ad06c..070397c 100644 --- a/lib/inject/adjacent-files.js +++ b/lib/inject/adjacent-files.js @@ -34,16 +34,19 @@ module.exports = function (extension, opts, recurse) { // use terms in the relative address, from none to all var split = fileRelative.split(/[\\\/]/g); - for(var i = 0, glob = [ ]; i < split.length; i++) { - extensions.forEach(function(extension) { + for(var i = 0, glob = []; i < split.length; i++) { + extensions.forEach(addSliceToGlob(glob, 0, i + 1)); + } + function addSliceToGlob(glob, start, stop) { + return function (extension) { var item = [ fileRecurse ] - .concat(split.slice(0, i + 1)) + .concat(split.slice(start, stop)) .concat('*.' + extension) .join('/'); if (glob.indexOf(item) < 0) { glob.push(item); } - }); + }; } return gulp.src(glob, { read: false }) .pipe(semiflat(file.base)) diff --git a/lib/inject/bower-files.js b/lib/inject/bower-files.js index fdcdad5..6b3cee0 100644 --- a/lib/inject/bower-files.js +++ b/lib/inject/bower-files.js @@ -84,7 +84,7 @@ module.exports = function () { function greatestCommonBase(absolute) { if (base) { - for (var i = 0; (base[i] === absolute[i]); i++); + for (var i = 0; (base[i] === absolute[i]); i++) {} /* jshint -W035 */ base = base.slice(0, i); } else if (options.base === true) { base = path.dirname(absolute); @@ -126,7 +126,9 @@ module.exports = function () { // combination of source streams with specific base path for each package stream = combined.create(); - (prepend) && stream.append(prepend); + if (prepend) { + stream.append(prepend); + } value.forEach(function (bowerPackage) { var src = gulp.src(bowerPackage.concat(), bowerPackage.options) .pipe(through.obj(function(file, encoding, done) { diff --git a/test/jshint.js b/test/jshint.js index dd4fe56..c99b5ad 100644 --- a/test/jshint.js +++ b/test/jshint.js @@ -15,4 +15,4 @@ gulp.task('lint', function() { .pipe(jshint.reporter(stylish)); }); -gulp.start('lint'); +gulp.start('lint'); \ No newline at end of file From 6b5ff57009b844e7c80898aa2975679fb44452ab Mon Sep 17 00:00:00 2001 From: Chris Decoster Date: Fri, 20 Mar 2015 09:18:34 +1100 Subject: [PATCH 38/39] run the linting test after the integration tests. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6bf28de..56afa80 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "babel" ], "scripts": { - "test": "npm run lint && node node_modules/jasmine-node/bin/jasmine-node --verbose --captureExceptions test/specs", + "test": "node node_modules/jasmine-node/bin/jasmine-node --verbose --captureExceptions test/specs && npm run lint", "testonly": "node node_modules/jasmine-node/bin/jasmine-node --captureExceptions test/specs", "lint": "node ./test/jshint.js" }, From 50d8903294bbd6280fbce75ac294c55b6e5c1567 Mon Sep 17 00:00:00 2001 From: benholloway Date: Fri, 20 Mar 2015 11:13:06 +1100 Subject: [PATCH 39/39] improvements suggested by @bguiz --- lib/build/browserify.js | 62 +++++++++++++++++++++--------------- lib/build/node-sass.js | 10 +++--- lib/inject/adjacent-files.js | 33 +++++++++---------- lib/inject/bower-files.js | 5 ++- lib/test/karma.js | 5 ++- 5 files changed, 64 insertions(+), 51 deletions(-) diff --git a/lib/build/browserify.js b/lib/build/browserify.js index 6bc7b83..9e4eb74 100644 --- a/lib/build/browserify.js +++ b/lib/build/browserify.js @@ -1,8 +1,9 @@ 'use strict'; var fs = require('fs'), - path = require('path'), - through = require('through2'), + path = require('path'); + +var through = require('through2'), merge = require('lodash.merge'), trackFilenames = require('gulp-track-filenames'), transformTools = require('browserify-transform-tools'), @@ -49,7 +50,7 @@ function isMethodAST(node) { * @return A jasmine transform */ function jasmineTransform(symbol) { - return transformTools.makeFalafelTransform('jasmineTransform', null, function (node, options, done) { + return transformTools.makeFalafelTransform('jasmineTransform', null, function jasmineASTWalker(node, options, done) { var isValid = isLiteralAST(node, symbol) && isMethodAST(node.parent, 'describe', 'module'); if (isValid) { node.update('\'' + options.file.replace(/\\/g, '\\\\') + ':0:0\''); @@ -178,26 +179,33 @@ function compile(bannerWidth, transforms) { // error handler var timeout; function errorHandler(error) { - var text = error.toString(); - [ + + // run a bunch of tests against the error in order to determine the appropriate error message + // there will be at least one truthy value, even if that is the final placeholder + var text = error.toString(); + var message = [ + // SyntaxError: ::: - function() { + function testSyntaxError() { var analysis = /^\s*SyntaxError\:\s*([^:]*)\s*\:\s*([^(]*)\s*\((\d+:\d+)\)\s*\n/.exec(text); return analysis && ([analysis[1], analysis[3], analysis[2]].join(':') + '\n'); }, + // Error: SyntaxError: while parsing json file - function() { + function testSyntaxErrorJSON() { var analysis = /^\s*Error: SyntaxError\:\s*(.*)\s*while parsing json file\s*([^]*)/.exec(text); return analysis && ([analysis[2], '0', '0', ' ' + analysis[1]].join(':') + '\n'); }, + // Line : : - function() { + function testGeneric() { var analysis = /Line\s*(\d+)\s*\:\s*([^:]*)\s*:\s*(.*)\s*/.exec(text); return analysis && ([analysis[3], analysis[1], 0, ' ' + analysis[2]].join(':') + '\n'); }, + // Error: Cannot find module '' from '' // find the first text match for any text quoted in - function() { + function testBadImport() { var analysis = /^\s*Error\: Cannot find module '(.*)\'\s*from\s*\'(.*)\'\s*$/.exec(text); if (analysis) { var filename = fs.readdirSync(analysis[2]) @@ -211,20 +219,22 @@ function compile(bannerWidth, transforms) { return path.join(analysis[2], filename) + ':0:0: Cannot find import ' + analysis[1] + '\n'; } }, + // Unknown - function() { + function otherwise() { return 'TODO parse this error\n' + text + '\n'; } ] - .map(function(method) { - return method(); + .map(function invokeTestMethod(testMethod) { + return testMethod(); }) .filter(Boolean) - .forEach(function addUnique(message) { - if (output.indexOf(message) < 0) { - output.push(message); - } - }); + .shift(); + + // add unique + if (output.indexOf(message) < 0) { + output.push(message); + } // complete overall only once there are no further errors clearTimeout(timeout); @@ -247,7 +257,7 @@ function compile(bannerWidth, transforms) { // transforms transforms .concat(requireTransform(false)) - .forEach(function (item, i, list) { + .forEach(function eachItem(item, i, list) { if (typeof item === 'function') { var opts = (typeof list[i+1] === 'object') ? merge({ global: true }, list[i+1]) : { global: true }; bundler.transform(item, opts); @@ -256,7 +266,7 @@ function compile(bannerWidth, transforms) { // require statements [].concat(files) - .forEach(function (item) { + .forEach(function eachItem(item) { bundler.require(item, {entry: true}); }); @@ -278,7 +288,7 @@ function compile(bannerWidth, transforms) { // when we use minification we will get: error, code, source-map // when we don't we will get: error, buffer(with embedded source map) - bundler.bundle(function (error, codeOrBuffer, map) { + bundler.bundle(function onComplete(error, codeOrBuffer, map) { if (!error) { var code = codeOrBuffer.toString(); var sourceMap = map ? JSON.parse(map) : convert.fromComment(code).toObject(); @@ -305,10 +315,10 @@ function compile(bannerWidth, transforms) { * @param {string} [sourceMapBase] Base path for source map file * @returns {stream.Through} */ - each: function (isMinify, sourceMapBase) { - return through.obj(function (file, encoding, done) { + each: function gulpBundleEach(isMinify, sourceMapBase) { + return through.obj(function transformFn(file, encoding, done) { bundle(this, [file.path], file.relative, isMinify, sourceMapBase, done); - }, function (done) { + }, function flushFn(done) { flushErrors(); done(); }); @@ -321,12 +331,12 @@ function compile(bannerWidth, transforms) { * @param {string} [sourceMapBase] Base path for source map file * @returns {stream.Through} */ - all: function (outPath, isMinify, sourceMapBase) { + all: function gulpBundleAll(outPath, isMinify, sourceMapBase) { var pending = []; - return through.obj(function (file, encoding, done) { + return through.obj(function transformFn(file, encoding, done) { pending.push(file.path); done(); - }, function (done) { + }, function flushFn(done) { if (pending.length) { bundle(this, pending, outPath, isMinify, sourceMapBase, function () { flushErrors(); diff --git a/lib/build/node-sass.js b/lib/build/node-sass.js index 7b50310..c874139 100644 --- a/lib/build/node-sass.js +++ b/lib/build/node-sass.js @@ -63,12 +63,12 @@ function encodeRelativeURL(startPath, uri) { // find path to the root, stopping at cwd, package.json or bower.json var pathToRoot = []; - var isWorking = true; - while (isWorking) { + var isWorking; + do { pathToRoot.push(absoluteStart); isWorking = (absoluteStart !== process.cwd()) && notPackage(absoluteStart); absoluteStart = path.resolve(absoluteStart, '..'); - } + } while (isWorking); // start a queue with the path to the root var queue = pathToRoot.concat(); @@ -83,9 +83,9 @@ function encodeRelativeURL(startPath, uri) { // file exists so convert to a dataURI and end if (fs.existsSync(fullPath)) { - var type = mime.lookup(fullPath); + var type = mime.lookup(fullPath); var contents = fs.readFileSync(fullPath); - var base64 = new Buffer(contents).toString('base64'); + var base64 = new Buffer(contents).toString('base64'); return 'url(data:' + type + ';base64,' + base64 + ')'; } // enqueue subdirectories that are not packages and are not in the root path diff --git a/lib/inject/adjacent-files.js b/lib/inject/adjacent-files.js index 070397c..183a3c4 100644 --- a/lib/inject/adjacent-files.js +++ b/lib/inject/adjacent-files.js @@ -32,22 +32,23 @@ module.exports = function (extension, opts, recurse) { throw new Error('encountered a file that is outside the given recurse path'); } - // use terms in the relative address, from none to all - var split = fileRelative.split(/[\\\/]/g); - for(var i = 0, glob = []; i < split.length; i++) { - extensions.forEach(addSliceToGlob(glob, 0, i + 1)); - } - function addSliceToGlob(glob, start, stop) { - return function (extension) { - var item = [ fileRecurse ] - .concat(split.slice(start, stop)) - .concat('*.' + extension) - .join('/'); - if (glob.indexOf(item) < 0) { - glob.push(item); - } - }; - } + // use elements in the relative address, from none to all + // for each term add a matcher for all files of the given extension + // TODO @bholloway can this be replaced by a single term? i.e. /**/*. + var glob = []; + fileRelative + .split(/[\\\/]/g) + .forEach(function eachPathElement(value, i, array) { + extensions.forEach(function eachExtension(extension) { + var item = [ fileRecurse ] + .concat(array.slice(0, i + 1)) + .concat('*.' + extension) + .join('/'); + if (glob.indexOf(item) < 0) { + glob.push(item); + } + }); + }); return gulp.src(glob, { read: false }) .pipe(semiflat(file.base)) .pipe(slash()); diff --git a/lib/inject/bower-files.js b/lib/inject/bower-files.js index 6b3cee0..7a150e6 100644 --- a/lib/inject/bower-files.js +++ b/lib/inject/bower-files.js @@ -84,7 +84,10 @@ module.exports = function () { function greatestCommonBase(absolute) { if (base) { - for (var i = 0; (base[i] === absolute[i]); i++) {} /* jshint -W035 */ + var i = 0; + while(base[i] === absolute[i]) { + i++; + } base = base.slice(0, i); } else if (options.base === true) { base = path.dirname(absolute); diff --git a/lib/test/karma.js b/lib/test/karma.js index 69e1d5c..f06e010 100644 --- a/lib/test/karma.js +++ b/lib/test/karma.js @@ -136,6 +136,8 @@ function karmaCreateConfig(reporters, configFileName) { done(); } function flushFn(done) { + /* jshint validthis:true */ + var stream = this; function requirePlugins(reporter) { return 'require("' + getKarmaReporterPluginPath(reporter) + '")'; } @@ -144,9 +146,6 @@ function karmaCreateConfig(reporters, configFileName) { } var filePath = path.resolve(configFileName); if (fs.existsSync(filePath)) { - // Can safely ignore JsHint warnign here because through2 sets the value of - // `this` to the file stream - var stream = this; // jshint ignore:line var contents = fs.readFileSync(filePath).toString() .replace(basePathRegex, encode(process.cwd())) .replace(filesAppendRegex, encode(files.concat(additional)))