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

36 lines 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetGitIgnorePatterns = GetGitIgnorePatterns; const path_1 = require("path"); const fs_1 = require("fs"); const ignore_1 = require("ignore"); /** * Retrieves the ignore patterns defined in a `.gitignore` file located within a specified directory. * * This function searches for a `.gitignore` file in the provided directory path. If the file exists, * it reads the file's content and returns an `ignore` object populated with the ignore patterns. * If the `.gitignore` file does not exist in the specified directory, the function returns `null`. * * @param {string} [directory=''] - The directory path where the `.gitignore` file is located. If no directory is specified, the current directory is used. * @returns {Ignore | null} An `ignore` object containing the patterns from the `.gitignore` file if it exists, otherwise `null`. * * @example * // Assuming there is a `.gitignore` file in the current directory with ignore patterns. * const ignorePatterns = GetGitIgnorePatterns(); * if (ignorePatterns) { * console.log("Ignore patterns loaded."); * } else { * console.log("No .gitignore file found."); * } */ function GetGitIgnorePatterns(directory = '') { const gitignorePath = (0, path_1.join)(directory, '.gitignore'); if ((0, fs_1.existsSync)(gitignorePath)) { const gitignoreContent = (0, fs_1.readFileSync)(gitignorePath, 'utf-8'); return (0, ignore_1.default)().add(gitignoreContent); } else { return null; } } //# sourceMappingURL=get-git-ignore-patterns.js.map