1 | 'use strict';
|
2 |
|
3 | var grunt = require('../grunt');
|
4 |
|
5 |
|
6 | var path = require('path');
|
7 |
|
8 |
|
9 | var col1len = 0;
|
10 | exports.initCol1 = function(str) {
|
11 | col1len = Math.max(col1len, str.length);
|
12 | };
|
13 | exports.initWidths = function() {
|
14 |
|
15 | exports.widths = [1, col1len, 2, 76 - col1len];
|
16 | };
|
17 |
|
18 |
|
19 | exports.table = function(arr) {
|
20 | arr.forEach(function(item) {
|
21 | grunt.log.writetableln(exports.widths, ['', grunt.util._.pad(item[0], col1len), '', item[1]]);
|
22 | });
|
23 | };
|
24 |
|
25 |
|
26 | exports.queue = [
|
27 | 'initOptions',
|
28 | 'initTasks',
|
29 | 'initWidths',
|
30 | 'header',
|
31 | 'usage',
|
32 | 'options',
|
33 | 'optionsFooter',
|
34 | 'tasks',
|
35 | 'footer',
|
36 | ];
|
37 |
|
38 |
|
39 | exports.display = function() {
|
40 | exports.queue.forEach(function(name) { exports[name](); });
|
41 | };
|
42 |
|
43 |
|
44 | exports.header = function() {
|
45 | grunt.log.writeln('Grunt: The JavaScript Task Runner (v' + grunt.version + ')');
|
46 | };
|
47 |
|
48 |
|
49 | exports.usage = function() {
|
50 | grunt.log.header('Usage');
|
51 | grunt.log.writeln(' ' + path.basename(process.argv[1]) + ' [options] [task [task ...]]');
|
52 | };
|
53 |
|
54 |
|
55 | exports.initOptions = function() {
|
56 |
|
57 | exports._options = Object.keys(grunt.cli.optlist).map(function(long) {
|
58 | var o = grunt.cli.optlist[long];
|
59 | var col1 = '--' + (o.negate ? 'no-' : '') + long + (o.short ? ', -' + o.short : '');
|
60 | exports.initCol1(col1);
|
61 | return [col1, o.info];
|
62 | });
|
63 | };
|
64 |
|
65 | exports.options = function() {
|
66 | grunt.log.header('Options');
|
67 | exports.table(exports._options);
|
68 | };
|
69 |
|
70 | exports.optionsFooter = function() {
|
71 | grunt.log.writeln().writelns(
|
72 | 'Options marked with * have methods exposed via the grunt API and should ' +
|
73 | 'instead be specified inside the Gruntfile wherever possible.'
|
74 | );
|
75 | };
|
76 |
|
77 |
|
78 | exports.initTasks = function() {
|
79 |
|
80 | grunt.task.init([], {help: true});
|
81 |
|
82 |
|
83 | exports._tasks = [];
|
84 | Object.keys(grunt.task._tasks).forEach(function(name) {
|
85 | exports.initCol1(name);
|
86 | var task = grunt.task._tasks[name];
|
87 | exports._tasks.push(task);
|
88 | });
|
89 | };
|
90 |
|
91 | exports.tasks = function() {
|
92 | grunt.log.header('Available tasks');
|
93 | if (exports._tasks.length === 0) {
|
94 | grunt.log.writeln('(no tasks found)');
|
95 | } else {
|
96 | exports.table(exports._tasks.map(function(task) {
|
97 | var info = task.info;
|
98 | if (task.multi) { info += ' *'; }
|
99 | return [task.name, info];
|
100 | }));
|
101 |
|
102 | grunt.log.writeln().writelns(
|
103 | 'Tasks run in the order specified. Arguments may be passed to tasks that ' +
|
104 | 'accept them by using colons, like "lint:files". Tasks marked with * are ' +
|
105 | '"multi tasks" and will iterate over all sub-targets if no argument is ' +
|
106 | 'specified.'
|
107 | );
|
108 | }
|
109 |
|
110 | grunt.log.writeln().writelns(
|
111 | 'The list of available tasks may change based on tasks directories or ' +
|
112 | 'grunt plugins specified in the Gruntfile or via command-line options.'
|
113 | );
|
114 | };
|
115 |
|
116 |
|
117 | exports.footer = function() {
|
118 | grunt.log.writeln().writeln('For more information, see http://gruntjs.com/');
|
119 | };
|