(projectDir: string)
| 52 | |
| 53 | /** Returns whether `.gitignore` in `projectDir` already ignores `.env` files. */ |
| 54 | export function checkGitignore(projectDir: string): GitignoreStatus { |
| 55 | const gitignorePath = path.join(projectDir, '.gitignore') |
| 56 | |
| 57 | if (!fs.existsSync(gitignorePath)) { |
| 58 | return 'no-file' |
| 59 | } |
| 60 | |
| 61 | const content = fs.readFileSync(gitignorePath, 'utf-8') |
| 62 | const lines = content.split('\n').map((l) => l.trim()) |
| 63 | |
| 64 | const hasEnvEntry = lines.some((line) => { |
| 65 | const normalized = line.startsWith('/') ? line.slice(1) : line |
| 66 | return normalized === '.env' || normalized === '.env*' |
| 67 | }) |
| 68 | return hasEnvEntry ? 'ok' : 'missing-entry' |
| 69 | } |
| 70 | |
| 71 | /** Combined result of writing `.env` and checking `.gitignore`. */ |
| 72 | export interface WriteLocalFilesResult { |
no test coverage detected