Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for jsdoc config file path inclusion in task config #8

Merged
merged 1 commit into from
Jan 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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