deprecate env.dirname in favor of __dirname (#286)

plus some minor cleanup to address JSHint warnings
This commit is contained in:
Jeff Williams 2012-12-23 09:45:11 -08:00
parent cd2fba4a3a
commit a17c90dfd2
16 changed files with 40 additions and 36 deletions

View File

@ -41,6 +41,7 @@ env = {
/**
The absolute path to the base directory of the jsdoc application.
@deprecated Use `__dirname` instead.
@type string
*/
dirname: '.',
@ -86,7 +87,7 @@ function include(filepath) {
load(filepath);
}
catch (e) {
console.log('Cannot include "' + env.dirname + '/' + filepath + '": '+e);
console.log('Cannot include "' + __dirname + '/' + filepath + '": '+e);
}
}
include.resolve = function(filepath) {
@ -94,7 +95,7 @@ include.resolve = function(filepath) {
return filepath;
}
return env.dirname + '/' + filepath;
return __dirname + '/' + filepath;
};
/** Print string/s out to the console.
@ -272,7 +273,7 @@ function main() {
result = path.resolve(template);
if ( !pathExists(result) ) {
// next, try resolving it relative to the JSDoc directory
result = path.resolve(env.dirname, template);
result = path.resolve(__dirname, template);
if ( !pathExists(result) ) {
result = null;
}
@ -295,12 +296,12 @@ function main() {
env.opts = jsdoc.opts.args.parse(env.args);
try {
env.conf = new Config( fs.readFileSync( env.opts.configure || path.join(env.dirname, 'conf.json') ) ).get();
env.conf = new Config( fs.readFileSync( env.opts.configure || path.join(__dirname, 'conf.json') ) ).get();
}
catch (e) {
try {
// Use the example file if possible
var example = fs.readFileSync(path.join(env.dirname, 'conf.json.EXAMPLE'), 'utf8');
var example = fs.readFileSync(path.join(__dirname, 'conf.json.EXAMPLE'), 'utf8');
env.conf = JSON.parse(example);
}
catch(e) {

View File

@ -92,7 +92,7 @@ console = {
* @see http://nodejs.org/api/process.html
*/
process = {
argv: [env.dirname + '/jsdoc.js'].concat(Array.prototype.slice.call(arguments, 0)),
argv: [__dirname + '/jsdoc.js'].concat(Array.prototype.slice.call(arguments, 0)),
cwd: function() {
return new Packages.java.io.File('.').getCanonicalPath() + '';
},

View File

@ -1,3 +1,4 @@
/*global describe: true, expect: true, installPlugins: true, it: true */
describe("railsTemplate plugin", function() {
var parser = new (require("jsdoc/src/parser")).Parser(),
plugin = require('plugins/railsTemplate');
@ -8,7 +9,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(env.dirname, "plugins/test/fixtures/railsTemplate.js.erb")]);
docSet = parser.parse([path.join(__dirname, "plugins/test/fixtures/railsTemplate.js.erb")]);
expect(docSet[2].description).toEqual("Remove rails tags from the source input (e.g. )");
});

View File

@ -68,7 +68,7 @@ function parseQuery(str) {
}
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 env.dirname + /conf.json');
argParser.addOption('c', 'configure', true, 'The path to the configuration file. Default: jsdoc __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: ./out/');

View File

@ -20,10 +20,10 @@ exports.publish = function(outputDirectory, outputFileName, sourceCode) {
outputDirectory = path.resolve(outputDirectory);
var staticFilesDirectory = path.resolve(env.dirname + '/templates/prettyPrintSource/static');
var staticFilesDirectory = path.resolve(__dirname + '/templates/prettyPrintSource/static');
var outputFile = path.join(outputDirectory, outputFileName + '.html');
var templateName = 'layout.tmpl';
var templatePath = path.resolve(env.dirname + '/templates/prettyPrintSource');
var templatePath = path.resolve(__dirname + '/templates/prettyPrintSource');
var temmplateFilesDirectory= path.join(templatePath, '/tmpl');
var templateData = {};

View File

@ -1,5 +1,5 @@
/**
@module {ConnectServer} blog/server
@module {ConnectServer} blog/server
*/
module.exports = require('connect').createServer(
@ -8,7 +8,7 @@ module.exports = require('connect').createServer(
Connect.favicon(),
Connect.cache(),
Connect.gzip(),
require('wheat')(env.dirname)
require('wheat')(__dirname)
);
/**

View File

@ -10,7 +10,7 @@ var jasmineAll = require('test/lib/jasmine');
var jasmine = jasmineAll.jasmine;
// due to scoping issues, requiring this file doesn't work
eval( fs.readFileSync(env.dirname + '/test/async-callback.js') );
eval( fs.readFileSync(__dirname + '/test/async-callback.js') );
var jasmineNode = require('test/reporter').jasmineNode;
@ -32,7 +32,7 @@ jasmine.loadHelpersInFolder = function(folder, matcher) {
for ( var i = 0, len = helpers.length; i < len; ++i) {
var file = helpers[i].path();
var helper = require(file.replace(/\\/g, '/').
replace(new RegExp('^' + env.dirname + '/'), "").
replace(new RegExp('^' + __dirname + '/'), "").
replace(/\.*$/, ""));
for (var key in helper) {
@ -96,7 +96,7 @@ jasmine.executeSpecsInFolder = function(folder, done, opts) {
for (var i = 0, len = specsList.length; i < len; ++i) {
filename = specsList[i];
require(filename.path().replace(/\\/g, '/').
replace(new RegExp('^' + env.dirname + '/'), "").
replace(new RegExp('^' + __dirname + '/'), "").
replace(/\.\w+$/, ""));
}

View File

@ -37,7 +37,7 @@ exports.load = function(loadpath, matcher, clear) {
var wannaBeSpecs = wrench.readdirSyncRecursive(loadpath);
for (var i = 0; i < wannaBeSpecs.length; i++) {
var file = path.join(env.dirname, loadpath, wannaBeSpecs[i]);
var file = path.join(__dirname, loadpath, wannaBeSpecs[i]);
try {
if (fs.statSync(file).isFile()) {
if (matcher.test(path.basename(file))) {

View File

@ -1,21 +1,22 @@
/*global beforeEach: true, describe: true, env: true, expect: true, it: true */
describe("module names", function() {
var parser = require('jsdoc/src/parser'),
srcParser = null, doclets;
beforeEach(function() {
env.opts._ = [env.dirname + '/test/fixtures/modules/'];
env.opts._ = [__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(env.dirname + '/test/fixtures/modules/data/mod-1.js');
doclets = srcParser.parse(__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(env.dirname + '/test/fixtures/modules/data/mod-2.js');
doclets = srcParser.parse(__dirname + '/test/fixtures/modules/data/mod-2.js');
expect(doclets.length).toBeGreaterThan(1);
expect(doclets[0].longname).toEqual('module:my/module/name');
});

View File

@ -1,7 +1,7 @@
var hasOwnProperty = Object.prototype.hasOwnProperty;
var hasOwnProp = Object.prototype.hasOwnProperty;
exports.getDocSetFromFile = function(filename, parser) {
var sourceCode = readFile(env.dirname + '/' + filename),
var sourceCode = readFile(__dirname + '/' + filename),
testParser = parser || new (require('jsdoc/src/parser')).Parser(),
doclets;
@ -28,7 +28,7 @@ exports.getDocSetFromFile = function(filename, parser) {
exports.indexAll = function(docs) {
var index = {};
docs.forEach(function(doc) {
if (!hasOwnProperty.call(index, doc.longname)){index[doc.longname] = [];}
if (!hasOwnProp.call(index, doc.longname)){index[doc.longname] = [];}
index[doc.longname].push(doc);
});
docs.index = index;

View File

@ -1,4 +1,4 @@
/*global describe: true, env: true, expect: true, include: true, it: true */
describe("include", function() {
it("should be a function", function() {
@ -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 env.dirname", function() {
expect( include.resolve('a/b/c') ).toEqual(env.dirname+'/'+'a/b/c');
it("should resolve relative filepaths relative to the __dirname", function() {
expect( include.resolve('a/b/c') ).toEqual(__dirname + '/' + 'a/b/c');
});
});

View File

@ -1,3 +1,4 @@
/*global describe: true, expect: true, it: true, jasmine: true */
describe("jsdoc/src/parser", function() {
var jsdoc = {src: { parser: require('jsdoc/src/parser')}};
@ -43,7 +44,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(env.dirname,
parserSrc = "javascript:" + fs.readFileSync( path.join(__dirname,
"rhino_modules", "jsdoc", "src", "parser.js") ),
parse = function() {
parser.parse(parserSrc);

View File

@ -6,10 +6,10 @@ describe("jsdoc/src/scanner", function() {
excludePattern: new RegExp("(^|\\/|\\\\)_")
}),
path = require('path'),
sourceFiles = scanner.scan([path.join(env.dirname, 'test', 'fixtures', 'src')], 3, filter);
sourceFiles = scanner.scan([path.join(__dirname, 'test', 'fixtures', 'src')], 3, filter);
sourceFiles = sourceFiles.map(function($) {
return path.relative(env.dirname, $);
return path.relative(__dirname, $);
});
it("should return the correct source files", function() {

View File

@ -1,4 +1,4 @@
/*global describe: true, env: true, it: true */
/*global afterEach: true, describe: true, env: true, expect: true, it: true */
describe("jsdoc/tutorial/resolver", function() {
/*jshint evil: true */
@ -9,8 +9,8 @@ describe("jsdoc/tutorial/resolver", function() {
log = eval(console.log);
function missingTutorial() {
resolver.load(env.dirname + "/test/tutorials/incomplete");
resolver.resolve();
resolver.load(__dirname + "/test/tutorials/incomplete");
resolver.resolve();
}
afterEach(function() {

View File

@ -3,7 +3,7 @@ var async = require('async'),
fs = require('fs'),
path = require('path');
var config = JSON.parse( fs.readFileSync( path.join(env.dirname, '.jshintrc'), 'utf-8' ) );
var config = JSON.parse( fs.readFileSync( path.join(__dirname, '.jshintrc'), 'utf-8' ) );
function jsHintCheck(filename, callback) {
var JSHINT = require('jshint').JSHINT;
@ -25,7 +25,7 @@ function jsHintCheck(filename, callback) {
describe('jshint-clean', function() {
it('should generate JSHint errors for bad code', function(done) {
var file = path.join(env.dirname, 'test', 'fixtures', 'jshint', 'badfile.js');
var file = path.join(__dirname, 'test', 'fixtures', 'jshint', 'badfile.js');
jsHintCheck(file, function(err, jsHintErrors) {
expect(err).toBeFalsy();
@ -35,7 +35,7 @@ describe('jshint-clean', function() {
});
it('should not generate JSHint errors for good code', function(done) {
var file = path.join(env.dirname, 'test', 'fixtures', 'jshint', 'goodfile.js');
var file = path.join(__dirname, 'test', 'fixtures', 'jshint', 'goodfile.js');
jsHintCheck(file, function(err, jsHintErrors) {
expect(err).toBeFalsy();
@ -57,7 +57,7 @@ describe('jshint-clean', function() {
};
filter = new (require('jsdoc/src/filter').Filter)(source);
files = app.jsdoc.scanner.scan([env.dirname], 10, filter);
files = app.jsdoc.scanner.scan([__dirname], 10, filter);
async.forEach(files, function(file, cb) {
jsHintCheck(file, function(err, jsHintErrors) {

View File

@ -6,7 +6,7 @@ describe("@overview tag", function() {
doclets;
require('jsdoc/src/handlers').attachTo(srcParser);
doclets = srcParser.parse(env.dirname + '/test/fixtures/file.js');
doclets = srcParser.parse(__dirname + '/test/fixtures/file.js');
it('When a file overview tag appears in a doclet, the name of the doclet should contain the path to the file.', function() {
expect(doclets[0].name).toMatch(/^(fixtures[\/\\]file\.js)$/);