| 7 | } |
| 8 | |
| 9 | export async function spec(ctx: PandaContext, options: SpecOptions) { |
| 10 | const { outdir } = options |
| 11 | |
| 12 | const specs = ctx.getSpec() |
| 13 | |
| 14 | // Use ctx.paths.specs (includes configured outdir) or override with provided outdir |
| 15 | const specDir = outdir ? [ctx.config.cwd, outdir] : ctx.paths.specs |
| 16 | const specDirPath = ctx.runtime.path.join(...specDir) |
| 17 | |
| 18 | const writeSpec = async (spec: SpecFile) => { |
| 19 | await ctx.output.write({ |
| 20 | id: `spec-${spec.type}` as ArtifactId, |
| 21 | dir: specDir, |
| 22 | files: [{ file: `${spec.type}.json`, code: JSON.stringify(spec, null, 2) }], |
| 23 | }) |
| 24 | } |
| 25 | |
| 26 | await Promise.all(specs.map(writeSpec)) |
| 27 | |
| 28 | const specTypes = specs.map((s) => s.type) |
| 29 | logger.info('spec', `Generated ${specTypes.length} spec file(s) → ${specDirPath}`) |
| 30 | return specs |
| 31 | } |