diff --git a/jsdoc.js b/jsdoc.js index 6e13842e..54ee1ccf 100644 --- a/jsdoc.js +++ b/jsdoc.js @@ -8,33 +8,6 @@ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// -/** The absolute path to the base directory of the jsdoc application. - @type string - @global - */ -__dirname = '.', -args = Array.prototype.slice.call(arguments, 0); - -// rhino has no native way to get the base dirname of the currently running script -// so this information must be manually passed in from the command line -for (var i = 0; i < args.length; i++) { - if ( /^--dirname(?:=(.+?)(\/|\/\.)?)?$/i.test(args[i]) ) { - if (RegExp.$1) { - __dirname = RegExp.$1; // last wins - args.splice(i--, 1); // remove --dirname opt from arguments - } - else { - __dirname = args[i + 1]; - args.splice(i--, 2); - } - } -} - -load(__dirname + '/lib/rhino-shim.js'); - -//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// - - /** Data representing the environment in which this app is running. @namespace */ @@ -49,8 +22,7 @@ env = { The command line arguments passed into jsdoc. @type Array */ - args: Array.prototype.slice.call(args, 0), - + args: [], /** The parsed JSON data from the configuration file. @@ -58,6 +30,12 @@ env = { */ conf: {}, + /** + The absolute path to the base directory of the jsdoc application. + @type string + */ + dirname: '.', + /** The command line arguments, parsed into a key/value hash. @type Object @@ -66,6 +44,29 @@ env = { opts: {} }; +args = Array.prototype.slice.call(arguments, 0); + +// rhino has no native way to get the base dirname of the currently running script +// so this information must be manually passed in from the command line +for (var i = 0; i < args.length; i++) { + if ( /^--dirname(?:=(.+?)(\/|\/\.)?)?$/i.test(args[i]) ) { + if (RegExp.$1) { + env.dirname = RegExp.$1; // last wins + args.splice(i--, 1); // remove --dirname opt from arguments + } + else { + env.dirname = args[i + 1]; + args.splice(i--, 2); + } + } +} + +env.args = args; + +load(env.dirname + '/lib/rhino-shim.js'); + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + /** @global @param {string} filepath The path to the script file to include (read and execute). @@ -76,7 +77,7 @@ function include(filepath) { load(filepath); } catch (e) { - console.log('Cannot include "' + __dirname + '/' + filepath + '": '+e); + console.log('Cannot include "' + env.dirname + '/' + filepath + '": '+e); } } include.resolve = function(filepath) { @@ -84,7 +85,7 @@ include.resolve = function(filepath) { return filepath; } - return __dirname + '/' + filepath; + return env.dirname + '/' + filepath; } @@ -188,13 +189,13 @@ function main() { env.opts = jsdoc.opts.parser.parse(env.args); try { - env.conf = new Config( fs.readFileSync( env.opts.configure || __dirname + '/conf.json' ) ).get(); + env.conf = new Config( fs.readFileSync( env.opts.configure || env.dirname + '/conf.json' ) ).get(); } catch (e) { try { //Try to copy over the example conf - var example = fs.readFileSync(__dirname + '/conf.json.EXAMPLE', 'utf8'); - fs.writeFileSync(__dirname + '/conf.json', example, 'utf8'); + var example = fs.readFileSync(env.dirname + '/conf.json.EXAMPLE', 'utf8'); + fs.writeFileSync(env.dirname + '/conf.json', example, 'utf8'); env.conf = JSON.parse(example); } catch(e) { diff --git a/lib/rhino-shim.js b/lib/rhino-shim.js index 08cdda85..19f68398 100644 --- a/lib/rhino-shim.js +++ b/lib/rhino-shim.js @@ -31,5 +31,5 @@ process = { n = n || 0; java.lang.System.exit(n); }, - argv: [__dirname + '/jsdoc.js'].concat(Array.prototype.slice.call(arguments, 0)) + argv: [env.dirname + '/jsdoc.js'].concat(Array.prototype.slice.call(arguments, 0)) }; diff --git a/plugins/test/specs/railsTemplate.js b/plugins/test/specs/railsTemplate.js index 7541f95b..00a649fc 100644 --- a/plugins/test/specs/railsTemplate.js +++ b/plugins/test/specs/railsTemplate.js @@ -8,7 +8,7 @@ describe("railsTemplate plugin", function() { it("should remove <% %> rails template tags from the source of *.erb files", function() { var path = require("path"), - docSet = parser.parse([path.join(__dirname, "plugins/test/fixtures/railsTemplate.js.erb")]); + docSet = parser.parse([path.join(env.dirname, "plugins/test/fixtures/railsTemplate.js.erb")]); expect(docSet[2].description).toEqual("Remove rails tags from the source input (e.g. )"); }); diff --git a/rhino_modules/jsdoc/opts/parser.js b/rhino_modules/jsdoc/opts/parser.js index 96128f47..03839914 100644 --- a/rhino_modules/jsdoc/opts/parser.js +++ b/rhino_modules/jsdoc/opts/parser.js @@ -17,7 +17,7 @@ var argParser = new common.args.ArgParser(), }; argParser.addOption('t', 'template', true, 'The name of the template to use. Default: the "default" template'); -argParser.addOption('c', 'configure', true, 'The path to the configuration file. Default: jsdoc __dirname + /conf.json'); +argParser.addOption('c', 'configure', true, 'The path to the configuration file. Default: jsdoc env.dirname + /conf.json'); argParser.addOption('e', 'encoding', true, 'Assume this encoding when reading all source files. Default: utf-8'); argParser.addOption('T', 'test', false, 'Run all tests and quit.'); argParser.addOption('d', 'destination', true, 'The path to the output folder. Use "console" to dump data to the console. Default: console'); diff --git a/templates/default/publish.js b/templates/default/publish.js index 8a96d7ff..85f554d4 100644 --- a/templates/default/publish.js +++ b/templates/default/publish.js @@ -16,7 +16,7 @@ var defaultTemplatePath = 'templates/default'; var templatePath = (opts.template) ? opts.template : defaultTemplate; var out = '', - view = new template.Template(__dirname + '/' + templatePath + '/tmpl'); + view = new template.Template(env.dirname + '/' + templatePath + '/tmpl'); // set up templating view.layout = 'layout.tmpl'; @@ -177,7 +177,7 @@ fs.mkPath(outdir); // copy static files to outdir - var fromDir = __dirname + '/' + templatePath + '/static', + var fromDir = env.dirname + '/' + templatePath + '/static', staticFiles = fs.ls(fromDir, 3); staticFiles.forEach(function(fileName) { diff --git a/test/fixtures/typekind.js b/test/fixtures/typekind.js index 687eb7d7..aacfcc70 100644 --- a/test/fixtures/typekind.js +++ b/test/fixtures/typekind.js @@ -8,7 +8,7 @@ module.exports = require('connect').createServer( Connect.favicon(), Connect.cache(), Connect.gzip(), - require('wheat')(__dirname) + require('wheat')(env.dirname) ); /** diff --git a/test/jasmine-jsdoc.js b/test/jasmine-jsdoc.js index eac659c9..e2c20299 100644 --- a/test/jasmine-jsdoc.js +++ b/test/jasmine-jsdoc.js @@ -15,7 +15,7 @@ jasmine.loadHelpersInFolder = function(folder, matcher) { helpers = helperCollection.getSpecs(); for ( var i = 0, len = helpers.length; i < len; ++i) { var file = helpers[i].path(); - var helper = require(file.replace(/\\/g, '/').replace(new RegExp('^' + __dirname + '/'), "").replace(/\.*$/, "")); + var helper = require(file.replace(/\\/g, '/').replace(new RegExp('^' + env.dirname + '/'), "").replace(/\.*$/, "")); for (var key in helper) { this[key] = helper[key]; @@ -79,7 +79,7 @@ jasmine.executeSpecsInFolder = function(folder, done, verbose, matcher) { var specsList = specs.getSpecs(); for ( var i = 0, len = specsList.length; i < len; ++i) { var filename = specsList[i]; - require(filename.path().replace(/\\/g, '/').replace(new RegExp('^' + __dirname + '/'), "").replace(/\.\w+$/, "")); + require(filename.path().replace(/\\/g, '/').replace(new RegExp('^' + env.dirname + '/'), "").replace(/\.\w+$/, "")); } //Run Jasmine diff --git a/test/spec-collection.js b/test/spec-collection.js index 1093c1a9..146d9833 100644 --- a/test/spec-collection.js +++ b/test/spec-collection.js @@ -33,7 +33,7 @@ exports.load = function(loadpath, matcher, clear) { } var wannaBeSpecs = wrench.readdirSyncRecursive(loadpath); for (var i = 0; i < wannaBeSpecs.length; i++) { - var file = path.join(__dirname, loadpath, wannaBeSpecs[i]); + var file = path.join(env.dirname, loadpath, wannaBeSpecs[i]); try { if (fs.statSync(file).isFile()) { if (!/.*node_modules.*/.test(file) && matcher.test(path.filename(file))) { diff --git a/test/specs/documentation/modules.js b/test/specs/documentation/modules.js index e682c757..c3b7debd 100644 --- a/test/specs/documentation/modules.js +++ b/test/specs/documentation/modules.js @@ -3,19 +3,19 @@ describe("module names", function() { srcParser = null, doclets; beforeEach(function() { - env.opts._ = [__dirname + '/test/fixtures/modules/']; + env.opts._ = [env.dirname + '/test/fixtures/modules/']; srcParser = new parser.Parser(); require('jsdoc/src/handlers').attachTo(srcParser); }); it("should create a name from the file path when no documented module name exists", function() { - doclets = srcParser.parse(__dirname + '/test/fixtures/modules/data/mod-1.js'); + doclets = srcParser.parse(env.dirname + '/test/fixtures/modules/data/mod-1.js'); expect(doclets.length).toBeGreaterThan(1); expect(doclets[0].longname).toEqual('module:data/mod-1'); }); it("should use the documented module name if available", function() { - doclets = srcParser.parse(__dirname + '/test/fixtures/modules/data/mod-2.js'); + doclets = srcParser.parse(env.dirname + '/test/fixtures/modules/data/mod-2.js'); expect(doclets.length).toBeGreaterThan(1); expect(doclets[0].longname).toEqual('module:my/module/name'); }); diff --git a/test/specs/helpers.js b/test/specs/helpers.js index 88d39db4..91af9678 100644 --- a/test/specs/helpers.js +++ b/test/specs/helpers.js @@ -1,7 +1,7 @@ var hasOwnProperty = Object.prototype.hasOwnProperty; exports.getDocSetFromFile = function(filename, parser) { - var sourceCode = readFile(__dirname + '/' + filename), + var sourceCode = readFile(env.dirname + '/' + filename), testParser = parser || new (require('jsdoc/src/parser')).Parser(), doclets; diff --git a/test/specs/jsdoc/functions/include.js b/test/specs/jsdoc/functions/include.js index dbfa1694..29d07a6e 100644 --- a/test/specs/jsdoc/functions/include.js +++ b/test/specs/jsdoc/functions/include.js @@ -15,8 +15,8 @@ describe("include", function() { expect( include.resolve('/a/b/c.js') ).toEqual('/a/b/c.js'); }); - it("should resolve relative filepaths relative to the __dirname", function() { - expect( include.resolve('a/b/c') ).toEqual(__dirname+'/'+'a/b/c'); + it("should resolve relative filepaths relative to the env.dirname", function() { + expect( include.resolve('a/b/c') ).toEqual(env.dirname+'/'+'a/b/c'); }); }); \ No newline at end of file diff --git a/test/specs/jsdoc/src/parser.js b/test/specs/jsdoc/src/parser.js index 113c96d7..2162583e 100644 --- a/test/specs/jsdoc/src/parser.js +++ b/test/specs/jsdoc/src/parser.js @@ -43,7 +43,7 @@ describe("jsdoc/src/parser", function() { it("should be able to parse its own source file", function() { var fs = require("fs"), path = require("path"), - parserSrc = "javascript:" + fs.readFileSync( path.join(__dirname, + parserSrc = "javascript:" + fs.readFileSync( path.join(env.dirname, "rhino_modules", "jsdoc", "src", "parser.js") ), parse = function() { parser.parse(parserSrc); diff --git a/test/specs/jsdoc/src/scanner.js b/test/specs/jsdoc/src/scanner.js index e9f127e7..206d286e 100644 --- a/test/specs/jsdoc/src/scanner.js +++ b/test/specs/jsdoc/src/scanner.js @@ -4,10 +4,10 @@ describe("jsdoc/src/scanner", function() { includePattern: new RegExp(".+\\.js(doc)?$"), excludePattern: new RegExp("(^|\\/)_") }), - sourceFiles = scanner.scan([__dirname+'/test/fixtures/src/'], 3, filter); + sourceFiles = scanner.scan([env.dirname+'/test/fixtures/src/'], 3, filter); sourceFiles = sourceFiles.map(function($) { - return $.replace(__dirname, ''); + return $.replace(env.dirname, ''); }); it("should return the correct source files", function() { diff --git a/test/specs/jshint/jshint-clean.js b/test/specs/jshint/jshint-clean.js index fa1b7461..436aaab3 100644 --- a/test/specs/jshint/jshint-clean.js +++ b/test/specs/jshint/jshint-clean.js @@ -2,7 +2,7 @@ var fs = require("fs"), path = require("path"); -var config = JSON.parse( fs.readFileSync( path.join(__dirname, ".jshintrc"), "utf-8" ) ); +var config = JSON.parse( fs.readFileSync( path.join(env.dirname, ".jshintrc"), "utf-8" ) ); function jsHintCheck(filename, source, conf) { var JSHINT = require("jshint/jshint").JSHINT; @@ -46,7 +46,7 @@ describe("jshint-clean", function() { }; filter = new (require('jsdoc/src/filter').Filter)(source); - files = app.jsdoc.scanner.scan([__dirname], 10, filter); + files = app.jsdoc.scanner.scan([env.dirname], 10, filter); check = function() { jsHintCheck(files[i]); diff --git a/test/specs/tags/overviewtag.js b/test/specs/tags/overviewtag.js index 21a688f3..5104fbf4 100644 --- a/test/specs/tags/overviewtag.js +++ b/test/specs/tags/overviewtag.js @@ -4,7 +4,7 @@ describe("@overview tag", function() { doclets; require('jsdoc/src/handlers').attachTo(srcParser); - doclets = srcParser.parse(__dirname + '/test/fixtures/file.js'); + doclets = srcParser.parse(env.dirname + '/test/fixtures/file.js'); it('When a file overview tag appears in a doclet, the name of the doclet should start with file: and should end with the path to the file.', function() { expect(doclets[0].name).toMatch(/^.*([\/\\]fixtures[\/\\]file\.js)$/);