UNPKG

@o3r/schematics

Version:

Schematics module of the Otter framework

30 lines 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ignorePatterns = ignorePatterns; /** * Add patterns to .gitignore file * @param tree Schematics files tree * @param patternsToAdd List of patterns with description to add to gitignore files */ function ignorePatterns(tree, patternsToAdd) { const gitIgnoreFileName = '/.gitignore'; const isGitIgnorePresent = tree.exists(gitIgnoreFileName); let gitIgnoreFileContent = isGitIgnorePresent ? tree.readText(gitIgnoreFileName) : ''; const filteredPatternsToAdd = patternsToAdd .map(({ description, patterns }) => ({ description, patterns: patterns.filter((pattern) => !new RegExp('^' + pattern.replace(/([*./\\])/g, '\\$1')).test(gitIgnoreFileContent)) })) .filter(({ patterns }) => patterns.length); if (filteredPatternsToAdd.length === 0) { return tree; } gitIgnoreFileContent += '\n' + filteredPatternsToAdd .map(({ description, patterns }) => (description ? `# ${description}\n` : '') + patterns.join('\n')) .join('\n'); if (isGitIgnorePresent) { tree.overwrite(gitIgnoreFileName, gitIgnoreFileContent); return tree; } tree.create(gitIgnoreFileName, gitIgnoreFileContent); return tree; } //# sourceMappingURL=gitignore.js.map