From ea2ef0687475a622898acb9e7544a231734bdc3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vesa=20Poikaj=C3=A4rvi?= Date: Fri, 24 Oct 2014 10:20:18 +0700 Subject: [PATCH 1/8] Sort deps for better npm install --save experience Template should keep deps sorted, otherwise when users use npm install --save the get a messed up diff because --save will sort the deps. --- package.json | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index d6df7f5..92d1edb 100644 --- a/package.json +++ b/package.json @@ -19,28 +19,28 @@ "coffee-script": "~1.7.1" }, "devDependencies": { - "gulp-uglify": "~0.1.0", - "gulp-util": "~2.2.17", - "gulp-stylus": "1.3.3", - "gulp-jade": "~0.6.0", - "gulp-livereload": "~2.1.0", "bower": "~1.3.5", - "gulp-autoprefixer": "0.0.7", "browserify": "~4.1.11", - "gulp-streamify": "0.0.5", - "vinyl-source-stream": "~0.1.1", + "browserify-shim": "~3.8.0", "coffeeify": "~0.7.0", + "deamdify": "^0.1.1", + "debowerify": "~0.8.2", + "ecstatic": "~0.5.3", + "gulp": "~3.8.1", + "gulp-autoprefixer": "0.0.7", + "gulp-jade": "~0.6.0", + "gulp-livereload": "~2.1.0", + "gulp-minify-css": "~0.3.5", + "gulp-streamify": "0.0.5", + "gulp-stylus": "1.3.3", + "gulp-uglify": "~0.1.0", + "gulp-util": "~2.2.17", "karma": "~0.12.21", - "karma-jasmine": "~0.1.5", "karma-chrome-launcher": "~0.1.4", "karma-coffee-preprocessor": "~0.2.1", - "gulp": "~3.8.1", - "watchify": "~0.10.2", - "ecstatic": "~0.5.3", - "gulp-minify-css": "~0.3.5", - "deamdify": "^0.1.1", - "debowerify": "~0.8.2", - "browserify-shim": "~3.8.0" + "karma-jasmine": "~0.1.5", + "vinyl-source-stream": "~0.1.1", + "watchify": "~0.10.2" }, "browser": {}, "browserify-shim": {}, From 3199a0fa655d92c4c5b013e0108eb182b4b89813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vesa=20Poikaj=C3=A4rvi?= Date: Fri, 24 Oct 2014 10:34:43 +0700 Subject: [PATCH 2/8] Update to latest deps and fix related code Couple of related changes in one commit: - Upgrade all dependencies to latest ones. - Change how Browserify/Watchify is called since it has changed - Added a task no-js that will not launch the 'scripts' task. This is because upon first run it would run simultaneously with Watchify and the outcome would not work. - Be consistent with quotes --- gulpfile.coffee | 20 ++++++++++++++------ package.json | 20 ++++++++++---------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/gulpfile.coffee b/gulpfile.coffee index f866da0..31a70a6 100644 --- a/gulpfile.coffee +++ b/gulpfile.coffee @@ -43,8 +43,9 @@ gulp.task 'scripts', -> bundle = browserify entries: [paths.scripts.source] extensions: ['.coffee'] + debug: not production - build = bundle.bundle(debug: not production) + build = bundle.bundle() .on 'error', handleError .pipe source paths.scripts.filename @@ -88,19 +89,23 @@ gulp.task 'server', -> .createServer ecstatic root: __dirname + '/public' .listen 9001 -gulp.task "watch", -> +gulp.task 'watch', -> livereload.listen() gulp.watch paths.templates.watch, ['templates'] gulp.watch paths.styles.watch, ['styles'] gulp.watch paths.assets.watch, ['assets'] - bundle = watchify + bundle = watchify browserify entries: [paths.scripts.source] extensions: ['.coffee'] + debug: not production + cache: {} + packageCache: {} + fullPaths: true bundle.on 'update', -> - build = bundle.bundle(debug: not production) + build = bundle.bundle() .on 'error', handleError .pipe source paths.scripts.filename @@ -111,5 +116,8 @@ gulp.task "watch", -> .emit 'update' -gulp.task "build", ['scripts', 'templates', 'styles', 'assets'] -gulp.task "default", ["build", "watch", "server"] +gulp.task 'no-js', ['templates', 'styles', 'assets'] +gulp.task 'build', ['scripts', 'no-js'] +# scripts and watch conflict and will produce invalid js upon first run +# which is why the no-js task exists. +gulp.task 'default', ['no-js', 'watch', 'server'] diff --git a/package.json b/package.json index 92d1edb..9c98301 100644 --- a/package.json +++ b/package.json @@ -16,31 +16,31 @@ "template" ], "dependencies": { - "coffee-script": "~1.7.1" + "coffee-script": "~1.8.0" }, "devDependencies": { "bower": "~1.3.5", - "browserify": "~4.1.11", + "browserify": "~6.1.0", "browserify-shim": "~3.8.0", "coffeeify": "~0.7.0", "deamdify": "^0.1.1", - "debowerify": "~0.8.2", + "debowerify": "~0.9.1", "ecstatic": "~0.5.3", "gulp": "~3.8.1", - "gulp-autoprefixer": "0.0.7", - "gulp-jade": "~0.6.0", + "gulp-autoprefixer": "1.0.1", + "gulp-jade": "~0.9.0", "gulp-livereload": "~2.1.0", "gulp-minify-css": "~0.3.5", "gulp-streamify": "0.0.5", "gulp-stylus": "1.3.3", - "gulp-uglify": "~0.1.0", - "gulp-util": "~2.2.17", + "gulp-uglify": "~1.0.1", + "gulp-util": "~3.0.1", "karma": "~0.12.21", "karma-chrome-launcher": "~0.1.4", "karma-coffee-preprocessor": "~0.2.1", - "karma-jasmine": "~0.1.5", - "vinyl-source-stream": "~0.1.1", - "watchify": "~0.10.2" + "karma-jasmine": "~0.2.2", + "vinyl-source-stream": "~1.0.0", + "watchify": "~2.0.0" }, "browser": {}, "browserify-shim": {}, From 4445fce04b1ba8bcc22245940467df691cc6bbe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vesa=20Poikaj=C3=A4rvi?= Date: Fri, 24 Oct 2014 10:49:19 +0700 Subject: [PATCH 3/8] Add auto: false to livereload calls so build works Build worked when env was production but jammed if it was not because of the livereload server being up and running. That can be prevented by using option auto: false, but this introduces an issue where the livereload server is not started at all if auto: false call gets executed first (and it would if the assets were built first). Thus, start the watch task first. --- gulpfile.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gulpfile.coffee b/gulpfile.coffee index 31a70a6..46e7c46 100644 --- a/gulpfile.coffee +++ b/gulpfile.coffee @@ -61,7 +61,7 @@ gulp.task 'templates', -> .on 'error', handleError .pipe gulp.dest paths.templates.destination - pipeline = pipeline.pipe livereload() unless production + pipeline = pipeline.pipe livereload(auto: false) unless production pipeline @@ -76,7 +76,7 @@ gulp.task 'styles', -> styles = styles.pipe(CSSmin()) if production styles = styles.pipe gulp.dest paths.styles.destination - styles = styles.pipe livereload() unless production + styles = styles.pipe livereload(auto: false) unless production styles gulp.task 'assets', -> @@ -120,4 +120,4 @@ gulp.task 'no-js', ['templates', 'styles', 'assets'] gulp.task 'build', ['scripts', 'no-js'] # scripts and watch conflict and will produce invalid js upon first run # which is why the no-js task exists. -gulp.task 'default', ['no-js', 'watch', 'server'] +gulp.task 'default', ['watch', 'no-js', 'server'] From c8138d5014e843feac81225f8e48843aebd363c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vesa=20Poikaj=C3=A4rvi?= Date: Fri, 24 Oct 2014 11:00:36 +0700 Subject: [PATCH 4/8] Pretty logging for rebundle Log the start and stop of rebundling the same way Gulp does, looks pretty. --- gulpfile.coffee | 5 +++++ package.json | 2 ++ 2 files changed, 7 insertions(+) diff --git a/gulpfile.coffee b/gulpfile.coffee index 46e7c46..95d9c82 100644 --- a/gulpfile.coffee +++ b/gulpfile.coffee @@ -12,6 +12,8 @@ uglify = require 'gulp-uglify' ecstatic = require 'ecstatic' livereload = require 'gulp-livereload' prefix = require 'gulp-autoprefixer' +chalk = require 'chalk' +prettyTime = require 'pretty-hrtime' production = process.env.NODE_ENV is 'production' @@ -105,6 +107,8 @@ gulp.task 'watch', -> fullPaths: true bundle.on 'update', -> + gutil.log "Starting '#{chalk.cyan 'rebundle'}'..." + start = process.hrtime() build = bundle.bundle() .on 'error', handleError @@ -113,6 +117,7 @@ gulp.task 'watch', -> build .pipe gulp.dest paths.scripts.destination .pipe(livereload()) + gutil.log "Finished '#{chalk.cyan 'rebundle'}' after #{chalk.magenta prettyTime process.hrtime start}" .emit 'update' diff --git a/package.json b/package.json index 9c98301..8de016e 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "bower": "~1.3.5", "browserify": "~6.1.0", "browserify-shim": "~3.8.0", + "chalk": "~0.5.1", "coffeeify": "~0.7.0", "deamdify": "^0.1.1", "debowerify": "~0.9.1", @@ -39,6 +40,7 @@ "karma-chrome-launcher": "~0.1.4", "karma-coffee-preprocessor": "~0.2.1", "karma-jasmine": "~0.2.2", + "pretty-hrtime": "~0.2.2", "vinyl-source-stream": "~1.0.0", "watchify": "~2.0.0" }, From 620bf836403f51c5eb9ed32d6e34c556e1b66481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vesa=20Poikaj=C3=A4rvi?= Date: Fri, 24 Oct 2014 11:02:08 +0700 Subject: [PATCH 5/8] Install karma-cli so that npm test works Karma does not install the cli to node_modules/.bin and thus npm test does not work unless user installs karma-cli globally. --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 8de016e..84e6e33 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "gulp-util": "~3.0.1", "karma": "~0.12.21", "karma-chrome-launcher": "~0.1.4", + "karma-cli": "0.0.4", "karma-coffee-preprocessor": "~0.2.1", "karma-jasmine": "~0.2.2", "pretty-hrtime": "~0.2.2", From 372e2503a87eab5c77dd5910e484e03764b33fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vesa=20Poikaj=C3=A4rvi?= Date: Fri, 24 Oct 2014 11:23:50 +0700 Subject: [PATCH 6/8] Sort also requires In order to make it somewhat sane to maintain the different branches also keep the require calls in gulpfile sorted. --- gulpfile.coffee | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gulpfile.coffee b/gulpfile.coffee index 95d9c82..caf4e12 100644 --- a/gulpfile.coffee +++ b/gulpfile.coffee @@ -1,19 +1,19 @@ -path = require 'path' +browserify = require 'browserify' +chalk = require 'chalk' +CSSmin = require 'gulp-minify-css' +ecstatic = require 'ecstatic' gulp = require 'gulp' gutil = require 'gulp-util' jade = require 'gulp-jade' -stylus = require 'gulp-stylus' -CSSmin = require 'gulp-minify-css' -browserify = require 'browserify' -watchify = require 'watchify' -source = require 'vinyl-source-stream' -streamify = require 'gulp-streamify' -uglify = require 'gulp-uglify' -ecstatic = require 'ecstatic' livereload = require 'gulp-livereload' +path = require 'path' prefix = require 'gulp-autoprefixer' -chalk = require 'chalk' prettyTime = require 'pretty-hrtime' +source = require 'vinyl-source-stream' +streamify = require 'gulp-streamify' +stylus = require 'gulp-stylus' +uglify = require 'gulp-uglify' +watchify = require 'watchify' production = process.env.NODE_ENV is 'production' From 4d21ddbbe47789afb9639fd164f9a15161fe2e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vesa=20Poikaj=C3=A4rvi?= Date: Fri, 24 Oct 2014 11:30:24 +0700 Subject: [PATCH 7/8] Use path.join for compatibility --- gulpfile.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gulpfile.coffee b/gulpfile.coffee index caf4e12..2e66c16 100644 --- a/gulpfile.coffee +++ b/gulpfile.coffee @@ -88,7 +88,7 @@ gulp.task 'assets', -> gulp.task 'server', -> require('http') - .createServer ecstatic root: __dirname + '/public' + .createServer ecstatic root: path.join(__dirname, '/public') .listen 9001 gulp.task 'watch', -> From 70cee196118a0cf9c7b7161ab81c213b0347bcbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vesa=20Poikaj=C3=A4rvi?= Date: Fri, 24 Oct 2014 11:31:29 +0700 Subject: [PATCH 8/8] Typo --- gulpfile.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gulpfile.coffee b/gulpfile.coffee index 2e66c16..4bf4d74 100644 --- a/gulpfile.coffee +++ b/gulpfile.coffee @@ -88,7 +88,7 @@ gulp.task 'assets', -> gulp.task 'server', -> require('http') - .createServer ecstatic root: path.join(__dirname, '/public') + .createServer ecstatic root: path.join(__dirname, 'public') .listen 9001 gulp.task 'watch', ->