UNPKG

3.18 kBJavaScriptView Raw
1'use strict';
2
3var grunt = require('../grunt');
4
5// Nodejs libs.
6var path = require('path');
7
8// Set column widths.
9var col1len = 0;
10exports.initCol1 = function(str) {
11 col1len = Math.max(col1len, str.length);
12};
13exports.initWidths = function() {
14 // Widths for options/tasks table output.
15 exports.widths = [1, col1len, 2, 76 - col1len];
16};
17
18// Render an array in table form.
19exports.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// Methods to run, in-order.
26exports.queue = [
27 'initOptions',
28 'initTasks',
29 'initWidths',
30 'header',
31 'usage',
32 'options',
33 'optionsFooter',
34 'tasks',
35 'footer',
36];
37
38// Actually display stuff.
39exports.display = function() {
40 exports.queue.forEach(function(name) { exports[name](); });
41};
42
43// Header.
44exports.header = function() {
45 grunt.log.writeln('Grunt: The JavaScript Task Runner (v' + grunt.version + ')');
46};
47
48// Usage info.
49exports.usage = function() {
50 grunt.log.header('Usage');
51 grunt.log.writeln(' ' + path.basename(process.argv[1]) + ' [options] [task [task ...]]');
52};
53
54// Options.
55exports.initOptions = function() {
56 // Build 2-column array for table view.
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
65exports.options = function() {
66 grunt.log.header('Options');
67 exports.table(exports._options);
68};
69
70exports.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// Tasks.
78exports.initTasks = function() {
79 // Initialize task system so that the tasks can be listed.
80 grunt.task.init([], {help: true});
81
82 // Build object of tasks by info (where they were loaded from).
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
91exports.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// Footer.
117exports.footer = function() {
118 grunt.log.writeln().writeln('For more information, see http://gruntjs.com/');
119};