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