mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
reformat function
This commit is contained in:
parent
957d94d215
commit
fee5d7f303
@ -85,21 +85,17 @@ exports.commonPrefix = function(paths) {
|
|||||||
/**
|
/**
|
||||||
* Retrieve the fully qualified path to the requested resource.
|
* Retrieve the fully qualified path to the requested resource.
|
||||||
*
|
*
|
||||||
* Plugins and templates will be found somewhat similar to how
|
* Plugins and templates will be found somewhat similar to how `require()` works, except that the
|
||||||
* require() works, except that the directory in which the JSDoc
|
* directory in which the JSDoc configuration file is will be considered, too, the JSDoc package
|
||||||
* configuration file is will be considered, too, the JSDoc package
|
* directory will be considered as a fallback, and a globally installed resource won't be found
|
||||||
* directory will be considered as a fallback, and a globally
|
* unless it comes with JSDoc.
|
||||||
* installed resource won't be found unless it comes with JSDoc.
|
|
||||||
*
|
*
|
||||||
* If the resource path is specified as a path relative to module or
|
* If the resource path is specified as a path relative to module or package (starting with `.` or
|
||||||
* package (starting with "`.`" or "`..`") JSDoc searches for the path
|
* `..``), JSDoc searches for the path first in the current working directory, then where the JSDoc
|
||||||
* first in the current working directory, then where the JSDoc
|
* configuration file is located, and finally as a fall-back under the JSDoc directory. Otherwise,
|
||||||
* configuration file is located, and finally as a fall-back under the
|
* if the resource path is relative (not starting with a path separator), JSDoc searches first under
|
||||||
* JSDoc directory. Otherwise, if the resource path is relative (not
|
* the `node_modules` directory in the current working directory and where the JSDoc configuration
|
||||||
* starting with a path separator), JSDoc searches first under the
|
* file is located, and then where JSDoc is installed.
|
||||||
* `node_modules` directory in the current working directory and where
|
|
||||||
* the JSDoc configuration file is located, and then where JSDoc is
|
|
||||||
* installed.
|
|
||||||
*
|
*
|
||||||
* If the resource path is specified as a fully qualified path, JSDoc uses the path as-is.
|
* If the resource path is specified as a fully qualified path, JSDoc uses the path as-is.
|
||||||
*
|
*
|
||||||
@ -110,7 +106,9 @@ exports.commonPrefix = function(paths) {
|
|||||||
* Includes the filename if one was provided.
|
* Includes the filename if one was provided.
|
||||||
*/
|
*/
|
||||||
exports.getResourcePath = function(filepath, filename) {
|
exports.getResourcePath = function(filepath, filename) {
|
||||||
|
var pathElems;
|
||||||
var result = null;
|
var result = null;
|
||||||
|
var searchDirs = [];
|
||||||
|
|
||||||
function pathExists(_path) {
|
function pathExists(_path) {
|
||||||
try {
|
try {
|
||||||
@ -123,31 +121,28 @@ exports.getResourcePath = function(filepath, filename) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var searchDirs = [];
|
// resources that are installed modules may not have been specified with a filepath
|
||||||
|
|
||||||
// resources that are installed modules may not have been
|
|
||||||
// specified with a filepath
|
|
||||||
if (!filepath) {
|
if (!filepath) {
|
||||||
filepath = filename;
|
filepath = filename;
|
||||||
filename = undefined;
|
filename = undefined;
|
||||||
}
|
}
|
||||||
var pathElems = filepath.split(path.sep);
|
pathElems = filepath.split(path.sep);
|
||||||
|
|
||||||
// Special case 'node_modules/foo', to accommodate this legacy
|
// Special case `node_modules/foo`, to accommodate this legacy workaround advertised by
|
||||||
// workaround advertised by 3rd party plugin and template authors
|
// third-party plugin and template authors
|
||||||
if (pathElems[0] === 'node_modules') {
|
if (pathElems[0] === 'node_modules') {
|
||||||
pathElems.unshift('.');
|
pathElems.unshift('.');
|
||||||
filepath = pathElems.join(path.sep);
|
filepath = pathElems.join(path.sep);
|
||||||
}
|
}
|
||||||
|
|
||||||
// search in different sets of directories depending on whether
|
// search in different sets of directories depending on whether filepath is expressly relative
|
||||||
// filepath is expressly relative to "current" directory or not
|
// to "current" directory or not
|
||||||
searchDirs = pathElems[0].indexOf('.') === 0 ?
|
searchDirs = pathElems[0].indexOf('.') === 0 ?
|
||||||
// look first in "current" (where jsdoc was executed), then in
|
// look first in "current" (where JSDoc was executed), then in directory of config, and
|
||||||
// directory of config, and _only then_ in jsdoc's directory
|
// _only then_ in JSDoc's directory
|
||||||
[env.pwd, path.dirname(env.opts.configure || ''), env.dirname] :
|
[env.pwd, path.dirname(env.opts.configure || ''), env.dirname] :
|
||||||
// otherwise, treat as relative to where plugins/templates are
|
// otherwise, treat as relative to where plugins/templates are found, either as a
|
||||||
// found, either as a dependency, or under jsdoc itself
|
// dependency, or under JSDoc itself
|
||||||
[path.join(env.pwd, 'node_modules'),
|
[path.join(env.pwd, 'node_modules'),
|
||||||
path.join(path.dirname(env.opts.configure || ''), 'node_modules'),
|
path.join(path.dirname(env.opts.configure || ''), 'node_modules'),
|
||||||
env.dirname];
|
env.dirname];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user