Skip to content

Instantly share code, notes, and snippets.

@gersongoulart
Last active December 11, 2015 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gersongoulart/4552595 to your computer and use it in GitHub Desktop.
Save gersongoulart/4552595 to your computer and use it in GitHub Desktop.
Simple gruntjs/grunt task to generate documentation using nevir/groc.
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