From 0a111f4395c8dff73a5ec7408b36c2fc3923f8b9 Mon Sep 17 00:00:00 2001 From: Drew Wells Date: Mon, 25 Jul 2011 15:24:02 -0400 Subject: [PATCH] jodoc can be configured by CommonJS Modules, AMD modules should work as well too --- jodoc.js | 71 ++++++++++++++++++++++++++++----------------- samples/config.json | 14 +++++++++ 2 files changed, 58 insertions(+), 27 deletions(-) create mode 100644 samples/config.json diff --git a/jodoc.js b/jodoc.js index 192a680..b7d77a1 100755 --- a/jodoc.js +++ b/jodoc.js @@ -10,45 +10,62 @@ var sys = require('sys'), //Return an options struct, with files function getOptions() { + var args = process.argv.slice(2), + config, arg = '', options = { files: [] - }; - - while(args.length > 0) { - arg = args.shift(); - switch(arg) - { - case '--server': - case '-s': options.server = true; - //Allow port to be passed optionally - if( !isNaN( args[0] ) ){ - options.server = args.shift(); - } - break; + }; - case '--output': - case '-o': options.output = args.shift(); - break; + if( args.length === 1 ){ - case '--template': options.template = args.shift(); - break; + try{ - case '--toc': options.toc = args.shift(); - break; + config = require( process.argv[2] ); + return config; + } catch ( err ){ - case '-t': - case '--title': options.title = args.shift(); - break; + sys.puts( "Configuration module not found or failed to load, is it a value CommonJS module?" ); + } - case '-ni': - case '--no-index': options.noindex = true; - break; + } else { - default: options.files.push(arg); + while(args.length > 0) { + arg = args.shift(); + switch(arg) + { + case '--server': + case '-s': options.server = true; + //Allow port to be passed optionally + if( !isNaN( args[0] ) ){ + options.server = args.shift(); + } + break; + + case '--output': + case '-o': options.output = args.shift(); + break; + + case '--template': options.template = args.shift(); + break; + + case '--toc': options.toc = args.shift(); + break; + + case '-t': + case '--title': options.title = args.shift(); + break; + + case '-ni': + case '--no-index': options.noindex = true; + break; + + default: options.files.push(arg); + } } } + return options; } diff --git a/samples/config.json b/samples/config.json new file mode 100644 index 0000000..6d0694a --- /dev/null +++ b/samples/config.json @@ -0,0 +1,14 @@ +module.exports = { + toc: 'doc/toc.mdown', + title: 'joDoc', + template: 'doc/template.html', + output: 'dist/doc', + server: true, + files: [ + //Order here decides the order which it appears in the non-output directory form + 'doc/main.mdown', + 'doc/styleguide.mdown', + 'src/core.js', + 'src/utility.js', + ] +};