Skip to content

Commit 612eab1

Browse files
louisremiphated
authored andcommitted
New: Support description task property
1 parent 0a4cdd1 commit 612eab1

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

index.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,38 @@ function handleArguments(env) {
136136

137137
function logTasks(env, localGulp) {
138138
var tree = taskTree(localGulp.tasks);
139+
var padding = 0;
139140
tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));
140141
archy(tree)
141142
.split('\n')
142-
.forEach(function (v) {
143-
if (v.trim().length === 0) {
144-
return;
143+
.filter(function (v, i) {
144+
// log first line as is
145+
if ( i === 0 ) {
146+
gutil.log(v);
147+
return false;
148+
}
149+
// search for longest line
150+
if ( v.length > padding ) {
151+
padding = v.length;
152+
}
153+
return v.trim().length !== 0;
154+
155+
}).forEach(function (v) {
156+
var line = v.split(' ');
157+
var task = line.slice(1).join(' ');
158+
159+
if ( /./.test(v) ) {
160+
// log dependencies as is
161+
gutil.log(v);
162+
} else {
163+
// pretty task with optionnal description
164+
gutil.log(
165+
line[0] + ' ' +
166+
chalk.cyan(task) +
167+
Array( padding + 3 - v.length ).join(' ') +
168+
( localGulp.tasks[task].fn.description || '' )
169+
);
145170
}
146-
gutil.log(v);
147171
});
148172
}
149173

test/flags-tasks.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ lab.experiment('flag: --tasks', function () {
99

1010
lab.test('prints the task list', function (done) {
1111
child.exec('node ' + __dirname + '/../bin/gulp.js --tasks --cwd ./test', function(err, stdout) {
12-
stdout = stdout.replace(/\\/g, '/');
13-
code.expect(stdout).to.contain('/gulp-cli/test');
14-
code.expect(stdout).to.contain('├── test1');
15-
code.expect(stdout).to.contain('├── test2');
16-
code.expect(stdout).to.contain('├── test3');
17-
code.expect(stdout).to.contain('└── default');
12+
code.expect(stdout).to.contain('Tasks for');
13+
stdout = stdout.replace(/\\/g, '/').split('Tasks for')[1].split('\n');
14+
code.expect(stdout[0]).to.contain('/gulp-cli/test');
15+
code.expect(stdout[1]).to.contain('├── test1');
16+
code.expect(stdout[2]).to.contain('├─┬ test2');
17+
code.expect(stdout[3]).to.contain('│ └── test1');
18+
code.expect(stdout[4]).to.contain('├── test3 description');
19+
code.expect(stdout[5]).to.contain('└── default');
1820
done(err);
1921
});
2022
});

test/gulpfile.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
var gulp = require('gulp');
44

55
function noop(){}
6+
function described(){}
7+
described.description = 'description';
68

79
gulp.task('test1', noop);
8-
gulp.task('test2', noop);
9-
gulp.task('test3', noop);
10+
gulp.task('test2', ['test1'], noop);
11+
gulp.task('test3', described);
1012

1113
gulp.task('default', noop);

0 commit comments

Comments
 (0)