From e910c757e57eee2a199fc0f0d036fc83dbdecfb6 Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Sun, 30 Nov 2014 14:39:56 -0500 Subject: [PATCH] Converting config into a module instead of just JSON Allows the browserify config to be further unified. Also added ability to build to different paths than just ./build --- config.js | 36 ++++++++++++++++++++++++++++++++++++ config.json | 22 ---------------------- gulpfile.js | 22 +++++++++++----------- karma.conf.js | 10 +--------- 4 files changed, 48 insertions(+), 42 deletions(-) create mode 100644 config.js delete mode 100644 config.json diff --git a/config.js b/config.js new file mode 100644 index 0000000..332046e --- /dev/null +++ b/config.js @@ -0,0 +1,36 @@ +var path = require('path'), + _ = require('lodash'), + buildRoot = process.env.BUILD_PATH || './build', + buildPath = _.bind(path.join, path, buildRoot); + +module.exports = { + buildRoot: buildRoot, + buildPath: buildPath, + templateFile: './template.html', + globs: { + other: './src/**/*.!(html|scss|js|peg)', + html: './src/**/*.html', + sass: './src/**/*.scss', + js: ['./src/**/*.js', './src/**/*.peg'], + spec: './spec/**/*_spec.js' + }, + compass: { + sass: './src/sass', + css: buildPath('css'), + javascript: buildPath('js'), + font: buildPath('font'), + sourcemap: true + }, + browserify: { + basedir: './src/js', + debug: true, + fullPaths: false, + prebundle: function(bundle) { + var es6ify = require('es6ify'); + + bundle.add(es6ify.runtime); + bundle.transform(require('./lib/canopy-transform')); + bundle.transform(es6ify.configure(/^(?!.*node_modules)+.+\.js$/)); + } + } +}; diff --git a/config.json b/config.json deleted file mode 100644 index 518bd42..0000000 --- a/config.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "templateFile": "./template.html", - "globs": { - "other": "./src/**/*.!(html|scss|js|peg)", - "html": "./src/**/*.html", - "sass": "./src/**/*.scss", - "js": ["./src/**/*.js", "./src/**/*.peg"], - "spec": "./spec/**/*_spec.js" - }, - "compass": { - "sass": "./src/sass", - "css": "./build/css", - "javascript": "./build/js", - "font": "./build/font", - "sourcemap": true - }, - "browserify": { - "basedir": "./src/js", - "debug": true, - "fullPaths": false - } -} diff --git a/gulpfile.js b/gulpfile.js index 628807b..44e4260 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -20,11 +20,11 @@ gulp.task('server', ['build'], function() { var connect = require('gulp-connect'), watch = require('gulp-watch'); - watch('./build/**/*', { name: 'Server' }) + watch(config.buildPath('**/*'), { name: 'Server' }) .pipe(connect.reload()); return connect.server({ - root: './build', + root: config.buildRoot, livereload: true }); }); @@ -32,18 +32,18 @@ gulp.task('server', ['build'], function() { gulp.task('build', ['static', 'markup', 'compass', 'browserify']); gulp.task('static', function() { - return gulp.src(config.globs.other, { base: 'src' }) + return gulp.src(config.globs.other, { base: './src' }) .pipe(errorHandler()) - .pipe(gulp.dest('./build')); + .pipe(gulp.dest(config.buildRoot)); }); gulp.task('markup', function() { var wrap = require('gulp-wrap'); - return gulp.src(config.globs.html, { base: 'src' }) + return gulp.src(config.globs.html, { base: './src' }) .pipe(errorHandler()) .pipe(wrap({ src: config.templateFile })) - .pipe(gulp.dest('./build')); + .pipe(gulp.dest(config.buildRoot)); }); gulp.task('compass', function() { @@ -66,16 +66,16 @@ gulp.task('browserify', function() { .pipe(tap(function(file) { var bundler = browserify(config.browserify); - bundler.add([file.path, es6ify.runtime]); - bundler.transform(require('./lib/canopy-transform')); - bundler.transform(es6ify.configure(/^(?!.*node_modules)+.+\.js$/)); + bundler.add(file.path); + + config.browserify.prebundle(bundler); file.contents = bundler.bundle(); })) .pipe(transform(function() { - return exorcist('./build/js/main.js.map'); + return exorcist(config.buildPath('js/main.js.map')); })) - .pipe(gulp.dest('./build/js')); + .pipe(gulp.dest(config.buildPath('js'))); }); gulp.task('karma', function(done) { diff --git a/karma.conf.js b/karma.conf.js index 1930756..80f2e43 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -17,14 +17,6 @@ module.exports = function(karma) { browsers: ['PhantomJS'], autoWatch: true, singleRun: false, - browserify: _.defaults({}, config.browserify, { - prebundle: function(bundle) { - var es6ify = require('es6ify'); - - bundle.add([es6ify.runtime]); - bundle.transform(require('./lib/canopy-transform')); - bundle.transform(es6ify.configure(/^(?!.*node_modules)+.+\.js$/)); - } - }) + browserify: config.browserify }); };