-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
58 lines (52 loc) · 1.96 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';
// use just like fs
var fs = require('graceful-fs'),
gutil = require('gulp-util'),
clitable = require('cli-table');
module.exports = function(gulp, ignoreTasks, files) {
if (Object.prototype.toString.call(ignoreTasks) !== '[object Array]') {
ignoreTasks = [];
}
gulp.task('task-list', function() {
var gulpfileCode = (files && files.length > 0) ? getCodeFromFiles(files) : fs.readFileSync('gulpfile.js').toString();
var table = new clitable({
head: ['Task name', 'Description', 'Dependencies'],
chars: {
'top': '' , 'top-mid': '' , 'top-left': '' , 'top-right': '',
'bottom': '' , 'bottom-mid': '' , 'bottom-left': '' , 'bottom-right': '',
'left': '' , 'left-mid': '' , 'mid': '' , 'mid-mid': '',
'right': '' , 'right-mid': '' , 'middle': ' '
}
}),
taskName,
start,
end,
comment,
deps;
for (taskName in gulp.tasks) {
if (-1 !== ignoreTasks.indexOf(taskName)) {
continue;
}
if (gulp.tasks.hasOwnProperty(taskName)) {
start = gulpfileCode.lastIndexOf("//", gulpfileCode.indexOf(gulp.tasks[taskName].fn.toString()));
end = gulpfileCode.indexOf('\n', start);
if (start !== -1 && end !== -1) {
start += 2;
comment = gulpfileCode.substring(start, end);
} else {
comment = "";
}
deps = gulp.tasks[taskName].dep.join(", ");
table.push([taskName, comment, deps]);
}
}
console.log(table.toString());
});
};
function getCodeFromFiles(files) {
var codes = [];
files.forEach(function(file) {
codes.push(fs.readFileSync(file).toString());
});
return codes.join('\n');
}