{"version":3,"file":"index.cjs","names":["wantsHelp","path","exportApiContracts","os"],"sources":["../../../../src/cli/commands/api-export/index.ts"],"sourcesContent":["import os from 'node:os';\nimport path from 'node:path';\n\nimport { exportApiContracts } from '../../../builders/apiContractExport';\nimport { wantsHelp } from '../../router';\n\nexport function apiExportHelp(): string {\n  return `Usage: doompi api-export --out <directory> [--major-mode <name>] [--strict]\n\nExport OpenAPI, AsyncAPI, and a coverage manifest from synced global and workspace\nAPI generations. No packages are installed and no services are started.\n\n  --out <directory>     Destination for openapi.json, asyncapi.json, manifest.json\n  --major-mode <name>   Session mode (defaults to the workspace default)\n  --strict              Exit nonzero when selected contract coverage is incomplete\n  -h, --help            Show this help\n`;\n}\n\nexport async function runApiExport(\n  args: readonly string[],\n  environment: NodeJS.ProcessEnv = process.env,\n  cwd = process.cwd(),\n  output: { write(chunk: string): void } = process.stdout,\n): Promise<number> {\n  if (wantsHelp(args.slice(1))) {\n    output.write(apiExportHelp());\n    return 0;\n  }\n  let destination: string | undefined;\n  let majorMode: string | undefined;\n  let strict = false;\n  for (let index = 1; index < args.length; index += 1) {\n    const option = args[index];\n    if (option === '--strict') {\n      strict = true;\n      continue;\n    }\n    if (option !== '--out' && option !== '--major-mode') throw new Error(`Unknown api-export argument: ${option}`);\n    const value = args[++index];\n    if (!value || value.startsWith('--')) throw new Error(`${option} requires a value`);\n    if (option === '--out') {\n      if (destination !== undefined) throw new Error('--out was specified more than once');\n      destination = value;\n    } else {\n      if (majorMode !== undefined) throw new Error('--major-mode was specified more than once');\n      majorMode = value;\n    }\n  }\n  if (!destination) throw new Error('api-export requires --out <directory>');\n  const outputDirectory = path.resolve(cwd, destination);\n  const manifest = exportApiContracts({\n    cwd,\n    homeDirectory: environment.HOME ?? os.homedir(),\n    outputDirectory,\n    majorMode,\n  });\n  output.write(`${JSON.stringify({ directory: outputDirectory, complete: manifest.complete, gaps: manifest.gaps })}\\n`);\n  return strict && !manifest.complete ? 1 : 0;\n}\n"],"mappings":";;;;;;;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