From 5b9f0b772dd2a66bc6b50ccafe6a4c2215d4e12a Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Mon, 19 Oct 2015 19:12:59 +0200 Subject: [PATCH 01/35] [BT-58]: Separate repository for reusable gulp tasks with lint module --- .eslintrc | 8 ++++++++ .gitignore | 1 + Gulpfile.js | 7 +++++++ package.json | 21 +++++++++++++++++++++ src/lint.js | 23 +++++++++++++++++++++++ 5 files changed, 60 insertions(+) create mode 100644 .eslintrc create mode 100644 .gitignore create mode 100644 Gulpfile.js create mode 100644 package.json create mode 100644 src/lint.js diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..25595de --- /dev/null +++ b/.eslintrc @@ -0,0 +1,8 @@ +// Added jsx-quotes and react/jsx-quotes to remove deprecation warning ("The react/jsx-quotes rule is deprecated. Please use the jsx-quotes rule instead.") +{ + "extends": "eslint-config-airbnb-es5", + "rules": { + "jsx-quotes": [2, "prefer-double"], + "react/jsx-quotes": 0 + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/Gulpfile.js b/Gulpfile.js new file mode 100644 index 0000000..e71b2604 --- /dev/null +++ b/Gulpfile.js @@ -0,0 +1,7 @@ +var gulp = require('gulp'); + +var LINT_SRC = './**/*.js'; + +require('./src/lint')(LINT_SRC); + +gulp.task('default', ['eslint']); diff --git a/package.json b/package.json new file mode 100644 index 0000000..1ea4b00 --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "name": "gulp-tasks", + "private": true, + "version": "0.0.1", + "description": "Collection of reusable gulp tasks", + "scripts": { + "test": "gulp" + }, + "devDependencies": { + "babel-eslint": "4.1.3", + "eslint": "1.7.1", + "eslint-config-airbnb-es5": "1.0.8", + "eslint-plugin-react": "3.6.2", + "gulp": "3.9.0", + "gulp-eslint": "1.0.0", + "pre-commit": "1.1.1" + }, + "pre-commit": [ + "test" + ] +} diff --git a/src/lint.js b/src/lint.js new file mode 100644 index 0000000..787c2d4 --- /dev/null +++ b/src/lint.js @@ -0,0 +1,23 @@ +/** + * @description Lint related tasks + */ + +module.exports = function lint(src) { + var gulp = require('gulp'); + var gulpEslint = require('gulp-eslint'); + + var LINT_SRC = src || []; + + /** + * @description ESLint + */ + gulp.task('eslint', function eslint() { + return gulp.src(LINT_SRC) + .pipe(gulpEslint()) + .pipe(gulpEslint.format()) + .pipe(gulpEslint.failAfterError()) + .on('error', function exitGulp() { + throw new Error('Linting failed'); + }); + }); +}; From 46e3eec2ab343b1c24ddc72999fb53dc90d47e61 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Tue, 20 Oct 2015 11:56:52 +0200 Subject: [PATCH 02/35] [BT-58]: Added style module --- src/styles.js | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/styles.js diff --git a/src/styles.js b/src/styles.js new file mode 100644 index 0000000..1cd9374 --- /dev/null +++ b/src/styles.js @@ -0,0 +1,82 @@ + +/** + * @description Style related tasks + */ + +module.exports = function styles(src, dst) { + var autoprefixer = require('autoprefixer'); + var cssMqpacker = require('css-mqpacker'); + var del = require('del'); + var gulp = require('gulp'); + var gulpCompass = require('gulp-compass'); + var gulpConnect = require('gulp-connect'); + var gulpCssmin = require('gulp-cssmin'); + var gulpPostcss = require('gulp-postcss'); + var gulpRename = require('gulp-rename'); + var gulpReplace = require('gulp-replace'); + var runSequence = require('run-sequence'); + + var STYLES_DST = dst || './dist/css'; + var STYLES_SRC = src || []; + + gulp.task('compass', function compass() { + return gulp.src(STYLES_SRC) + .pipe(gulpCompass({ + css: STYLES_DST, + import_path: './node_modules', + sass: './app', + sourcemap: true + })) + .on('error', function exitGulp() { + throw new Error('Compass failed'); + }) + .pipe(gulp.dest(STYLES_DST)); + }); + + gulp.task('postCss', function postCss() { + return gulp.src((STYLES_DST + '/index.css')) + .pipe(gulpPostcss([ + autoprefixer({ + browsers: ['last 2 versions'] + }), + cssMqpacker + ])) + .pipe(gulp.dest(STYLES_DST)); + }); + + gulp.task('renameDstIndexCss', function renameDstIndexCss() { + return gulp.src((STYLES_DST + '/*')) + // Replace occurences of index.css with dist.css inside of files + .pipe(gulpReplace('index.css', 'dist.css')) + // Rename files from *index*.* to *dist*.* + .pipe(gulpRename(function rename(path) { + path.basename = path.basename.replace('index', 'dist'); + })) + .pipe(gulp.dest(STYLES_DST)) + .pipe(gulpConnect.reload()); + }); + + gulp.task('deleteDstIndexCss', function deleteDstIndexCss() { + return del([ + (STYLES_DST + '/index.css'), + (STYLES_DST + '/index.css.map') + ]); + }); + + gulp.task('sass', function sass(callback) { + runSequence( + 'compass', + 'postCss', + 'renameDstIndexCss', + 'deleteDstIndexCss', + callback + ); + }); + + gulp.task('minifyCss', function minifyCss() { + return gulp.src((STYLES_DST + '/dist.css')) + .pipe(gulpCssmin()) + .pipe(gulpRename('dist.min.css')) + .pipe(gulp.dest(STYLES_DST)); + }); +}; From 6772ca2cdeb9596f43caed63f1ade1cea8c642c3 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Tue, 20 Oct 2015 12:17:53 +0200 Subject: [PATCH 03/35] [BT-58]: Added deploy module --- src/deploy.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/deploy.js diff --git a/src/deploy.js b/src/deploy.js new file mode 100644 index 0000000..0f9da09 --- /dev/null +++ b/src/deploy.js @@ -0,0 +1,43 @@ + +/** + * @description Deployment related tasks + */ + +module.exports = function deploy(bucketEnv) { + var gulp = require('gulp'); + var gulpAwspublish = require('gulp-awspublish'); + var minimist = require('minimist'); + + var BUCKET_ENV = bucketEnv || 'AWS_S3_BUCKET'; + + /** + * @description AWS S3 deployment task + * To manually deploy the working copy the following command can be used: + * gulp awsS3Deploy --accessKeyId=XXX --bucket=XXX --secretAccessKey=XXX + * + * The arguments can be provided via the command line as in this example where + * - accessKeyId is the AWS access key id, + * - bucket is the AWS S3 bucket and + * - secretAccessKey is the AWS secret access key. + * + * If the arguments are not provided via the command line they will be read + * from the environment variables + * - AWS_ACCESS_KEY_ID + * - AWS_SECRET_ACCESS_KEY + * - the environment variable for the bucket is set via the bucketEnv argument + */ + gulp.task('awsS3Deploy', function awsS3Deploy() { + var commandLineArguments = minimist(process.argv.slice(2)); + var publisher = gulpAwspublish.create({ + accessKeyId: commandLineArguments.accessKeyId || process.env.AWS_ACCESS_KEY_ID, + params: { + Bucket: commandLineArguments.bucket || process.env[BUCKET_ENV] + }, + secretAccessKey: commandLineArguments.secretAccessKey || process.env.AWS_SECRET_ACCESS_KEY + }); + return gulp.src('./dist/**/*.*') + .pipe(publisher.publish()) + .pipe(publisher.sync()) + .pipe(gulpAwspublish.reporter()); + }); +}; From 94d0c2a98829f1e47540294366f80a469efb07c9 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Tue, 20 Oct 2015 13:09:58 +0200 Subject: [PATCH 04/35] [BT-58]: Added script module --- src/scripts.js | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/scripts.js diff --git a/src/scripts.js b/src/scripts.js new file mode 100644 index 0000000..b7a8ed8 --- /dev/null +++ b/src/scripts.js @@ -0,0 +1,85 @@ + +/** + * @description Script related tasks + */ + +module.exports = function scripts(src, dst) { + var babelify = require('babelify'); + var browserify = require('browserify'); + var gulp = require('gulp'); + var gulpConnect = require('gulp-connect'); + var gulpRename = require('gulp-rename'); + var gulpUglify = require('gulp-uglify'); + var gulpUtil = require('gulp-util'); + var vinylSourceStream = require('vinyl-source-stream'); + var watchify = require('watchify'); + + var BROWSERIFY_CFG = {}; + var SCRIPTS_DST = dst || './dist/js'; + var SCRIPTS_SRC = src || ''; + + function bundleUsingBrowserify(withWatchify) { + /* + Watchify, a watch mode for browserify builds, will be enabled if + withWatchify is true. The task will not exit and if a source file is changed + the browserify bundler will emit an update event and the scripts will be + rewritten. Since the browserify bundler is changed incrementally it is much + faster than creating a new browserify bundler. + If withWatchify is false the scripts will only be written once and the task + will exit. + */ + var writeScriptsFromBundle = function writeScriptsFromBundle(bundle) { + return bundle + .pipe(vinylSourceStream('dist.js')) + .pipe(gulp.dest(SCRIPTS_DST)) + .pipe(gulpConnect.reload()); + }; + var bundler; + var startTime; + + if (withWatchify) { + BROWSERIFY_CFG = watchify.args; + } + + BROWSERIFY_CFG.debug = !process.env.GULP_IS_PRODUCTION; + + bundler = browserify(SCRIPTS_SRC, BROWSERIFY_CFG); + + if (withWatchify) { + bundler = watchify(bundler); + } + + bundler.transform(babelify); + + if (withWatchify) { + bundler.on('update', function update() { + gulpUtil.log('Starting to update scripts'); + startTime = (new Date().getTime()); + + writeScriptsFromBundle(bundler.bundle()) + .on('end', function end() { + gulpUtil.log('Finished updating scripts after', ((new Date().getTime()) - startTime), 'ms'); + }); + }); + } + + return writeScriptsFromBundle(bundler.bundle()); + } + + gulp.task('browserifyScripts', function browserifyScripts() { + return bundleUsingBrowserify(false); + }); + + gulp.task('browserifyScriptsAndWatch', function browserifyScriptsAndWatch() { + return bundleUsingBrowserify(true); + }); + + gulp.task('minifyJs', function minifyJs() { + return gulp.src((SCRIPTS_DST + '/dist.js')) + .pipe(gulpUglify({ + mangle: true + })) + .pipe(gulpRename('dist.min.js')) + .pipe(gulp.dest(SCRIPTS_DST)); + }); +}; From a83db776b9292751c6b250f3f60a89055ae565b8 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Wed, 21 Oct 2015 11:34:31 +0200 Subject: [PATCH 05/35] [BT-58]: Added assets module --- src/assets.js | 19 +++++++++++++++++++ src/deploy.js | 2 +- src/lint.js | 2 +- src/scripts.js | 2 +- src/styles.js | 2 +- 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 src/assets.js diff --git a/src/assets.js b/src/assets.js new file mode 100644 index 0000000..b7d4269 --- /dev/null +++ b/src/assets.js @@ -0,0 +1,19 @@ + +/** + * @description Asset related tasks + */ + +module.exports = function assetGulpTasks(src, dst) { + var gulp = require('gulp'); + var gulpConnect = require('gulp-connect'); + + var ASSETS_DST = dst || './dist/assets'; + var ASSETS_SRC = src || []; + + gulp.task('assets', function assets() { + gulp + .src(ASSETS_SRC) + .pipe(gulp.dest(ASSETS_DST)) + .pipe(gulpConnect.reload()); + }); +}; diff --git a/src/deploy.js b/src/deploy.js index 0f9da09..fa2f0f7 100644 --- a/src/deploy.js +++ b/src/deploy.js @@ -3,7 +3,7 @@ * @description Deployment related tasks */ -module.exports = function deploy(bucketEnv) { +module.exports = function deployGulpTasks(bucketEnv) { var gulp = require('gulp'); var gulpAwspublish = require('gulp-awspublish'); var minimist = require('minimist'); diff --git a/src/lint.js b/src/lint.js index 787c2d4..fc69d87 100644 --- a/src/lint.js +++ b/src/lint.js @@ -2,7 +2,7 @@ * @description Lint related tasks */ -module.exports = function lint(src) { +module.exports = function lintGulpTasks(src) { var gulp = require('gulp'); var gulpEslint = require('gulp-eslint'); diff --git a/src/scripts.js b/src/scripts.js index b7a8ed8..5ec12c6 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -3,7 +3,7 @@ * @description Script related tasks */ -module.exports = function scripts(src, dst) { +module.exports = function scriptGulpTasks(src, dst) { var babelify = require('babelify'); var browserify = require('browserify'); var gulp = require('gulp'); diff --git a/src/styles.js b/src/styles.js index 1cd9374..1bf2d78 100644 --- a/src/styles.js +++ b/src/styles.js @@ -3,7 +3,7 @@ * @description Style related tasks */ -module.exports = function styles(src, dst) { +module.exports = function styleGulpTasks(src, dst) { var autoprefixer = require('autoprefixer'); var cssMqpacker = require('css-mqpacker'); var del = require('del'); From 1cdf8b1af7c5a2b4e88d2e807171b21462d8ff6c Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Wed, 21 Oct 2015 11:42:34 +0200 Subject: [PATCH 06/35] [BT-58]: Added templates module --- src/templates.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/templates.js diff --git a/src/templates.js b/src/templates.js new file mode 100644 index 0000000..3e11d3a --- /dev/null +++ b/src/templates.js @@ -0,0 +1,24 @@ + +/** + * @description Template related tasks + */ + +module.exports = function templateGulpTasks(src, dst) { + var gulp = require('gulp'); + var gulpConnect = require('gulp-connect'); + var gulpJade = require('gulp-jade'); + + var TEMPLATES_DST = dst || './dist'; + var TEMPLATES_SRC = src || []; + + gulp.task('jade', function jade() { + return gulp.src(TEMPLATES_SRC) + .pipe(gulpJade({ + locals: { + DATE_TIME: (new Date().getTime()) + } + })) + .pipe(gulp.dest(TEMPLATES_DST)) + .pipe(gulpConnect.reload()); + }); +}; From 22b0d3290b5cea7799ef4452f266ab081032830a Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Wed, 21 Oct 2015 11:44:28 +0200 Subject: [PATCH 07/35] [BT-58]: Improved deploy module --- src/deploy.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/deploy.js b/src/deploy.js index fa2f0f7..0e454f7 100644 --- a/src/deploy.js +++ b/src/deploy.js @@ -3,12 +3,13 @@ * @description Deployment related tasks */ -module.exports = function deployGulpTasks(bucketEnv) { +module.exports = function deployGulpTasks(bucketEnv, src) { var gulp = require('gulp'); var gulpAwspublish = require('gulp-awspublish'); var minimist = require('minimist'); var BUCKET_ENV = bucketEnv || 'AWS_S3_BUCKET'; + var DEPLOY_SRC = src || './dist/**/*.*'; /** * @description AWS S3 deployment task @@ -35,7 +36,7 @@ module.exports = function deployGulpTasks(bucketEnv) { }, secretAccessKey: commandLineArguments.secretAccessKey || process.env.AWS_SECRET_ACCESS_KEY }); - return gulp.src('./dist/**/*.*') + return gulp.src(DEPLOY_SRC) .pipe(publisher.publish()) .pipe(publisher.sync()) .pipe(gulpAwspublish.reporter()); From 24b8d607d151c49b7b558c42c21db0f31789c84c Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Wed, 21 Oct 2015 12:02:56 +0200 Subject: [PATCH 08/35] [BT-58]: Added tests module --- src/tests.js | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 src/tests.js diff --git a/src/tests.js b/src/tests.js new file mode 100644 index 0000000..9e341a5 --- /dev/null +++ b/src/tests.js @@ -0,0 +1,105 @@ + +/** + * @description Test related tasks + */ + +module.exports = function testGulpTasks(config) { + var del = require('del'); + var gulp = require('gulp'); + var gulpBabel = require('gulp-babel'); + var gulpConnect = require('gulp-connect'); + var gulpNightwatch = require('gulp-nightwatch'); + var gulpReplace = require('gulp-replace'); + var karmaServer = require('karma').Server; + var runSequence = require('run-sequence'); + + var TEST_CFG = config || { + e2e: { + connect: {}, + dir: './e2e/', + shim: '', + wasNightwatchFailing: false + }, + karma: {} + }; + + /** + * @description Unit test task + */ + gulp.task('unit', function unit(callback) { + return karmaServer.start(TEST_CFG.karma, function exitGulp(exitStatus) { + if (exitStatus) { + throw new Error('Unit testing failed'); + } else { + callback(exitStatus); + } + }); + }); + + /** + * @description End-to-end test tasks + */ + gulp.task('e2e:startConnect', function e2eStartConnect() { + gulpConnect.server(TEST_CFG.e2e.connect); + }); + + gulp.task('e2e:clean', function e2eClean(callback) { + return del([ + TEST_CFG.e2e.dir + 'dist/**/*', + TEST_CFG.e2e.dir + 'dist/' + ], callback); + }); + + gulp.task('e2e:compileTests', function e2eCompileTests() { + return gulp.src(TEST_CFG.e2e.dir + 'src/**/*.js') + .pipe(gulpBabel()) + .pipe(gulp.dest(TEST_CFG.e2e.dir + 'dist')); + }); + + gulp.task('e2e:addShim', function e2eAddShim() { + return gulp.src(['./dist/index.html']) + .pipe(gulpReplace(' Date: Wed, 21 Oct 2015 12:13:39 +0200 Subject: [PATCH 09/35] [BT-58]: Added local web server module --- src/localwebserver.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/localwebserver.js diff --git a/src/localwebserver.js b/src/localwebserver.js new file mode 100644 index 0000000..1a84d5a --- /dev/null +++ b/src/localwebserver.js @@ -0,0 +1,15 @@ + +/** + * @description Local web server tasks + */ + +module.exports = function localWebServerGulpTasks(config) { + var gulp = require('gulp'); + var gulpConnect = require('gulp-connect'); + + var CONNECT_CFG = config || {}; + + gulp.task('connect', function connect() { + gulpConnect.server(CONNECT_CFG); + }); +}; From 4412b27e7a3cb153d28c7c92145a51d24d990135 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Wed, 21 Oct 2015 14:51:55 +0200 Subject: [PATCH 10/35] [BT-58]: Improved module exports for better dependency management --- Gulpfile.js | 4 +-- src/assets.js | 3 +- src/deploy.js | 36 +++++++++++----------- src/lint.js | 9 +++--- src/localwebserver.js | 5 ++-- src/scripts.js | 24 ++++++++++----- src/styles.js | 21 +++++++++---- src/templates.js | 5 ++-- src/tests.js | 69 +++++++++++++++++++++---------------------- 9 files changed, 97 insertions(+), 79 deletions(-) diff --git a/Gulpfile.js b/Gulpfile.js index e71b2604..7bd5204 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -2,6 +2,6 @@ var gulp = require('gulp'); var LINT_SRC = './**/*.js'; -require('./src/lint')(LINT_SRC); +require('./src/lint').eslint(LINT_SRC); -gulp.task('default', ['eslint']); +gulp.task('default', ['lint']); diff --git a/src/assets.js b/src/assets.js index b7d4269..f96a239 100644 --- a/src/assets.js +++ b/src/assets.js @@ -3,7 +3,8 @@ * @description Asset related tasks */ -module.exports = function assetGulpTasks(src, dst) { +// Copy and trigger live reload +module.exports.copy = function copy(src, dst) { var gulp = require('gulp'); var gulpConnect = require('gulp-connect'); diff --git a/src/deploy.js b/src/deploy.js index 0e454f7..145803f 100644 --- a/src/deploy.js +++ b/src/deploy.js @@ -3,7 +3,8 @@ * @description Deployment related tasks */ -module.exports = function deployGulpTasks(bucketEnv, src) { +// AWS SDK +module.exports.awsS3 = function awsS3(bucketEnv, src) { var gulp = require('gulp'); var gulpAwspublish = require('gulp-awspublish'); var minimist = require('minimist'); @@ -11,23 +12,22 @@ module.exports = function deployGulpTasks(bucketEnv, src) { var BUCKET_ENV = bucketEnv || 'AWS_S3_BUCKET'; var DEPLOY_SRC = src || './dist/**/*.*'; - /** - * @description AWS S3 deployment task - * To manually deploy the working copy the following command can be used: - * gulp awsS3Deploy --accessKeyId=XXX --bucket=XXX --secretAccessKey=XXX - * - * The arguments can be provided via the command line as in this example where - * - accessKeyId is the AWS access key id, - * - bucket is the AWS S3 bucket and - * - secretAccessKey is the AWS secret access key. - * - * If the arguments are not provided via the command line they will be read - * from the environment variables - * - AWS_ACCESS_KEY_ID - * - AWS_SECRET_ACCESS_KEY - * - the environment variable for the bucket is set via the bucketEnv argument - */ - gulp.task('awsS3Deploy', function awsS3Deploy() { + gulp.task('deploy', function deploy() { + /* + To manually deploy the working copy the following command can be used: + gulp deploy --accessKeyId=XXX --bucket=XXX --secretAccessKey=XXX + + The arguments can be provided via the command line as in this example where + - accessKeyId is the AWS access key id, + - bucket is the AWS S3 bucket and + - secretAccessKey is the AWS secret access key. + + If the arguments are not provided via the command line they will be read + from the environment variables + - AWS_ACCESS_KEY_ID + - AWS_SECRET_ACCESS_KEY + - the environment variable for the bucket is set via the bucketEnv argument + */ var commandLineArguments = minimist(process.argv.slice(2)); var publisher = gulpAwspublish.create({ accessKeyId: commandLineArguments.accessKeyId || process.env.AWS_ACCESS_KEY_ID, diff --git a/src/lint.js b/src/lint.js index fc69d87..569ed6f 100644 --- a/src/lint.js +++ b/src/lint.js @@ -1,17 +1,16 @@ + /** * @description Lint related tasks */ -module.exports = function lintGulpTasks(src) { +// ESLint +module.exports.eslint = function eslint(src) { var gulp = require('gulp'); var gulpEslint = require('gulp-eslint'); var LINT_SRC = src || []; - /** - * @description ESLint - */ - gulp.task('eslint', function eslint() { + gulp.task('lint', function lint() { return gulp.src(LINT_SRC) .pipe(gulpEslint()) .pipe(gulpEslint.format()) diff --git a/src/localwebserver.js b/src/localwebserver.js index 1a84d5a..80618e6 100644 --- a/src/localwebserver.js +++ b/src/localwebserver.js @@ -3,13 +3,14 @@ * @description Local web server tasks */ -module.exports = function localWebServerGulpTasks(config) { +// Connect +module.exports.connect = function connect(config) { var gulp = require('gulp'); var gulpConnect = require('gulp-connect'); var CONNECT_CFG = config || {}; - gulp.task('connect', function connect() { + gulp.task('serveLocally', function serveLocally() { gulpConnect.server(CONNECT_CFG); }); }; diff --git a/src/scripts.js b/src/scripts.js index 5ec12c6..f8e7947 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -3,13 +3,12 @@ * @description Script related tasks */ -module.exports = function scriptGulpTasks(src, dst) { +// Browserify, Babelify, Watchify +module.exports.browserifyAndWatchify = function browserifyAndWatchify(src, dst) { var babelify = require('babelify'); var browserify = require('browserify'); var gulp = require('gulp'); var gulpConnect = require('gulp-connect'); - var gulpRename = require('gulp-rename'); - var gulpUglify = require('gulp-uglify'); var gulpUtil = require('gulp-util'); var vinylSourceStream = require('vinyl-source-stream'); var watchify = require('watchify'); @@ -66,20 +65,29 @@ module.exports = function scriptGulpTasks(src, dst) { return writeScriptsFromBundle(bundler.bundle()); } - gulp.task('browserifyScripts', function browserifyScripts() { + gulp.task('scripts', function scripts() { return bundleUsingBrowserify(false); }); - gulp.task('browserifyScriptsAndWatch', function browserifyScriptsAndWatch() { + gulp.task('scriptsThenWatch', function scriptsThenWatch() { return bundleUsingBrowserify(true); }); +}; + +// UglifyJS +module.exports.uglify = function uglify(src) { + var gulp = require('gulp'); + var gulpRename = require('gulp-rename'); + var gulpUglify = require('gulp-uglify'); + + var SCRIPTS_SRC = src || './dist/js'; - gulp.task('minifyJs', function minifyJs() { - return gulp.src((SCRIPTS_DST + '/dist.js')) + gulp.task('minifyScripts', function minifyScripts() { + return gulp.src((SCRIPTS_SRC + '/dist.js')) .pipe(gulpUglify({ mangle: true })) .pipe(gulpRename('dist.min.js')) - .pipe(gulp.dest(SCRIPTS_DST)); + .pipe(gulp.dest(SCRIPTS_SRC)); }); }; diff --git a/src/styles.js b/src/styles.js index 1bf2d78..57e33a4 100644 --- a/src/styles.js +++ b/src/styles.js @@ -3,14 +3,14 @@ * @description Style related tasks */ -module.exports = function styleGulpTasks(src, dst) { +// Compass and PostCSS +module.exports.compassAndPostcss = function compassAndPostcss(src, dst) { var autoprefixer = require('autoprefixer'); var cssMqpacker = require('css-mqpacker'); var del = require('del'); var gulp = require('gulp'); var gulpCompass = require('gulp-compass'); var gulpConnect = require('gulp-connect'); - var gulpCssmin = require('gulp-cssmin'); var gulpPostcss = require('gulp-postcss'); var gulpRename = require('gulp-rename'); var gulpReplace = require('gulp-replace'); @@ -63,7 +63,7 @@ module.exports = function styleGulpTasks(src, dst) { ]); }); - gulp.task('sass', function sass(callback) { + gulp.task('styles', function styles(callback) { runSequence( 'compass', 'postCss', @@ -72,11 +72,20 @@ module.exports = function styleGulpTasks(src, dst) { callback ); }); +}; + +// clean-css +module.exports.cleanCss = function cleanCss(src) { + var gulp = require('gulp'); + var gulpCssmin = require('gulp-cssmin'); + var gulpRename = require('gulp-rename'); - gulp.task('minifyCss', function minifyCss() { - return gulp.src((STYLES_DST + '/dist.css')) + var STYLES_SRC = src || './dist/css'; + + gulp.task('minifyStyles', function minifyStyles() { + return gulp.src((STYLES_SRC + '/dist.css')) .pipe(gulpCssmin()) .pipe(gulpRename('dist.min.css')) - .pipe(gulp.dest(STYLES_DST)); + .pipe(gulp.dest(STYLES_SRC)); }); }; diff --git a/src/templates.js b/src/templates.js index 3e11d3a..a2a8f57 100644 --- a/src/templates.js +++ b/src/templates.js @@ -3,7 +3,8 @@ * @description Template related tasks */ -module.exports = function templateGulpTasks(src, dst) { +// Jade +module.exports.jade = function jade(src, dst) { var gulp = require('gulp'); var gulpConnect = require('gulp-connect'); var gulpJade = require('gulp-jade'); @@ -11,7 +12,7 @@ module.exports = function templateGulpTasks(src, dst) { var TEMPLATES_DST = dst || './dist'; var TEMPLATES_SRC = src || []; - gulp.task('jade', function jade() { + gulp.task('templates', function templates() { return gulp.src(TEMPLATES_SRC) .pipe(gulpJade({ locals: { diff --git a/src/tests.js b/src/tests.js index 9e341a5..ad9f0f9 100644 --- a/src/tests.js +++ b/src/tests.js @@ -3,31 +3,15 @@ * @description Test related tasks */ -module.exports = function testGulpTasks(config) { - var del = require('del'); +// Karma +module.exports.karma = function karma(config) { var gulp = require('gulp'); - var gulpBabel = require('gulp-babel'); - var gulpConnect = require('gulp-connect'); - var gulpNightwatch = require('gulp-nightwatch'); - var gulpReplace = require('gulp-replace'); var karmaServer = require('karma').Server; - var runSequence = require('run-sequence'); - var TEST_CFG = config || { - e2e: { - connect: {}, - dir: './e2e/', - shim: '', - wasNightwatchFailing: false - }, - karma: {} - }; + var KARMA_CFG = config || {}; - /** - * @description Unit test task - */ - gulp.task('unit', function unit(callback) { - return karmaServer.start(TEST_CFG.karma, function exitGulp(exitStatus) { + gulp.task('unit', function karmaGulpTask(callback) { + return karmaServer.start(KARMA_CFG, function exitGulp(exitStatus) { if (exitStatus) { throw new Error('Unit testing failed'); } else { @@ -35,49 +19,64 @@ module.exports = function testGulpTasks(config) { } }); }); +}; + +// Nightwatch +module.exports.nightwatch = function nightwatch(config) { + var del = require('del'); + var gulp = require('gulp'); + var gulpBabel = require('gulp-babel'); + var gulpConnect = require('gulp-connect'); + var gulpNightwatch = require('gulp-nightwatch'); + var gulpReplace = require('gulp-replace'); + var runSequence = require('run-sequence'); + + var NIGHTWATCH_CFG = config || { + connect: {}, + dir: './e2e/', + shim: '', + wasNightwatchFailing: false + }; - /** - * @description End-to-end test tasks - */ gulp.task('e2e:startConnect', function e2eStartConnect() { - gulpConnect.server(TEST_CFG.e2e.connect); + gulpConnect.server(NIGHTWATCH_CFG.connect); }); gulp.task('e2e:clean', function e2eClean(callback) { return del([ - TEST_CFG.e2e.dir + 'dist/**/*', - TEST_CFG.e2e.dir + 'dist/' + NIGHTWATCH_CFG.dir + 'dist/**/*', + NIGHTWATCH_CFG.dir + 'dist/' ], callback); }); gulp.task('e2e:compileTests', function e2eCompileTests() { - return gulp.src(TEST_CFG.e2e.dir + 'src/**/*.js') + return gulp.src(NIGHTWATCH_CFG.dir + 'src/**/*.js') .pipe(gulpBabel()) - .pipe(gulp.dest(TEST_CFG.e2e.dir + 'dist')); + .pipe(gulp.dest(NIGHTWATCH_CFG.dir + 'dist')); }); gulp.task('e2e:addShim', function e2eAddShim() { return gulp.src(['./dist/index.html']) - .pipe(gulpReplace(' Date: Wed, 21 Oct 2015 18:17:42 +0200 Subject: [PATCH 11/35] Added browserify-hmr and removed gulp-connect in browserify scripts gulp task --- src/scripts.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/scripts.js b/src/scripts.js index f8e7947..5d57b76 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -3,12 +3,12 @@ * @description Script related tasks */ -// Browserify, Babelify, Watchify +// Browserify, Browserify-HMR, Babelify, Watchify module.exports.browserifyAndWatchify = function browserifyAndWatchify(src, dst) { var babelify = require('babelify'); var browserify = require('browserify'); + var browserifyHmr = require('browserify-hmr'); var gulp = require('gulp'); - var gulpConnect = require('gulp-connect'); var gulpUtil = require('gulp-util'); var vinylSourceStream = require('vinyl-source-stream'); var watchify = require('watchify'); @@ -30,8 +30,7 @@ module.exports.browserifyAndWatchify = function browserifyAndWatchify(src, dst) var writeScriptsFromBundle = function writeScriptsFromBundle(bundle) { return bundle .pipe(vinylSourceStream('dist.js')) - .pipe(gulp.dest(SCRIPTS_DST)) - .pipe(gulpConnect.reload()); + .pipe(gulp.dest(SCRIPTS_DST)); }; var bundler; var startTime; @@ -40,11 +39,12 @@ module.exports.browserifyAndWatchify = function browserifyAndWatchify(src, dst) BROWSERIFY_CFG = watchify.args; } - BROWSERIFY_CFG.debug = !process.env.GULP_IS_PRODUCTION; + BROWSERIFY_CFG.debug = (process.env.NODE_ENV !== 'production'); bundler = browserify(SCRIPTS_SRC, BROWSERIFY_CFG); if (withWatchify) { + bundler.plugin(browserifyHmr); bundler = watchify(bundler); } From adbb6e39e6bcd5e302950a2bceeaee48725418f2 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Mon, 26 Oct 2015 17:20:06 +0100 Subject: [PATCH 12/35] [BT-58]: Consistent config argument for gulp task defining functions --- Gulpfile.js | 6 +++++- src/assets.js | 12 +++++++----- src/deploy.js | 12 +++++++----- src/lint.js | 8 +++++--- src/scripts.js | 22 +++++++++++++--------- src/styles.js | 36 ++++++++++++++++++++---------------- src/templates.js | 12 +++++++----- 7 files changed, 64 insertions(+), 44 deletions(-) diff --git a/Gulpfile.js b/Gulpfile.js index 7bd5204..307c03e 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -1,7 +1,11 @@ + var gulp = require('gulp'); +var lintGulpTaskCollection = require('./src/lint'); var LINT_SRC = './**/*.js'; -require('./src/lint').eslint(LINT_SRC); +lintGulpTaskCollection.eslint({ + src: LINT_SRC +}); gulp.task('default', ['lint']); diff --git a/src/assets.js b/src/assets.js index f96a239..1e257d2 100644 --- a/src/assets.js +++ b/src/assets.js @@ -4,17 +4,19 @@ */ // Copy and trigger live reload -module.exports.copy = function copy(src, dst) { +module.exports.copy = function copy(config) { var gulp = require('gulp'); var gulpConnect = require('gulp-connect'); - var ASSETS_DST = dst || './dist/assets'; - var ASSETS_SRC = src || []; + var ASSETS_CFG = config || { + dst: './dist/assets', + src: [] + }; gulp.task('assets', function assets() { gulp - .src(ASSETS_SRC) - .pipe(gulp.dest(ASSETS_DST)) + .src(ASSETS_CFG.src) + .pipe(gulp.dest(ASSETS_CFG.dst)) .pipe(gulpConnect.reload()); }); }; diff --git a/src/deploy.js b/src/deploy.js index 145803f..a3ad7a6 100644 --- a/src/deploy.js +++ b/src/deploy.js @@ -4,13 +4,15 @@ */ // AWS SDK -module.exports.awsS3 = function awsS3(bucketEnv, src) { +module.exports.awsS3 = function awsS3(config) { var gulp = require('gulp'); var gulpAwspublish = require('gulp-awspublish'); var minimist = require('minimist'); - var BUCKET_ENV = bucketEnv || 'AWS_S3_BUCKET'; - var DEPLOY_SRC = src || './dist/**/*.*'; + var DEPLOY_CFG = config || { + bucketEnv: 'AWS_S3_BUCKET', + src: './dist/**/*.*' + }; gulp.task('deploy', function deploy() { /* @@ -32,11 +34,11 @@ module.exports.awsS3 = function awsS3(bucketEnv, src) { var publisher = gulpAwspublish.create({ accessKeyId: commandLineArguments.accessKeyId || process.env.AWS_ACCESS_KEY_ID, params: { - Bucket: commandLineArguments.bucket || process.env[BUCKET_ENV] + Bucket: commandLineArguments.bucket || process.env[DEPLOY_CFG.bucketEnv] }, secretAccessKey: commandLineArguments.secretAccessKey || process.env.AWS_SECRET_ACCESS_KEY }); - return gulp.src(DEPLOY_SRC) + return gulp.src(DEPLOY_CFG.src) .pipe(publisher.publish()) .pipe(publisher.sync()) .pipe(gulpAwspublish.reporter()); diff --git a/src/lint.js b/src/lint.js index 569ed6f..9f3fb2e 100644 --- a/src/lint.js +++ b/src/lint.js @@ -4,14 +4,16 @@ */ // ESLint -module.exports.eslint = function eslint(src) { +module.exports.eslint = function eslint(config) { var gulp = require('gulp'); var gulpEslint = require('gulp-eslint'); - var LINT_SRC = src || []; + var LINT_CFG = config || { + src: [] + }; gulp.task('lint', function lint() { - return gulp.src(LINT_SRC) + return gulp.src(LINT_CFG.src) .pipe(gulpEslint()) .pipe(gulpEslint.format()) .pipe(gulpEslint.failAfterError()) diff --git a/src/scripts.js b/src/scripts.js index 5d57b76..1e15373 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -4,7 +4,7 @@ */ // Browserify, Browserify-HMR, Babelify, Watchify -module.exports.browserifyAndWatchify = function browserifyAndWatchify(src, dst) { +module.exports.browserifyAndWatchify = function browserifyAndWatchify(config) { var babelify = require('babelify'); var browserify = require('browserify'); var browserifyHmr = require('browserify-hmr'); @@ -14,8 +14,10 @@ module.exports.browserifyAndWatchify = function browserifyAndWatchify(src, dst) var watchify = require('watchify'); var BROWSERIFY_CFG = {}; - var SCRIPTS_DST = dst || './dist/js'; - var SCRIPTS_SRC = src || ''; + var SCRIPTS_CFG = config || { + dst: './dist/js', + src: '' + }; function bundleUsingBrowserify(withWatchify) { /* @@ -30,7 +32,7 @@ module.exports.browserifyAndWatchify = function browserifyAndWatchify(src, dst) var writeScriptsFromBundle = function writeScriptsFromBundle(bundle) { return bundle .pipe(vinylSourceStream('dist.js')) - .pipe(gulp.dest(SCRIPTS_DST)); + .pipe(gulp.dest(SCRIPTS_CFG.dst)); }; var bundler; var startTime; @@ -41,7 +43,7 @@ module.exports.browserifyAndWatchify = function browserifyAndWatchify(src, dst) BROWSERIFY_CFG.debug = (process.env.NODE_ENV !== 'production'); - bundler = browserify(SCRIPTS_SRC, BROWSERIFY_CFG); + bundler = browserify(SCRIPTS_CFG.src, BROWSERIFY_CFG); if (withWatchify) { bundler.plugin(browserifyHmr); @@ -75,19 +77,21 @@ module.exports.browserifyAndWatchify = function browserifyAndWatchify(src, dst) }; // UglifyJS -module.exports.uglify = function uglify(src) { +module.exports.uglify = function uglify(config) { var gulp = require('gulp'); var gulpRename = require('gulp-rename'); var gulpUglify = require('gulp-uglify'); - var SCRIPTS_SRC = src || './dist/js'; + var SCRIPTS_CFG = config || { + src: './dist/js' + }; gulp.task('minifyScripts', function minifyScripts() { - return gulp.src((SCRIPTS_SRC + '/dist.js')) + return gulp.src((SCRIPTS_CFG.src + '/dist.js')) .pipe(gulpUglify({ mangle: true })) .pipe(gulpRename('dist.min.js')) - .pipe(gulp.dest(SCRIPTS_SRC)); + .pipe(gulp.dest(SCRIPTS_CFG.src)); }); }; diff --git a/src/styles.js b/src/styles.js index 57e33a4..a082576 100644 --- a/src/styles.js +++ b/src/styles.js @@ -4,7 +4,7 @@ */ // Compass and PostCSS -module.exports.compassAndPostcss = function compassAndPostcss(src, dst) { +module.exports.compassAndPostcss = function compassAndPostcss(config) { var autoprefixer = require('autoprefixer'); var cssMqpacker = require('css-mqpacker'); var del = require('del'); @@ -16,13 +16,15 @@ module.exports.compassAndPostcss = function compassAndPostcss(src, dst) { var gulpReplace = require('gulp-replace'); var runSequence = require('run-sequence'); - var STYLES_DST = dst || './dist/css'; - var STYLES_SRC = src || []; + var STYLES_CFG = config || { + dst: './dist/css', + src: [] + }; gulp.task('compass', function compass() { - return gulp.src(STYLES_SRC) + return gulp.src(STYLES_CFG.src) .pipe(gulpCompass({ - css: STYLES_DST, + css: STYLES_CFG.dst, import_path: './node_modules', sass: './app', sourcemap: true @@ -30,36 +32,36 @@ module.exports.compassAndPostcss = function compassAndPostcss(src, dst) { .on('error', function exitGulp() { throw new Error('Compass failed'); }) - .pipe(gulp.dest(STYLES_DST)); + .pipe(gulp.dest(STYLES_CFG.dst)); }); gulp.task('postCss', function postCss() { - return gulp.src((STYLES_DST + '/index.css')) + return gulp.src((STYLES_CFG.dst + '/index.css')) .pipe(gulpPostcss([ autoprefixer({ browsers: ['last 2 versions'] }), cssMqpacker ])) - .pipe(gulp.dest(STYLES_DST)); + .pipe(gulp.dest(STYLES_CFG.dst)); }); gulp.task('renameDstIndexCss', function renameDstIndexCss() { - return gulp.src((STYLES_DST + '/*')) + return gulp.src((STYLES_CFG.dst + '/*')) // Replace occurences of index.css with dist.css inside of files .pipe(gulpReplace('index.css', 'dist.css')) // Rename files from *index*.* to *dist*.* .pipe(gulpRename(function rename(path) { path.basename = path.basename.replace('index', 'dist'); })) - .pipe(gulp.dest(STYLES_DST)) + .pipe(gulp.dest(STYLES_CFG.dst)) .pipe(gulpConnect.reload()); }); gulp.task('deleteDstIndexCss', function deleteDstIndexCss() { return del([ - (STYLES_DST + '/index.css'), - (STYLES_DST + '/index.css.map') + (STYLES_CFG.dst + '/index.css'), + (STYLES_CFG.dst + '/index.css.map') ]); }); @@ -75,17 +77,19 @@ module.exports.compassAndPostcss = function compassAndPostcss(src, dst) { }; // clean-css -module.exports.cleanCss = function cleanCss(src) { +module.exports.cleanCss = function cleanCss(config) { var gulp = require('gulp'); var gulpCssmin = require('gulp-cssmin'); var gulpRename = require('gulp-rename'); - var STYLES_SRC = src || './dist/css'; + var STYLES_CFG = config || { + src: './dist/css' + }; gulp.task('minifyStyles', function minifyStyles() { - return gulp.src((STYLES_SRC + '/dist.css')) + return gulp.src((STYLES_CFG.src + '/dist.css')) .pipe(gulpCssmin()) .pipe(gulpRename('dist.min.css')) - .pipe(gulp.dest(STYLES_SRC)); + .pipe(gulp.dest(STYLES_CFG.src)); }); }; diff --git a/src/templates.js b/src/templates.js index a2a8f57..22a7120 100644 --- a/src/templates.js +++ b/src/templates.js @@ -4,22 +4,24 @@ */ // Jade -module.exports.jade = function jade(src, dst) { +module.exports.jade = function jade(config) { var gulp = require('gulp'); var gulpConnect = require('gulp-connect'); var gulpJade = require('gulp-jade'); - var TEMPLATES_DST = dst || './dist'; - var TEMPLATES_SRC = src || []; + var TEMPLATES_CFG = config || { + dst: './dist', + src: [] + }; gulp.task('templates', function templates() { - return gulp.src(TEMPLATES_SRC) + return gulp.src(TEMPLATES_CFG.src) .pipe(gulpJade({ locals: { DATE_TIME: (new Date().getTime()) } })) - .pipe(gulp.dest(TEMPLATES_DST)) + .pipe(gulp.dest(TEMPLATES_CFG.dst)) .pipe(gulpConnect.reload()); }); }; From eb0389a34e83f91743f3349661dc9d57e5cce083 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Mon, 26 Oct 2015 19:59:57 +0100 Subject: [PATCH 13/35] [BT-58]: Improved assets gulp task collection and added tests with jasmine --- .eslintrc | 3 +++ Gulpfile.js | 8 ++++++- package.json | 5 ++++- src/assets.js | 6 ++++- src/assets.spec.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 src/assets.spec.js diff --git a/.eslintrc b/.eslintrc index 25595de..83eb143 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,5 +1,8 @@ // Added jsx-quotes and react/jsx-quotes to remove deprecation warning ("The react/jsx-quotes rule is deprecated. Please use the jsx-quotes rule instead.") { + "env": { + "jasmine": true + }, "extends": "eslint-config-airbnb-es5", "rules": { "jsx-quotes": [2, "prefer-double"], diff --git a/Gulpfile.js b/Gulpfile.js index 307c03e..5ccb746 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -1,5 +1,6 @@ var gulp = require('gulp'); +var gulpJasmine = require('gulp-jasmine'); var lintGulpTaskCollection = require('./src/lint'); var LINT_SRC = './**/*.js'; @@ -8,4 +9,9 @@ lintGulpTaskCollection.eslint({ src: LINT_SRC }); -gulp.task('default', ['lint']); +gulp.task('test', ['lint'], function test() { + return gulp.src('./src/**/*.js') + .pipe(gulpJasmine()); +}); + +gulp.task('default', ['test']); diff --git a/package.json b/package.json index 1ea4b00..756f165 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,11 @@ "eslint-config-airbnb-es5": "1.0.8", "eslint-plugin-react": "3.6.2", "gulp": "3.9.0", + "gulp-connect": "2.2.0", "gulp-eslint": "1.0.0", - "pre-commit": "1.1.1" + "gulp-jasmine": "2.1.0", + "pre-commit": "1.1.1", + "run-sequence": "1.1.4" }, "pre-commit": [ "test" diff --git a/src/assets.js b/src/assets.js index 1e257d2..ff197ff 100644 --- a/src/assets.js +++ b/src/assets.js @@ -13,8 +13,12 @@ module.exports.copy = function copy(config) { src: [] }; + if (!ASSETS_CFG.dst || !ASSETS_CFG.src) { + throw new Error('Invalid configuration'); + } + gulp.task('assets', function assets() { - gulp + return gulp .src(ASSETS_CFG.src) .pipe(gulp.dest(ASSETS_CFG.dst)) .pipe(gulpConnect.reload()); diff --git a/src/assets.spec.js b/src/assets.spec.js new file mode 100644 index 0000000..687a44c --- /dev/null +++ b/src/assets.spec.js @@ -0,0 +1,55 @@ + +describe('Assets Gulp Task Collection', function() { + var assetsGulpTaskCollection = require('./assets.js'); + var gulp = require('gulp'); + var runSequence = require('run-sequence'); + + it('can be imported', function() { + expect(assetsGulpTaskCollection).toBeDefined(); + }); + + describe('Copy Gulp Task Definition', function() { + it('is defined', function() { + expect(assetsGulpTaskCollection.copy).toBeDefined(); + }); + + it('can not be called with an invalid configuration', function() { + expect(function() { + return assetsGulpTaskCollection.copy({}); + }).toThrow(); + + expect(function() { + return assetsGulpTaskCollection.copy({ + dst: './dist/assets' + }); + }).toThrow(); + + expect(function() { + return assetsGulpTaskCollection.copy({ + src: [] + }); + }).toThrow(); + }); + + it('can be called without a configuration', function() { + expect(assetsGulpTaskCollection.copy).not.toThrow(); + }); + + it('registers a gulp task', function() { + expect(gulp.tasks.assets).toBeDefined(); + }); + + describe('Copy Gulp Task', function() { + beforeEach(function(done) { + runSequence( + 'assets', + done + ); + }); + + it('can be executed', function() { + expect(gulp.tasks.assets.done).toBe(true); + }); + }); + }); +}); From 97cf79b57c3180114f647ff2dda167d40b46ae1f Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Tue, 27 Oct 2015 11:21:08 +0100 Subject: [PATCH 14/35] [BT-58]: Improved gulp tasks - arrow functions, renamed _CFG to _CONFIG, set jasmine verbose option to true --- Gulpfile.js | 6 +++-- src/assets.js | 12 +++++----- src/assets.spec.js | 26 +++++++++++----------- src/deploy.js | 10 ++++----- src/lint.js | 10 ++++----- src/localwebserver.js | 8 +++---- src/scripts.js | 38 +++++++++++++++---------------- src/styles.js | 46 +++++++++++++++++++------------------- src/templates.js | 10 ++++----- src/tests.js | 52 +++++++++++++++++++++---------------------- 10 files changed, 110 insertions(+), 108 deletions(-) diff --git a/Gulpfile.js b/Gulpfile.js index 5ccb746..e3e9b13 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -9,9 +9,11 @@ lintGulpTaskCollection.eslint({ src: LINT_SRC }); -gulp.task('test', ['lint'], function test() { +gulp.task('test', ['lint'], () => { return gulp.src('./src/**/*.js') - .pipe(gulpJasmine()); + .pipe(gulpJasmine({ + verbose: true + })); }); gulp.task('default', ['test']); diff --git a/src/assets.js b/src/assets.js index ff197ff..f0e2cb8 100644 --- a/src/assets.js +++ b/src/assets.js @@ -4,23 +4,23 @@ */ // Copy and trigger live reload -module.exports.copy = function copy(config) { +module.exports.copy = (config) => { var gulp = require('gulp'); var gulpConnect = require('gulp-connect'); - var ASSETS_CFG = config || { + var ASSETS_CONFIG = config || { dst: './dist/assets', src: [] }; - if (!ASSETS_CFG.dst || !ASSETS_CFG.src) { + if (!ASSETS_CONFIG.dst || !ASSETS_CONFIG.src) { throw new Error('Invalid configuration'); } - gulp.task('assets', function assets() { + gulp.task('assets', () => { return gulp - .src(ASSETS_CFG.src) - .pipe(gulp.dest(ASSETS_CFG.dst)) + .src(ASSETS_CONFIG.src) + .pipe(gulp.dest(ASSETS_CONFIG.dst)) .pipe(gulpConnect.reload()); }); }; diff --git a/src/assets.spec.js b/src/assets.spec.js index 687a44c..0ea989c 100644 --- a/src/assets.spec.js +++ b/src/assets.spec.js @@ -1,53 +1,53 @@ -describe('Assets Gulp Task Collection', function() { +describe('Assets Gulp Task Collection', () => { var assetsGulpTaskCollection = require('./assets.js'); var gulp = require('gulp'); var runSequence = require('run-sequence'); - it('can be imported', function() { + it('can be imported', () => { expect(assetsGulpTaskCollection).toBeDefined(); }); - describe('Copy Gulp Task Definition', function() { - it('is defined', function() { + describe('Copy Gulp Task Definition', () => { + it('is defined', () => { expect(assetsGulpTaskCollection.copy).toBeDefined(); }); - it('can not be called with an invalid configuration', function() { - expect(function() { + it('can not be called with an invalid configuration', () => { + expect(() => { return assetsGulpTaskCollection.copy({}); }).toThrow(); - expect(function() { + expect(() => { return assetsGulpTaskCollection.copy({ dst: './dist/assets' }); }).toThrow(); - expect(function() { + expect(() => { return assetsGulpTaskCollection.copy({ src: [] }); }).toThrow(); }); - it('can be called without a configuration', function() { + it('can be called without a configuration', () => { expect(assetsGulpTaskCollection.copy).not.toThrow(); }); - it('registers a gulp task', function() { + it('registers a gulp task', () => { expect(gulp.tasks.assets).toBeDefined(); }); - describe('Copy Gulp Task', function() { - beforeEach(function(done) { + describe('Copy Gulp Task', () => { + beforeEach((done) => { runSequence( 'assets', done ); }); - it('can be executed', function() { + it('can be executed', () => { expect(gulp.tasks.assets.done).toBe(true); }); }); diff --git a/src/deploy.js b/src/deploy.js index a3ad7a6..109ec7b 100644 --- a/src/deploy.js +++ b/src/deploy.js @@ -4,17 +4,17 @@ */ // AWS SDK -module.exports.awsS3 = function awsS3(config) { +module.exports.awsS3 = (config) => { var gulp = require('gulp'); var gulpAwspublish = require('gulp-awspublish'); var minimist = require('minimist'); - var DEPLOY_CFG = config || { + var DEPLOY_CONFIG = config || { bucketEnv: 'AWS_S3_BUCKET', src: './dist/**/*.*' }; - gulp.task('deploy', function deploy() { + gulp.task('deploy', () => { /* To manually deploy the working copy the following command can be used: gulp deploy --accessKeyId=XXX --bucket=XXX --secretAccessKey=XXX @@ -34,11 +34,11 @@ module.exports.awsS3 = function awsS3(config) { var publisher = gulpAwspublish.create({ accessKeyId: commandLineArguments.accessKeyId || process.env.AWS_ACCESS_KEY_ID, params: { - Bucket: commandLineArguments.bucket || process.env[DEPLOY_CFG.bucketEnv] + Bucket: commandLineArguments.bucket || process.env[DEPLOY_CONFIG.bucketEnv] }, secretAccessKey: commandLineArguments.secretAccessKey || process.env.AWS_SECRET_ACCESS_KEY }); - return gulp.src(DEPLOY_CFG.src) + return gulp.src(DEPLOY_CONFIG.src) .pipe(publisher.publish()) .pipe(publisher.sync()) .pipe(gulpAwspublish.reporter()); diff --git a/src/lint.js b/src/lint.js index 9f3fb2e..e69ee6d 100644 --- a/src/lint.js +++ b/src/lint.js @@ -4,20 +4,20 @@ */ // ESLint -module.exports.eslint = function eslint(config) { +module.exports.eslint = (config) => { var gulp = require('gulp'); var gulpEslint = require('gulp-eslint'); - var LINT_CFG = config || { + var LINT_CONFIG = config || { src: [] }; - gulp.task('lint', function lint() { - return gulp.src(LINT_CFG.src) + gulp.task('lint', () => { + return gulp.src(LINT_CONFIG.src) .pipe(gulpEslint()) .pipe(gulpEslint.format()) .pipe(gulpEslint.failAfterError()) - .on('error', function exitGulp() { + .on('error', () => { throw new Error('Linting failed'); }); }); diff --git a/src/localwebserver.js b/src/localwebserver.js index 80618e6..8abd169 100644 --- a/src/localwebserver.js +++ b/src/localwebserver.js @@ -4,13 +4,13 @@ */ // Connect -module.exports.connect = function connect(config) { +module.exports.connect = (config) => { var gulp = require('gulp'); var gulpConnect = require('gulp-connect'); - var CONNECT_CFG = config || {}; + var CONNECT_CONFIG = config || {}; - gulp.task('serveLocally', function serveLocally() { - gulpConnect.server(CONNECT_CFG); + gulp.task('serveLocally', () => { + gulpConnect.server(CONNECT_CONFIG); }); }; diff --git a/src/scripts.js b/src/scripts.js index 1e15373..2edf3a9 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -4,7 +4,7 @@ */ // Browserify, Browserify-HMR, Babelify, Watchify -module.exports.browserifyAndWatchify = function browserifyAndWatchify(config) { +module.exports.browserifyAndWatchify = (config) => { var babelify = require('babelify'); var browserify = require('browserify'); var browserifyHmr = require('browserify-hmr'); @@ -13,13 +13,13 @@ module.exports.browserifyAndWatchify = function browserifyAndWatchify(config) { var vinylSourceStream = require('vinyl-source-stream'); var watchify = require('watchify'); - var BROWSERIFY_CFG = {}; - var SCRIPTS_CFG = config || { + var BROWSERIFY_CONFIG = {}; + var SCRIPTS_CONFIG = config || { dst: './dist/js', src: '' }; - function bundleUsingBrowserify(withWatchify) { + var bundleUsingBrowserify = (withWatchify) => { /* Watchify, a watch mode for browserify builds, will be enabled if withWatchify is true. The task will not exit and if a source file is changed @@ -29,21 +29,21 @@ module.exports.browserifyAndWatchify = function browserifyAndWatchify(config) { If withWatchify is false the scripts will only be written once and the task will exit. */ - var writeScriptsFromBundle = function writeScriptsFromBundle(bundle) { + var writeScriptsFromBundle = (bundle) => { return bundle .pipe(vinylSourceStream('dist.js')) - .pipe(gulp.dest(SCRIPTS_CFG.dst)); + .pipe(gulp.dest(SCRIPTS_CONFIG.dst)); }; var bundler; var startTime; if (withWatchify) { - BROWSERIFY_CFG = watchify.args; + BROWSERIFY_CONFIG = watchify.args; } - BROWSERIFY_CFG.debug = (process.env.NODE_ENV !== 'production'); + BROWSERIFY_CONFIG.debug = (process.env.NODE_ENV !== 'production'); - bundler = browserify(SCRIPTS_CFG.src, BROWSERIFY_CFG); + bundler = browserify(SCRIPTS_CONFIG.src, BROWSERIFY_CONFIG); if (withWatchify) { bundler.plugin(browserifyHmr); @@ -53,45 +53,45 @@ module.exports.browserifyAndWatchify = function browserifyAndWatchify(config) { bundler.transform(babelify); if (withWatchify) { - bundler.on('update', function update() { + bundler.on('update', () => { gulpUtil.log('Starting to update scripts'); startTime = (new Date().getTime()); writeScriptsFromBundle(bundler.bundle()) - .on('end', function end() { + .on('end', () => { gulpUtil.log('Finished updating scripts after', ((new Date().getTime()) - startTime), 'ms'); }); }); } return writeScriptsFromBundle(bundler.bundle()); - } + }; - gulp.task('scripts', function scripts() { + gulp.task('scripts', () => { return bundleUsingBrowserify(false); }); - gulp.task('scriptsThenWatch', function scriptsThenWatch() { + gulp.task('scriptsThenWatch', () => { return bundleUsingBrowserify(true); }); }; // UglifyJS -module.exports.uglify = function uglify(config) { +module.exports.uglify = (config) => { var gulp = require('gulp'); var gulpRename = require('gulp-rename'); var gulpUglify = require('gulp-uglify'); - var SCRIPTS_CFG = config || { + var SCRIPTS_CONFIG = config || { src: './dist/js' }; - gulp.task('minifyScripts', function minifyScripts() { - return gulp.src((SCRIPTS_CFG.src + '/dist.js')) + gulp.task('minifyScripts', () => { + return gulp.src((SCRIPTS_CONFIG.src + '/dist.js')) .pipe(gulpUglify({ mangle: true })) .pipe(gulpRename('dist.min.js')) - .pipe(gulp.dest(SCRIPTS_CFG.src)); + .pipe(gulp.dest(SCRIPTS_CONFIG.src)); }); }; diff --git a/src/styles.js b/src/styles.js index a082576..e2f4923 100644 --- a/src/styles.js +++ b/src/styles.js @@ -4,7 +4,7 @@ */ // Compass and PostCSS -module.exports.compassAndPostcss = function compassAndPostcss(config) { +module.exports.compassAndPostcss = (config) => { var autoprefixer = require('autoprefixer'); var cssMqpacker = require('css-mqpacker'); var del = require('del'); @@ -16,56 +16,56 @@ module.exports.compassAndPostcss = function compassAndPostcss(config) { var gulpReplace = require('gulp-replace'); var runSequence = require('run-sequence'); - var STYLES_CFG = config || { + var STYLES_CONFIG = config || { dst: './dist/css', src: [] }; - gulp.task('compass', function compass() { - return gulp.src(STYLES_CFG.src) + gulp.task('compass', () => { + return gulp.src(STYLES_CONFIG.src) .pipe(gulpCompass({ - css: STYLES_CFG.dst, + css: STYLES_CONFIG.dst, import_path: './node_modules', sass: './app', sourcemap: true })) - .on('error', function exitGulp() { + .on('error', () => { throw new Error('Compass failed'); }) - .pipe(gulp.dest(STYLES_CFG.dst)); + .pipe(gulp.dest(STYLES_CONFIG.dst)); }); - gulp.task('postCss', function postCss() { - return gulp.src((STYLES_CFG.dst + '/index.css')) + gulp.task('postCss', () => { + return gulp.src((STYLES_CONFIG.dst + '/index.css')) .pipe(gulpPostcss([ autoprefixer({ browsers: ['last 2 versions'] }), cssMqpacker ])) - .pipe(gulp.dest(STYLES_CFG.dst)); + .pipe(gulp.dest(STYLES_CONFIG.dst)); }); - gulp.task('renameDstIndexCss', function renameDstIndexCss() { - return gulp.src((STYLES_CFG.dst + '/*')) + gulp.task('renameDstIndexCss', () => { + return gulp.src((STYLES_CONFIG.dst + '/*')) // Replace occurences of index.css with dist.css inside of files .pipe(gulpReplace('index.css', 'dist.css')) // Rename files from *index*.* to *dist*.* - .pipe(gulpRename(function rename(path) { + .pipe(gulpRename((path) => { path.basename = path.basename.replace('index', 'dist'); })) - .pipe(gulp.dest(STYLES_CFG.dst)) + .pipe(gulp.dest(STYLES_CONFIG.dst)) .pipe(gulpConnect.reload()); }); - gulp.task('deleteDstIndexCss', function deleteDstIndexCss() { + gulp.task('deleteDstIndexCss', () => { return del([ - (STYLES_CFG.dst + '/index.css'), - (STYLES_CFG.dst + '/index.css.map') + (STYLES_CONFIG.dst + '/index.css'), + (STYLES_CONFIG.dst + '/index.css.map') ]); }); - gulp.task('styles', function styles(callback) { + gulp.task('styles', (callback) => { runSequence( 'compass', 'postCss', @@ -77,19 +77,19 @@ module.exports.compassAndPostcss = function compassAndPostcss(config) { }; // clean-css -module.exports.cleanCss = function cleanCss(config) { +module.exports.cleanCss = (config) => { var gulp = require('gulp'); var gulpCssmin = require('gulp-cssmin'); var gulpRename = require('gulp-rename'); - var STYLES_CFG = config || { + var STYLES_CONFIG = config || { src: './dist/css' }; - gulp.task('minifyStyles', function minifyStyles() { - return gulp.src((STYLES_CFG.src + '/dist.css')) + gulp.task('minifyStyles', () => { + return gulp.src((STYLES_CONFIG.src + '/dist.css')) .pipe(gulpCssmin()) .pipe(gulpRename('dist.min.css')) - .pipe(gulp.dest(STYLES_CFG.src)); + .pipe(gulp.dest(STYLES_CONFIG.src)); }); }; diff --git a/src/templates.js b/src/templates.js index 22a7120..5555c2b 100644 --- a/src/templates.js +++ b/src/templates.js @@ -4,24 +4,24 @@ */ // Jade -module.exports.jade = function jade(config) { +module.exports.jade = (config) => { var gulp = require('gulp'); var gulpConnect = require('gulp-connect'); var gulpJade = require('gulp-jade'); - var TEMPLATES_CFG = config || { + var TEMPLATES_CONFIG = config || { dst: './dist', src: [] }; - gulp.task('templates', function templates() { - return gulp.src(TEMPLATES_CFG.src) + gulp.task('templates', () => { + return gulp.src(TEMPLATES_CONFIG.src) .pipe(gulpJade({ locals: { DATE_TIME: (new Date().getTime()) } })) - .pipe(gulp.dest(TEMPLATES_CFG.dst)) + .pipe(gulp.dest(TEMPLATES_CONFIG.dst)) .pipe(gulpConnect.reload()); }); }; diff --git a/src/tests.js b/src/tests.js index ad9f0f9..6aef861 100644 --- a/src/tests.js +++ b/src/tests.js @@ -4,14 +4,14 @@ */ // Karma -module.exports.karma = function karma(config) { +module.exports.karma = (config) => { var gulp = require('gulp'); var karmaServer = require('karma').Server; - var KARMA_CFG = config || {}; + var KARMA_CONFIG = config || {}; - gulp.task('unit', function karmaGulpTask(callback) { - return karmaServer.start(KARMA_CFG, function exitGulp(exitStatus) { + gulp.task('unit', (callback) => { + return karmaServer.start(KARMA_CONFIG, (exitStatus) => { if (exitStatus) { throw new Error('Unit testing failed'); } else { @@ -22,7 +22,7 @@ module.exports.karma = function karma(config) { }; // Nightwatch -module.exports.nightwatch = function nightwatch(config) { +module.exports.nightwatch = (config) => { var del = require('del'); var gulp = require('gulp'); var gulpBabel = require('gulp-babel'); @@ -31,60 +31,60 @@ module.exports.nightwatch = function nightwatch(config) { var gulpReplace = require('gulp-replace'); var runSequence = require('run-sequence'); - var NIGHTWATCH_CFG = config || { + var NIGHTWATCH_CONFIG = config || { connect: {}, dir: './e2e/', shim: '', wasNightwatchFailing: false }; - gulp.task('e2e:startConnect', function e2eStartConnect() { - gulpConnect.server(NIGHTWATCH_CFG.connect); + gulp.task('e2e:startConnect', () => { + gulpConnect.server(NIGHTWATCH_CONFIG.connect); }); - gulp.task('e2e:clean', function e2eClean(callback) { + gulp.task('e2e:clean', (callback) => { return del([ - NIGHTWATCH_CFG.dir + 'dist/**/*', - NIGHTWATCH_CFG.dir + 'dist/' + NIGHTWATCH_CONFIG.dir + 'dist/**/*', + NIGHTWATCH_CONFIG.dir + 'dist/' ], callback); }); - gulp.task('e2e:compileTests', function e2eCompileTests() { - return gulp.src(NIGHTWATCH_CFG.dir + 'src/**/*.js') + gulp.task('e2e:compileTests', () => { + return gulp.src(NIGHTWATCH_CONFIG.dir + 'src/**/*.js') .pipe(gulpBabel()) - .pipe(gulp.dest(NIGHTWATCH_CFG.dir + 'dist')); + .pipe(gulp.dest(NIGHTWATCH_CONFIG.dir + 'dist')); }); - gulp.task('e2e:addShim', function e2eAddShim() { + gulp.task('e2e:addShim', () => { return gulp.src(['./dist/index.html']) - .pipe(gulpReplace(' { return gulp.src('') .pipe(gulpNightwatch({ - configFile: NIGHTWATCH_CFG.dir + 'config/nightwatch.json', + configFile: NIGHTWATCH_CONFIG.dir + 'config/nightwatch.json', cliArgs: ['--env phantomjs'] })) - .on('error', function continueGulp() { + .on('error', () => { // If there's an error we need to complete the task and remove the shim - NIGHTWATCH_CFG.wasNightwatchFailing = true; + NIGHTWATCH_CONFIG.wasNightwatchFailing = true; this.emit('end'); }); }); - gulp.task('e2e:removeShim', function e2eRemoveShim() { + gulp.task('e2e:removeShim', () => { return gulp.src(['./dist/index.html']) - .pipe(gulpReplace((NIGHTWATCH_CFG.shim + ' { gulpConnect.serverClose(); }); - gulp.task('e2e', function nightwatchGulpTask(callback) { + gulp.task('e2e', (callback) => { runSequence( 'e2e:startConnect', 'e2e:clean', @@ -93,8 +93,8 @@ module.exports.nightwatch = function nightwatch(config) { 'e2e:nightwatch', 'e2e:removeShim', 'e2e:stopConnect', - function catchNightwatchFail(error) { - if (NIGHTWATCH_CFG.wasNightwatchFailing) { + (error) => { + if (NIGHTWATCH_CONFIG.wasNightwatchFailing) { throw new Error('E2E testing failed'); } callback(error); From a303f240ac304b00886a4842fbccfa8983d83ec0 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Tue, 27 Oct 2015 12:21:37 +0100 Subject: [PATCH 15/35] [BT-58]: Added comment to explain gulp task test --- src/assets.spec.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/assets.spec.js b/src/assets.spec.js index 0ea989c..a31ee91 100644 --- a/src/assets.spec.js +++ b/src/assets.spec.js @@ -8,7 +8,7 @@ describe('Assets Gulp Task Collection', () => { expect(assetsGulpTaskCollection).toBeDefined(); }); - describe('Copy Gulp Task Definition', () => { + describe('Copy Gulp Task Declaration', () => { it('is defined', () => { expect(assetsGulpTaskCollection.copy).toBeDefined(); }); @@ -41,6 +41,13 @@ describe('Assets Gulp Task Collection', () => { describe('Copy Gulp Task', () => { beforeEach((done) => { + /* + The provided done function has to be called to proceed and therefore + allows to do async operations here + runSequence runs gulp tasks in order and accepts a callback as the last + argument which is used to ensure that the assets gulp task finished + before assertions are evaluated + */ runSequence( 'assets', done From 7aaff4cc2436082ec6b0115b1bcc82cead1e1e83 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Tue, 27 Oct 2015 12:33:19 +0100 Subject: [PATCH 16/35] [BT-58]: Improved deploy gulp task collection with tests --- package.json | 2 ++ src/deploy.js | 4 ++++ src/deploy.spec.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 src/deploy.spec.js diff --git a/package.json b/package.json index 756f165..28b5220 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,11 @@ "eslint-config-airbnb-es5": "1.0.8", "eslint-plugin-react": "3.6.2", "gulp": "3.9.0", + "gulp-awspublish": "^3.0.1", "gulp-connect": "2.2.0", "gulp-eslint": "1.0.0", "gulp-jasmine": "2.1.0", + "minimist": "^1.2.0", "pre-commit": "1.1.1", "run-sequence": "1.1.4" }, diff --git a/src/deploy.js b/src/deploy.js index 109ec7b..ea889e1 100644 --- a/src/deploy.js +++ b/src/deploy.js @@ -14,6 +14,10 @@ module.exports.awsS3 = (config) => { src: './dist/**/*.*' }; + if (!DEPLOY_CONFIG.src) { + throw new Error('Invalid configuration'); + } + gulp.task('deploy', () => { /* To manually deploy the working copy the following command can be used: diff --git a/src/deploy.spec.js b/src/deploy.spec.js new file mode 100644 index 0000000..b19220a --- /dev/null +++ b/src/deploy.spec.js @@ -0,0 +1,35 @@ + +describe('Deploy Gulp Task Collection', () => { + var deployGulpTaskCollection = require('./deploy.js'); + var gulp = require('gulp'); + + it('can be imported', () => { + expect(deployGulpTaskCollection).toBeDefined(); + }); + + describe('AWS S3 Gulp Task Declaration', () => { + it('is defined', () => { + expect(deployGulpTaskCollection.awsS3).toBeDefined(); + }); + + it('can not be called with an invalid configuration', () => { + expect(() => { + return deployGulpTaskCollection.awsS3({}); + }).toThrow(); + + expect(() => { + return deployGulpTaskCollection.awsS3({ + bucketEnv: 'AWS_S3_BUCKET' + }); + }).toThrow(); + }); + + it('can be called without a configuration', () => { + expect(deployGulpTaskCollection.awsS3).not.toThrow(); + }); + + it('registers a gulp task', () => { + expect(gulp.tasks.deploy).toBeDefined(); + }); + }); +}); From e171cb3341a3085dc4f5086430df30501c8aa3ee Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Tue, 27 Oct 2015 14:39:34 +0100 Subject: [PATCH 17/35] [BT-58]: Task names can be set via config --- src/assets.js | 2 +- src/deploy.js | 2 +- src/lint.js | 2 +- src/localwebserver.js | 2 +- src/scripts.js | 6 +++--- src/styles.js | 4 ++-- src/templates.js | 2 +- src/tests.js | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/assets.js b/src/assets.js index f0e2cb8..748c3dc 100644 --- a/src/assets.js +++ b/src/assets.js @@ -17,7 +17,7 @@ module.exports.copy = (config) => { throw new Error('Invalid configuration'); } - gulp.task('assets', () => { + gulp.task((ASSETS_CONFIG.taskName || 'assets'), () => { return gulp .src(ASSETS_CONFIG.src) .pipe(gulp.dest(ASSETS_CONFIG.dst)) diff --git a/src/deploy.js b/src/deploy.js index ea889e1..cf821f8 100644 --- a/src/deploy.js +++ b/src/deploy.js @@ -18,7 +18,7 @@ module.exports.awsS3 = (config) => { throw new Error('Invalid configuration'); } - gulp.task('deploy', () => { + gulp.task((DEPLOY_CONFIG.taskName || 'deploy'), () => { /* To manually deploy the working copy the following command can be used: gulp deploy --accessKeyId=XXX --bucket=XXX --secretAccessKey=XXX diff --git a/src/lint.js b/src/lint.js index e69ee6d..892da03 100644 --- a/src/lint.js +++ b/src/lint.js @@ -12,7 +12,7 @@ module.exports.eslint = (config) => { src: [] }; - gulp.task('lint', () => { + gulp.task((LINT_CONFIG.taskName || 'lint'), () => { return gulp.src(LINT_CONFIG.src) .pipe(gulpEslint()) .pipe(gulpEslint.format()) diff --git a/src/localwebserver.js b/src/localwebserver.js index 8abd169..128f8c8 100644 --- a/src/localwebserver.js +++ b/src/localwebserver.js @@ -10,7 +10,7 @@ module.exports.connect = (config) => { var CONNECT_CONFIG = config || {}; - gulp.task('serveLocally', () => { + gulp.task((CONNECT_CONFIG.taskName || 'serveLocally'), () => { gulpConnect.server(CONNECT_CONFIG); }); }; diff --git a/src/scripts.js b/src/scripts.js index 2edf3a9..fe9d55c 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -67,11 +67,11 @@ module.exports.browserifyAndWatchify = (config) => { return writeScriptsFromBundle(bundler.bundle()); }; - gulp.task('scripts', () => { + gulp.task((SCRIPTS_CONFIG.taskName || 'scripts'), () => { return bundleUsingBrowserify(false); }); - gulp.task('scriptsThenWatch', () => { + gulp.task(((SCRIPTS_CONFIG.taskName + 'ThenWatch') || 'scriptsThenWatch'), () => { return bundleUsingBrowserify(true); }); }; @@ -86,7 +86,7 @@ module.exports.uglify = (config) => { src: './dist/js' }; - gulp.task('minifyScripts', () => { + gulp.task((SCRIPTS_CONFIG.taskName || 'minifyScripts'), () => { return gulp.src((SCRIPTS_CONFIG.src + '/dist.js')) .pipe(gulpUglify({ mangle: true diff --git a/src/styles.js b/src/styles.js index e2f4923..04fed49 100644 --- a/src/styles.js +++ b/src/styles.js @@ -65,7 +65,7 @@ module.exports.compassAndPostcss = (config) => { ]); }); - gulp.task('styles', (callback) => { + gulp.task((STYLES_CONFIG.taskName || 'styles'), (callback) => { runSequence( 'compass', 'postCss', @@ -86,7 +86,7 @@ module.exports.cleanCss = (config) => { src: './dist/css' }; - gulp.task('minifyStyles', () => { + gulp.task((STYLES_CONFIG.taskName || 'minifyStyles'), () => { return gulp.src((STYLES_CONFIG.src + '/dist.css')) .pipe(gulpCssmin()) .pipe(gulpRename('dist.min.css')) diff --git a/src/templates.js b/src/templates.js index 5555c2b..d20150e 100644 --- a/src/templates.js +++ b/src/templates.js @@ -14,7 +14,7 @@ module.exports.jade = (config) => { src: [] }; - gulp.task('templates', () => { + gulp.task((TEMPLATES_CONFIG.taskName || 'templates'), () => { return gulp.src(TEMPLATES_CONFIG.src) .pipe(gulpJade({ locals: { diff --git a/src/tests.js b/src/tests.js index 6aef861..982aef5 100644 --- a/src/tests.js +++ b/src/tests.js @@ -10,7 +10,7 @@ module.exports.karma = (config) => { var KARMA_CONFIG = config || {}; - gulp.task('unit', (callback) => { + gulp.task((KARMA_CONFIG.taskName || 'unit'), (callback) => { return karmaServer.start(KARMA_CONFIG, (exitStatus) => { if (exitStatus) { throw new Error('Unit testing failed'); @@ -84,7 +84,7 @@ module.exports.nightwatch = (config) => { gulpConnect.serverClose(); }); - gulp.task('e2e', (callback) => { + gulp.task((NIGHTWATCH_CONFIG.taskName || 'e2e'), (callback) => { runSequence( 'e2e:startConnect', 'e2e:clean', From 90e34b5acb68bfa773ed396f5e2908ec400c1f5e Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Tue, 27 Oct 2015 14:43:25 +0100 Subject: [PATCH 18/35] [BT-58]: Improved lint gulp task collection with tests --- src/lint.js | 4 ++++ src/lint.spec.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/lint.spec.js diff --git a/src/lint.js b/src/lint.js index 892da03..072e0b9 100644 --- a/src/lint.js +++ b/src/lint.js @@ -12,6 +12,10 @@ module.exports.eslint = (config) => { src: [] }; + if (!LINT_CONFIG.src) { + throw new Error('Invalid configuration'); + } + gulp.task((LINT_CONFIG.taskName || 'lint'), () => { return gulp.src(LINT_CONFIG.src) .pipe(gulpEslint()) diff --git a/src/lint.spec.js b/src/lint.spec.js new file mode 100644 index 0000000..0db9c84 --- /dev/null +++ b/src/lint.spec.js @@ -0,0 +1,55 @@ + +describe('Lint Gulp Task Collection', () => { + var gulp = require('gulp'); + var lintGulpTaskCollection = require('./lint.js'); + var runSequence = require('run-sequence'); + + it('can be imported', () => { + expect(lintGulpTaskCollection).toBeDefined(); + }); + + describe('ESLint Gulp Task Declaration', () => { + it('is defined', () => { + expect(lintGulpTaskCollection.eslint).toBeDefined(); + }); + + it('can not be called with an invalid configuration', () => { + expect(() => { + return lintGulpTaskCollection.eslint({}); + }).toThrow(); + }); + + it('can be called with a valid configuration', () => { + expect(() => { + lintGulpTaskCollection.eslint({ + src: [], + taskName: 'lintTest' + }); + }).not.toThrow(); + }); + + it('registers a gulp task', () => { + expect(gulp.tasks.lintTest).toBeDefined(); + }); + + describe('ESLint Gulp Task', () => { + beforeEach((done) => { + /* + The provided done function has to be called to proceed and therefore + allows to do async operations here + runSequence runs gulp tasks in order and accepts a callback as the last + argument which is used to ensure that the gulp task finished before + assertions are evaluated + */ + runSequence( + 'lintTest', + done + ); + }); + + it('can be executed', () => { + expect(gulp.tasks.lintTest.done).toBe(true); + }); + }); + }); +}); From 0026b0c3b68428363fc1c0ea45c2b209415703c8 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Tue, 27 Oct 2015 14:44:35 +0100 Subject: [PATCH 19/35] [BT-58]: Improved assets and deploy gulp task collection tests --- src/assets.spec.js | 20 +++++++++++++------- src/deploy.spec.js | 12 +++++++++--- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/assets.spec.js b/src/assets.spec.js index a31ee91..9fd0cc9 100644 --- a/src/assets.spec.js +++ b/src/assets.spec.js @@ -31,12 +31,18 @@ describe('Assets Gulp Task Collection', () => { }).toThrow(); }); - it('can be called without a configuration', () => { - expect(assetsGulpTaskCollection.copy).not.toThrow(); + it('can be called with a valid configuration', () => { + expect(() => { + assetsGulpTaskCollection.copy({ + dst: './dist/assets', + src: [], + taskName: 'assetsTest' + }); + }).not.toThrow(); }); it('registers a gulp task', () => { - expect(gulp.tasks.assets).toBeDefined(); + expect(gulp.tasks.assetsTest).toBeDefined(); }); describe('Copy Gulp Task', () => { @@ -45,17 +51,17 @@ describe('Assets Gulp Task Collection', () => { The provided done function has to be called to proceed and therefore allows to do async operations here runSequence runs gulp tasks in order and accepts a callback as the last - argument which is used to ensure that the assets gulp task finished - before assertions are evaluated + argument which is used to ensure that the gulp task finished before + assertions are evaluated */ runSequence( - 'assets', + 'assetsTest', done ); }); it('can be executed', () => { - expect(gulp.tasks.assets.done).toBe(true); + expect(gulp.tasks.assetsTest.done).toBe(true); }); }); }); diff --git a/src/deploy.spec.js b/src/deploy.spec.js index b19220a..58d5305 100644 --- a/src/deploy.spec.js +++ b/src/deploy.spec.js @@ -24,12 +24,18 @@ describe('Deploy Gulp Task Collection', () => { }).toThrow(); }); - it('can be called without a configuration', () => { - expect(deployGulpTaskCollection.awsS3).not.toThrow(); + it('can be called with a valid configuration', () => { + expect(() => { + deployGulpTaskCollection.awsS3({ + bucketEnv: 'AWS_S3_BUCKET', + src: './dist/**/*.*', + taskName: 'deployTest' + }); + }).not.toThrow(); }); it('registers a gulp task', () => { - expect(gulp.tasks.deploy).toBeDefined(); + expect(gulp.tasks.deployTest).toBeDefined(); }); }); }); From 6f82e060a3b7a1a4759b9953933a42c4c05e87dc Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Tue, 27 Oct 2015 14:56:34 +0100 Subject: [PATCH 20/35] [BT-58]: Added tests for local web server gulp task collection --- src/localwebserver.spec.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/localwebserver.spec.js diff --git a/src/localwebserver.spec.js b/src/localwebserver.spec.js new file mode 100644 index 0000000..1902004 --- /dev/null +++ b/src/localwebserver.spec.js @@ -0,0 +1,27 @@ + +describe('Local Web Server Gulp Task Collection', () => { + var gulp = require('gulp'); + var localWebServerGulpTaskCollection = require('./localwebserver.js'); + + it('can be imported', () => { + expect(localWebServerGulpTaskCollection).toBeDefined(); + }); + + describe('Connect Gulp Task Declaration', () => { + it('is defined', () => { + expect(localWebServerGulpTaskCollection.connect).toBeDefined(); + }); + + it('can be called with a valid configuration', () => { + expect(() => { + localWebServerGulpTaskCollection.connect({ + taskName: 'localWebServerTest' + }); + }).not.toThrow(); + }); + + it('registers a gulp task', () => { + expect(gulp.tasks.localWebServerTest).toBeDefined(); + }); + }); +}); From 7347e9e8777382c99eec2ae6e79e3967875374cd Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Tue, 27 Oct 2015 15:32:20 +0100 Subject: [PATCH 21/35] [BT-58]: Improved scripts gulp task collection with tests --- package.json | 14 +++++++-- src/scripts.js | 10 ++++++- src/scripts.spec.js | 73 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 src/scripts.spec.js diff --git a/package.json b/package.json index 28b5220..0ebb5c1 100644 --- a/package.json +++ b/package.json @@ -8,17 +8,25 @@ }, "devDependencies": { "babel-eslint": "4.1.3", + "babelify": "6.4.0", + "browserify": "12.0.0", + "browserify-hmr": "0.3.1", "eslint": "1.7.1", "eslint-config-airbnb-es5": "1.0.8", "eslint-plugin-react": "3.6.2", "gulp": "3.9.0", - "gulp-awspublish": "^3.0.1", + "gulp-awspublish": "3.0.1", "gulp-connect": "2.2.0", "gulp-eslint": "1.0.0", "gulp-jasmine": "2.1.0", - "minimist": "^1.2.0", + "gulp-rename": "1.2.2", + "gulp-uglify": "1.4.2", + "gulp-util": "3.0.7", + "minimist": "1.2.0", "pre-commit": "1.1.1", - "run-sequence": "1.1.4" + "run-sequence": "1.1.4", + "vinyl-source-stream": "1.1.0", + "watchify": "3.5.0" }, "pre-commit": [ "test" diff --git a/src/scripts.js b/src/scripts.js index fe9d55c..9c4d9e2 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -16,9 +16,13 @@ module.exports.browserifyAndWatchify = (config) => { var BROWSERIFY_CONFIG = {}; var SCRIPTS_CONFIG = config || { dst: './dist/js', - src: '' + src: './src/index.js' }; + if (!SCRIPTS_CONFIG.dst || !SCRIPTS_CONFIG.src) { + throw new Error('Invalid configuration'); + } + var bundleUsingBrowserify = (withWatchify) => { /* Watchify, a watch mode for browserify builds, will be enabled if @@ -86,6 +90,10 @@ module.exports.uglify = (config) => { src: './dist/js' }; + if (!SCRIPTS_CONFIG.src) { + throw new Error('Invalid configuration'); + } + gulp.task((SCRIPTS_CONFIG.taskName || 'minifyScripts'), () => { return gulp.src((SCRIPTS_CONFIG.src + '/dist.js')) .pipe(gulpUglify({ diff --git a/src/scripts.spec.js b/src/scripts.spec.js new file mode 100644 index 0000000..4423261 --- /dev/null +++ b/src/scripts.spec.js @@ -0,0 +1,73 @@ + +describe('Scripts Gulp Task Collection', () => { + var gulp = require('gulp'); + var scriptsGulpTaskCollection = require('./scripts.js'); + + it('can be imported', () => { + expect(scriptsGulpTaskCollection).toBeDefined(); + }); + + describe('Browserify/Watchify Gulp Task Declaration', () => { + it('is defined', () => { + expect(scriptsGulpTaskCollection.browserifyAndWatchify).toBeDefined(); + }); + + it('can not be called with an invalid configuration', () => { + expect(() => { + return scriptsGulpTaskCollection.browserifyAndWatchify({}); + }).toThrow(); + + expect(() => { + return scriptsGulpTaskCollection.browserifyAndWatchify({ + dst: './dist/js' + }); + }).toThrow(); + + expect(() => { + return scriptsGulpTaskCollection.browserifyAndWatchify({ + src: './src/index.js' + }); + }).toThrow(); + }); + + it('can be called with a valid configuration', () => { + expect(() => { + scriptsGulpTaskCollection.browserifyAndWatchify({ + dst: './dist/js', + src: './src/index.js', + taskName: 'scriptsTest' + }); + }).not.toThrow(); + }); + + it('registers two gulp tasks', () => { + expect(gulp.tasks.scriptsTest).toBeDefined(); + expect(gulp.tasks.scriptsTestThenWatch).toBeDefined(); + }); + }); + + describe('Uglify Gulp Task Declaration', () => { + it('is defined', () => { + expect(scriptsGulpTaskCollection.uglify).toBeDefined(); + }); + + it('can not be called with an invalid configuration', () => { + expect(() => { + return scriptsGulpTaskCollection.uglify({}); + }).toThrow(); + }); + + it('can be called with a valid configuration', () => { + expect(() => { + scriptsGulpTaskCollection.uglify({ + src: './dist/js', + taskName: 'minifyScriptsTest' + }); + }).not.toThrow(); + }); + + it('registers a gulp task', () => { + expect(gulp.tasks.minifyScriptsTest).toBeDefined(); + }); + }); +}); From 3f79bfc578e64cb60ff7bb02c637e081f3e137b0 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Tue, 27 Oct 2015 15:33:31 +0100 Subject: [PATCH 22/35] [BT-58]: Improved assets and lint gulp task collection default configurations --- src/assets.js | 4 +++- src/assets.spec.js | 8 ++++++-- src/lint.js | 4 +++- src/lint.spec.js | 4 +++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/assets.js b/src/assets.js index 748c3dc..039deba 100644 --- a/src/assets.js +++ b/src/assets.js @@ -10,7 +10,9 @@ module.exports.copy = (config) => { var ASSETS_CONFIG = config || { dst: './dist/assets', - src: [] + src: [ + './src/assets/**/*' + ] }; if (!ASSETS_CONFIG.dst || !ASSETS_CONFIG.src) { diff --git a/src/assets.spec.js b/src/assets.spec.js index 9fd0cc9..23e2398 100644 --- a/src/assets.spec.js +++ b/src/assets.spec.js @@ -26,7 +26,9 @@ describe('Assets Gulp Task Collection', () => { expect(() => { return assetsGulpTaskCollection.copy({ - src: [] + src: [ + './src/assets/**/*' + ] }); }).toThrow(); }); @@ -35,7 +37,9 @@ describe('Assets Gulp Task Collection', () => { expect(() => { assetsGulpTaskCollection.copy({ dst: './dist/assets', - src: [], + src: [ + './src/assets/**/*' + ], taskName: 'assetsTest' }); }).not.toThrow(); diff --git a/src/lint.js b/src/lint.js index 072e0b9..8b5b7cd 100644 --- a/src/lint.js +++ b/src/lint.js @@ -9,7 +9,9 @@ module.exports.eslint = (config) => { var gulpEslint = require('gulp-eslint'); var LINT_CONFIG = config || { - src: [] + src: [ + './src/**/*.js' + ] }; if (!LINT_CONFIG.src) { diff --git a/src/lint.spec.js b/src/lint.spec.js index 0db9c84..92323fd 100644 --- a/src/lint.spec.js +++ b/src/lint.spec.js @@ -22,7 +22,9 @@ describe('Lint Gulp Task Collection', () => { it('can be called with a valid configuration', () => { expect(() => { lintGulpTaskCollection.eslint({ - src: [], + src: [ + './src/**/*.js' + ], taskName: 'lintTest' }); }).not.toThrow(); From 60572265ec43b35f3ca33c8e1e7033e72a1fee30 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Tue, 27 Oct 2015 15:34:00 +0100 Subject: [PATCH 23/35] Removed unneeded var in Gulpfile --- Gulpfile.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Gulpfile.js b/Gulpfile.js index e3e9b13..14da8c6 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -3,10 +3,11 @@ var gulp = require('gulp'); var gulpJasmine = require('gulp-jasmine'); var lintGulpTaskCollection = require('./src/lint'); -var LINT_SRC = './**/*.js'; - lintGulpTaskCollection.eslint({ - src: LINT_SRC + src: [ + './*.js', + './src/**/*.js' + ] }); gulp.task('test', ['lint'], () => { From 6e391b353f4ecffc44b56a9964f8f99c7421bbde Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Tue, 27 Oct 2015 16:01:21 +0100 Subject: [PATCH 24/35] [BT-58]: Improved styles gulp task collection with tests --- package.json | 8 +++++ src/styles.js | 28 ++++++++++------ src/styles.spec.js | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 src/styles.spec.js diff --git a/package.json b/package.json index 0ebb5c1..835bfe7 100644 --- a/package.json +++ b/package.json @@ -7,19 +7,27 @@ "test": "gulp" }, "devDependencies": { + "autoprefixer": "6.0.3", "babel-eslint": "4.1.3", "babelify": "6.4.0", "browserify": "12.0.0", "browserify-hmr": "0.3.1", + "css-mqpacker": "4.0.0", + "del": "2.0.2", "eslint": "1.7.1", "eslint-config-airbnb-es5": "1.0.8", "eslint-plugin-react": "3.6.2", "gulp": "3.9.0", "gulp-awspublish": "3.0.1", + "gulp-compass": "2.1.0", "gulp-connect": "2.2.0", + "gulp-cssmin": "0.1.7", "gulp-eslint": "1.0.0", + "gulp-jade": "1.1.0", "gulp-jasmine": "2.1.0", + "gulp-postcss": "6.0.1", "gulp-rename": "1.2.2", + "gulp-replace": "0.5.4", "gulp-uglify": "1.4.2", "gulp-util": "3.0.7", "minimist": "1.2.0", diff --git a/src/styles.js b/src/styles.js index 04fed49..6387ad3 100644 --- a/src/styles.js +++ b/src/styles.js @@ -18,10 +18,16 @@ module.exports.compassAndPostcss = (config) => { var STYLES_CONFIG = config || { dst: './dist/css', - src: [] + src: [ + './src/**/*.scss' + ] }; - gulp.task('compass', () => { + if (!STYLES_CONFIG.dst || !STYLES_CONFIG.src) { + throw new Error('Invalid configuration'); + } + + gulp.task(((STYLES_CONFIG.taskName || 'styles') + ':compass'), () => { return gulp.src(STYLES_CONFIG.src) .pipe(gulpCompass({ css: STYLES_CONFIG.dst, @@ -35,7 +41,7 @@ module.exports.compassAndPostcss = (config) => { .pipe(gulp.dest(STYLES_CONFIG.dst)); }); - gulp.task('postCss', () => { + gulp.task(((STYLES_CONFIG.taskName || 'styles') + ':postCss'), () => { return gulp.src((STYLES_CONFIG.dst + '/index.css')) .pipe(gulpPostcss([ autoprefixer({ @@ -46,7 +52,7 @@ module.exports.compassAndPostcss = (config) => { .pipe(gulp.dest(STYLES_CONFIG.dst)); }); - gulp.task('renameDstIndexCss', () => { + gulp.task(((STYLES_CONFIG.taskName || 'styles') + ':renameDstIndexCss'), () => { return gulp.src((STYLES_CONFIG.dst + '/*')) // Replace occurences of index.css with dist.css inside of files .pipe(gulpReplace('index.css', 'dist.css')) @@ -58,7 +64,7 @@ module.exports.compassAndPostcss = (config) => { .pipe(gulpConnect.reload()); }); - gulp.task('deleteDstIndexCss', () => { + gulp.task(((STYLES_CONFIG.taskName || 'styles') + ':deleteDstIndexCss'), () => { return del([ (STYLES_CONFIG.dst + '/index.css'), (STYLES_CONFIG.dst + '/index.css.map') @@ -67,10 +73,10 @@ module.exports.compassAndPostcss = (config) => { gulp.task((STYLES_CONFIG.taskName || 'styles'), (callback) => { runSequence( - 'compass', - 'postCss', - 'renameDstIndexCss', - 'deleteDstIndexCss', + ((STYLES_CONFIG.taskName || 'styles') + ':compass'), + ((STYLES_CONFIG.taskName || 'styles') + ':postCss'), + ((STYLES_CONFIG.taskName || 'styles') + ':renameDstIndexCss'), + ((STYLES_CONFIG.taskName || 'styles') + ':deleteDstIndexCss'), callback ); }); @@ -86,6 +92,10 @@ module.exports.cleanCss = (config) => { src: './dist/css' }; + if (!STYLES_CONFIG.src) { + throw new Error('Invalid configuration'); + } + gulp.task((STYLES_CONFIG.taskName || 'minifyStyles'), () => { return gulp.src((STYLES_CONFIG.src + '/dist.css')) .pipe(gulpCssmin()) diff --git a/src/styles.spec.js b/src/styles.spec.js new file mode 100644 index 0000000..6770b79 --- /dev/null +++ b/src/styles.spec.js @@ -0,0 +1,80 @@ + +describe('Styles Gulp Task Collection', () => { + var gulp = require('gulp'); + var stylesGulpTaskCollection = require('./styles.js'); + + it('can be imported', () => { + expect(stylesGulpTaskCollection).toBeDefined(); + }); + + describe('Compass/Postcss Gulp Task Declaration', () => { + it('is defined', () => { + expect(stylesGulpTaskCollection.compassAndPostcss).toBeDefined(); + }); + + it('can not be called with an invalid configuration', () => { + expect(() => { + return stylesGulpTaskCollection.compassAndPostcss({}); + }).toThrow(); + + expect(() => { + return stylesGulpTaskCollection.compassAndPostcss({ + dst: './dist/css' + }); + }).toThrow(); + + expect(() => { + return stylesGulpTaskCollection.compassAndPostcss({ + src: [ + './src/**/*.scss' + ] + }); + }).toThrow(); + }); + + it('can be called with a valid configuration', () => { + expect(() => { + stylesGulpTaskCollection.compassAndPostcss({ + dst: './dist/css', + src: [ + './src/**/*.scss' + ], + taskName: 'stylesTest' + }); + }).not.toThrow(); + }); + + it('registers five gulp tasks', () => { + expect(gulp.tasks.stylesTest).toBeDefined(); + expect(gulp.tasks['stylesTest:compass']).toBeDefined(); + expect(gulp.tasks['stylesTest:postCss']).toBeDefined(); + expect(gulp.tasks['stylesTest:renameDstIndexCss']).toBeDefined(); + expect(gulp.tasks['stylesTest:deleteDstIndexCss']).toBeDefined(); + }); + }); + + describe('clean-css Gulp Task Declaration', () => { + it('is defined', () => { + expect(stylesGulpTaskCollection.cleanCss).toBeDefined(); + }); + + it('can not be called with an invalid configuration', () => { + expect(() => { + return stylesGulpTaskCollection.cleanCss({}); + }).toThrow(); + }); + + it('can be called with a valid configuration', () => { + expect(() => { + stylesGulpTaskCollection.cleanCss({ + src: './dist/css', + taskName: 'minifyStylesTest' + }); + }).not.toThrow(); + }); + + it('registers a gulp task', () => { + expect(gulp.tasks.minifyStylesTest).toBeDefined(); + }); + }); +}); From 957f7818288c988fd0a9a5e420992737594ad837 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Tue, 27 Oct 2015 16:03:31 +0100 Subject: [PATCH 25/35] [BT-58]: Improved templates gulp task collection with tests --- src/templates.js | 8 ++++- src/templates.spec.js | 72 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/templates.spec.js diff --git a/src/templates.js b/src/templates.js index d20150e..2d79481 100644 --- a/src/templates.js +++ b/src/templates.js @@ -11,9 +11,15 @@ module.exports.jade = (config) => { var TEMPLATES_CONFIG = config || { dst: './dist', - src: [] + src: [ + './src/**/*.jade' + ] }; + if (!TEMPLATES_CONFIG.dst || !TEMPLATES_CONFIG.src) { + throw new Error('Invalid configuration'); + } + gulp.task((TEMPLATES_CONFIG.taskName || 'templates'), () => { return gulp.src(TEMPLATES_CONFIG.src) .pipe(gulpJade({ diff --git a/src/templates.spec.js b/src/templates.spec.js new file mode 100644 index 0000000..a071943 --- /dev/null +++ b/src/templates.spec.js @@ -0,0 +1,72 @@ + +describe('Templates Gulp Task Collection', () => { + var gulp = require('gulp'); + var runSequence = require('run-sequence'); + var templatesGulpTaskCollection = require('./templates.js'); + + it('can be imported', () => { + expect(templatesGulpTaskCollection).toBeDefined(); + }); + + describe('Jade Gulp Task Declaration', () => { + it('is defined', () => { + expect(templatesGulpTaskCollection.jade).toBeDefined(); + }); + + it('can not be called with an invalid configuration', () => { + expect(() => { + return templatesGulpTaskCollection.jade({}); + }).toThrow(); + + expect(() => { + return templatesGulpTaskCollection.jade({ + dst: './dist' + }); + }).toThrow(); + + expect(() => { + return templatesGulpTaskCollection.jade({ + src: [ + './src/**/*.jade' + ] + }); + }).toThrow(); + }); + + it('can be called with a valid configuration', () => { + expect(() => { + templatesGulpTaskCollection.jade({ + dst: './dist', + src: [ + './src/**/*.jade' + ], + taskName: 'templatesTest' + }); + }).not.toThrow(); + }); + + it('registers a gulp task', () => { + expect(gulp.tasks.templatesTest).toBeDefined(); + }); + + describe('Jade Gulp Task', () => { + beforeEach((done) => { + /* + The provided done function has to be called to proceed and therefore + allows to do async operations here + runSequence runs gulp tasks in order and accepts a callback as the last + argument which is used to ensure that the gulp task finished before + assertions are evaluated + */ + runSequence( + 'templatesTest', + done + ); + }); + + it('can be executed', () => { + expect(gulp.tasks.templatesTest.done).toBe(true); + }); + }); + }); +}); From af6030a7bbb39684365ab3f1845e8c2f190d7e47 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Tue, 27 Oct 2015 16:04:27 +0100 Subject: [PATCH 26/35] Scripts gulp task collection fix --- src/scripts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts.js b/src/scripts.js index 9c4d9e2..3701446 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -75,7 +75,7 @@ module.exports.browserifyAndWatchify = (config) => { return bundleUsingBrowserify(false); }); - gulp.task(((SCRIPTS_CONFIG.taskName + 'ThenWatch') || 'scriptsThenWatch'), () => { + gulp.task(((SCRIPTS_CONFIG.taskName || 'scripts') + 'ThenWatch'), () => { return bundleUsingBrowserify(true); }); }; From e49827ce8abfb7d2558b4a767d12eedd7572303a Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Tue, 27 Oct 2015 16:33:42 +0100 Subject: [PATCH 27/35] [BT-58]: Improved tests gulp task collection with tests --- package.json | 3 ++ src/tests.js | 39 ++++++++++++---------- src/tests.spec.js | 83 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 17 deletions(-) create mode 100644 src/tests.spec.js diff --git a/package.json b/package.json index 835bfe7..9740451 100644 --- a/package.json +++ b/package.json @@ -19,17 +19,20 @@ "eslint-plugin-react": "3.6.2", "gulp": "3.9.0", "gulp-awspublish": "3.0.1", + "gulp-babel": "5.3.0", "gulp-compass": "2.1.0", "gulp-connect": "2.2.0", "gulp-cssmin": "0.1.7", "gulp-eslint": "1.0.0", "gulp-jade": "1.1.0", "gulp-jasmine": "2.1.0", + "gulp-nightwatch": "0.2.6", "gulp-postcss": "6.0.1", "gulp-rename": "1.2.2", "gulp-replace": "0.5.4", "gulp-uglify": "1.4.2", "gulp-util": "3.0.7", + "karma": "0.13.14", "minimist": "1.2.0", "pre-commit": "1.1.1", "run-sequence": "1.1.4", diff --git a/src/tests.js b/src/tests.js index 982aef5..5d2d36a 100644 --- a/src/tests.js +++ b/src/tests.js @@ -32,36 +32,41 @@ module.exports.nightwatch = (config) => { var runSequence = require('run-sequence'); var NIGHTWATCH_CONFIG = config || { - connect: {}, + connect: { + root: './dist' + }, dir: './e2e/', - shim: '', - wasNightwatchFailing: false + shim: '' }; - gulp.task('e2e:startConnect', () => { + if (!NIGHTWATCH_CONFIG.connect || !NIGHTWATCH_CONFIG.dir || !NIGHTWATCH_CONFIG.shim) { + throw new Error('Invalid configuration'); + } + + gulp.task(((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':startConnect'), () => { gulpConnect.server(NIGHTWATCH_CONFIG.connect); }); - gulp.task('e2e:clean', (callback) => { + gulp.task(((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':clean'), (callback) => { return del([ NIGHTWATCH_CONFIG.dir + 'dist/**/*', NIGHTWATCH_CONFIG.dir + 'dist/' ], callback); }); - gulp.task('e2e:compileTests', () => { + gulp.task(((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':compileTests'), () => { return gulp.src(NIGHTWATCH_CONFIG.dir + 'src/**/*.js') .pipe(gulpBabel()) .pipe(gulp.dest(NIGHTWATCH_CONFIG.dir + 'dist')); }); - gulp.task('e2e:addShim', () => { + gulp.task(((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':addShim'), () => { return gulp.src(['./dist/index.html']) .pipe(gulpReplace(' { + gulp.task(((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':nightwatch'), () => { return gulp.src('') .pipe(gulpNightwatch({ configFile: NIGHTWATCH_CONFIG.dir + 'config/nightwatch.json', @@ -74,25 +79,25 @@ module.exports.nightwatch = (config) => { }); }); - gulp.task('e2e:removeShim', () => { + gulp.task(((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':removeShim'), () => { return gulp.src(['./dist/index.html']) .pipe(gulpReplace((NIGHTWATCH_CONFIG.shim + ' { + gulp.task(((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':stopConnect'), () => { gulpConnect.serverClose(); }); gulp.task((NIGHTWATCH_CONFIG.taskName || 'e2e'), (callback) => { runSequence( - 'e2e:startConnect', - 'e2e:clean', - 'e2e:compileTests', - 'e2e:addShim', - 'e2e:nightwatch', - 'e2e:removeShim', - 'e2e:stopConnect', + ((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':startConnect'), + ((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':clean'), + ((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':compileTests'), + ((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':addShim'), + ((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':nightwatch'), + ((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':removeShim'), + ((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':stopConnect'), (error) => { if (NIGHTWATCH_CONFIG.wasNightwatchFailing) { throw new Error('E2E testing failed'); diff --git a/src/tests.spec.js b/src/tests.spec.js new file mode 100644 index 0000000..97fe22f --- /dev/null +++ b/src/tests.spec.js @@ -0,0 +1,83 @@ + +describe('Tests Gulp Task Collection', () => { + var gulp = require('gulp'); + var testsGulpTaskCollection = require('./tests.js'); + + it('can be imported', () => { + expect(testsGulpTaskCollection).toBeDefined(); + }); + + describe('Karma Gulp Task Declaration', () => { + it('is defined', () => { + expect(testsGulpTaskCollection.karma).toBeDefined(); + }); + + it('can be called with a valid configuration', () => { + expect(() => { + testsGulpTaskCollection.karma({ + taskName: 'unitTest' + }); + }).not.toThrow(); + }); + + it('registers a gulp task', () => { + expect(gulp.tasks.unitTest).toBeDefined(); + }); + }); + + describe('Nightwatch Gulp Task Declaration', () => { + it('is defined', () => { + expect(testsGulpTaskCollection.nightwatch).toBeDefined(); + }); + + it('can not be called with an invalid configuration', () => { + expect(() => { + return testsGulpTaskCollection.nightwatch({}); + }).toThrow(); + + expect(() => { + return testsGulpTaskCollection.nightwatch({ + connect: { + root: './shouldNotExist/dist' + } + }); + }).toThrow(); + + expect(() => { + return testsGulpTaskCollection.nightwatch({ + dir: './shouldNotExist/e2e/' + }); + }).toThrow(); + + expect(() => { + return testsGulpTaskCollection.nightwatch({ + shim: '' + }); + }).toThrow(); + }); + + it('can be called with a valid configuration', () => { + expect(() => { + testsGulpTaskCollection.nightwatch({ + connect: { + root: './shouldNotExist/dist' + }, + dir: './shouldNotExist/e2e/', + shim: '', + taskName: 'e2eTest' + }); + }).not.toThrow(); + }); + + it('registers eight gulp tasks', () => { + expect(gulp.tasks.e2eTest).toBeDefined(); + expect(gulp.tasks['e2eTest:startConnect']).toBeDefined(); + expect(gulp.tasks['e2eTest:clean']).toBeDefined(); + expect(gulp.tasks['e2eTest:compileTests']).toBeDefined(); + expect(gulp.tasks['e2eTest:addShim']).toBeDefined(); + expect(gulp.tasks['e2eTest:nightwatch']).toBeDefined(); + expect(gulp.tasks['e2eTest:removeShim']).toBeDefined(); + expect(gulp.tasks['e2eTest:stopConnect']).toBeDefined(); + }); + }); +}); From 7d386289b1d58250d5bc50af643cc1f329433fa7 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Tue, 27 Oct 2015 16:34:36 +0100 Subject: [PATCH 28/35] [BT-58]: Improved test configurations --- src/assets.spec.js | 8 ++++---- src/deploy.spec.js | 6 +++--- src/lint.spec.js | 2 +- src/scripts.spec.js | 10 +++++----- src/styles.spec.js | 10 +++++----- src/templates.spec.js | 8 ++++---- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/assets.spec.js b/src/assets.spec.js index 23e2398..dc21225 100644 --- a/src/assets.spec.js +++ b/src/assets.spec.js @@ -20,14 +20,14 @@ describe('Assets Gulp Task Collection', () => { expect(() => { return assetsGulpTaskCollection.copy({ - dst: './dist/assets' + dst: './shouldNotExist/dist/assets' }); }).toThrow(); expect(() => { return assetsGulpTaskCollection.copy({ src: [ - './src/assets/**/*' + './shouldNotExist/src/assets/**/*' ] }); }).toThrow(); @@ -36,9 +36,9 @@ describe('Assets Gulp Task Collection', () => { it('can be called with a valid configuration', () => { expect(() => { assetsGulpTaskCollection.copy({ - dst: './dist/assets', + dst: './shouldNotExist/dist/assets', src: [ - './src/assets/**/*' + './shouldNotExist/src/assets/**/*' ], taskName: 'assetsTest' }); diff --git a/src/deploy.spec.js b/src/deploy.spec.js index 58d5305..fee69f9 100644 --- a/src/deploy.spec.js +++ b/src/deploy.spec.js @@ -19,7 +19,7 @@ describe('Deploy Gulp Task Collection', () => { expect(() => { return deployGulpTaskCollection.awsS3({ - bucketEnv: 'AWS_S3_BUCKET' + bucketEnv: 'SHOULD_NOT_EXIST' }); }).toThrow(); }); @@ -27,8 +27,8 @@ describe('Deploy Gulp Task Collection', () => { it('can be called with a valid configuration', () => { expect(() => { deployGulpTaskCollection.awsS3({ - bucketEnv: 'AWS_S3_BUCKET', - src: './dist/**/*.*', + bucketEnv: 'SHOULD_NOT_EXIST', + src: './shouldNotExist/dist/**/*.*', taskName: 'deployTest' }); }).not.toThrow(); diff --git a/src/lint.spec.js b/src/lint.spec.js index 92323fd..c6bf6a6 100644 --- a/src/lint.spec.js +++ b/src/lint.spec.js @@ -23,7 +23,7 @@ describe('Lint Gulp Task Collection', () => { expect(() => { lintGulpTaskCollection.eslint({ src: [ - './src/**/*.js' + './shouldNotExist/src/**/*.js' ], taskName: 'lintTest' }); diff --git a/src/scripts.spec.js b/src/scripts.spec.js index 4423261..79ccdfd 100644 --- a/src/scripts.spec.js +++ b/src/scripts.spec.js @@ -19,13 +19,13 @@ describe('Scripts Gulp Task Collection', () => { expect(() => { return scriptsGulpTaskCollection.browserifyAndWatchify({ - dst: './dist/js' + dst: './shouldNotExist/dist/js' }); }).toThrow(); expect(() => { return scriptsGulpTaskCollection.browserifyAndWatchify({ - src: './src/index.js' + src: './shouldNotExist/src/index.js' }); }).toThrow(); }); @@ -33,8 +33,8 @@ describe('Scripts Gulp Task Collection', () => { it('can be called with a valid configuration', () => { expect(() => { scriptsGulpTaskCollection.browserifyAndWatchify({ - dst: './dist/js', - src: './src/index.js', + dst: './shouldNotExist/dist/js', + src: './shouldNotExist/src/index.js', taskName: 'scriptsTest' }); }).not.toThrow(); @@ -60,7 +60,7 @@ describe('Scripts Gulp Task Collection', () => { it('can be called with a valid configuration', () => { expect(() => { scriptsGulpTaskCollection.uglify({ - src: './dist/js', + src: './shouldNotExist/dist/js', taskName: 'minifyScriptsTest' }); }).not.toThrow(); diff --git a/src/styles.spec.js b/src/styles.spec.js index 6770b79..99d4485 100644 --- a/src/styles.spec.js +++ b/src/styles.spec.js @@ -19,14 +19,14 @@ describe('Styles Gulp Task Collection', () => { expect(() => { return stylesGulpTaskCollection.compassAndPostcss({ - dst: './dist/css' + dst: './shouldNotExist/dist/css' }); }).toThrow(); expect(() => { return stylesGulpTaskCollection.compassAndPostcss({ src: [ - './src/**/*.scss' + './shouldNotExist/src/**/*.scss' ] }); }).toThrow(); @@ -35,9 +35,9 @@ describe('Styles Gulp Task Collection', () => { it('can be called with a valid configuration', () => { expect(() => { stylesGulpTaskCollection.compassAndPostcss({ - dst: './dist/css', + dst: './shouldNotExist/dist/css', src: [ - './src/**/*.scss' + './shouldNotExist/src/**/*.scss' ], taskName: 'stylesTest' }); @@ -67,7 +67,7 @@ describe('Styles Gulp Task Collection', () => { it('can be called with a valid configuration', () => { expect(() => { stylesGulpTaskCollection.cleanCss({ - src: './dist/css', + src: './shouldNotExist/dist/css', taskName: 'minifyStylesTest' }); }).not.toThrow(); diff --git a/src/templates.spec.js b/src/templates.spec.js index a071943..c7395d1 100644 --- a/src/templates.spec.js +++ b/src/templates.spec.js @@ -20,14 +20,14 @@ describe('Templates Gulp Task Collection', () => { expect(() => { return templatesGulpTaskCollection.jade({ - dst: './dist' + dst: './shouldNotExist/dist' }); }).toThrow(); expect(() => { return templatesGulpTaskCollection.jade({ src: [ - './src/**/*.jade' + './shouldNotExist/src/**/*.jade' ] }); }).toThrow(); @@ -36,9 +36,9 @@ describe('Templates Gulp Task Collection', () => { it('can be called with a valid configuration', () => { expect(() => { templatesGulpTaskCollection.jade({ - dst: './dist', + dst: './shouldNotExist/dist', src: [ - './src/**/*.jade' + './shouldNotExist/src/**/*.jade' ], taskName: 'templatesTest' }); From e094fe2c4636ed6c9aaec0f4e5850e00aa19ffb8 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Wed, 28 Oct 2015 14:53:46 +0100 Subject: [PATCH 29/35] [BT-58]: Implemented PR feedback: Object.assign for configurations, more specific error messages and tests, improved variable naming --- src/assets.js | 13 ++++---- src/assets.spec.js | 32 +++++++------------ src/deploy.js | 11 ++++--- src/deploy.spec.js | 22 ++++++------- src/lint.js | 13 ++++---- src/lint.spec.js | 22 ++++++------- src/localwebserver.js | 6 ++-- src/localwebserver.spec.js | 14 ++++---- src/scripts.js | 24 +++++++------- src/scripts.spec.js | 36 ++++++++++----------- src/styles.js | 44 +++++++++++++------------- src/styles.spec.js | 42 +++++++++++------------- src/templates.js | 13 ++++---- src/templates.spec.js | 32 +++++++------------ src/tests.js | 65 ++++++++++++++++++++++---------------- src/tests.spec.js | 40 ++++++++--------------- 16 files changed, 200 insertions(+), 229 deletions(-) diff --git a/src/assets.js b/src/assets.js index 039deba..c7bc486 100644 --- a/src/assets.js +++ b/src/assets.js @@ -8,18 +8,17 @@ module.exports.copy = (config) => { var gulp = require('gulp'); var gulpConnect = require('gulp-connect'); - var ASSETS_CONFIG = config || { + var ASSETS_CONFIG = Object.assign({ dst: './dist/assets', - src: [ - './src/assets/**/*' - ] - }; + src: './src/assets/**/*', + taskName: 'assets' + }, config); if (!ASSETS_CONFIG.dst || !ASSETS_CONFIG.src) { - throw new Error('Invalid configuration'); + throw new Error('Invalid configuration: value of dst needs to be a path and value of src needs to be a glob or an array of globs.'); } - gulp.task((ASSETS_CONFIG.taskName || 'assets'), () => { + gulp.task(ASSETS_CONFIG.taskName, () => { return gulp .src(ASSETS_CONFIG.src) .pipe(gulp.dest(ASSETS_CONFIG.dst)) diff --git a/src/assets.spec.js b/src/assets.spec.js index dc21225..bc71408 100644 --- a/src/assets.spec.js +++ b/src/assets.spec.js @@ -1,45 +1,37 @@ -describe('Assets Gulp Task Collection', () => { - var assetsGulpTaskCollection = require('./assets.js'); +describe('Assets Gulp Task Module', () => { + var assets = require('./assets.js'); var gulp = require('gulp'); var runSequence = require('run-sequence'); - it('can be imported', () => { - expect(assetsGulpTaskCollection).toBeDefined(); + it('is an object', () => { + expect(typeof assets).toBe('object'); }); describe('Copy Gulp Task Declaration', () => { - it('is defined', () => { - expect(assetsGulpTaskCollection.copy).toBeDefined(); + it('is a function', () => { + expect(typeof assets.copy).toBe('function'); }); it('can not be called with an invalid configuration', () => { expect(() => { - return assetsGulpTaskCollection.copy({}); - }).toThrow(); - - expect(() => { - return assetsGulpTaskCollection.copy({ - dst: './shouldNotExist/dist/assets' + return assets.copy({ + dst: false }); }).toThrow(); expect(() => { - return assetsGulpTaskCollection.copy({ - src: [ - './shouldNotExist/src/assets/**/*' - ] + return assets.copy({ + src: false }); }).toThrow(); }); it('can be called with a valid configuration', () => { expect(() => { - assetsGulpTaskCollection.copy({ + assets.copy({ dst: './shouldNotExist/dist/assets', - src: [ - './shouldNotExist/src/assets/**/*' - ], + src: './shouldNotExist/src/assets/**/*', taskName: 'assetsTest' }); }).not.toThrow(); diff --git a/src/deploy.js b/src/deploy.js index cf821f8..a6c0ff9 100644 --- a/src/deploy.js +++ b/src/deploy.js @@ -9,16 +9,17 @@ module.exports.awsS3 = (config) => { var gulpAwspublish = require('gulp-awspublish'); var minimist = require('minimist'); - var DEPLOY_CONFIG = config || { + var DEPLOY_CONFIG = Object.assign({ bucketEnv: 'AWS_S3_BUCKET', - src: './dist/**/*.*' - }; + src: './dist/**/*.*', + taskName: 'deploy' + }, config); if (!DEPLOY_CONFIG.src) { - throw new Error('Invalid configuration'); + throw new Error('Invalid configuration: value of src needs to be a glob or an array of globs.'); } - gulp.task((DEPLOY_CONFIG.taskName || 'deploy'), () => { + gulp.task(DEPLOY_CONFIG.taskName, () => { /* To manually deploy the working copy the following command can be used: gulp deploy --accessKeyId=XXX --bucket=XXX --secretAccessKey=XXX diff --git a/src/deploy.spec.js b/src/deploy.spec.js index fee69f9..ff839df 100644 --- a/src/deploy.spec.js +++ b/src/deploy.spec.js @@ -1,32 +1,28 @@ -describe('Deploy Gulp Task Collection', () => { - var deployGulpTaskCollection = require('./deploy.js'); +describe('Deploy Gulp Task Module', () => { + var deploy = require('./deploy.js'); var gulp = require('gulp'); - it('can be imported', () => { - expect(deployGulpTaskCollection).toBeDefined(); + it('is an object', () => { + expect(typeof deploy).toBe('object'); }); describe('AWS S3 Gulp Task Declaration', () => { - it('is defined', () => { - expect(deployGulpTaskCollection.awsS3).toBeDefined(); + it('is a function', () => { + expect(typeof deploy.awsS3).toBe('function'); }); it('can not be called with an invalid configuration', () => { expect(() => { - return deployGulpTaskCollection.awsS3({}); - }).toThrow(); - - expect(() => { - return deployGulpTaskCollection.awsS3({ - bucketEnv: 'SHOULD_NOT_EXIST' + return deploy.awsS3({ + src: false }); }).toThrow(); }); it('can be called with a valid configuration', () => { expect(() => { - deployGulpTaskCollection.awsS3({ + deploy.awsS3({ bucketEnv: 'SHOULD_NOT_EXIST', src: './shouldNotExist/dist/**/*.*', taskName: 'deployTest' diff --git a/src/lint.js b/src/lint.js index 8b5b7cd..f736e35 100644 --- a/src/lint.js +++ b/src/lint.js @@ -8,17 +8,16 @@ module.exports.eslint = (config) => { var gulp = require('gulp'); var gulpEslint = require('gulp-eslint'); - var LINT_CONFIG = config || { - src: [ - './src/**/*.js' - ] - }; + var LINT_CONFIG = Object.assign({ + src: './src/**/*.js', + taskName: 'lint' + }, config); if (!LINT_CONFIG.src) { - throw new Error('Invalid configuration'); + throw new Error('Invalid configuration: value of src needs to be a glob or an array of globs.'); } - gulp.task((LINT_CONFIG.taskName || 'lint'), () => { + gulp.task(LINT_CONFIG.taskName, () => { return gulp.src(LINT_CONFIG.src) .pipe(gulpEslint()) .pipe(gulpEslint.format()) diff --git a/src/lint.spec.js b/src/lint.spec.js index c6bf6a6..a22c6d4 100644 --- a/src/lint.spec.js +++ b/src/lint.spec.js @@ -1,30 +1,30 @@ -describe('Lint Gulp Task Collection', () => { +describe('Lint Gulp Task Module', () => { var gulp = require('gulp'); - var lintGulpTaskCollection = require('./lint.js'); + var lint = require('./lint.js'); var runSequence = require('run-sequence'); - it('can be imported', () => { - expect(lintGulpTaskCollection).toBeDefined(); + it('is an object', () => { + expect(typeof lint).toBe('object'); }); describe('ESLint Gulp Task Declaration', () => { - it('is defined', () => { - expect(lintGulpTaskCollection.eslint).toBeDefined(); + it('is a function', () => { + expect(typeof lint.eslint).toBe('function'); }); it('can not be called with an invalid configuration', () => { expect(() => { - return lintGulpTaskCollection.eslint({}); + return lint.eslint({ + src: false + }); }).toThrow(); }); it('can be called with a valid configuration', () => { expect(() => { - lintGulpTaskCollection.eslint({ - src: [ - './shouldNotExist/src/**/*.js' - ], + lint.eslint({ + src: './shouldNotExist/src/**/*.js', taskName: 'lintTest' }); }).not.toThrow(); diff --git a/src/localwebserver.js b/src/localwebserver.js index 128f8c8..14d111c 100644 --- a/src/localwebserver.js +++ b/src/localwebserver.js @@ -8,9 +8,11 @@ module.exports.connect = (config) => { var gulp = require('gulp'); var gulpConnect = require('gulp-connect'); - var CONNECT_CONFIG = config || {}; + var CONNECT_CONFIG = Object.assign({ + taskName: 'serveLocally' + }, config); - gulp.task((CONNECT_CONFIG.taskName || 'serveLocally'), () => { + gulp.task(CONNECT_CONFIG.taskName, () => { gulpConnect.server(CONNECT_CONFIG); }); }; diff --git a/src/localwebserver.spec.js b/src/localwebserver.spec.js index 1902004..4e9c7bd 100644 --- a/src/localwebserver.spec.js +++ b/src/localwebserver.spec.js @@ -1,20 +1,20 @@ -describe('Local Web Server Gulp Task Collection', () => { +describe('Local Web Server Gulp Task Module', () => { var gulp = require('gulp'); - var localWebServerGulpTaskCollection = require('./localwebserver.js'); + var localWebServer = require('./localwebserver.js'); - it('can be imported', () => { - expect(localWebServerGulpTaskCollection).toBeDefined(); + it('is an object', () => { + expect(typeof localWebServer).toBe('object'); }); describe('Connect Gulp Task Declaration', () => { - it('is defined', () => { - expect(localWebServerGulpTaskCollection.connect).toBeDefined(); + it('is a function', () => { + expect(typeof localWebServer.connect).toBe('function'); }); it('can be called with a valid configuration', () => { expect(() => { - localWebServerGulpTaskCollection.connect({ + localWebServer.connect({ taskName: 'localWebServerTest' }); }).not.toThrow(); diff --git a/src/scripts.js b/src/scripts.js index 3701446..b4e5bf3 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -14,13 +14,14 @@ module.exports.browserifyAndWatchify = (config) => { var watchify = require('watchify'); var BROWSERIFY_CONFIG = {}; - var SCRIPTS_CONFIG = config || { + var SCRIPTS_CONFIG = Object.assign({ dst: './dist/js', - src: './src/index.js' - }; + src: './src/index.js', + taskName: 'scripts' + }, config); if (!SCRIPTS_CONFIG.dst || !SCRIPTS_CONFIG.src) { - throw new Error('Invalid configuration'); + throw new Error('Invalid configuration: value of dst needs to be a path and value of src needs to be a glob or an array of globs.'); } var bundleUsingBrowserify = (withWatchify) => { @@ -71,11 +72,11 @@ module.exports.browserifyAndWatchify = (config) => { return writeScriptsFromBundle(bundler.bundle()); }; - gulp.task((SCRIPTS_CONFIG.taskName || 'scripts'), () => { + gulp.task(SCRIPTS_CONFIG.taskName, () => { return bundleUsingBrowserify(false); }); - gulp.task(((SCRIPTS_CONFIG.taskName || 'scripts') + 'ThenWatch'), () => { + gulp.task((SCRIPTS_CONFIG.taskName + 'ThenWatch'), () => { return bundleUsingBrowserify(true); }); }; @@ -86,15 +87,16 @@ module.exports.uglify = (config) => { var gulpRename = require('gulp-rename'); var gulpUglify = require('gulp-uglify'); - var SCRIPTS_CONFIG = config || { - src: './dist/js' - }; + var SCRIPTS_CONFIG = Object.assign({ + src: './dist/js', + taskName: 'minifyScripts' + }, config); if (!SCRIPTS_CONFIG.src) { - throw new Error('Invalid configuration'); + throw new Error('Invalid configuration: value of src needs to be a glob or an array of globs.'); } - gulp.task((SCRIPTS_CONFIG.taskName || 'minifyScripts'), () => { + gulp.task(SCRIPTS_CONFIG.taskName, () => { return gulp.src((SCRIPTS_CONFIG.src + '/dist.js')) .pipe(gulpUglify({ mangle: true diff --git a/src/scripts.spec.js b/src/scripts.spec.js index 79ccdfd..7e18e89 100644 --- a/src/scripts.spec.js +++ b/src/scripts.spec.js @@ -1,38 +1,34 @@ -describe('Scripts Gulp Task Collection', () => { +describe('Scripts Gulp Task Module', () => { var gulp = require('gulp'); - var scriptsGulpTaskCollection = require('./scripts.js'); + var scripts = require('./scripts.js'); - it('can be imported', () => { - expect(scriptsGulpTaskCollection).toBeDefined(); + it('is an object', () => { + expect(typeof scripts).toBe('object'); }); describe('Browserify/Watchify Gulp Task Declaration', () => { - it('is defined', () => { - expect(scriptsGulpTaskCollection.browserifyAndWatchify).toBeDefined(); + it('is a function', () => { + expect(typeof scripts.browserifyAndWatchify).toBe('function'); }); it('can not be called with an invalid configuration', () => { expect(() => { - return scriptsGulpTaskCollection.browserifyAndWatchify({}); - }).toThrow(); - - expect(() => { - return scriptsGulpTaskCollection.browserifyAndWatchify({ - dst: './shouldNotExist/dist/js' + return scripts.browserifyAndWatchify({ + dst: false }); }).toThrow(); expect(() => { - return scriptsGulpTaskCollection.browserifyAndWatchify({ - src: './shouldNotExist/src/index.js' + return scripts.browserifyAndWatchify({ + src: false }); }).toThrow(); }); it('can be called with a valid configuration', () => { expect(() => { - scriptsGulpTaskCollection.browserifyAndWatchify({ + scripts.browserifyAndWatchify({ dst: './shouldNotExist/dist/js', src: './shouldNotExist/src/index.js', taskName: 'scriptsTest' @@ -47,19 +43,21 @@ describe('Scripts Gulp Task Collection', () => { }); describe('Uglify Gulp Task Declaration', () => { - it('is defined', () => { - expect(scriptsGulpTaskCollection.uglify).toBeDefined(); + it('is a function', () => { + expect(typeof scripts.uglify).toBe('function'); }); it('can not be called with an invalid configuration', () => { expect(() => { - return scriptsGulpTaskCollection.uglify({}); + return scripts.uglify({ + src: false + }); }).toThrow(); }); it('can be called with a valid configuration', () => { expect(() => { - scriptsGulpTaskCollection.uglify({ + scripts.uglify({ src: './shouldNotExist/dist/js', taskName: 'minifyScriptsTest' }); diff --git a/src/styles.js b/src/styles.js index 6387ad3..c205ada 100644 --- a/src/styles.js +++ b/src/styles.js @@ -16,18 +16,17 @@ module.exports.compassAndPostcss = (config) => { var gulpReplace = require('gulp-replace'); var runSequence = require('run-sequence'); - var STYLES_CONFIG = config || { + var STYLES_CONFIG = Object.assign({ dst: './dist/css', - src: [ - './src/**/*.scss' - ] - }; + src: './src/**/*.scss', + taskName: 'styles' + }, config); if (!STYLES_CONFIG.dst || !STYLES_CONFIG.src) { - throw new Error('Invalid configuration'); + throw new Error('Invalid configuration: value of dst needs to be a path and value of src needs to be a glob or an array of globs.'); } - gulp.task(((STYLES_CONFIG.taskName || 'styles') + ':compass'), () => { + gulp.task((STYLES_CONFIG.taskName + ':compass'), () => { return gulp.src(STYLES_CONFIG.src) .pipe(gulpCompass({ css: STYLES_CONFIG.dst, @@ -41,7 +40,7 @@ module.exports.compassAndPostcss = (config) => { .pipe(gulp.dest(STYLES_CONFIG.dst)); }); - gulp.task(((STYLES_CONFIG.taskName || 'styles') + ':postCss'), () => { + gulp.task((STYLES_CONFIG.taskName + ':postCss'), () => { return gulp.src((STYLES_CONFIG.dst + '/index.css')) .pipe(gulpPostcss([ autoprefixer({ @@ -52,7 +51,7 @@ module.exports.compassAndPostcss = (config) => { .pipe(gulp.dest(STYLES_CONFIG.dst)); }); - gulp.task(((STYLES_CONFIG.taskName || 'styles') + ':renameDstIndexCss'), () => { + gulp.task((STYLES_CONFIG.taskName + ':renameDstIndexCss'), () => { return gulp.src((STYLES_CONFIG.dst + '/*')) // Replace occurences of index.css with dist.css inside of files .pipe(gulpReplace('index.css', 'dist.css')) @@ -64,39 +63,40 @@ module.exports.compassAndPostcss = (config) => { .pipe(gulpConnect.reload()); }); - gulp.task(((STYLES_CONFIG.taskName || 'styles') + ':deleteDstIndexCss'), () => { + gulp.task((STYLES_CONFIG.taskName + ':deleteDstIndexCss'), () => { return del([ (STYLES_CONFIG.dst + '/index.css'), (STYLES_CONFIG.dst + '/index.css.map') ]); }); - gulp.task((STYLES_CONFIG.taskName || 'styles'), (callback) => { + gulp.task(STYLES_CONFIG.taskName, (callback) => { runSequence( - ((STYLES_CONFIG.taskName || 'styles') + ':compass'), - ((STYLES_CONFIG.taskName || 'styles') + ':postCss'), - ((STYLES_CONFIG.taskName || 'styles') + ':renameDstIndexCss'), - ((STYLES_CONFIG.taskName || 'styles') + ':deleteDstIndexCss'), + (STYLES_CONFIG.taskName + ':compass'), + (STYLES_CONFIG.taskName + ':postCss'), + (STYLES_CONFIG.taskName + ':renameDstIndexCss'), + (STYLES_CONFIG.taskName + ':deleteDstIndexCss'), callback ); }); }; -// clean-css -module.exports.cleanCss = (config) => { +// Minifying styles with clean-css +module.exports.minifyCss = (config) => { var gulp = require('gulp'); var gulpCssmin = require('gulp-cssmin'); var gulpRename = require('gulp-rename'); - var STYLES_CONFIG = config || { - src: './dist/css' - }; + var STYLES_CONFIG = Object.assign({ + src: './dist/css', + taskName: 'minifyStyles' + }, config); if (!STYLES_CONFIG.src) { - throw new Error('Invalid configuration'); + throw new Error('Invalid configuration: value of src needs to be a glob or an array of globs.'); } - gulp.task((STYLES_CONFIG.taskName || 'minifyStyles'), () => { + gulp.task(STYLES_CONFIG.taskName, () => { return gulp.src((STYLES_CONFIG.src + '/dist.css')) .pipe(gulpCssmin()) .pipe(gulpRename('dist.min.css')) diff --git a/src/styles.spec.js b/src/styles.spec.js index 99d4485..f7289a6 100644 --- a/src/styles.spec.js +++ b/src/styles.spec.js @@ -1,44 +1,36 @@ -describe('Styles Gulp Task Collection', () => { +describe('Styles Gulp Task Module', () => { var gulp = require('gulp'); - var stylesGulpTaskCollection = require('./styles.js'); + var styles = require('./styles.js'); - it('can be imported', () => { - expect(stylesGulpTaskCollection).toBeDefined(); + it('is an object', () => { + expect(typeof styles).toBe('object'); }); describe('Compass/Postcss Gulp Task Declaration', () => { - it('is defined', () => { - expect(stylesGulpTaskCollection.compassAndPostcss).toBeDefined(); + it('is a function', () => { + expect(typeof styles.compassAndPostcss).toBe('function'); }); it('can not be called with an invalid configuration', () => { expect(() => { - return stylesGulpTaskCollection.compassAndPostcss({}); - }).toThrow(); - - expect(() => { - return stylesGulpTaskCollection.compassAndPostcss({ - dst: './shouldNotExist/dist/css' + return styles.compassAndPostcss({ + dst: false }); }).toThrow(); expect(() => { - return stylesGulpTaskCollection.compassAndPostcss({ - src: [ - './shouldNotExist/src/**/*.scss' - ] + return styles.compassAndPostcss({ + src: false }); }).toThrow(); }); it('can be called with a valid configuration', () => { expect(() => { - stylesGulpTaskCollection.compassAndPostcss({ + styles.compassAndPostcss({ dst: './shouldNotExist/dist/css', - src: [ - './shouldNotExist/src/**/*.scss' - ], + src: './shouldNotExist/src/**/*.scss', taskName: 'stylesTest' }); }).not.toThrow(); @@ -54,19 +46,21 @@ describe('Styles Gulp Task Collection', () => { }); describe('clean-css Gulp Task Declaration', () => { - it('is defined', () => { - expect(stylesGulpTaskCollection.cleanCss).toBeDefined(); + it('is a function', () => { + expect(typeof styles.minifyCss).toBe('function'); }); it('can not be called with an invalid configuration', () => { expect(() => { - return stylesGulpTaskCollection.cleanCss({}); + return styles.minifyCss({ + src: false + }); }).toThrow(); }); it('can be called with a valid configuration', () => { expect(() => { - stylesGulpTaskCollection.cleanCss({ + styles.minifyCss({ src: './shouldNotExist/dist/css', taskName: 'minifyStylesTest' }); diff --git a/src/templates.js b/src/templates.js index 2d79481..a7e407e 100644 --- a/src/templates.js +++ b/src/templates.js @@ -9,18 +9,17 @@ module.exports.jade = (config) => { var gulpConnect = require('gulp-connect'); var gulpJade = require('gulp-jade'); - var TEMPLATES_CONFIG = config || { + var TEMPLATES_CONFIG = Object.assign({ dst: './dist', - src: [ - './src/**/*.jade' - ] - }; + src: './src/**/*.jade', + taskName: 'templates' + }, config); if (!TEMPLATES_CONFIG.dst || !TEMPLATES_CONFIG.src) { - throw new Error('Invalid configuration'); + throw new Error('Invalid configuration: value of dst needs to be a path and value of src needs to be a glob or an array of globs.'); } - gulp.task((TEMPLATES_CONFIG.taskName || 'templates'), () => { + gulp.task(TEMPLATES_CONFIG.taskName, () => { return gulp.src(TEMPLATES_CONFIG.src) .pipe(gulpJade({ locals: { diff --git a/src/templates.spec.js b/src/templates.spec.js index c7395d1..47aaa9f 100644 --- a/src/templates.spec.js +++ b/src/templates.spec.js @@ -1,45 +1,37 @@ -describe('Templates Gulp Task Collection', () => { +describe('Templates Gulp Task Module', () => { var gulp = require('gulp'); var runSequence = require('run-sequence'); - var templatesGulpTaskCollection = require('./templates.js'); + var templates = require('./templates.js'); - it('can be imported', () => { - expect(templatesGulpTaskCollection).toBeDefined(); + it('is an object', () => { + expect(typeof templates).toBe('object'); }); describe('Jade Gulp Task Declaration', () => { - it('is defined', () => { - expect(templatesGulpTaskCollection.jade).toBeDefined(); + it('is a function', () => { + expect(typeof templates.jade).toBe('function'); }); it('can not be called with an invalid configuration', () => { expect(() => { - return templatesGulpTaskCollection.jade({}); - }).toThrow(); - - expect(() => { - return templatesGulpTaskCollection.jade({ - dst: './shouldNotExist/dist' + return templates.jade({ + dst: false }); }).toThrow(); expect(() => { - return templatesGulpTaskCollection.jade({ - src: [ - './shouldNotExist/src/**/*.jade' - ] + return templates.jade({ + src: false }); }).toThrow(); }); it('can be called with a valid configuration', () => { expect(() => { - templatesGulpTaskCollection.jade({ + templates.jade({ dst: './shouldNotExist/dist', - src: [ - './shouldNotExist/src/**/*.jade' - ], + src: './shouldNotExist/src/**/*.jade', taskName: 'templatesTest' }); }).not.toThrow(); diff --git a/src/tests.js b/src/tests.js index 5d2d36a..7ee9734 100644 --- a/src/tests.js +++ b/src/tests.js @@ -8,9 +8,11 @@ module.exports.karma = (config) => { var gulp = require('gulp'); var karmaServer = require('karma').Server; - var KARMA_CONFIG = config || {}; + var KARMA_CONFIG = Object.assign({ + taskName: 'unit' + }, config); - gulp.task((KARMA_CONFIG.taskName || 'unit'), (callback) => { + gulp.task(KARMA_CONFIG.taskName, (callback) => { return karmaServer.start(KARMA_CONFIG, (exitStatus) => { if (exitStatus) { throw new Error('Unit testing failed'); @@ -31,42 +33,46 @@ module.exports.nightwatch = (config) => { var gulpReplace = require('gulp-replace'); var runSequence = require('run-sequence'); - var NIGHTWATCH_CONFIG = config || { + var NIGHTWATCH_CONFIG = Object.assign({ connect: { root: './dist' }, dir: './e2e/', - shim: '' - }; + shim: false, + taskName: 'e2e' + }, config); - if (!NIGHTWATCH_CONFIG.connect || !NIGHTWATCH_CONFIG.dir || !NIGHTWATCH_CONFIG.shim) { - throw new Error('Invalid configuration'); + if (!NIGHTWATCH_CONFIG.connect || !NIGHTWATCH_CONFIG.dir) { + throw new Error('Invalid configuration: value of connect needs to be an object and value of dir needs to be a path.'); } - gulp.task(((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':startConnect'), () => { + gulp.task((NIGHTWATCH_CONFIG.taskName + ':startConnect'), () => { gulpConnect.server(NIGHTWATCH_CONFIG.connect); }); - gulp.task(((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':clean'), (callback) => { + gulp.task((NIGHTWATCH_CONFIG.taskName + ':clean'), (callback) => { return del([ NIGHTWATCH_CONFIG.dir + 'dist/**/*', NIGHTWATCH_CONFIG.dir + 'dist/' ], callback); }); - gulp.task(((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':compileTests'), () => { + gulp.task((NIGHTWATCH_CONFIG.taskName + ':compileTests'), () => { return gulp.src(NIGHTWATCH_CONFIG.dir + 'src/**/*.js') .pipe(gulpBabel()) .pipe(gulp.dest(NIGHTWATCH_CONFIG.dir + 'dist')); }); - gulp.task(((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':addShim'), () => { - return gulp.src(['./dist/index.html']) - .pipe(gulpReplace(' { + if (NIGHTWATCH_CONFIG.shim) { + return gulp.src(['./dist/index.html']) + .pipe(gulpReplace(' { + gulp.task((NIGHTWATCH_CONFIG.taskName + ':nightwatch'), () => { return gulp.src('') .pipe(gulpNightwatch({ configFile: NIGHTWATCH_CONFIG.dir + 'config/nightwatch.json', @@ -79,25 +85,28 @@ module.exports.nightwatch = (config) => { }); }); - gulp.task(((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':removeShim'), () => { - return gulp.src(['./dist/index.html']) - .pipe(gulpReplace((NIGHTWATCH_CONFIG.shim + ' { + if (NIGHTWATCH_CONFIG.shim) { + return gulp.src(['./dist/index.html']) + .pipe(gulpReplace((NIGHTWATCH_CONFIG.shim + ' { + gulp.task((NIGHTWATCH_CONFIG.taskName + ':stopConnect'), () => { gulpConnect.serverClose(); }); - gulp.task((NIGHTWATCH_CONFIG.taskName || 'e2e'), (callback) => { + gulp.task(NIGHTWATCH_CONFIG.taskName, (callback) => { runSequence( - ((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':startConnect'), - ((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':clean'), - ((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':compileTests'), - ((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':addShim'), - ((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':nightwatch'), - ((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':removeShim'), - ((NIGHTWATCH_CONFIG.taskName || 'e2e') + ':stopConnect'), + (NIGHTWATCH_CONFIG.taskName + ':startConnect'), + (NIGHTWATCH_CONFIG.taskName + ':clean'), + (NIGHTWATCH_CONFIG.taskName + ':compileTests'), + (NIGHTWATCH_CONFIG.taskName + ':addShim'), + (NIGHTWATCH_CONFIG.taskName + ':nightwatch'), + (NIGHTWATCH_CONFIG.taskName + ':removeShim'), + (NIGHTWATCH_CONFIG.taskName + ':stopConnect'), (error) => { if (NIGHTWATCH_CONFIG.wasNightwatchFailing) { throw new Error('E2E testing failed'); diff --git a/src/tests.spec.js b/src/tests.spec.js index 97fe22f..adccf36 100644 --- a/src/tests.spec.js +++ b/src/tests.spec.js @@ -1,20 +1,20 @@ -describe('Tests Gulp Task Collection', () => { +describe('Tests Gulp Task Module', () => { var gulp = require('gulp'); - var testsGulpTaskCollection = require('./tests.js'); + var tests = require('./tests.js'); - it('can be imported', () => { - expect(testsGulpTaskCollection).toBeDefined(); + it('is an object', () => { + expect(typeof tests).toBe('object'); }); describe('Karma Gulp Task Declaration', () => { - it('is defined', () => { - expect(testsGulpTaskCollection.karma).toBeDefined(); + it('is a function', () => { + expect(typeof tests.karma).toBe('function'); }); it('can be called with a valid configuration', () => { expect(() => { - testsGulpTaskCollection.karma({ + tests.karma({ taskName: 'unitTest' }); }).not.toThrow(); @@ -26,39 +26,27 @@ describe('Tests Gulp Task Collection', () => { }); describe('Nightwatch Gulp Task Declaration', () => { - it('is defined', () => { - expect(testsGulpTaskCollection.nightwatch).toBeDefined(); + it('is a function', () => { + expect(typeof tests.nightwatch).toBe('function'); }); it('can not be called with an invalid configuration', () => { expect(() => { - return testsGulpTaskCollection.nightwatch({}); - }).toThrow(); - - expect(() => { - return testsGulpTaskCollection.nightwatch({ - connect: { - root: './shouldNotExist/dist' - } - }); - }).toThrow(); - - expect(() => { - return testsGulpTaskCollection.nightwatch({ - dir: './shouldNotExist/e2e/' + return tests.nightwatch({ + connect: false }); }).toThrow(); expect(() => { - return testsGulpTaskCollection.nightwatch({ - shim: '' + return tests.nightwatch({ + dir: false }); }).toThrow(); }); it('can be called with a valid configuration', () => { expect(() => { - testsGulpTaskCollection.nightwatch({ + tests.nightwatch({ connect: { root: './shouldNotExist/dist' }, From 6d26071bd80ab863c928049ca9b9d0a15a0a30dd Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Wed, 28 Oct 2015 15:01:43 +0100 Subject: [PATCH 30/35] [BT-58]: More PR feedback: localwebserver.* -> localWebServer.* --- src/{localwebserver.js => localWebServer.js} | 0 src/{localwebserver.spec.js => localWebServer.spec.js} | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename src/{localwebserver.js => localWebServer.js} (100%) rename src/{localwebserver.spec.js => localWebServer.spec.js} (92%) diff --git a/src/localwebserver.js b/src/localWebServer.js similarity index 100% rename from src/localwebserver.js rename to src/localWebServer.js diff --git a/src/localwebserver.spec.js b/src/localWebServer.spec.js similarity index 92% rename from src/localwebserver.spec.js rename to src/localWebServer.spec.js index 4e9c7bd..5fc66c6 100644 --- a/src/localwebserver.spec.js +++ b/src/localWebServer.spec.js @@ -1,7 +1,7 @@ describe('Local Web Server Gulp Task Module', () => { var gulp = require('gulp'); - var localWebServer = require('./localwebserver.js'); + var localWebServer = require('./localWebServer.js'); it('is an object', () => { expect(typeof localWebServer).toBe('object'); From ec1e44e30cbb08f76d3effac147b20ef0316e240 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Wed, 28 Oct 2015 15:25:46 +0100 Subject: [PATCH 31/35] Improved readme and tiny gulp file improvement --- README.md | 45 ++++++++++++++++++++++++++++++++++++-- Gulpfile.js => gulpfile.js | 4 ++-- 2 files changed, 45 insertions(+), 4 deletions(-) rename Gulpfile.js => gulpfile.js (77%) diff --git a/README.md b/README.md index 02e91b9..cfa1f4d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,43 @@ -# gulp-tasks -Collection of reusable gulp tasks + +# Gulp Tasks + +> Collection of reusable gulp tasks + +## Usage + +Set up Gulp: https://github.com/gulpjs/gulp/blob/master/docs/getting-started.md + +Install this repository as an NPM dependency to integrate its gulp tasks: + +In your package.json: +```json +{ + ... + "devDependencies": { + ... + "gulp-tasks": "git@github.com:SmaatoUI/gulp-tasks.git#v0.1.0", + ... + } + ... +} +``` + +On the command line: +```bash +npm install +``` + +In your gulpfile.js: +```javascript +var lint = require('gulp-tasks/src/lint'); + +lint.eslint({ + src: './**/*.js', + taskName: 'lint' +}); +``` + +Use 'lint' in other gulp tasks or run it from the command line: +```bash +gulp lint +``` diff --git a/Gulpfile.js b/gulpfile.js similarity index 77% rename from Gulpfile.js rename to gulpfile.js index 14da8c6..cbc1e85 100644 --- a/Gulpfile.js +++ b/gulpfile.js @@ -1,9 +1,9 @@ var gulp = require('gulp'); var gulpJasmine = require('gulp-jasmine'); -var lintGulpTaskCollection = require('./src/lint'); +var lint = require('./src/lint'); -lintGulpTaskCollection.eslint({ +lint.eslint({ src: [ './*.js', './src/**/*.js' From 87d2e8be7a8b978dedfbce358d6174b30a45252c Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Wed, 28 Oct 2015 15:40:18 +0100 Subject: [PATCH 32/35] Added available gulp tasks to readme --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index cfa1f4d..a0f2816 100644 --- a/README.md +++ b/README.md @@ -41,3 +41,25 @@ Use 'lint' in other gulp tasks or run it from the command line: ```bash gulp lint ``` + +## Available Gulp Tasks + +assets +├--copy +deploy +├--awsS3 +lint +├--eslint +localWebServer +├--connect +scripts +├--browserifyAndWatchify +├--uglify +styles +├--compassAndPostcss +├--minifyCss +templates +├--jade +tests +├--karma +├--nightwatch From 3a4ee631672d3f9cee87ba0910c50ac268e417e6 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Wed, 28 Oct 2015 17:15:41 +0100 Subject: [PATCH 33/35] Improved readme --- README.md | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index a0f2816..ebfc70e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Set up Gulp: https://github.com/gulpjs/gulp/blob/master/docs/getting-started.md Install this repository as an NPM dependency to integrate its gulp tasks: In your package.json: -```json +``` { ... "devDependencies": { @@ -44,22 +44,14 @@ gulp lint ## Available Gulp Tasks -assets -├--copy -deploy -├--awsS3 -lint -├--eslint -localWebServer -├--connect -scripts -├--browserifyAndWatchify -├--uglify -styles -├--compassAndPostcss -├--minifyCss -templates -├--jade -tests -├--karma -├--nightwatch +### assets.copy +### deploy.awsS3 +### lint.eslint +### localWebServer.connect +### scripts.browserifyAndWatchify +### scripts.uglify +### styles.compassAndPostcss +### styles.minifyCss +### templates.jade +### tests.karma +### tests.nightwatch From 05fda2d0d69698283e18a042a55b0a1f0f5d4290 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Thu, 29 Oct 2015 11:00:04 +0100 Subject: [PATCH 34/35] Improved test descriptions --- src/assets.spec.js | 2 +- src/lint.spec.js | 2 +- src/templates.spec.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/assets.spec.js b/src/assets.spec.js index bc71408..ad6efdb 100644 --- a/src/assets.spec.js +++ b/src/assets.spec.js @@ -56,7 +56,7 @@ describe('Assets Gulp Task Module', () => { ); }); - it('can be executed', () => { + it('completes successfully', () => { expect(gulp.tasks.assetsTest.done).toBe(true); }); }); diff --git a/src/lint.spec.js b/src/lint.spec.js index a22c6d4..905fdd1 100644 --- a/src/lint.spec.js +++ b/src/lint.spec.js @@ -49,7 +49,7 @@ describe('Lint Gulp Task Module', () => { ); }); - it('can be executed', () => { + it('completes successfully', () => { expect(gulp.tasks.lintTest.done).toBe(true); }); }); diff --git a/src/templates.spec.js b/src/templates.spec.js index 47aaa9f..1f629c6 100644 --- a/src/templates.spec.js +++ b/src/templates.spec.js @@ -56,7 +56,7 @@ describe('Templates Gulp Task Module', () => { ); }); - it('can be executed', () => { + it('completes successfully', () => { expect(gulp.tasks.templatesTest.done).toBe(true); }); }); From 4ba89d35b9584dfe4f63e3f1ec4a50565a980ee4 Mon Sep 17 00:00:00 2001 From: Jens Lonkowski Date: Thu, 29 Oct 2015 11:02:24 +0100 Subject: [PATCH 35/35] Version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9740451..28e7283 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "gulp-tasks", "private": true, - "version": "0.0.1", + "version": "0.1.0", "description": "Collection of reusable gulp tasks", "scripts": { "test": "gulp"