diff --git a/README.md b/README.md index ad759e66..a9986378 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ Supported configurations properties: | flags.silent | Silence logging by default | | flags.series | Run tasks given on the CLI in series (the default is parallel) | | flags.require | An array of modules to require before running the gulpfile. Any relative paths will be resolved against the `--cwd` directory (if you don't want that behavior, use absolute paths) | +| flags.nodeFlags | An array of flags used to forcibly respawn the process upon startup. For example, if you always want your gulpfiles to run in node's harmony mode, you can set `--harmony` here | ## Flags diff --git a/index.js b/index.js index 9dfde83c..bc1a1c31 100644 --- a/index.js +++ b/index.js @@ -98,7 +98,7 @@ function run() { // Set up event listeners for logging again after configuring. toConsole(log, opts); - cli.execute(env, handleArguments); + cli.execute(env, env.nodeFlags, handleArguments); }); } diff --git a/lib/shared/config/env-flags.js b/lib/shared/config/env-flags.js index 3aa2d4d4..0e18bf9b 100644 --- a/lib/shared/config/env-flags.js +++ b/lib/shared/config/env-flags.js @@ -7,6 +7,7 @@ var toFrom = { configPath: 'flags.gulpfile', configBase: 'flags.gulpfile', require: 'flags.require', + nodeFlags: 'flags.nodeFlags', }; function mergeConfigToEnvFlags(env, config, cliOpts) { @@ -33,6 +34,10 @@ function mergeConfigToEnvFlags(env, config, cliOpts) { return [].concat(envInfo.value, configInfo.value); } + if (envInfo.keyChain === 'nodeFlags') { + return [].concat(configInfo.value || []); + } + return configInfo.value; } } diff --git a/test/config-flags-node-flags.js b/test/config-flags-node-flags.js new file mode 100644 index 00000000..0aaa2685 --- /dev/null +++ b/test/config-flags-node-flags.js @@ -0,0 +1,70 @@ +'use strict'; + +var expect = require('expect'); +var path = require('path'); + +var fixturesDir = path.join(__dirname, 'fixtures/config'); + +var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); +var headLines = require('gulp-test-tools').headLines; +var eraseTime = require('gulp-test-tools').eraseTime; + +describe('config: nodeFlags', function() { + + it('Should respawn by a node flag: --lazy', function(done) { + runner + .chdir('flags/nodeFlags/string') + .gulp() + .run(cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stderr).toEqual(''); + + var line = eraseTime(headLines(stdout, 1)); + expect(line).toEqual('Node flags detected: --lazy'); + + line = eraseTime(headLines(stdout, 2, 1)); + expect(line).toMatch('Respawned to PID: '); + done(err); + } + }); + + it('Should respawn by a node flag: --lazy --trace-deprecation', function(done) { + runner + .chdir('flags/nodeFlags/array') + .gulp() + .run(cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stderr).toEqual(''); + + var line = eraseTime(headLines(stdout, 1)); + expect(line).toEqual('Node flags detected: --lazy, --trace-deprecation'); + + line = eraseTime(headLines(stdout, 2, 1)); + expect(line).toMatch('Respawned to PID: '); + done(err); + } + }); + + it('Should respawn with flags in config file and command line', function(done) { + runner + .chdir('flags/nodeFlags/string') + .gulp('--harmony') + .run(cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stderr).toEqual(''); + + var line = eraseTime(headLines(stdout, 1)); + expect(line).toEqual('Node flags detected: --lazy, --harmony'); + + line = eraseTime(headLines(stdout, 2, 1)); + expect(line).toMatch('Respawned to PID: '); + done(err); + } + }); +}); diff --git a/test/fixtures/config/flags/nodeFlags/array/.gulp.json b/test/fixtures/config/flags/nodeFlags/array/.gulp.json new file mode 100644 index 00000000..f327928a --- /dev/null +++ b/test/fixtures/config/flags/nodeFlags/array/.gulp.json @@ -0,0 +1,5 @@ +{ + "flags": { + "nodeFlags": ["--lazy", "--trace-deprecation"] + } +} diff --git a/test/fixtures/config/flags/nodeFlags/array/gulpfile.js b/test/fixtures/config/flags/nodeFlags/array/gulpfile.js new file mode 100644 index 00000000..b1e4e02a --- /dev/null +++ b/test/fixtures/config/flags/nodeFlags/array/gulpfile.js @@ -0,0 +1,6 @@ +'use strict'; + +exports.default = function(done) { + console.log('Default'); + done(); +}; diff --git a/test/fixtures/config/flags/nodeFlags/string/.gulp.js b/test/fixtures/config/flags/nodeFlags/string/.gulp.js new file mode 100644 index 00000000..608862dd --- /dev/null +++ b/test/fixtures/config/flags/nodeFlags/string/.gulp.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = { + flags: { + nodeFlags: '--lazy', + }, +}; diff --git a/test/fixtures/config/flags/nodeFlags/string/gulpfile.js b/test/fixtures/config/flags/nodeFlags/string/gulpfile.js new file mode 100644 index 00000000..b1e4e02a --- /dev/null +++ b/test/fixtures/config/flags/nodeFlags/string/gulpfile.js @@ -0,0 +1,6 @@ +'use strict'; + +exports.default = function(done) { + console.log('Default'); + done(); +};