grunt-verb
grunt-verb copied to clipboard
Verb compiler ignores custom docs path passed in options
In projects, it is not uncommon to use a docs directory off the root as the destination for auto-generated code documentation from JSDocs, docco, yuidocs, whatever. This conflicts with verb's default preference for using that directory to store partials.
I noticed that the grunt-verb task specified a docs option in the default block:
var options = this.options({
sep: '\n',
ext: '.md',
data: ['docs/*.{json,yml}'],
prefixBase: true,
cwd: process.cwd(),
destBase: process.cwd(),
docs: 'docs'
});
I setup a verb config block in Gruntfile.js that passed a docs parameter with a custom path...
// In Gruntfile.js
// Generate README.md using verb
verb: {
docs: "src/docs/verb",
data: [
"package.json",
"src/docs/verb/*.{json,yml}"
],
changelog: {
files:[
{
src: "src/docs/verb/changelog.tmpl.md",
dest: "src/docs/verb/changelog.md"
}
]
},
readme: {
files:[
{
src: "src/docs/verb/README.tmpl.md",
dest: "README.md"
}
]
},
all: {
files:[
{
expand: true,
cwd: 'src/docs/verb',
src: ['src/docs/verb/**/*.tmpl.md'],
dest: '.',
ext: '.md'
}
]
}
},
The task failed to find the files at the custom path, so I traced the option through to the point of page generation. When I inspected verb's properties just before the verb.process(src);
call, I saw that verb.docs
was still set to the default value.
I was able to get it working by updating line 34 as follows...
// OLD LINE: This call doesn't pick up verb task config from Gruntfile.js
//verb.options = _.extend(verb.options || {}, options);
// NEW LINE: Merge grunt.config('verb') into verb.options after the default task options
verb.options = _.extend(verb.options || {}, options, grunt.config('verb'));
// NEW LINE: Verb does not pick up the docs param if set in .options, so explicitly set it here
verb.docs = verb.options.docs;
This isn't the correct fix IMHO. It just gets it working. It seems like verb itself is failing to allow a docs param in verb.options to override the default. That being the case, maybe I should have logged this issue over on that project?