chore(gulpfile): ensure NODE_ENV=production before running harp

This commit is contained in:
Ward Bell 2016-02-16 17:40:46 -08:00
parent 1ac9316171
commit d401716fc2
2 changed files with 27 additions and 1 deletions

View File

@ -5,6 +5,7 @@ var path = require('canonical-path');
var del = require('del'); var del = require('del');
var _ = require('lodash'); var _ = require('lodash');
var argv = require('yargs').argv; var argv = require('yargs').argv;
var env = require('gulp-env');
var Q = require("q"); var Q = require("q");
// delPromise is a 'promise' version of del // delPromise is a 'promise' version of del
var delPromise = Q.denodeify(del); var delPromise = Q.denodeify(del);
@ -394,6 +395,14 @@ gulp.task('test-api-builder', function (cb) {
// Internal tasks // 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 // used to test just harpCompile without a build step
gulp.task('_harp-compile', function() { gulp.task('_harp-compile', function() {
@ -447,11 +456,19 @@ gulp.task('_zip-examples', function() {
// Helper functions // Helper functions
function harpCompile() { 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(); var deferred = Q.defer();
gutil.log('running harp compile...'); gutil.log('running harp compile...');
showHideExampleNodeModules('hide'); showHideExampleNodeModules('hide');
var spawnInfo = spawnExt('npm',['run','harp', '--', 'compile', '.', './www' ]); var spawnInfo = spawnExt('npm',['run','harp', '--', 'compile', '.', './www' ]);
spawnInfo.promise.then(function(x) { spawnInfo.promise.then(function(x) {
gutil.log("NODE_ENV: " + process.env.NODE_ENV);
showHideExampleNodeModules('show'); showHideExampleNodeModules('show');
if (x !== 0) { if (x !== 0) {
deferred.reject(x) deferred.reject(x)
@ -459,6 +476,7 @@ function harpCompile() {
deferred.resolve(x); deferred.resolve(x);
} }
}).catch(function(e) { }).catch(function(e) {
gutil.log("NODE_ENV: " + process.env.NODE_ENV);
showHideExampleNodeModules('show'); showHideExampleNodeModules('show');
deferred.reject(e); deferred.reject(e);
}); });
@ -560,6 +578,11 @@ function getFilenames(basePath, filename, includeBase) {
} }
function watchAndSync(options, cb) { 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); execCommands(['npm run harp -- server .'], {}, cb);
@ -847,6 +870,8 @@ function execCommands(cmds, options, cb) {
options.shouldLog = options.shouldLog == null ? true : options.shouldLog; options.shouldLog = options.shouldLog == null ? true : options.shouldLog;
if (!cmds || cmds.length == 0) cb(null, null, null); if (!cmds || cmds.length == 0) cb(null, null, null);
var exec = require('child_process').exec; // just to make it more portable. 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) { exec(cmds[0], options, function(err, stdout, stderr) {
if (err == null) { if (err == null) {
if (options.shouldLog) { if (options.shouldLog) {

View File

@ -39,6 +39,7 @@
"glob": "^5.0.14", "glob": "^5.0.14",
"globby": "^4.0.0", "globby": "^4.0.0",
"gulp": "^3.5.6", "gulp": "^3.5.6",
"gulp-env": "0.4.0",
"gulp-task-listing": "^1.0.1", "gulp-task-listing": "^1.0.1",
"gulp-util": "^3.0.6", "gulp-util": "^3.0.6",
"gulp-watch": "^4.3.4", "gulp-watch": "^4.3.4",