schema-update.js
892 Bytes
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath, pathToFileURL } from 'node:url'
import { stableStringify } from './schema-check.js'
const here = path.dirname(fileURLToPath(import.meta.url))
const repoRoot = path.resolve(here, '../..')
const snapshotPath = path.join(repoRoot, 'packages/contracts/schema-snapshot.json')
async function main() {
const contracts = await import(pathToFileURL(path.join(repoRoot, 'packages/contracts/src/index.js')).href)
if (typeof contracts.dumpSchemas !== 'function') {
throw new Error('schema-update: packages/contracts does not export dumpSchemas')
}
fs.writeFileSync(snapshotPath, `${stableStringify(contracts.dumpSchemas())}\n`)
console.log(`[schema:update] wrote ${path.relative(repoRoot, snapshotPath)}`)
}
main().catch((err) => {
console.error(err instanceof Error ? err.stack : err)
process.exit(1)
})