Last active
December 11, 2015 05:28
-
-
Save gersongoulart/4552595 to your computer and use it in GitHub Desktop.
Simple gruntjs/grunt task to generate documentation using nevir/groc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(grunt) { | |
// Groc task to generate documentation. | |
grunt.registerTask('groc', 'groc processor.', function() { | |
var groc = require('groc'); | |
var done = this.async(); | |
var opts = grunt.config.get('groc'); | |
var clis = []; | |
// Convert `opts` object to a CLI list of arguments. | |
for ( var key in opts ) { | |
var flag = '--' + key; | |
var value = opts[key]; | |
// If value is an array push each value | |
if( Object.prototype.toString.call( value ) === '[object Array]' ) { | |
for ( var i = 0, len = value.length; i < len; i++ ) { | |
clis.push(flag); | |
clis.push(value[i]); | |
} | |
} | |
else { | |
clis.push(flag); | |
clis.push(value); | |
} | |
} | |
// Run Groc's CLI command. | |
groc.CLI(clis, function(error) { | |
if (error) { | |
grunt.warn(error); | |
process.exit(1); | |
done(false); | |
return; | |
} | |
done(); | |
}); | |
}); | |
// Then, among your grunt config options add a `groc` task | |
// which has the content of your (no longer necessary) .groc.json | |
grunt.initConfig({ | |
groc: { | |
strip: ["src"], | |
glob: ["./README.md", "./src/apps/**/*.js", "./src/extensions/**/*.js", "./src/widgets/**/*.js"], | |
out: "./docs", | |
index: "README.md" | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment