Skip to content

Commit

Permalink
chore(build): turn --prod on dist task by default
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksueiR committed Sep 12, 2016
1 parent c9998cc commit 1665d34
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
52 changes: 31 additions & 21 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1665d34

Please sign in to comment.