Skip to content

Commit

Permalink
feat(root-array): add support to list of 'root' directories
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Mar 23, 2020
1 parent 2346fbc commit b63fced
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lib/ejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,24 @@ function getIncludePath(path, options) {
var views = options.views;
var match = /^[A-Za-z]+:\\|^\//.exec(path);

// Try to resolve on multiple directories
var tryPathsList = function(paths) {
if (paths.some(function (v) {
filePath = exports.resolveInclude(path, v, true);
return fs.existsSync(filePath);
})) {
includePath = filePath;
}
}

// Abs path
if (match && match.length) {
includePath = exports.resolveInclude(path.replace(/^\/*/,''), options.root || '/', true);
path = path.replace(/^\/*/, '');
if (Array.isArray(options.root)) {
tryPathsList(options.root);
} else {
includePath = exports.resolveInclude(path, options.root || '/', true);
}
}
// Relative paths
else {
Expand All @@ -154,13 +169,8 @@ function getIncludePath(path, options) {
}
}
// Then look in any views directories
if (!includePath) {
if (Array.isArray(views) && views.some(function (v) {
filePath = exports.resolveInclude(path, v, true);
return fs.existsSync(filePath);
})) {
includePath = filePath;
}
if (!includePath && Array.isArray(views)) {
tryPathsList(views);
}
if (!includePath) {
throw new Error('Could not find the include file "' +
Expand Down

0 comments on commit b63fced

Please sign in to comment.