Skip to content

Commit

Permalink
Update: Share task logging logic
Browse files Browse the repository at this point in the history
  • Loading branch information
= authored and phated committed Dec 21, 2017
1 parent ab6e623 commit 5cdfb35
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ var archy = require('archy');
var chalk = require('chalk');
var gutil = require('gulp-util');

function logTasks(tree, tasks) {
function logTasks(tree, getDescription) {
var padding = 0;
var rdependency = /[ │] [├└]/;
archy(tree)
.split('\n')
.filter(function(v, i) {
Expand All @@ -23,17 +24,18 @@ function logTasks(tree, tasks) {
var line = v.split(' ');
var task = line.slice(1).join(' ');

if (/.└/.test(v)) {
// Log dependencies as is
// Log dependencies as is
if (rdependency.test(v)) {
gutil.log(v);
} else {
// Pretty task with optionnal description
gutil.log(
line[0] + ' ' + chalk.cyan(task) +
Array(padding + 3 - v.length).join(' ') +
(tasks.get(task).description || '')
);
return;
}

// Pretty task with optionnal description
gutil.log(
line[0] + ' ' + chalk.cyan(task) +
Array(padding + 3 - v.length).join(' ') +
(getDescription(task) || '')
);
});
}

Expand Down
9 changes: 7 additions & 2 deletions lib/versioned/^3.7.0/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var chalk = require('chalk');
var gutil = require('gulp-util');
var tildify = require('tildify');

var logTasks = require('./log/tasks');
var taskTree = require('./taskTree');
var logTasks = require('../../shared/log/tasks');
var logEvents = require('./log/events');
var logTasksSimple = require('./log/tasksSimple');

Expand All @@ -25,7 +26,11 @@ function execute(opts, env) {
return logTasksSimple(env, gulpInst);
}
if (opts.tasks) {
return logTasks(env, gulpInst);
var tree = taskTree(gulpInst.tasks);
tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));
return logTasks(tree, function(task) {
return gulpInst.tasks[task].fn.description;
});
}
gulpInst.start.apply(gulpInst, toRun);
});
Expand Down
45 changes: 0 additions & 45 deletions lib/versioned/^3.7.0/log/tasks.js

This file was deleted.

6 changes: 4 additions & 2 deletions lib/versioned/^4.0.0-alpha.1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var tildify = require('tildify');

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

var logTasks = require('./log/tasks');
var logTasks = require('../../shared/log/tasks');
var logEvents = require('./log/events');
var logTasksSimple = require('./log/tasksSimple');

Expand All @@ -30,7 +30,9 @@ function execute(opts, env) {
label: 'Tasks for ' + chalk.magenta(tildify(env.configPath)),
nodes: gulpInst.tree({ deep: true }),
};
return logTasks(tree, gulpInst);
return logTasks(tree, function(task) {
return gulpInst.get(task).description;
});
}
if (opts.tasksJson) {
return console.log(
Expand Down

0 comments on commit 5cdfb35

Please sign in to comment.