Skip to content

Commit

Permalink
Add support for jsdoc config file path inclusion in task config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Walter committed Jan 2, 2013
1 parent 6841072 commit b6622bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The only supported options are
`src` : an array of pattern that matches the files to extract the documentation from
`dest`: the directory where the documentation will be generated (it will be created if needed).
`config` : (optional) a path to a jsdoc config file (refer the usejsdoc documentation below for more information).
Then, load the plugin
Expand Down
18 changes: 14 additions & 4 deletions tasks/jsdoc-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = function jsDocTask(grunt) {
done = grunt.task.current.async(),
srcs = grunt.file.expandFiles(grunt.task.current.file.src),
dest = grunt.task.current.file.dest || 'doc',
config = grunt.task.current.data.config,
javaHome = process.env.JAVA_HOME,
timeout = 60000,
jsDoc;
Expand All @@ -43,10 +44,13 @@ module.exports = function jsDocTask(grunt) {
* @param {String} bin the path to the command
* @param {Array} sources the list of sources files
* @param {String} destination the destination directory
* @param {String} [config] the path to a jsdoc config file
* @return {String} command the command ready to be executed
*/
var buildCmd = function(bin, sources, destination){
var cmd = '"' + bin + '"' + ' -d ' + destination +' ' + sources.join(' ');
var buildCmd = function(bin, sources, destination, config){
var cmd = '"' + bin + '"';
if (config !== undefined) cmd += ' -c ' + config;
cmd += ' -d ' + destination + ' ' + sources.join(' ');
grunt.log.debug(cmd);
return cmd;
};
Expand Down Expand Up @@ -99,15 +103,21 @@ module.exports = function jsDocTask(grunt) {
grunt.log.error('No source files defined');
grunt.fail.warn('Wrong configuration', errorCode.generic);
}


//check if jsdoc config file path is provided and does exist
if (config !== undefined && !fs.existsSync(config)){
grunt.log.error('jsdoc config file path does not exist');
grunt.fail.warn('Wrong configuration', errorCode.generic);
}

fs.exists(dest, function(exists){
//if the destination don't exists, we create it
if(!exists){
grunt.file.mkdir(dest);
}

//execution of the jsdoc command
exec(buildCmd(jsDoc, srcs, dest), {timeout: timeout}, function (error, stdout, stderr) {
exec(buildCmd(jsDoc, srcs, dest, config), {timeout: timeout}, function (error, stdout, stderr) {
grunt.log.debug('stdout: ' + stdout);
grunt.log.debug('stderr: ' + stderr);
if (error) {
Expand Down

0 comments on commit b6622bd

Please sign in to comment.