Skip to content

Commit ab6e623

Browse files
=phated
authored andcommitted
New: Support task descriptions
1 parent 2a8bfd0 commit ab6e623

File tree

4 files changed

+57
-12
lines changed

4 files changed

+57
-12
lines changed

lib/versioned/^3.7.0/log/tasks.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,36 @@ var taskTree = require('../taskTree');
99

1010
function logTasks(env, localGulp) {
1111
var tree = taskTree(localGulp.tasks);
12+
var padding = 0;
1213
tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));
1314
archy(tree)
1415
.split('\n')
15-
.forEach(function(v) {
16-
if (v.trim().length === 0) {
17-
return;
16+
.filter(function(v, i) {
17+
// Log first line as is
18+
if (i === 0) {
19+
gutil.log(v);
20+
return false;
21+
}
22+
// Search for longest line
23+
if (v.length > padding) {
24+
padding = v.length;
25+
}
26+
return v.trim().length !== 0;
27+
}).forEach(function(v) {
28+
var line = v.split(' ');
29+
var task = line.slice(1).join(' ');
30+
31+
if (/./.test(v)) {
32+
// Log dependencies as is
33+
gutil.log(v);
34+
} else {
35+
// Pretty task with optionnal description
36+
gutil.log(
37+
line[0] + ' ' + chalk.cyan(task) +
38+
Array(padding + 3 - v.length).join(' ') +
39+
(localGulp.tasks[task].fn.description || '')
40+
);
1841
}
19-
gutil.log(v);
2042
});
2143
}
2244

lib/versioned/^4.0.0-alpha.1/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function execute(opts, env) {
3030
label: 'Tasks for ' + chalk.magenta(tildify(env.configPath)),
3131
nodes: gulpInst.tree({ deep: true }),
3232
};
33-
return logTasks(tree);
33+
return logTasks(tree, gulpInst);
3434
}
3535
if (opts.tasksJson) {
3636
return console.log(

lib/versioned/^4.0.0-alpha.1/log/tasks.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
11
'use strict';
22

33
var archy = require('archy');
4+
var chalk = require('chalk');
45
var gutil = require('gulp-util');
56

6-
function logTasks(tree) {
7+
function logTasks(tree, tasks) {
8+
var padding = 0;
79
archy(tree)
810
.split('\n')
9-
.filter(function(v) {
10-
return v.trim().length > 0;
11-
})
12-
.forEach(function(v) {
13-
gutil.log(v);
11+
.filter(function(v, i) {
12+
// Log first line as is
13+
if (i === 0) {
14+
gutil.log(v);
15+
return false;
16+
}
17+
// Search for longest line
18+
if (v.length > padding) {
19+
padding = v.length;
20+
}
21+
return v.trim().length !== 0;
22+
}).forEach(function(v) {
23+
var line = v.split(' ');
24+
var task = line.slice(1).join(' ');
25+
26+
if (/./.test(v)) {
27+
// Log dependencies as is
28+
gutil.log(v);
29+
} else {
30+
// Pretty task with optionnal description
31+
gutil.log(
32+
line[0] + ' ' + chalk.cyan(task) +
33+
Array(padding + 3 - v.length).join(' ') +
34+
(tasks.get(task).description || '')
35+
);
36+
}
1437
});
1538
}
1639

test/flags-tasks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ lab.experiment('flag: --tasks', function() {
1515
code.expect(stdout[1]).to.contain('├── test1');
1616
code.expect(stdout[2]).to.contain('├─┬ test2');
1717
code.expect(stdout[3]).to.contain('│ └── test1');
18-
code.expect(stdout[4]).to.contain('├── test3');
18+
code.expect(stdout[4]).to.contain('├── test3 description');
1919
code.expect(stdout[5]).to.contain('└─┬ default');
2020
code.expect(stdout[6]).to.contain(' ├── test1');
2121
code.expect(stdout[7]).to.contain(' └── test3');

0 commit comments

Comments
 (0)