Skip to content

Commit d4fcc86

Browse files
committed
Merge pull request #145 from phase2/task/global-options
Upgrades to 'grunt help'
2 parents 5ccd7d7 + 1bde28b commit d4fcc86

File tree

6 files changed

+77
-4
lines changed

6 files changed

+77
-4
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ install:
1313
- npm install -g mocha
1414
script:
1515
- export PATH=$PATH:`pwd`/bin
16+
- grunt help
1617
- grunt --timer
1718
- echo "Example fully built disk usage"; du -chs .
1819
- grunt drush:liteinstall --timer

bootstrap.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,6 @@ module.exports = function(grunt) {
5858
if (grunt.option('timer')) {
5959
require('time-grunt')(grunt);
6060
}
61+
62+
require('grunt-log-headers')(grunt);
6163
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"grunt-contrib-symlink": "0.3.0",
1515
"grunt-contrib-watch": "0.6.1",
1616
"grunt-drush": "0.0.6",
17+
"grunt-log-headers": "^1.0.1",
1718
"grunt-mkdir": "0.1.2",
1819
"grunt-newer": "1.1.0",
1920
"grunt-notify": "git+https://github.com/grayside/grunt-notify.git#0.5.0",

tasks/help.js

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module.exports = function(grunt) {
77
* Provides an overview of intended and useful grunt tasks.
88
*/
99

10-
grunt.loadNpmTasks('grunt-available-tasks');
1110
var Help = require('../lib/help')(grunt);
1211

1312
Help.add({
@@ -16,7 +15,75 @@ module.exports = function(grunt) {
1615
description: 'The default build process that executes when "grunt" runs, which includes verifying dependencies and assembling the build directory.'
1716
});
1817

18+
// Specify that only configured help entries should be displayed.
1919
grunt.config('availabletasks.help.options.filter', 'include');
2020

21-
grunt.registerTask('help', ['availabletasks:help']);
21+
// Suppress task headings for help to keep it lean.
22+
grunt.config('help.options.gruntLogHeader', false);
23+
grunt.config('availabletasks.help.options.gruntLogHeader', false);
24+
grunt.config('help-after.options.gruntLogHeader', false);
25+
26+
grunt.registerTask('help', 'Output grunt-drupal-tasks specialized help.', function() {
27+
var gdt = {};
28+
var gruntHelp = require('grunt/lib/grunt/help');
29+
var process = function(queue) { queue.forEach(function(cb) { cb(); }); };
30+
31+
gdt.cleanOptions = function() {
32+
for (var i in gruntHelp._options) {
33+
item = gruntHelp._options[i];
34+
if (item[0] == '--base' || item[0] == '--gruntfile' || item[0] == '--tasks' || item[0] == '--npm') delete gruntHelp._options[i];
35+
if (item[0] == '--help, -h') gruntHelp._options[i][1] = 'Display the default Grunt help text.';
36+
}
37+
};
38+
39+
gdt.header = function() {
40+
grunt.log.writeln('Used with Grunt Drupal Tasks (v' + require('../package.json').version + ')');
41+
grunt.log.writeln().writeln('To display this help, run `grunt help`');
42+
};
43+
44+
gdt.options = function() {
45+
var options = [
46+
[ '--quiet', 'Suppress desktop notifications.' ],
47+
[ '--timer', 'Output task execution timing info.' ],
48+
[ '--concurrency', 'Override the dynamic concurrency parameter used by Drush Make.' ]
49+
];
50+
gruntHelp.table(options);
51+
};
52+
53+
gdt.tasks = function() {
54+
grunt.loadNpmTasks('grunt-available-tasks');
55+
grunt.task.run('availabletasks:help', 'help-after');
56+
};
57+
58+
gdt.footer = function() {
59+
grunt.log.writeln('For help with Grunt Drupal Tasks, see ' + require('../package.json').homepage);
60+
};
61+
62+
// Dispatch to grunt tasks is asynchronous, in order to display text after
63+
// dispatching to availabletasks we need a dedicated task so grunt's internal
64+
// task sequencing will ensure the proper order of execution.
65+
grunt.registerTask('help-after', 'Generate a footer to follow primary help text.', function() {
66+
var queue = [
67+
gruntHelp.footer,
68+
gdt.footer
69+
];
70+
71+
process(queue);
72+
});
73+
74+
var queue = [
75+
gruntHelp.initOptions,
76+
gdt.cleanOptions,
77+
gruntHelp.initWidths,
78+
gruntHelp.header,
79+
gdt.header,
80+
gruntHelp.usage,
81+
gruntHelp.options,
82+
gdt.options,
83+
gruntHelp.optionsFooter,
84+
gdt.tasks
85+
];
86+
87+
process(queue);
88+
});
2289
};

tasks/notify.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ module.exports = function(grunt) {
1919
// configured notifyThreshold.
2020
success: true,
2121
threshold: grunt.config.get('config.notify.threshold') || 10,
22-
duration: 5
22+
duration: 5,
23+
// Supposed to suppress notify_hooks log header, but not working.
24+
gruntLogHeader: false
2325
}
2426
});
2527

tasks/theme.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ module.exports = function(grunt) {
8686
Help.add({
8787
task: 'compile-theme',
8888
group: 'Asset & Code Compilation',
89-
description: 'Run compilers for the theme, such as Compass.'
89+
description: 'Run compilers for all themes (such as Compass).'
9090
});
9191
}
9292

0 commit comments

Comments
 (0)