mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
fixing #1081:
- tightened-up detection of the correct path for the plugins by checking if the plugin file *itself* actually exists in the given path; it's done this way to cope with scenarios where JSDoc is executed in another project's working directory where *that* project has plugins of itself in a similar directory structure (`plugins/*`). We DO NOT change the search path used by JSDoc. - ditto for templates: we know that a template MUST have a `publish.js` file at least, so we go and check if that one exists at the location where we would otherwise have assumed it does.
This commit is contained in:
parent
ab2d8626c1
commit
6be9dac616
21
cli.js
21
cli.js
@ -314,11 +314,17 @@ function resolvePluginPaths(paths) {
|
|||||||
paths.forEach(function(plugin) {
|
paths.forEach(function(plugin) {
|
||||||
var basename = path.basename(plugin);
|
var basename = path.basename(plugin);
|
||||||
var dirname = path.dirname(plugin);
|
var dirname = path.dirname(plugin);
|
||||||
var pluginPath = path.getResourcePath(dirname);
|
// convoluted way to detect the correct path for the plugins; done this round-about way to cope
|
||||||
|
// with scenarios where JSDoc is executed in another project's working directory where that
|
||||||
|
// project has plugins of itself in a similar directory structure (plugins/*)
|
||||||
|
var pluginPath = path.getResourcePath(dirname, basename + ".js");
|
||||||
|
|
||||||
if (!pluginPath) {
|
if (!pluginPath) {
|
||||||
logger.error('Unable to find the plugin "%s"', plugin);
|
logger.error('Unable to find the plugin "%s"', plugin);
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
// correct the path to the plugin:
|
||||||
|
pluginPath = path.dirname(pluginPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginPaths.push( path.join(pluginPath, basename) );
|
pluginPaths.push( path.join(pluginPath, basename) );
|
||||||
@ -410,7 +416,18 @@ cli.generateDocs = function() {
|
|||||||
|
|
||||||
env.opts.template = (function() {
|
env.opts.template = (function() {
|
||||||
var publish = env.opts.template || 'templates/default';
|
var publish = env.opts.template || 'templates/default';
|
||||||
var templatePath = path.getResourcePath(publish);
|
// convoluted way to detect the correct path for the templates; done this round-about way to cope
|
||||||
|
// with scenarios where JSDoc is executed in another project's working directory where that
|
||||||
|
// project has templates of itself in a similar directory structure (templates/<name>/)
|
||||||
|
var templatePath = path.getResourcePath(publish, "publish.js");
|
||||||
|
|
||||||
|
if (!templatePath) {
|
||||||
|
logger.error('Unable to find the template "%s"', publish);
|
||||||
|
return publish;
|
||||||
|
} else {
|
||||||
|
// correct the path to the template:
|
||||||
|
templatePath = path.dirname(templatePath);
|
||||||
|
}
|
||||||
|
|
||||||
// if we didn't find the template, keep the user-specified value so the error message is
|
// if we didn't find the template, keep the user-specified value so the error message is
|
||||||
// useful
|
// useful
|
||||||
|
|||||||
@ -111,11 +111,25 @@ exports.getResourcePath = function(filepath, filename) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fileExists(_path) {
|
||||||
|
// see also:
|
||||||
|
// - http://stackoverflow.com/questions/4482686/check-synchronously-if-file-directory-exists-in-node-js
|
||||||
|
// - https://nodejs.org/api/fs.html#fs_fs_existssync_path
|
||||||
|
try {
|
||||||
|
var stats = fs.lstatSync(_path);
|
||||||
|
|
||||||
|
return stats.isFile();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// absolute paths are normalized by path.resolve on the first pass
|
// absolute paths are normalized by path.resolve on the first pass
|
||||||
[path.dirname(env.opts.configure || ''), env.pwd, env.dirname].forEach(function(_path) {
|
[path.dirname(env.opts.configure || ''), env.pwd, env.dirname].forEach(function(_path) {
|
||||||
if (!result && _path) {
|
if (!result && _path) {
|
||||||
_path = path.resolve(_path, filepath);
|
_path = path.resolve(_path, filepath);
|
||||||
if ( pathExists(_path) ) {
|
if ( pathExists(_path) && (filename ? fileExists(path.join(_path, filename)) : true)) {
|
||||||
result = _path;
|
result = _path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user