From 2a9cdb7be24f889cc75693f42f4f025d9898860f Mon Sep 17 00:00:00 2001
From: Peter Jaszkowiak
Date: Tue, 23 May 2017 14:00:37 -0600
Subject: [PATCH] Add `--threads=#` option for setting max threads
Make grunt NODE_ENV development by default
---
Gruntfile.js | 2 ++
src/meta/build.js | 5 +++++
src/meta/minifier.js | 16 ++++++++++++++--
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/Gruntfile.js b/Gruntfile.js
index c97795e743..9a84c15aa0 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -8,6 +8,8 @@ var initWorker;
var incomplete = [];
var running = 0;
+env.NODE_ENV = env.NODE_ENV || 'development';
+
module.exports = function (grunt) {
var args = [];
var initArgs = ['--build'];
diff --git a/src/meta/build.js b/src/meta/build.js
index cc3321923f..290957512a 100644
--- a/src/meta/build.js
+++ b/src/meta/build.js
@@ -180,6 +180,11 @@ function build(targets, callback) {
async.series([
beforeBuild,
function (next) {
+ var threads = parseInt(nconf.get('threads'), 10);
+ if (threads) {
+ require('./minifier').maxThreads = threads - 1;
+ }
+
var parallel = !nconf.get('series');
if (parallel) {
winston.info('[build] Building in parallel mode');
diff --git a/src/meta/minifier.js b/src/meta/minifier.js
index 7c1a83bea4..07f33d8253 100644
--- a/src/meta/minifier.js
+++ b/src/meta/minifier.js
@@ -41,9 +41,21 @@ function setupDebugging() {
var pool = [];
var free = [];
-Minifier.maxThreads = os.cpus().length - 1;
+var maxThreads = 0;
+
+Object.defineProperty(Minifier, 'maxThreads', {
+ get: function () {
+ return maxThreads;
+ },
+ set: function (val) {
+ maxThreads = val;
+ winston.verbose('[minifier] utilizing a maximum of ' + maxThreads + ' additional threads');
+ },
+ configurable: true,
+ enumerable: true,
+});
-winston.verbose('[minifier] utilizing a maximum of ' + Minifier.maxThreads + ' additional threads');
+Minifier.maxThreads = os.cpus().length - 1;
Minifier.killAll = function () {
pool.forEach(function (child) {