From d401716fc2f2fc4b7950accd72966a0a4ffb5d4f Mon Sep 17 00:00:00 2001 From: Ward Bell Date: Tue, 16 Feb 2016 17:40:46 -0800 Subject: [PATCH] chore(gulpfile): ensure NODE_ENV=production before running harp --- gulpfile.js | 27 ++++++++++++++++++++++++++- package.json | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index cfcd8efb11..4766afc558 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,6 +5,7 @@ var path = require('canonical-path'); var del = require('del'); var _ = require('lodash'); var argv = require('yargs').argv; +var env = require('gulp-env'); var Q = require("q"); // delPromise is a 'promise' version of del var delPromise = Q.denodeify(del); @@ -394,6 +395,14 @@ gulp.task('test-api-builder', function (cb) { // Internal tasks +gulp.task('set-prod-env', function () { + // Supposedly running in production makes harp faster + // and less likely to drown in node_modules. + env({ + vars: { NODE_ENV: "production" } + }); + gutil.log("NODE_ENV: " + process.env.NODE_ENV); +}); // used to test just harpCompile without a build step gulp.task('_harp-compile', function() { @@ -447,11 +456,19 @@ gulp.task('_zip-examples', function() { // Helper functions function harpCompile() { + // Supposedly running in production makes harp faster + // and less likely to drown in node_modules. + env({ + vars: { NODE_ENV: "production" } + }); + gutil.log("NODE_ENV: " + process.env.NODE_ENV); + var deferred = Q.defer(); gutil.log('running harp compile...'); showHideExampleNodeModules('hide'); var spawnInfo = spawnExt('npm',['run','harp', '--', 'compile', '.', './www' ]); spawnInfo.promise.then(function(x) { + gutil.log("NODE_ENV: " + process.env.NODE_ENV); showHideExampleNodeModules('show'); if (x !== 0) { deferred.reject(x) @@ -459,6 +476,7 @@ function harpCompile() { deferred.resolve(x); } }).catch(function(e) { + gutil.log("NODE_ENV: " + process.env.NODE_ENV); showHideExampleNodeModules('show'); deferred.reject(e); }); @@ -560,7 +578,12 @@ function getFilenames(basePath, filename, includeBase) { } function watchAndSync(options, cb) { - + // Supposedly running in production makes harp faster + // and less likely to drown in node_modules. + env({ + vars: { NODE_ENV: "production" } + }); + execCommands(['npm run harp -- server .'], {}, cb); var browserSync = require('browser-sync').create(); @@ -847,6 +870,8 @@ function execCommands(cmds, options, cb) { options.shouldLog = options.shouldLog == null ? true : options.shouldLog; if (!cmds || cmds.length == 0) cb(null, null, null); var exec = require('child_process').exec; // just to make it more portable. + gutil.log("NODE_ENV: " + process.env.NODE_ENV); + exec(cmds[0], options, function(err, stdout, stderr) { if (err == null) { if (options.shouldLog) { diff --git a/package.json b/package.json index 207324642e..2fd87fa130 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "glob": "^5.0.14", "globby": "^4.0.0", "gulp": "^3.5.6", + "gulp-env": "0.4.0", "gulp-task-listing": "^1.0.1", "gulp-util": "^3.0.6", "gulp-watch": "^4.3.4",