Files
meteor/lib/util/meta/getRootPath.js
Dominik Ferber 0b9622dedd fix(internal): Add locus resloving capabilities
Resolve all Meteor.isClient, Meteor.isServer and Meteor.isCordova LogicalExpressions
2015-10-13 18:42:31 +02:00

28 lines
652 B
JavaScript

import find from 'lodash.find'
import isMeteorProject from './isMeteorProject'
const findOneUpwards = require('./findOneUpwards')
function hasFile (parent, filename) {
return filename.substr(0, parent.length) === parent
}
// cache for root paths
const rootPaths = []
export default function (filename) {
// check whether the project root is already known or not
let rootPath = find(rootPaths, function (currentPath) {
return hasFile(currentPath, filename)
})
if (!rootPath) {
// project root is unkown. search for it
rootPath = findOneUpwards(filename, isMeteorProject)
rootPaths.push(rootPath)
}
return rootPath
}