UNPKG

@rxap/node-utilities

Version:

Provides a set of utility functions for Node.js development, including file system operations, git integration, and package.json manipulation. It offers functionalities like copying folders, reading JSON files with retry logic, retrieving the current git

30 lines 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SearchFileInDirectory = SearchFileInDirectory; const fs_1 = require("fs"); const path_1 = require("path"); /** * Searches for files in a directory recursively. * * @param {string} directory - The directory path to search in. * @param {Ignore|null} gitignore - The gitignore object to check if a file is ignored. Default is null. * @yields {Object} - An object containing the file content and file path. */ function* SearchFileInDirectory(directory, gitignore = null) { const files = (0, fs_1.readdirSync)(directory); for (const file of files) { if (gitignore && gitignore.ignores(file)) { continue; // If the file is in the .gitignore list, skip it } const filePath = (0, path_1.join)(directory, file); // Check if current path is a directory if ((0, fs_1.statSync)(filePath).isDirectory()) { yield* SearchFileInDirectory(filePath, gitignore); } else { const content = (0, fs_1.readFileSync)(filePath, 'utf-8'); yield { content, filePath }; } } } //# sourceMappingURL=search-file-in-directory.js.map