Skip to content

Commit

Permalink
use chalk directly
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 25, 2014
1 parent f91719b commit f7d8333
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
31 changes: 16 additions & 15 deletions bin/gulp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'use strict';
var gutil = require('gulp-util');
var prettyTime = require('pretty-hrtime');
var chalk = require('chalk');
var semver = require('semver');
var archy = require('archy');
var Liftoff = require('liftoff');
Expand All @@ -14,11 +15,11 @@ var cli = new Liftoff({
});

cli.on('require', function (name) {
gutil.log('Requiring external module', gutil.colors.magenta(name));
gutil.log('Requiring external module', chalk.magenta(name));
});

cli.on('requireFail', function (name) {
gutil.log(gutil.colors.red('Failed to load external module'), gutil.colors.magenta(name));
gutil.log(chalk.red('Failed to load external module'), chalk.magenta(name));
});

cli.launch(handleArguments);
Expand All @@ -41,32 +42,32 @@ function handleArguments(env) {
}

if (!env.modulePath) {
gutil.log(gutil.colors.red('No local gulp install found in'), gutil.colors.magenta(env.cwd));
gutil.log(gutil.colors.red('Try running: npm install gulp'));
gutil.log(chalk.red('No local gulp install found in'), chalk.magenta(env.cwd));
gutil.log(chalk.red('Try running: npm install gulp'));
process.exit(1);
}

if (!env.configPath) {
gutil.log(gutil.colors.red('No gulpfile found'));
gutil.log(chalk.red('No gulpfile found'));
process.exit(1);
}

// check for semver difference between cli and local installation
if (semver.gt(cliPackage.version, env.modulePackage.version)) {
gutil.log(gutil.colors.red('Warning: gulp version mismatch:'));
gutil.log(gutil.colors.red('Running gulp is', cliPackage.version));
gutil.log(gutil.colors.red('Local gulp (installed in gulpfile dir) is', env.modulePackage.version));
gutil.log(chalk.red('Warning: gulp version mismatch:'));
gutil.log(chalk.red('Running gulp is', cliPackage.version));
gutil.log(chalk.red('Local gulp (installed in gulpfile dir) is', env.modulePackage.version));
}

var gulpFile = require(env.configPath);
gutil.log('Using gulpfile', gutil.colors.magenta(env.configPath));
gutil.log('Using gulpfile', chalk.magenta(env.configPath));

var gulpInst = require(env.modulePath);
logEvents(gulpInst);

if (process.cwd() !== env.cwd) {
process.chdir(env.cwd);
gutil.log('Working directory changed to', gutil.colors.magenta(env.cwd));
gutil.log('Working directory changed to', chalk.magenta(env.cwd));
}

process.nextTick(function () {
Expand All @@ -79,7 +80,7 @@ function handleArguments(env) {

function logTasks(gulpFile, localGulp) {
var tree = taskTree(localGulp.tasks);
tree.label = 'Tasks for ' + gutil.colors.magenta(gulpFile);
tree.label = 'Tasks for ' + chalk.magenta(gulpFile);
archy(tree).split('\n').forEach(function (v) {
if (v.trim().length === 0) return;
gutil.log(v);
Expand All @@ -96,22 +97,22 @@ function formatError(e) {
// wire up logging events
function logEvents(gulpInst) {
gulpInst.on('task_start', function (e) {
gutil.log('Starting', "'" + gutil.colors.cyan(e.task) + "'...");
gutil.log('Starting', "'" + chalk.cyan(e.task) + "'...");
});

gulpInst.on('task_stop', function (e) {
var time = prettyTime(e.hrDuration);
gutil.log('Finished', "'" + gutil.colors.cyan(e.task) + "'", 'after', gutil.colors.magenta(time));
gutil.log('Finished', "'" + chalk.cyan(e.task) + "'", 'after', chalk.magenta(time));
});

gulpInst.on('task_err', function (e) {
var msg = formatError(e);
var time = prettyTime(e.hrDuration);
gutil.log("'" + gutil.colors.cyan(e.task) + "'", 'errored after', gutil.colors.magenta(time), gutil.colors.red(msg));
gutil.log("'" + chalk.cyan(e.task) + "'", 'errored after', chalk.magenta(time), chalk.red(msg));
});

gulpInst.on('task_not_found', function (err) {
gutil.log(gutil.colors.red("Task '" + err.task + "' was not defined in your gulpfile but you tried to run it."));
gutil.log(chalk.red("Task '" + err.task + "' was not defined in your gulpfile but you tried to run it."));
gutil.log('Please check the documentation for proper gulpfile formatting.');
process.exit(1);
});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"semver": "^2.2.1",
"archy": "^0.0.2",
"deprecated": "^0.0.1",
"liftoff": "^0.8.7"
"liftoff": "^0.8.7",
"chalk": "^0.4.0"
},
"devDependencies": {
"mocha": "^1.17.0",
Expand Down

0 comments on commit f7d8333

Please sign in to comment.