charlike
Version:
Small, fast, simple and streaming project scaffolder for myself, but not only. Supports hundreds of template engines through the @JSTransformers API or if you want custom `render` function passed through options
25 lines (22 loc) • 538 B
JavaScript
var path = require('path')
var fs = require('fs')
function findRoot(start) {
start = start || module.parent.filename
if (typeof start === 'string') {
if (start[start.length-1] !== path.sep) {
start+=path.sep
}
start = start.split(path.sep)
}
if(!start.length) {
throw new Error('package.json not found in path')
}
start.pop()
var dir = start.join(path.sep)
try {
fs.statSync(path.join(dir, 'package.json'));
return dir;
} catch (e) {}
return findRoot(start)
}
module.exports = findRoot