UNPKG

nitro-codegen

Version:

The code-generator for react-native-nitro-modules.

29 lines (28 loc) 799 B
import { Dirent, promises as fs } from 'fs'; import path from 'path'; function getFilePath(file, rootDir) { const dir = file.parentPath ?? file.path ?? rootDir; return path.join(dir, file.name); } export async function getFiles(directory) { try { const files = await fs.readdir(directory, { recursive: true, withFileTypes: true, }); return files.filter((f) => f.isFile()).map((f) => getFilePath(f, directory)); } catch (error) { if (typeof error === 'object' && error != null && 'code' in error && error.code === 'ENOENT') { // directory does not exist return []; } else { // different error throw error; } } }