UNPKG

gitignore-synthesizer

Version:

Generate smart .gitignore files based on your project's actual contents

18 lines (16 loc) 509 B
import fs from 'fs/promises'; import path from 'path'; export async function backupGitignore(dir) { const gitignorePath = path.join(dir, '.gitignore'); try { const stat = await fs.stat(gitignorePath); if (stat.isFile()) { const backupName = `.gitignore.bak-${new Date().toISOString().replace(/[:.]/g, '-')}`; await fs.copyFile(gitignorePath, path.join(dir, backupName)); return backupName; } } catch { // no .gitignore file, skip } return null; }