search-dir
v1.0.1
Published
Given a root path, recursively searches subdirectories and lists basic information about node projects
Downloads
1
Readme
search-dir
Given a root path (absolute), recursively searches subdirectories for for files or directories meeting matching functions
npm install search-dir
findFiles
and findDirectories
both return an array of objects like
{ name: string; path: string; }
import {
findFiles,
FileSearch,
FileMatch,
findDirectories,
DirectorySearch,
DirectoryMatch
} from 'search-dir';
const isServiceDir: Function = (name: string): boolean => name.includes('service');
const hasPackageJson: Function = (fileName: string): boolean => fileName === 'package.json';
const dirSearch: DirectorySearch = {
name: isServiceDir,
withFile: hasPackageJson,
ignoreDirs: ['node_modules', '.git']
};
const dirs: DirectoryMatch[] = findDirectories('some/directory/to/search', dirSearch);
const includesConfig: Function = (name: string): boolean => name.toLowerCase().includes('config');
const inEntitiesFolder: Function = (dirName: string): boolean => dirName === 'entities';
const fileSearch: FileSearch = {
name: includesConfig,
parentDir: inEntitiesFolder,
ignoreDirs: ['node_modules', '.git']
};
const files: FileMatch[] = findFiles('some/directory/to/search', fileSearch);