mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
24 lines
647 B
TypeScript
24 lines
647 B
TypeScript
import { readdirSync, statSync } from 'fs';
|
|
import { join } from 'path';
|
|
|
|
function isDirectory(path: string) {
|
|
return statSync(path).isDirectory();
|
|
}
|
|
|
|
export function getFolders(dir: string) {
|
|
return readdirSync(dir).filter(file => isDirectory(join(dir, file)));
|
|
}
|
|
|
|
export function getDirs(base: string) {
|
|
return getFolders(base).map(path => `${base}/${path}`);
|
|
}
|
|
|
|
/**
|
|
* Checks if the directory contains a package.json file
|
|
* @param dir Path to the directory
|
|
* @returns True if the directory contains a package.json
|
|
*/
|
|
export function containsPackageJson(dir: string) {
|
|
return readdirSync(dir).some(file => file === 'package.json');
|
|
}
|