Hans Larsen 00f913c8cd fix(@angular/cli): fix angular-cli logic
The old logic was failing if the global angular-cli config was .angular-cli.json.
2017-02-22 13:23:45 -08:00

31 lines
691 B
TypeScript

import * as path from 'path';
import { existsSync } from 'fs';
export function findUp(names: string | string[], from: string, stopOnNodeModules = false) {
if (!Array.isArray(names)) {
names = [names];
}
const root = path.parse(from).root;
let currentDir = from;
while (currentDir && currentDir !== root) {
for (const name of names) {
const p = path.join(currentDir, name);
if (existsSync(p)) {
return p;
}
}
if (stopOnNodeModules) {
const nodeModuleP = path.join(currentDir, 'node_modules');
if (existsSync(nodeModuleP)) {
return null;
}
}
currentDir = path.dirname(currentDir);
}
return null;
}