Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
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 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 tildify = require('./lib/shared/tildify');
var cliOptions = require('./lib/shared/cliOptions');
Expand Down Expand Up @@ -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;
Expand All @@ -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);
});
Expand Down Expand Up @@ -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);
}

Expand All @@ -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))
);
}

Expand All @@ -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)
);
}

Expand Down
38 changes: 38 additions & 0 deletions lib/shared/ansi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

var colors = require('ansi-colors');
var supportsColor = require('color-support');

var hasColors = colorize();

module.exports = {
red: hasColors ? colors.red : noColor,
green: hasColors ? colors.green : noColor,
blue: hasColors ? colors.blue : noColor,
magenta: hasColors ? colors.magenta : noColor,
cyan: hasColors ? colors.cyan : noColor,
white: hasColors ? colors.white : noColor,
gray: hasColors ? colors.gray : noColor,
bgred: hasColors ? colors.bgred : noColor,
bold: hasColors ? colors.bold : noColor,
};

function noColor(message) {
return message;
}

function hasFlag(flag) {
return (process.argv.indexOf('--' + flag) !== -1);
}

function colorize() {
if (hasFlag('no-color')) {
return false;
}

if (hasFlag('color')) {
return true;
}

return supportsColor();
}
36 changes: 18 additions & 18 deletions lib/shared/cliOptions.js
Original file line number Diff line number Diff line change
@@ -1,110 +1,110 @@
'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: {
alias: 'f',
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.'),
},
'tasks-depth': {
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': {
alias: 'L',
// 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.'),
},
Expand Down
4 changes: 2 additions & 2 deletions lib/shared/log/blacklistError.js
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down
14 changes: 7 additions & 7 deletions lib/shared/log/tasks.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

var archy = require('archy');
var chalk = require('chalk');
var log = require('gulplog');

var sortBy = require('array-sort');
var isObject = require('isobject');

var ansi = require('../ansi');
var copyTree = require('./copy-tree');

function logTasks(tree, opts, getTask) {
Expand Down Expand Up @@ -140,20 +140,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);
Expand Down
8 changes: 4 additions & 4 deletions lib/shared/log/verify.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
'use strict';

var chalk = require('chalk');
var log = require('gulplog');

var ansi = require('../ansi');
var exit = require('../exit');

function logVerify(blacklisted) {
var pluginNames = Object.keys(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);
Expand Down
6 changes: 3 additions & 3 deletions lib/versioned/^3.7.0/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';

var chalk = require('chalk');
var log = require('gulplog');
var stdout = require('mute-stdout');

var taskTree = require('./taskTree');

var tildify = require('../../shared/tildify');
var logTasks = require('../../shared/log/tasks');
var ansi = require('../../shared/ansi');
var logEvents = require('./log/events');
var logTasksSimple = require('./log/tasksSimple');
var registerExports = require('../../shared/registerExports');
Expand All @@ -23,7 +23,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);
Expand All @@ -44,7 +44,7 @@ function execute(opts, env, config) {
if (config.description && typeof config.description === 'string') {
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;
Expand Down
Loading