diff --git a/.eslintrc b/.eslintrc index 5155060d..ea9ec781 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,6 +1,7 @@ { "extends": "gulp", "rules": { + "max-len": [1, 90], "max-statements": [1, 40], "no-console": "off" } diff --git a/index.js b/index.js index cf884aef..e1cb3223 100644 --- a/index.js +++ b/index.js @@ -61,9 +61,6 @@ var usage = var parser = yargs.usage(usage, cliOptions); var opts = parser.argv; -// Set up event listeners for logging temporarily. -toConsole(log, opts); - cli.on('require', function(name) { log.info('Requiring external module', ansi.magenta(name)); }); @@ -85,7 +82,6 @@ cli.on('respawn', function(flags, child) { log.info('Respawned to PID:', pid); }); - function run() { cli.prepare({ cwd: opts.cwd, @@ -93,13 +89,15 @@ function run() { require: opts.require, completion: opts.completion, }, function(env) { - var cfgLoadOrder = ['home', 'cwd']; var cfg = loadConfigFiles(env.configFiles['.gulp'], cfgLoadOrder); opts = mergeConfigToCliFlags(opts, cfg); env = mergeConfigToEnvFlags(env, cfg); env.configProps = cfg; + // Set up event listeners for logging again after configuring. + toConsole(log, opts); + cli.execute(env, handleArguments); }); } @@ -117,18 +115,16 @@ function handleArguments(env) { process.env.UNDERTAKER_SETTLE = 'true'; } - // Set up event listeners for logging again after configuring. - toConsole(log, opts); - if (opts.help) { parser.showHelp(console.log); exit(0); } + // Anything that needs to print outside of the logging mechanism should use console.log if (opts.version) { - log.info('CLI version', cliVersion); + console.log('CLI version', cliVersion); if (env.modulePackage && typeof env.modulePackage.version !== 'undefined') { - log.info('Local version', env.modulePackage.version); + console.log('Local version', env.modulePackage.version); } exit(0); } diff --git a/lib/shared/log/to-console.js b/lib/shared/log/to-console.js index 2c290f0d..05103710 100644 --- a/lib/shared/log/to-console.js +++ b/lib/shared/log/to-console.js @@ -32,7 +32,7 @@ function toConsole(log, opts) { // Return immediately if logging is // not desired. - if (opts.tasksSimple || opts.silent) { + if (opts.tasksSimple || opts.tasksJson || opts.help || opts.version || opts.silent) { // Keep from crashing process when silent. log.on('error', noop); return; diff --git a/test/config-flags-gulpfile.js b/test/config-flags-gulpfile.js index 6f6af20b..bac65e84 100644 --- a/test/config-flags-gulpfile.js +++ b/test/config-flags-gulpfile.js @@ -100,11 +100,14 @@ describe('config: flags.gulpfile', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - expect(eraseTime(stdout)).toEqual( - 'Requiring external module babel-register\n' + - 'clean!\n' + - 'build!\n' + - ''); + + var requiring = eraseTime(headLines(stdout, 1)); + expect(requiring).toEqual('Requiring external module babel-register'); + var clean = eraseTime(headLines(stdout, 1, 4)); + expect(clean).toEqual('clean!'); + var build = eraseTime(headLines(stdout, 1, 7)); + expect(build).toEqual('build!'); + done(err); } }); diff --git a/test/fixtures/config/flags/gulpfile/autoload/.gulp.json b/test/fixtures/config/flags/gulpfile/autoload/.gulp.json index fba4be3c..0d5c0009 100644 --- a/test/fixtures/config/flags/gulpfile/autoload/.gulp.json +++ b/test/fixtures/config/flags/gulpfile/autoload/.gulp.json @@ -1,6 +1,5 @@ { "flags": { - "silent": true, "gulpfile": "other_folder/gulpfile-exports.babel.js" } } diff --git a/test/fixtures/gulpfiles/gulpfile-babel.babel.js b/test/fixtures/gulpfiles/gulpfile-babel.babel.js new file mode 100644 index 00000000..24cbbd5b --- /dev/null +++ b/test/fixtures/gulpfiles/gulpfile-babel.babel.js @@ -0,0 +1,43 @@ +'use strict'; + +var gulp = require('gulp'); + +function noop(cb) { + cb(); +} + +function described(cb) { + cb(); +} + +function delayed(cb) { + setTimeout(cb, 100); +} + +function errorFunction() { + throw new Error('Error!'); +} +function anon(cb) { + cb(); +} + +function notCompleting1() { + // Callback is not called +} + +function notCompleting2() { + // Callback is not called +} + +described.description = 'description'; + +gulp.task('test1', gulp.series(noop)); +gulp.task('test2', gulp.series('test1', noop)); +gulp.task('test3', gulp.series(described)); +gulp.task('test4', gulp.series(errorFunction, anon)); +gulp.task('test5', delayed); +gulp.task('test6', noop); +gulp.task('test7', notCompleting1); +gulp.task('test8', notCompleting2); + +gulp.task('default', gulp.series('test1', 'test3', noop)); diff --git a/test/flags-help.js b/test/flags-help.js index f9dcad0a..e781665b 100644 --- a/test/flags-help.js +++ b/test/flags-help.js @@ -44,4 +44,18 @@ describe('flag: --help', function() { } }); + it('avoids printing "Requiring external module *"', function(done) { + runner({ verbose: false }) + .gulp('--help --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') + .run(cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stderr).toEqual(''); + stdout = eraseFirstSpace(stdout); + expect(stdout).toEqual(outputText); + done(err); + } + }); + }); diff --git a/test/flags-tasks-json.js b/test/flags-tasks-json.js index b4182ccc..364779ff 100644 --- a/test/flags-tasks-json.js +++ b/test/flags-tasks-json.js @@ -19,7 +19,6 @@ describe('flag: --tasks-json', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - stdout = skipLines(stdout, 1); expect(JSON.parse(stdout)).toEqual(expected); done(err); } @@ -48,4 +47,19 @@ describe('flag: --tasks-json', function() { } }); + it('avoids printing "Requiring external module *"', function(done) { + // Disable the timeout for old node versions + this.timeout(0); + + runner({ verbose: false }) + .gulp('--tasks-json --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') + .run(cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stderr).toEqual(''); + expect(JSON.parse(stdout)).toEqual(expected); + done(err); + } + }); }); diff --git a/test/flags-tasks-simple.js b/test/flags-tasks-simple.js index cf6de089..a44bd91c 100644 --- a/test/flags-tasks-simple.js +++ b/test/flags-tasks-simple.js @@ -23,4 +23,20 @@ describe('flag: --tasks-simple', function() { } }); + it('avoids printing "Requiring external module *"', function(done) { + // Disable the timeout for old node versions + this.timeout(0); + + runner({ verbose: false }) + .gulp('--tasks-simple --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') + .run(cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stderr).toEqual(''); + expect(stdout).toEqual(outputText); + done(err); + } + }); + }); diff --git a/test/flags-version.js b/test/flags-version.js index f768f8bb..39244e10 100644 --- a/test/flags-version.js +++ b/test/flags-version.js @@ -2,7 +2,6 @@ var expect = require('expect'); var runner = require('gulp-test-tools').gulpRunner; -var eraseTime = require('gulp-test-tools').eraseTime; var cliVersion = require('../package.json').version; var gulpVersion = require('gulp/package.json').version; @@ -17,7 +16,23 @@ describe('flag: --version', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - stdout = eraseTime(stdout); + expect(stdout).toEqual( + 'CLI version ' + cliVersion + '\n' + + 'Local version ' + gulpVersion + '\n' + + '' + ); + done(err); + } + }); + + it('avoids printing "Requiring external module *"', function(done) { + runner({ verbose: false }) + .gulp('--version --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') + .run(cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stderr).toEqual(''); expect(stdout).toEqual( 'CLI version ' + cliVersion + '\n' + 'Local version ' + gulpVersion + '\n' +