Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lx9FNLG2CqeBbVGGd9bFsP
19 lines
816 B
JavaScript
19 lines
816 B
JavaScript
// Generates src/api/schema.d.ts with openapi-typescript.
|
|
// Usage: npm run gen:api [-- <path-or-url>]
|
|
// Default: ../openapi.json when it exists, else openapi.contract.json.
|
|
import { existsSync } from 'node:fs'
|
|
import { spawnSync } from 'node:child_process'
|
|
import path from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
let src = process.argv[2]
|
|
if (!src) {
|
|
const real = path.resolve(root, '..', 'openapi.json')
|
|
src = existsSync(real) ? real : path.join(root, 'openapi.contract.json')
|
|
}
|
|
console.log(`gen:api from ${src}`)
|
|
const bin = path.join(root, 'node_modules', '.bin', 'openapi-typescript')
|
|
const r = spawnSync(bin, [src, '-o', path.join(root, 'src/api/schema.d.ts')], { stdio: 'inherit' })
|
|
process.exit(r.status ?? 1)
|