diff --git a/gulpfile.js b/gulpfile.js index 54bd9cea..48602c28 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,26 +1,29 @@ /* globals -$ */ 'use strict'; -var gulp = require('gulp'); -var del = require('del'); -var yargs = require('yargs'); -var args = yargs.argv; -var browserify = require('browserify'); -var buffer = require('vinyl-buffer'); -var source = require('vinyl-source-stream'); -var babelify = require('babelify'); -var pkg = require('./package.json'); -var $ = require('gulp-load-plugins')({ lazy: true }); -var Dgeni = require('dgeni'); +const gulp = require('gulp'); +const del = require('del'); +const yargs = require('yargs'); +const args = yargs.argv; +const runSequence = require('run-sequence'); +const browserify = require('browserify'); +const buffer = require('vinyl-buffer'); +const source = require('vinyl-source-stream'); +const babelify = require('babelify'); +const pkg = require('./package.json'); +const $ = require('gulp-load-plugins')({ lazy: true }); +const Dgeni = require('dgeni'); require('gulp-help')(gulp); +let PROD_MODE = args.prod; + /** - * --prod: generate source maps and uglify code + * --prod: generate source maps and uglify code; this is turned on when running 'gulp dist' * --guts: skip style checks */ -gulp.task('clean', 'Remove dist folder', function (done) { - del('dist', done); +gulp.task('clean', 'Remove dist folder', function () { + del.sync('dist'); }); gulp.task('check', 'Checks code against style guidelines', function (done) { @@ -52,25 +55,32 @@ gulp.task('zip', 'Generate zip for distribution', ['build'], function () { .pipe(gulp.dest('dist')); }); -gulp.task('dist', 'Generate tgz and zip files for distribution', ['zip', 'tgz']); +// gulp.task('dist', 'Generate tgz and zip files for distribution', ['zip', 'tgz']); + +gulp.task('dist', 'Generate tgz and zip files for distribution', done => { + // turn on --prod flag to enable minification + runSequence('prod', 'check', ['zip', 'tgz'], done); +}); -gulp.task('build', 'Transpile and concatenate the code', function () { +gulp.task('build', 'Transpile and concatenate the code', ['clean'], function () { var b = browserify({ entries: 'src/index.js', standalone: 'geoapi' }).transform(babelify); return b.bundle() .pipe(source('gapi.js')) .pipe(buffer()) .pipe($.derequire()) - .pipe($.if(args.prod, $.sourcemaps.init())) + .pipe($.if(PROD_MODE, $.sourcemaps.init())) /* .pipe($.babel()) */ .pipe($.concat('geoapi.js')) /* .pipe(gulp.dest('dist/v' + pkg.version)) */ .pipe(gulp.dest('dist')) - .pipe($.rename('geoapi.min.js')) - .pipe($.if(args.prod, $.uglify())) - .pipe($.if(args.prod, $.sourcemaps.write('.'))) - .pipe(gulp.dest('dist')); + .pipe($.if(PROD_MODE, $.rename('geoapi.min.js'))) // do not create a minified file unless --prod is provided + .pipe($.if(PROD_MODE, $.uglify())) + .pipe($.if(PROD_MODE, $.sourcemaps.write('.'))) + .pipe($.if(PROD_MODE, gulp.dest('dist'))); }); +gulp.task('prod', 'Sets production mode', () => PROD_MODE = true); + gulp.task('test', 'Run unit tests in jasmine', ['check', 'build'], function () { return gulp .src('spec/*Spec.js') diff --git a/package.json b/package.json index 03ddd0d1..a09bfafc 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,9 @@ "jshint-stylish": "^2.0.1", "lodash": "^3.10.1", "proj4": "^2.3.12", + "run-sequence": "^1.2.2", "shpjs": "https://github.com/calvinmetcalf/shapefile-js.git#v3.3.1", + "svg.js": "^2.3.4", "terraformer": "~1.0.4", "terraformer-arcgis-parser": "~1.0.4", "terraformer-proj4js": "https://github.com/RAMP-PCAR/terraformer-proj4js.git#v0.2.2",