// Helper for editing bench/slint/refs-100.json from the shell: node bench/slint/refs.mjs '<json patch of crops>'
import { readFileSync, writeFileSync } from 'node:fs'
const file = new URL('./refs-100.json', import.meta.url)
const j = JSON.parse(readFileSync(file, 'utf8'))
const patch = JSON.parse(process.argv[2])
for (const [k, v] of Object.entries(patch)) { if (v === null) delete j.crops[k]; else j.crops[k] = v }
const keys = Object.keys(j.crops).sort((a, b) => a.localeCompare(b, 'en', { numeric: true }))
const crops = Object.fromEntries(keys.map(k => [k, j.crops[k]]))
const out = { ...j, crops }
const lines = JSON.stringify({ ...out, crops: undefined }, null, 2).replace(/\n}$/, '')
const body = keys.map(k => ` ${JSON.stringify(k)}: ${JSON.stringify(crops[k])}`).join(',\n')
writeFileSync(file, lines.replace(/,?\s*$/, '') + `,\n "crops": {\n${body}\n }\n}\n`)
console.log(`${keys.length} crops`)