// Fails when a committed generated file differs from what its source gives (part of npm run check): // src/api/schema.d.ts from ../contracts/openapi.yaml, src/i18n/{sv,en}.json, src/design/icons.generated.ts. import { execFileSync } from 'node:child_process'; import { mkdtempSync, readFileSync, rmSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; const web = new URL('../', import.meta.url); let failed = false; const dir = mkdtempSync(join(tmpdir(), 'kvitt-web-api-')); try { const fresh = join(dir, 'schema.d.ts'); execFileSync('npx', ['openapi-typescript', '../contracts/openapi.yaml', '-o', fresh], { cwd: web, stdio: 'pipe' }); const committed = readFileSync(new URL('src/api/schema.d.ts', web), 'utf-8'); if (readFileSync(fresh, 'utf-8') !== committed) { console.error('src/api/schema.d.ts is stale: run npm run api:types'); failed = true; } else { console.log('src/api/schema.d.ts: up to date'); } } finally { rmSync(dir, { recursive: true, force: true }); } for (const script of ['scripts/gen-i18n.mjs', 'scripts/gen-icons.mjs']) { try { execFileSync(process.execPath, [script, '--check'], { cwd: web, stdio: 'inherit' }); console.log(`${script}: up to date`); } catch (error) { console.error(`${script} --check failed: ${error instanceof Error ? error.message : String(error)}`); failed = true; } } if (failed) process.exit(1);