Skip to content

Commit

Permalink
New: Support description task property
Browse files Browse the repository at this point in the history
  • Loading branch information
louisremi authored and phated committed Dec 21, 2017
1 parent 0a4cdd1 commit 612eab1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
32 changes: 28 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,38 @@ function handleArguments(env) {

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
14 changes: 8 additions & 6 deletions test/flags-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ lab.experiment('flag: --tasks', function () {

lab.test('prints the task list', function (done) {
child.exec('node ' + __dirname + '/../bin/gulp.js --tasks --cwd ./test', function(err, stdout) {
stdout = stdout.replace(/\\/g, '/');
code.expect(stdout).to.contain('/gulp-cli/test');
code.expect(stdout).to.contain('├── test1');
code.expect(stdout).to.contain('├── test2');
code.expect(stdout).to.contain('├── test3');
code.expect(stdout).to.contain('└── default');
code.expect(stdout).to.contain('Tasks for');
stdout = stdout.replace(/\\/g, '/').split('Tasks for')[1].split('\n');
code.expect(stdout[0]).to.contain('/gulp-cli/test');
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 description');
code.expect(stdout[5]).to.contain('└── default');
done(err);
});
});
Expand Down
6 changes: 4 additions & 2 deletions test/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
var gulp = require('gulp');

function noop(){}
function described(){}
described.description = 'description';

gulp.task('test1', noop);
gulp.task('test2', noop);
gulp.task('test3', noop);
gulp.task('test2', ['test1'], noop);
gulp.task('test3', described);

gulp.task('default', noop);

0 comments on commit 612eab1

Please sign in to comment.