just-build
Version:
A simple task runner that doesn't bloat your package
28 lines (24 loc) • 918 B
JavaScript
var path = require('path');
var fs = require('fs');
var debug = require('./debug');
/** Navigates upwards to the closest dir that contains a 'package.json'.
* @param dir {string} Directory to start from.
*/
function getPackageRoot (dir) {
debug.log(("getPackageRoot(" + (JSON.stringify(dir)) + ")"));
var lastDir = null;
while (lastDir !== dir && !fs.existsSync(path.resolve(dir, "./package.json"))) {
lastDir = dir;
dir = path.dirname(dir);
}
return (lastDir === dir ? null : dir);
}
function getBinLocation (dir, bin) {
var lastDir = null;
while (lastDir !== dir && !fs.existsSync(path.resolve(dir, "./node_modules/.bin/" + bin))) {
lastDir = dir;
dir = path.dirname(dir);
}
return (lastDir === dir ? null : path.resolve(dir, "./node_modules/.bin/" + bin));
}
module.exports = {getPackageRoot: getPackageRoot, getBinLocation: getBinLocation};