#!/usr/bin/env bun
/**
 * Appends the PostgREST cache entry to .gitignore.
 * Safe to run multiple times — no-op if already present.
 */
import { readFileSync, writeFileSync } from 'node:fs'

const GITIGNORE = '.gitignore'
const MARKER = '.cache/'
const BLOCK = '\n# PostgREST OpenAPI spec cache (local per developer)\n.cache/\n'

const content = readFileSync(GITIGNORE, 'utf-8')

if (content.includes(MARKER)) {
  console.log('.gitignore already has .cache/ — skipping.')
  process.exit(0)
}

writeFileSync(GITIGNORE, content + BLOCK, 'utf-8')
console.log('.gitignore — .cache/ added.')
