UNPKG

@mintlify/common

Version:

Commonly shared code within Mintlify

41 lines (40 loc) 1.5 kB
import ignore from 'ignore'; /** * Default patterns that Mintlify always ignores, regardless of .mintignore configuration. * These directories are typically version control, IDE configs, or dependencies. */ export const DEFAULT_MINT_IGNORES = [ '.git', '.github', '.claude', '.agents', '.idea', 'node_modules', 'README.md', 'LICENSE.md', 'CHANGELOG.md', 'CONTRIBUTING.md', ]; /** * Processes the contents of a .mintignore file and returns an array of relevant patterns. * The ignore package automatically handles comments (lines starting with #) and empty lines. * * @param mintIgnoreContent The content of the .mintignore file. * @returns An array of glob patterns. */ export function processMintIgnoreString(mintIgnoreContent) { return mintIgnoreContent.split(/\r?\n/).map((line) => line.trim()); } /** * Checks if a file path is ignored based on the provided glob patterns and default ignores. * Always includes DEFAULT_MINT_IGNORES in addition to any custom patterns provided. * * @param filePath The path of the file to check. * @param globs An array of custom glob patterns (output from processMintIgnoreString). * @returns True if the file matches any of the ignore patterns (default or custom), false otherwise. */ export function isMintIgnored(filePath, globs = []) { const allPatterns = Array.from(new Set([...DEFAULT_MINT_IGNORES, ...globs])); const ig = ignore().add(allPatterns); return ig.ignores(filePath); }