gruntfile
Gruntfile helper for making modular gruntfiles. This module will always set the current working directory relative to the gruntfile. This allows you to use a gruntfile as a module.
example
We have a gruntfile that loads common things across many projects.
First npm install gruntfile --save
in a module and setup your gruntfile:
./node_modules/modulargrunt/Gruntfile.js
moduleexports = { // These will become a default configs for inherited gruntfiles grunt; // All tasks must be loaded relative to the module in node_modules // This should also be --save as they're now dependencies grunt; grunt; grunt;};
Now you can install your module with npm install
(if published) or npm link
as a local development dependency:
./Gruntfile.js
module { // Init our modular gruntfile and return the tasks it uses var tasks = grunt; grunt; grunt; // Run the tasks from modulargrunt and append the watch task at the end grunt;};
api
require('gruntfile')(gruntfile)
It accepts a gruntfile
function as the only argument and returns a wrapped
gruntfile like function(grunt, parentCWD)
.
Will default the cwd
relative to the gruntfile. If parentCWD
is false
then
the gruntfile has no parent otherwise it will be the path to the parent that
called the child gruntfile.
By default it will return the tasks initialized within the modular gruntfile. You can override this and return whatever you like instead:
moduleexports = { /* gruntfile stuff */ return 'some' 'other' 'tasks';};
Is this a good idea?
I don't know. Probably not but a lot of people keep asking for this. FWIW, I've used a similar setup to this and it worked well. But I was always careful to keep my gruntfiles as simple as possible.
Release History
- 0.1.0 initial release
License
Copyright (c) 2013 Kyle Robinson Young
Licensed under the MIT license.