diff --git a/index.js b/index.js index 87ef29e9..1e4cd879 100644 --- a/index.js +++ b/index.js @@ -3,13 +3,13 @@ var fs = require('fs'); var path = require('path'); var log = require('gulplog'); -var chalk = require('chalk'); var yargs = require('yargs'); var Liftoff = require('liftoff'); var tildify = require('tildify'); var interpret = require('interpret'); var v8flags = require('v8flags'); var findRange = require('semver-greatest-satisfied-range'); +var ansi = require('./lib/shared/ansi'); var exit = require('./lib/shared/exit'); var cliOptions = require('./lib/shared/cliOptions'); var completion = require('./lib/shared/completion'); @@ -53,8 +53,8 @@ var cli = new Liftoff({ }); var usage = - '\n' + chalk.bold('Usage:') + - ' gulp ' + chalk.blue('[options]') + ' tasks'; + '\n' + ansi.bold('Usage:') + + ' gulp ' + ansi.blue('[options]') + ' tasks'; var parser = yargs.usage(usage, cliOptions); var opts = parser.argv; @@ -63,16 +63,16 @@ var opts = parser.argv; toConsole(log, opts); cli.on('require', function(name) { - log.info('Requiring external module', chalk.magenta(name)); + log.info('Requiring external module', ansi.magenta(name)); }); cli.on('requireFail', function(name) { - log.error(chalk.red('Failed to load external module'), chalk.magenta(name)); + log.error(ansi.red('Failed to load external module'), ansi.magenta(name)); }); cli.on('respawn', function(flags, child) { - var nodeFlags = chalk.magenta(flags.join(', ')); - var pid = chalk.magenta(child.pid); + var nodeFlags = ansi.magenta(flags.join(', ')); + var pid = ansi.magenta(child.pid); log.info('Node flags detected:', nodeFlags); log.info('Respawned to PID:', pid); }); @@ -138,15 +138,15 @@ function handleArguments(env) { if (!env.modulePath) { log.error( - chalk.red('Local gulp not found in'), - chalk.magenta(tildify(env.cwd)) + ansi.red('Local gulp not found in'), + ansi.magenta(tildify(env.cwd)) ); - log.error(chalk.red('Try running: npm install gulp')); + log.error(ansi.red('Try running: npm install gulp')); exit(1); } if (!env.configPath) { - log.error(chalk.red('No gulpfile found')); + log.error(ansi.red('No gulpfile found')); exit(1); } @@ -156,7 +156,7 @@ function handleArguments(env) { process.chdir(env.cwd); log.info( 'Working directory changed to', - chalk.magenta(tildify(env.cwd)) + ansi.magenta(tildify(env.cwd)) ); } @@ -165,7 +165,7 @@ function handleArguments(env) { if (!range) { return log.error( - chalk.red('Unsupported gulp version', env.modulePackage.version) + ansi.red('Unsupported gulp version', env.modulePackage.version) ); } diff --git a/lib/shared/ansi.js b/lib/shared/ansi.js new file mode 100644 index 00000000..1e4fcb95 --- /dev/null +++ b/lib/shared/ansi.js @@ -0,0 +1,36 @@ +'use strict'; + +var red = require('ansi-red'); +var green = require('ansi-green'); +var blue = require('ansi-blue'); +var magenta = require('ansi-magenta'); +var cyan = require('ansi-cyan'); +var white = require('ansi-white'); +var gray = require('ansi-gray'); +var bgred = require('ansi-bgred'); +var bold = require('ansi-bold'); +var hasFlag = require('has-flag'); + +module.exports = { + red: colorize() ? red : noColor, + green: colorize() ? green : noColor, + blue: colorize() ? blue : noColor, + magenta: colorize() ? magenta : noColor, + cyan: colorize() ? cyan : noColor, + white: colorize() ? white : noColor, + gray: colorize() ? gray : noColor, + bgred: colorize() ? bgred : noColor, + bold: colorize() ? bold : noColor, +}; + +function noColor(message) { + return message; +} + +function colorize() { + var noColorFlag = + hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false'); + var isTTY = process.stdout && process.stdout.isTTY; + var colorOutput = !noColorFlag && isTTY; + return colorOutput; +} diff --git a/lib/shared/cliOptions.js b/lib/shared/cliOptions.js index 90eba586..5b145c62 100644 --- a/lib/shared/cliOptions.js +++ b/lib/shared/cliOptions.js @@ -1,59 +1,59 @@ 'use strict'; -var chalk = require('chalk'); +var ansi = require('./ansi'); module.exports = { help: { alias: 'h', type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Show this help.'), }, version: { alias: 'v', type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Print the global and local gulp versions.'), }, require: { type: 'string', requiresArg: true, - desc: chalk.gray( + desc: ansi.gray( 'Will require a module before running the gulpfile. ' + 'This is useful for transpilers but also has other applications.'), }, gulpfile: { type: 'string', requiresArg: true, - desc: chalk.gray( + desc: ansi.gray( 'Manually set path of gulpfile. Useful if you have multiple gulpfiles. ' + 'This will set the CWD to the gulpfile directory as well.'), }, cwd: { type: 'string', requiresArg: true, - desc: chalk.gray( + desc: ansi.gray( 'Manually set the CWD. The search for the gulpfile, ' + 'as well as the relativity of all requires will be from here.'), }, verify: { - desc: chalk.gray( + desc: ansi.gray( 'Will verify plugins referenced in project\'s package.json against ' + 'the plugins blacklist.'), }, tasks: { alias: 'T', type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Print the task dependency tree for the loaded gulpfile.'), }, 'tasks-simple': { type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Print a plaintext list of tasks for the loaded gulpfile.'), }, 'tasks-json': { - desc: chalk.gray( + desc: ansi.gray( 'Print the task dependency tree, ' + 'in JSON format, for the loaded gulpfile.'), }, @@ -61,41 +61,41 @@ module.exports = { alias: 'depth', type: 'number', requiresArg: true, - desc: chalk.gray( + desc: ansi.gray( 'Specify the depth of the task dependency tree.'), }, 'compact-tasks': { type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Reduce the output of task dependency tree by printing ' + 'only top tasks and their child tasks.'), }, 'sort-tasks': { type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Will sort top tasks of task dependency tree.'), }, color: { type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Will force gulp and gulp plugins to display colors, ' + 'even when no color support is detected.'), }, 'no-color': { type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Will force gulp and gulp plugins to not display colors, ' + 'even when color support is detected.'), }, silent: { alias: 'S', type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Suppress all gulp logging.'), }, continue: { type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Continue execution of tasks upon failure.'), }, 'log-level': { @@ -103,7 +103,7 @@ module.exports = { // Type isn't needed because count acts as a boolean count: true, // Can't use `default` because it seems to be off by one - desc: chalk.gray( + desc: ansi.gray( 'Set the loglevel. -L for least verbose and -LLLL for most verbose. ' + '-LLL is default.'), }, diff --git a/lib/shared/log/blacklistError.js b/lib/shared/log/blacklistError.js index c3c5bf32..396436ac 100644 --- a/lib/shared/log/blacklistError.js +++ b/lib/shared/log/blacklistError.js @@ -1,12 +1,12 @@ 'use strict'; -var chalk = require('chalk'); var log = require('gulplog'); +var ansi = require('../ansi'); var exit = require('../exit'); function logBlacklistError(err) { - log.error(chalk.red('Error: failed to retrieve plugins black-list')); + log.error(ansi.red('Error: failed to retrieve plugins black-list')); log.error(err.message); // Avoid duplicating for each version exit(1); } diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 3e4a7c91..37084d1d 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -1,11 +1,11 @@ 'use strict'; var archy = require('archy'); -var chalk = require('chalk'); var log = require('gulplog'); var sortBy = require('lodash.sortby'); var isObject = require('lodash.isplainobject'); +var ansi = require('../ansi'); var isString = require('../is-string'); var copyTree = require('./copy-tree'); @@ -145,20 +145,20 @@ function printTreeList(lines, spacer, lineInfos) { lines.forEach(function(branch, index) { var info = lineInfos[index]; - var line = chalk.white(branch); + var line = ansi.white(branch); if (info.type === 'top') { - line += chalk.cyan(info.name); + line += ansi.cyan(info.name); if (info.desc.length > 0) { - line += spacer(index) + chalk.white(info.desc); + line += spacer(index) + ansi.white(info.desc); } } else if (info.type === 'option') { - line += chalk.magenta(info.name); + line += ansi.magenta(info.name); if (info.desc.length > 0) { - line += spacer(index) + chalk.white('…' + info.desc); + line += spacer(index) + ansi.white('…' + info.desc); } } else { // If (info.type === 'child') { - line += chalk.white(info.name); + line += ansi.white(info.name); } log.info(line); diff --git a/lib/shared/log/verify.js b/lib/shared/log/verify.js index 795867a7..71046237 100644 --- a/lib/shared/log/verify.js +++ b/lib/shared/log/verify.js @@ -1,8 +1,8 @@ 'use strict'; -var chalk = require('chalk'); var log = require('gulplog'); +var ansi = require('../ansi'); var exit = require('../exit'); function logVerify(blacklisted) { @@ -10,16 +10,16 @@ function logVerify(blacklisted) { if (!pluginNames.length) { log.info( - chalk.green('There are no blacklisted plugins in this project') + ansi.green('There are no blacklisted plugins in this project') ); exit(0); } - log.warn(chalk.red('Blacklisted plugins found in this project:')); + log.warn(ansi.red('Blacklisted plugins found in this project:')); pluginNames.map(function(pluginName) { var reason = blacklisted[pluginName]; - log.warn(chalk.bgRed(pluginName) + ': ' + reason); + log.warn(ansi.bgred(pluginName) + ': ' + reason); }); exit(1); diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index 6e3eda7e..f91b175d 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -1,6 +1,5 @@ 'use strict'; -var chalk = require('chalk'); var log = require('gulplog'); var stdout = require('mute-stdout'); var tildify = require('tildify'); @@ -8,6 +7,7 @@ var tildify = require('tildify'); var taskTree = require('./taskTree'); var logTasks = require('../../shared/log/tasks'); +var ansi = require('../../shared/ansi'); var isString = require('../../shared/is-string'); var logEvents = require('./log/events'); var logTasksSimple = require('./log/tasksSimple'); @@ -24,7 +24,7 @@ function execute(opts, env, config) { // This is what actually loads up the gulpfile var exported = require(env.configPath); - log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); + log.info('Using gulpfile', ansi.magenta(tildify(env.configPath))); var gulpInst = require(env.modulePath); logEvents(gulpInst); @@ -45,7 +45,7 @@ function execute(opts, env, config) { if (config.description && isString(config.description)) { tree.label = config.description; } else { - tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); + tree.label = 'Tasks for ' + ansi.magenta(tildify(env.configPath)); } return logTasks(tree, opts, function(task) { return gulpInst.tasks[task].fn; diff --git a/lib/versioned/^3.7.0/log/events.js b/lib/versioned/^3.7.0/log/events.js index 3b15be3b..f88136d0 100644 --- a/lib/versioned/^3.7.0/log/events.js +++ b/lib/versioned/^3.7.0/log/events.js @@ -1,9 +1,9 @@ 'use strict'; -var chalk = require('chalk'); var log = require('gulplog'); var prettyTime = require('pretty-hrtime'); +var ansi = require('../../../shared/ansi'); var exit = require('../../../shared/exit'); var formatError = require('../formatError'); @@ -26,14 +26,14 @@ function logEvents(gulpInst) { gulpInst.on('task_start', function(e) { // TODO: batch these // so when 5 tasks start at once it only logs one time with all 5 - log.info('Starting', '\'' + chalk.cyan(e.task) + '\'...'); + log.info('Starting', '\'' + ansi.cyan(e.task) + '\'...'); }); gulpInst.on('task_stop', function(e) { var time = prettyTime(e.hrDuration); log.info( - 'Finished', '\'' + chalk.cyan(e.task) + '\'', - 'after', chalk.magenta(time) + 'Finished', '\'' + ansi.cyan(e.task) + '\'', + 'after', ansi.magenta(time) ); }); @@ -41,16 +41,16 @@ function logEvents(gulpInst) { var msg = formatError(e); var time = prettyTime(e.hrDuration); log.error( - '\'' + chalk.cyan(e.task) + '\'', - chalk.red('errored after'), - chalk.magenta(time) + '\'' + ansi.cyan(e.task) + '\'', + ansi.red('errored after'), + ansi.magenta(time) ); log.error(msg); }); gulpInst.on('task_not_found', function(err) { log.error( - chalk.red('Task \'' + err.task + '\' is not in your gulpfile') + ansi.red('Task \'' + err.task + '\' is not in your gulpfile') ); log.error('Please check the documentation for proper gulpfile formatting'); exit(1); diff --git a/lib/versioned/^4.0.0-alpha.1/index.js b/lib/versioned/^4.0.0-alpha.1/index.js index 3b3aa0f1..a791b87d 100644 --- a/lib/versioned/^4.0.0-alpha.1/index.js +++ b/lib/versioned/^4.0.0-alpha.1/index.js @@ -3,10 +3,10 @@ var fs = require('fs'); var log = require('gulplog'); -var chalk = require('chalk'); var stdout = require('mute-stdout'); var tildify = require('tildify'); +var ansi = require('../../shared/ansi'); var exit = require('../../shared/exit'); var isString = require('../../shared/is-string'); @@ -51,7 +51,7 @@ function execute(opts, env, config) { if (config.description && isString(config.description)) { tree.label = config.description; } else { - tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); + tree.label = 'Tasks for ' + ansi.magenta(tildify(env.configPath)); } tree.nodes = gulpInst.tree({ deep: true }); return logTasks(tree, opts, function(taskname) { @@ -74,14 +74,14 @@ function execute(opts, env, config) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); + log.info('Using gulpfile', ansi.magenta(tildify(env.configPath))); gulpInst.parallel(toRun)(function(err) { if (err) { exit(1); } }); } catch (err) { - log.error(chalk.red(err.message)); + log.error(ansi.red(err.message)); log.error('To list available tasks, try running: gulp --tasks'); exit(1); } diff --git a/lib/versioned/^4.0.0-alpha.2/index.js b/lib/versioned/^4.0.0-alpha.2/index.js index aba74979..dc616461 100644 --- a/lib/versioned/^4.0.0-alpha.2/index.js +++ b/lib/versioned/^4.0.0-alpha.2/index.js @@ -3,10 +3,10 @@ var fs = require('fs'); var log = require('gulplog'); -var chalk = require('chalk'); var stdout = require('mute-stdout'); var tildify = require('tildify'); +var ansi = require('../../shared/ansi'); var exit = require('../../shared/exit'); var isString = require('../../shared/is-string'); @@ -53,7 +53,7 @@ function execute(opts, env, config) { if (config.description && isString(config.description)) { tree.label = config.description; } else { - tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); + tree.label = 'Tasks for ' + ansi.magenta(tildify(env.configPath)); } return logTasks(tree, opts, getTask(gulpInst)); @@ -74,14 +74,14 @@ function execute(opts, env, config) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); + log.info('Using gulpfile', ansi.magenta(tildify(env.configPath))); gulpInst.parallel(toRun)(function(err) { if (err) { exit(1); } }); } catch (err) { - log.error(chalk.red(err.message)); + log.error(ansi.red(err.message)); log.error('To list available tasks, try running: gulp --tasks'); exit(1); } diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index 73c19c8b..85cb1ace 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -3,10 +3,10 @@ var fs = require('fs'); var log = require('gulplog'); -var chalk = require('chalk'); var stdout = require('mute-stdout'); var tildify = require('tildify'); +var ansi = require('../../shared/ansi'); var exit = require('../../shared/exit'); var isString = require('../../shared/is-string'); @@ -53,7 +53,7 @@ function execute(opts, env, config) { if (config.description && isString(config.description)) { tree.label = config.description; } else { - tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); + tree.label = 'Tasks for ' + ansi.magenta(tildify(env.configPath)); } return logTasks(tree, opts, getTask(gulpInst)); @@ -74,14 +74,14 @@ function execute(opts, env, config) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); + log.info('Using gulpfile', ansi.magenta(tildify(env.configPath))); gulpInst.parallel(toRun)(function(err) { if (err) { exit(1); } }); } catch (err) { - log.error(chalk.red(err.message)); + log.error(ansi.red(err.message)); log.error('To list available tasks, try running: gulp --tasks'); exit(1); } diff --git a/lib/versioned/^4.0.0/log/events.js b/lib/versioned/^4.0.0/log/events.js index 8c2f2d22..64938dcc 100644 --- a/lib/versioned/^4.0.0/log/events.js +++ b/lib/versioned/^4.0.0/log/events.js @@ -1,9 +1,9 @@ 'use strict'; var log = require('gulplog'); -var chalk = require('chalk'); var prettyTime = require('pretty-hrtime'); var formatError = require('../formatError'); +var ansi = require('../../../shared/ansi'); // Wire up logging events function logEvents(gulpInst) { @@ -14,15 +14,15 @@ function logEvents(gulpInst) { // TODO: batch these // so when 5 tasks start at once it only logs one time with all 5 var level = evt.branch ? 'debug' : 'info'; - log[level]('Starting', '\'' + chalk.cyan(evt.name) + '\'...'); + log[level]('Starting', '\'' + ansi.cyan(evt.name) + '\'...'); }); gulpInst.on('stop', function(evt) { var time = prettyTime(evt.duration); var level = evt.branch ? 'debug' : 'info'; log[level]( - 'Finished', '\'' + chalk.cyan(evt.name) + '\'', - 'after', chalk.magenta(time) + 'Finished', '\'' + ansi.cyan(evt.name) + '\'', + 'after', ansi.magenta(time) ); }); @@ -31,9 +31,9 @@ function logEvents(gulpInst) { var time = prettyTime(evt.duration); var level = evt.branch ? 'debug' : 'error'; log[level]( - '\'' + chalk.cyan(evt.name) + '\'', - chalk.red('errored after'), - chalk.magenta(time) + '\'' + ansi.cyan(evt.name) + '\'', + ansi.red('errored after'), + ansi.magenta(time) ); // If we haven't logged this before, log it and add to list diff --git a/lib/versioned/^4.0.0/log/syncTask.js b/lib/versioned/^4.0.0/log/syncTask.js index 493654fc..1932e89c 100644 --- a/lib/versioned/^4.0.0/log/syncTask.js +++ b/lib/versioned/^4.0.0/log/syncTask.js @@ -1,7 +1,7 @@ 'use strict'; var log = require('gulplog'); -var chalk = require('chalk'); +var ansi = require('../../../shared/ansi'); var tasks = {}; @@ -17,11 +17,11 @@ function warn() { }).join(', '); log.warn( - chalk.red('The following tasks did not complete:'), - chalk.cyan(taskNames) + ansi.red('The following tasks did not complete:'), + ansi.cyan(taskNames) ); log.warn( - chalk.red('Did you forget to signal async completion?') + ansi.red('Did you forget to signal async completion?') ); } diff --git a/package.json b/package.json index ebfa3c0c..c2217486 100644 --- a/package.json +++ b/package.json @@ -32,11 +32,20 @@ "changelog": "github-changes -o gulpjs -r gulp-cli -b master -f ./CHANGELOG.md --order-semver --use-commit-body" }, "dependencies": { + "ansi-bgred": "^0.1.1", + "ansi-blue": "^0.1.1", + "ansi-bold": "^0.1.1", + "ansi-cyan": "^0.1.1", + "ansi-gray": "^0.1.1", + "ansi-green": "^0.1.1", + "ansi-magenta": "^0.1.1", + "ansi-red": "^0.1.1", + "ansi-white": "^0.1.1", "archy": "^1.0.0", - "chalk": "^1.1.0", "copy-props": "^2.0.1", "fancy-log": "^1.1.0", "gulplog": "^1.0.0", + "has-flag": "^2.0.0", "interpret": "^1.0.0", "liftoff": "^2.3.0", "lodash.isfunction": "^3.0.8", diff --git a/test/config-description.js b/test/config-description.js index 41709909..e64d4630 100644 --- a/test/config-description.js +++ b/test/config-description.js @@ -12,7 +12,6 @@ var fixturesDir = path.join(__dirname, 'fixtures', 'config'); var expectedDir = path.join(__dirname, 'expected', 'config'); describe('config: description', function() { - it('Should configure with a .gulp.* file in cwd', function(done) { runner({ verbose: false }) .basedir(fixturesDir) @@ -23,8 +22,7 @@ describe('config: description', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), - 'utf-8'); + var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), 'utf-8'); stdout = eraseTime(stdout); expect(stdout).toEqual(expected); done(err); @@ -41,8 +39,7 @@ describe('config: description', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), - 'utf-8'); + var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), 'utf-8'); stdout = eraseTime(skipLines(stdout, 1)); expect(stdout).toEqual(expected); done(err); @@ -59,8 +56,7 @@ describe('config: description', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output1.txt'), - 'utf-8'); + var expected = fs.readFileSync(path.join(expectedDir, 'output1.txt'), 'utf-8'); stdout = eraseTime(stdout); expect(stdout).toEqual(expected); done(err); diff --git a/test/config-flags-compactTasks.js b/test/config-flags-compactTasks.js index 7019646a..cf4bb488 100644 --- a/test/config-flags-compactTasks.js +++ b/test/config-flags-compactTasks.js @@ -8,12 +8,12 @@ var eraseTime = require('gulp-test-tools').eraseTime; var fixturesDir = path.join(__dirname, 'fixtures/config'); var expectedDir = path.join(__dirname, 'expected'); -var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); +var runner = require('gulp-test-tools') + .gulpRunner() + .basedir(fixturesDir); -describe ('config: flags.compactTasks', function() { - - it('Should compact task lists when `flags.compactTasks` is true in .gulp.*', - function(done) { +describe('config: flags.compactTasks', function() { + it('Should compact task lists when `flags.compactTasks` is true in .gulp.*', function(done) { runner .chdir('flags/compactTasks/t') .gulp('--tasks') @@ -32,8 +32,7 @@ describe ('config: flags.compactTasks', function() { } }); - it('Should not compact task lists when `flags.compactTasks` is false in ' + - '.gulp.*', function(done) { + it('Should not compact task lists when `flags.compactTasks` is false in ' + '.gulp.*', function(done) { runner .chdir('flags/compactTasks/f') .gulp('--tasks') @@ -51,5 +50,4 @@ describe ('config: flags.compactTasks', function() { done(err); } }); - }); diff --git a/test/config-flags-continue.js b/test/config-flags-continue.js index 753fe8d5..b24b8a6d 100644 --- a/test/config-flags-continue.js +++ b/test/config-flags-continue.js @@ -11,7 +11,6 @@ var fixturesDir = path.join(__dirname, 'fixtures/config'); var runner = require('gulp-test-tools').gulpRunner({ verbose: false }).basedir(fixturesDir); describe('config: flags.continue', function() { - it('Should continue if `flags.continue` is true in .gulp.*', function(done) { runner @@ -63,5 +62,4 @@ describe('config: flags.continue', function() { done(); } }); - }); diff --git a/test/config-flags-log-level.js b/test/config-flags-log-level.js index 6a960b81..12fd20b9 100644 --- a/test/config-flags-log-level.js +++ b/test/config-flags-log-level.js @@ -6,7 +6,6 @@ var eraseTime = require('gulp-test-tools').eraseTime; var runner = require('gulp-test-tools').gulpRunner; describe('config: flag.logLevel', function() { - describe('log level 3 by default', function() { it('Should output error log', function(done) { runner({ verbose: false }) @@ -20,33 +19,34 @@ describe('config: flag.logLevel', function() { }); it('Should output warn log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'invalid-package.json'); + var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', 'invalid-package.json'); runner({ verbose: false }) .gulp('--verify', packageJsonPath) .run(function(err, stdout, stderr) { expect(err).toNotEqual(null); expect(eraseTime(stdout)).toEqual( - 'Verifying plugins in ' + packageJsonPath + '\n' + - 'Blacklisted plugins found in this project:\n' + - 'gulp-blink: deprecated. use \`blink` instead.\n'); + 'Verifying plugins in ' + + packageJsonPath + + '\n' + + 'Blacklisted plugins found in this project:\n' + + 'gulp-blink: deprecated. use `blink` instead.\n' + ); expect(stderr).toEqual(''); done(); }); }); it('Should output info log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'valid-package.json'); + var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', 'valid-package.json'); runner({ verbose: false }) .gulp('--verify', packageJsonPath) .run(function(err, stdout, stderr) { expect(err).toEqual(null); expect(eraseTime(stdout)).toEqual( - 'Verifying plugins in ' + packageJsonPath + '\n' + - 'There are no blacklisted plugins in this project\n'); + 'Verifying plugins in ' + packageJsonPath + '\n' + 'There are no blacklisted plugins in this project\n' + ); expect(stderr).toEqual(''); done(err); }); @@ -54,135 +54,117 @@ describe('config: flag.logLevel', function() { }); describe('log level 1 by config `flags.logLevel`', function() { - var gulp = runner({ verbose: false }) - .basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/L')) - .gulp; + var gulp = runner({ verbose: false }).basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/L')).gulp; it('Should output error log', function(done) { - gulp('--gulpfile x') - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(stdout).toEqual(''); - expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); - done(); - }); + gulp('--gulpfile x').run(function(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + done(); + }); }); it('Should output warn log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'invalid-package.json'); - - gulp('--verify', packageJsonPath) - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(stdout).toEqual(''); - expect(stderr).toEqual(''); - done(); - }); + var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', 'invalid-package.json'); + + gulp('--verify', packageJsonPath).run(function(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(stdout).toEqual(''); + expect(stderr).toEqual(''); + done(); + }); }); it('Should output info log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'valid-package.json'); - - gulp('--verify', packageJsonPath) - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stdout).toEqual(''); - expect(stderr).toEqual(''); - done(err); - }); + var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', 'valid-package.json'); + + gulp('--verify', packageJsonPath).run(function(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stdout).toEqual(''); + expect(stderr).toEqual(''); + done(err); + }); }); }); describe('log level 2 by config `flags.logLevel`', function() { - var gulp = runner({ verbose: false }) - .basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/LL')) - .gulp; + var gulp = runner({ verbose: false }).basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/LL')).gulp; it('Should output error log', function(done) { - gulp('--gulpfile x') - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(stdout).toEqual(''); - expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); - done(); - }); + gulp('--gulpfile x').run(function(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + done(); + }); }); it('Should output warn log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'invalid-package.json'); - - gulp('--verify', packageJsonPath) - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(eraseTime(stdout)).toEqual( - 'Blacklisted plugins found in this project:\n' + - 'gulp-blink: deprecated. use \`blink` instead.\n'); - expect(stderr).toEqual(''); - done(); - }); + var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', 'invalid-package.json'); + + gulp('--verify', packageJsonPath).run(function(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(eraseTime(stdout)).toEqual( + 'Blacklisted plugins found in this project:\n' + 'gulp-blink: deprecated. use `blink` instead.\n' + ); + expect(stderr).toEqual(''); + done(); + }); }); it('Should output info log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'valid-package.json'); - - gulp('--verify', packageJsonPath) - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stdout).toEqual(''); - expect(stderr).toEqual(''); - done(err); - }); + var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', 'valid-package.json'); + + gulp('--verify', packageJsonPath).run(function(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stdout).toEqual(''); + expect(stderr).toEqual(''); + done(err); + }); }); }); describe('log level 3 by config `flags.logLevel`', function() { - var gulp = runner({ verbose: false }) - .basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/LLL')) - .gulp; + var gulp = runner({ verbose: false }).basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/LLL')).gulp; it('Should output error log', function(done) { - gulp('--gulpfile x') - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(stdout).toEqual(''); - expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); - done(); - }); + gulp('--gulpfile x').run(function(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + done(); + }); }); it('Should output warn log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'invalid-package.json'); - - gulp('--verify', packageJsonPath) - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(eraseTime(stdout)).toEqual( - 'Verifying plugins in ' + packageJsonPath + '\n' + + var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', 'invalid-package.json'); + + gulp('--verify', packageJsonPath).run(function(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(eraseTime(stdout)).toEqual( + 'Verifying plugins in ' + + packageJsonPath + + '\n' + 'Blacklisted plugins found in this project:\n' + - 'gulp-blink: deprecated. use \`blink` instead.\n'); - expect(stderr).toEqual(''); - done(); - }); + 'gulp-blink: deprecated. use `blink` instead.\n' + ); + expect(stderr).toEqual(''); + done(); + }); }); it('Should output info log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'valid-package.json'); - - gulp('--verify', packageJsonPath) - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(eraseTime(stdout)).toEqual( - 'Verifying plugins in ' + packageJsonPath + '\n' + - 'There are no blacklisted plugins in this project\n'); - expect(stderr).toEqual(''); - done(err); - }); + var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', 'valid-package.json'); + + gulp('--verify', packageJsonPath).run(function(err, stdout, stderr) { + expect(err).toEqual(null); + expect(eraseTime(stdout)).toEqual( + 'Verifying plugins in ' + packageJsonPath + '\n' + 'There are no blacklisted plugins in this project\n' + ); + expect(stderr).toEqual(''); + done(err); + }); }); }); }); diff --git a/test/config-flags-silent.js b/test/config-flags-silent.js index ee0ff1d0..a56e91c1 100644 --- a/test/config-flags-silent.js +++ b/test/config-flags-silent.js @@ -10,7 +10,6 @@ var fixturesDir = path.join(__dirname, 'fixtures/config'); var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); describe('config: flags.silent', function() { - it('Should be silent if `flags.silent` is true in .gulp.*', function(done) { runner @@ -45,5 +44,4 @@ describe('config: flags.silent', function() { done(err); } }); - }); diff --git a/test/config-flags-sortTasks.js b/test/config-flags-sortTasks.js index 1da46918..8762fda4 100644 --- a/test/config-flags-sortTasks.js +++ b/test/config-flags-sortTasks.js @@ -8,12 +8,12 @@ var eraseTime = require('gulp-test-tools').eraseTime; var fixturesDir = path.join(__dirname, 'fixtures/config'); var expectedDir = path.join(__dirname, 'expected'); -var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); +var runner = require('gulp-test-tools') + .gulpRunner() + .basedir(fixturesDir); -describe ('config: flags.sortTasks', function() { - - it('Should sort top tasks in task list when `flags.sortTasks` is true in ' + - '.gulp.*', function(done) { +describe('config: flags.sortTasks', function() { + it('Should sort top tasks in task list when `flags.sortTasks` is true in ' + '.gulp.*', function(done) { runner .chdir('flags/sortTasks/t') .gulp('--tasks') @@ -32,8 +32,7 @@ describe ('config: flags.sortTasks', function() { } }); - it('Should sort top tasks in task list when `flags.sortTasks` is false in ' + - '.gulp.*', function(done) { + it('Should sort top tasks in task list when `flags.sortTasks` is false in ' + '.gulp.*', function(done) { runner .chdir('flags/sortTasks/f') .gulp('--tasks') @@ -51,5 +50,4 @@ describe ('config: flags.sortTasks', function() { done(err); } }); - }); diff --git a/test/config-flags-tasksDepth.js b/test/config-flags-tasksDepth.js index 90c7822f..3c9d687e 100644 --- a/test/config-flags-tasksDepth.js +++ b/test/config-flags-tasksDepth.js @@ -8,12 +8,12 @@ var eraseTime = require('gulp-test-tools').eraseTime; var fixturesDir = path.join(__dirname, 'fixtures/config'); var expectedDir = path.join(__dirname, 'expected'); -var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); +var runner = require('gulp-test-tools') + .gulpRunner() + .basedir(fixturesDir); -describe ('config: flags.tasksDepth', function() { - - it('Should limit depth of task list when `flags.tasksDepth` is ' + - 'specified', function(done) { +describe('config: flags.tasksDepth', function() { + it('Should limit depth of task list when `flags.tasksDepth` is ' + 'specified', function(done) { runner .chdir('flags/tasksDepth') .gulp('--tasks') @@ -31,5 +31,4 @@ describe ('config: flags.tasksDepth', function() { done(err); } }); - }); diff --git a/test/exports-as-tasks.js b/test/exports-as-tasks.js index 708c9a52..2f922a94 100644 --- a/test/exports-as-tasks.js +++ b/test/exports-as-tasks.js @@ -15,8 +15,7 @@ describe('exports as tasks', function() { it('prints the task list', function(done) { runner({ verbose: false }) - .gulp('--tasks', '--sort-tasks', - '--gulpfile ./test/fixtures/gulpfiles/gulpfile-exports.babel.js') + .gulp('--tasks', '--sort-tasks', '--gulpfile ./test/fixtures/gulpfiles/gulpfile-exports.babel.js') .run(cb); function cb(err, stdout, stderr) { @@ -29,5 +28,4 @@ describe('exports as tasks', function() { done(err); } }); - }); diff --git a/test/flags-continue.js b/test/flags-continue.js index fbfe644a..b9774df7 100644 --- a/test/flags-continue.js +++ b/test/flags-continue.js @@ -8,7 +8,6 @@ var skipLines = require('gulp-test-tools').skipLines; var headLines = require('gulp-test-tools').headLines; describe('flag: --continue', function() { - it('continues execution when flag is set', function(done) { runner({ verbose: false }) .gulp('test4', '--continue', '--cwd ./test/fixtures/gulpfiles') @@ -57,5 +56,4 @@ describe('flag: --continue', function() { done(); } }); - }); diff --git a/test/flags-gulpfile.js b/test/flags-gulpfile.js index 2f75a4e9..8ae5e69a 100644 --- a/test/flags-gulpfile.js +++ b/test/flags-gulpfile.js @@ -9,7 +9,6 @@ var eraseLapse = require('gulp-test-tools').eraseLapse; var path = require('path'); describe('flag: --gulpfile', function() { - it('Manually set path of gulpfile', function(done) { var gulpfilePath = 'test/fixtures/gulpfiles/gulpfile-2.js'; @@ -25,7 +24,6 @@ describe('flag: --gulpfile', function() { var workdir = path.dirname(gulpfilePath).replace(/\//g, path.sep); expect(chgWorkdirLog).toMatch('Working directory changed to '); expect(chgWorkdirLog).toMatch(workdir); - stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); expect(stdout).toEqual( 'Starting \'default\'...\n' + @@ -38,5 +36,4 @@ describe('flag: --gulpfile', function() { done(err); } }); - }); diff --git a/test/flags-help.js b/test/flags-help.js index f9dcad0a..8b2108b2 100644 --- a/test/flags-help.js +++ b/test/flags-help.js @@ -6,7 +6,7 @@ var runner = require('gulp-test-tools').gulpRunner; var path = require('path'); var fs = require('fs'); -// Erases a first space inserted by `chalk`. +// Erases a first space inserted function eraseFirstSpace(s) { return s.replace(/^(\r\n|\n|\r)\s?/g, '\n'); } @@ -15,7 +15,6 @@ var outputFile = path.join(__dirname, 'expected/flags-help.txt'); var outputText = fs.readFileSync(outputFile, 'utf8'); describe('flag: --help', function() { - it('shows help using --help', function(done) { runner({ verbose: false }) .gulp('--help', '--cwd ./test/fixtures/gulpfiles') @@ -43,5 +42,4 @@ describe('flag: --help', function() { done(err); } }); - }); diff --git a/test/flags-require.js b/test/flags-require.js index 4e8decca..12f19f21 100644 --- a/test/flags-require.js +++ b/test/flags-require.js @@ -9,7 +9,6 @@ var eraseLapse = require('gulp-test-tools').eraseLapse; var path = require('path'); describe('flag: --require', function() { - it('requires module before running gulpfile', function(done) { runner({ verbose: false }) .gulp('--require ../test-module.js', '--cwd ./test/fixtures/gulpfiles') @@ -91,5 +90,4 @@ describe('flag: --require', function() { done(err); } }); - }); diff --git a/test/flags-tasks.js b/test/flags-tasks.js index 10662cc1..afae45af 100644 --- a/test/flags-tasks.js +++ b/test/flags-tasks.js @@ -10,7 +10,6 @@ var runner = require('gulp-test-tools').gulpRunner; var expectedDir = path.join(__dirname, 'expected'); describe('flag: --tasks', function() { - it('prints the task list', function(done) { runner({ verbose: false }) .gulp('--tasks --sort-tasks --cwd ./test/fixtures/gulpfiles') @@ -29,9 +28,12 @@ describe('flag: --tasks', function() { it('print the task list with description and flags', function(done) { runner({ verbose: false }) - .gulp('--tasks', '--sort-tasks', + .gulp( + '--tasks', + '--sort-tasks', '--gulpfile ./test/fixtures/gulpfiles/with-desc-and-flags.js', - '--cwd ./test/fixtures') + '--cwd ./test/fixtures' + ) .run(cb); function cb(err, stdout, stderr) { @@ -45,12 +47,14 @@ describe('flag: --tasks', function() { } }); - it('print the task list by gulp.task(s).unwrap and gulp.task(s)', - function(done) { + it('print the task list by gulp.task(s).unwrap and gulp.task(s)', function(done) { runner({ verbose: false }) - .gulp('--tasks', '--sort-tasks', + .gulp( + '--tasks', + '--sort-tasks', '--gulpfile ./test/fixtures/gulpfiles/by-unwrap-and-not-by-unwrap.js', - '--cwd ./test/fixtures') + '--cwd ./test/fixtures' + ) .run(cb); function cb(err, stdout, stderr) { @@ -82,8 +86,7 @@ describe('flag: --tasks', function() { it('prints the task list with --sort-tasks flag', function(done) { runner({ verbose: false }) - .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', - '--sort-tasks') + .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', '--sort-tasks') .run(cb); function cb(err, stdout, stderr) { @@ -99,8 +102,7 @@ describe('flag: --tasks', function() { it('prints the task list with --tasks-depth flag', function(done) { runner({ verbose: false }) - .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', - '--tasks-depth 4') + .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', '--tasks-depth 4') .run(cb); function cb(err, stdout, stderr) { @@ -116,8 +118,7 @@ describe('flag: --tasks', function() { it('prints the task list with --depth flag', function(done) { runner({ verbose: false }) - .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', - '--depth 4') + .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', '--depth 4') .run(cb); function cb(err, stdout, stderr) { @@ -133,8 +134,7 @@ describe('flag: --tasks', function() { it('prints the task list with --compact-tasks flag', function(done) { runner({ verbose: false }) - .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', - '--compact-tasks') + .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', '--compact-tasks') .run(cb); function cb(err, stdout, stderr) { @@ -147,5 +147,4 @@ describe('flag: --tasks', function() { done(err); } }); - }); diff --git a/test/flags-verify.js b/test/flags-verify.js index e296b1ff..7f5deb66 100644 --- a/test/flags-verify.js +++ b/test/flags-verify.js @@ -6,7 +6,6 @@ var eraseTime = require('gulp-test-tools').eraseTime; var path = require('path'); describe('flag: --verify', function() { - it('dependencies with invalid dependency', function(done) { runner({ verbose: false }) .gulp('--verify invalid-package.json', '--cwd ./test/fixtures/packages/') @@ -20,9 +19,9 @@ describe('flag: --verify', function() { 'Verifying plugins in ' + path.resolve('./test/fixtures/packages/invalid-package.json') + '\n' + - 'Blacklisted plugins found in this project:\n' + - 'gulp-blink: deprecated. use `blink` instead.\n' + - '' + 'Blacklisted plugins found in this project:\n' + + 'gulp-blink: deprecated. use `blink` instead.\n' + + '' ); done(); } @@ -41,8 +40,8 @@ describe('flag: --verify', function() { 'Verifying plugins in ' + path.resolve('./test/fixtures/packages/valid-package.json') + '\n' + - 'There are no blacklisted plugins in this project\n' + - '' + 'There are no blacklisted plugins in this project\n' + + '' ); done(err); } @@ -59,13 +58,13 @@ describe('flag: --verify', function() { stdout = eraseTime(stdout); expect(stdout).toEqual( 'Verifying plugins in ' + - path.resolve('./test/fixtures/packages/package.json') + '\n' + - 'Blacklisted plugins found in this project:\n' + - 'gulp-blink: deprecated. use `blink` instead.\n' + - '' + path.resolve('./test/fixtures/packages/package.json') + + '\n' + + 'Blacklisted plugins found in this project:\n' + + 'gulp-blink: deprecated. use `blink` instead.\n' + + '' ); done(); } }); - });