|
1 | | -import { readFile, writeFile } from 'fs/promises' |
2 | | -import path from 'path' |
| 1 | +import { ensureNetlifyIgnore as originalEnsureNetlifyIgnore } from '@netlify/dev-utils' |
3 | 2 |
|
4 | | -import parseIgnore from 'parse-gitignore' |
| 3 | +import { log, warn, logError } from './command-helpers.js' |
5 | 4 |
|
6 | | -import { fileExistsAsync } from '../lib/fs.js' |
7 | | - |
8 | | -import { log } from './command-helpers.js' |
9 | | - |
10 | | -const hasGitIgnore = async function (dir: string) { |
11 | | - const gitIgnorePath = path.join(dir, '.gitignore') |
12 | | - const hasIgnore = await fileExistsAsync(gitIgnorePath) |
13 | | - return hasIgnore |
14 | | -} |
15 | | - |
16 | | -export const ensureNetlifyIgnore = async function (dir: string) { |
17 | | - const gitIgnorePath = path.join(dir, '.gitignore') |
18 | | - const ignoreContent = '# Local Netlify folder\n.netlify\n' |
19 | | - |
20 | | - /* No .gitignore file. Create one and ignore .netlify folder */ |
21 | | - if (!(await hasGitIgnore(dir))) { |
22 | | - await writeFile(gitIgnorePath, ignoreContent, 'utf8') |
23 | | - return false |
24 | | - } |
25 | | - |
26 | | - let gitIgnoreContents |
27 | | - let ignorePatterns |
28 | | - try { |
29 | | - gitIgnoreContents = await readFile(gitIgnorePath, 'utf8') |
30 | | - ignorePatterns = parseIgnore.parse(gitIgnoreContents) |
31 | | - } catch { |
32 | | - // ignore |
33 | | - } |
34 | | - /* Not ignoring .netlify folder. Add to .gitignore */ |
35 | | - if (!ignorePatterns || !ignorePatterns.patterns.some((pattern) => /(^|\/|\\)\.netlify($|\/|\\)/.test(pattern))) { |
36 | | - log() |
37 | | - log('Adding local .netlify folder to .gitignore file...') |
38 | | - const newContents = `${gitIgnoreContents}\n${ignoreContent}` |
39 | | - await writeFile(gitIgnorePath, newContents, 'utf8') |
40 | | - } |
41 | | -} |
| 5 | +export const ensureNetlifyIgnore = async (rootDir: string) => |
| 6 | + originalEnsureNetlifyIgnore(rootDir, { log, warn, error: logError }) |
0 commit comments