teqo-backup/scripts/regenerate-municipality-catalog-snapshot.mjs
Francisco Ignácio Fontoura Solla 4806c417c8 Engineering Pass 3: consolidate patterns and lock them with guards.
Fold duplicated campanha access, loaders, list/filter/form shells, and scripts into shared modules; reorganize utilities by domain; stabilize e2e; and document prevention-first audit workflow so the same smells cannot creep back in.
2026-07-29 06:11:29 -03:00

38 lines
1.1 KiB
JavaScript

import { writeFileSync } from 'node:fs'
import { sha256Hex } from './lib/cli.mjs'
import { municipalityCatalog, ZONE_MUNICIPALITY_CITIES } from '../src/lib/municipalityCatalog.ts'
const entries = municipalityCatalog.map(
({ slug, name, kind, city, region, ibgeCode, tseCityCode, zoneNumber, tseZones }) => ({
slug,
name,
kind,
city,
region,
ibgeCode,
tseCityCode,
...(zoneNumber === undefined ? {} : { zoneNumber }),
tseZones: [...tseZones],
}),
)
const rows = entries
.map(
(entry) =>
`P\t${entry.slug}\t${entry.name}\t${entry.kind}\t${entry.city}\t${entry.zoneNumber ?? ''}\n`,
)
.join('')
const snapshot = {
description:
'Frozen snapshot of the derived municipality catalog (slug/name identity must stay stable).',
generatedFrom: 'src/lib/municipalityCatalog.ts',
municipalityCount: entries.length,
zoneMunicipalityCities: [...ZONE_MUNICIPALITY_CITIES],
identitySha256: sha256Hex(rows),
entries,
}
writeFileSync(
'tests/fixtures/municipality-catalog.snapshot.json',
`${JSON.stringify(snapshot, null, 2)}\n`,
)
console.log(`Wrote ${entries.length} entries`)