mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 11:03:53 +08:00
24 lines
497 B
TypeScript
24 lines
497 B
TypeScript
import * as path from 'path';
|
|
import { existsSync } from 'fs';
|
|
|
|
export function findUp(names: string | string[], from: string) {
|
|
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;
|
|
}
|
|
}
|
|
|
|
currentDir = path.dirname(currentDir);
|
|
}
|
|
|
|
return null;
|
|
}
|