merge-gitignore.mjs
814 Bytes
// lib/merge-gitignore.mjs
export function mergeGitignore(baseText, addText) {
const seen = new Set()
const out = []
const push = (line) => {
const key = line.trim()
if (!key) return // drop blank lines
if (seen.has(key)) return // dedupe by trimmed content
seen.add(key)
out.push(line)
}
for (const l of baseText.split('\n')) push(l)
for (const l of addText.split('\n')) push(l)
let text = out.join('\n').replace(/\n+$/,'') + '\n'
return text
}
if (import.meta.url === `file://${process.argv[1]}`) {
const [basePath, addPath] = process.argv.slice(2)
const { readFileSync, writeFileSync } = await import('node:fs')
const base = readFileSync(basePath, 'utf8')
const add = readFileSync(addPath, 'utf8')
writeFileSync(basePath, mergeGitignore(base, add))
}