Skip to content

Commit

Permalink
New: Support task descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
= authored and phated committed Dec 21, 2017
1 parent 2a8bfd0 commit ab6e623
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 12 deletions.
30 changes: 26 additions & 4 deletions lib/versioned/^3.7.0/log/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,36 @@ var taskTree = require('../taskTree');

function logTasks(env, localGulp) {
var tree = taskTree(localGulp.tasks);
var padding = 0;
tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));
archy(tree)
.split('\n')
.forEach(function(v) {
if (v.trim().length === 0) {
return;
.filter(function(v, i) {
// Log first line as is
if (i === 0) {
gutil.log(v);
return false;
}
// Search for longest line
if (v.length > padding) {
padding = v.length;
}
return v.trim().length !== 0;
}).forEach(function(v) {
var line = v.split(' ');
var task = line.slice(1).join(' ');

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

Expand Down
2 changes: 1 addition & 1 deletion lib/versioned/^4.0.0-alpha.1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function execute(opts, env) {
label: 'Tasks for ' + chalk.magenta(tildify(env.configPath)),
nodes: gulpInst.tree({ deep: true }),
};
return logTasks(tree);
return logTasks(tree, gulpInst);
}
if (opts.tasksJson) {
return console.log(
Expand Down
35 changes: 29 additions & 6 deletions lib/versioned/^4.0.0-alpha.1/log/tasks.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
'use strict';

var archy = require('archy');
var chalk = require('chalk');
var gutil = require('gulp-util');

function logTasks(tree) {
function logTasks(tree, tasks) {
var padding = 0;
archy(tree)
.split('\n')
.filter(function(v) {
return v.trim().length > 0;
})
.forEach(function(v) {
gutil.log(v);
.filter(function(v, i) {
// Log first line as is
if (i === 0) {
gutil.log(v);
return false;
}
// Search for longest line
if (v.length > padding) {
padding = v.length;
}
return v.trim().length !== 0;
}).forEach(function(v) {
var line = v.split(' ');
var task = line.slice(1).join(' ');

if (/.└/.test(v)) {
// Log dependencies as is
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 || '')
);
}
});
}

Expand Down
2 changes: 1 addition & 1 deletion test/flags-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ lab.experiment('flag: --tasks', function() {
code.expect(stdout[1]).to.contain('├── test1');
code.expect(stdout[2]).to.contain('├─┬ test2');
code.expect(stdout[3]).to.contain('│ └── test1');
code.expect(stdout[4]).to.contain('├── test3');
code.expect(stdout[4]).to.contain('├── test3 description');
code.expect(stdout[5]).to.contain('└─┬ default');
code.expect(stdout[6]).to.contain(' ├── test1');
code.expect(stdout[7]).to.contain(' └── test3');
Expand Down

0 comments on commit ab6e623

Please sign in to comment.