mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
change __dirname to env.dirname
this fixes a JSHint error that cannot be suppressed.
This commit is contained in:
parent
16bee54b4c
commit
22e899fa9d
69
jsdoc.js
69
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) {
|
||||
|
||||
@ -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))
|
||||
};
|
||||
|
||||
@ -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. )");
|
||||
});
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -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) {
|
||||
|
||||
2
test/fixtures/typekind.js
vendored
2
test/fixtures/typekind.js
vendored
@ -8,7 +8,7 @@ module.exports = require('connect').createServer(
|
||||
Connect.favicon(),
|
||||
Connect.cache(),
|
||||
Connect.gzip(),
|
||||
require('wheat')(__dirname)
|
||||
require('wheat')(env.dirname)
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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))) {
|
||||
|
||||
@ -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');
|
||||
});
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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');
|
||||
});
|
||||
|
||||
});
|
||||
@ -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);
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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]);
|
||||
|
||||
@ -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)$/);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user