{"version":3,"file":"index.mjs","names":[],"sources":["../src/generate.ts"],"sourcesContent":["import {\n  getWarningCount,\n  type GlobalOptions,\n  isString,\n  logError,\n  type OptionsExport,\n  resetWarnings,\n  setVerbose,\n} from '@orval/core';\n\nimport { generateSpec } from './generate-spec';\nimport { findConfigFile, loadConfigFile } from './utils/config';\nimport { normalizeOptions } from './utils/options';\nimport { startWatcher } from './utils/watcher';\n\nexport async function generate(\n  optionsExport?: string | OptionsExport,\n  workspace = process.cwd(),\n  options?: GlobalOptions,\n) {\n  setVerbose(!!options?.verbose);\n  resetWarnings();\n\n  if (!optionsExport || isString(optionsExport)) {\n    const configFilePath = findConfigFile(optionsExport);\n    const configFile = await loadConfigFile(configFilePath);\n\n    const configs = Object.entries(configFile);\n\n    let hasErrors = false;\n    for (const [projectName, config] of configs) {\n      const normalizedOptions = await normalizeOptions(\n        config,\n        workspace,\n        options,\n      );\n\n      try {\n        await generateSpec(workspace, normalizedOptions, projectName);\n      } catch (error) {\n        hasErrors = true;\n        logError(error, projectName);\n      }\n\n      if (options?.watch !== undefined) {\n        const fileToWatch = isString(normalizedOptions.input.target)\n          ? normalizedOptions.input.target\n          : undefined;\n\n        await startWatcher(\n          options.watch,\n          async () => {\n            resetWarnings();\n            try {\n              await generateSpec(workspace, normalizedOptions, projectName);\n            } catch (error) {\n              logError(error, projectName);\n            }\n            if (options.failOnWarnings && getWarningCount() > 0) {\n              throw new Error(\n                `Process failed with ${getWarningCount()} warning(s) due to failOnWarnings option`,\n              );\n            }\n          },\n          fileToWatch,\n        );\n      }\n    }\n\n    if (hasErrors)\n      logError('One or more project failed, see above for details');\n\n    if (options?.failOnWarnings && getWarningCount() > 0) {\n      throw new Error(\n        `Process failed with ${getWarningCount()} warning(s) due to failOnWarnings option`,\n      );\n    }\n\n    return;\n  }\n\n  const normalizedOptions = await normalizeOptions(\n    optionsExport,\n    workspace,\n    options,\n  );\n\n  try {\n    await generateSpec(workspace, normalizedOptions);\n  } catch (error) {\n    logError(error);\n  }\n\n  if (options?.watch) {\n    await startWatcher(\n      options.watch,\n      async () => {\n        resetWarnings();\n        try {\n          await generateSpec(workspace, normalizedOptions);\n        } catch (error) {\n          logError(error);\n        }\n        if (options.failOnWarnings && getWarningCount() > 0) {\n          throw new Error(\n            `Process failed with ${getWarningCount()} warning(s) due to failOnWarnings option`,\n          );\n        }\n      },\n      normalizedOptions.input.target as string,\n    );\n  }\n\n  if (options?.failOnWarnings && getWarningCount() > 0) {\n    throw new Error(\n      `Process failed with ${getWarningCount()} warning(s) due to failOnWarnings option`,\n    );\n  }\n}\n"],"mappings":";;;;AAeA,eAAsB,SACpB,eACA,YAAY,QAAQ,IAAI,GACxB,SACA;CACA,WAAW,CAAC,CAAC,SAAS,OAAO;CAC7B,cAAc;CAEd,IAAI,CAAC,iBAAiB,SAAS,aAAa,GAAG;EAE7C,MAAM,aAAa,MAAM,eADF,eAAe,aACe,CAAC;EAEtD,MAAM,UAAU,OAAO,QAAQ,UAAU;EAEzC,IAAI,YAAY;EAChB,KAAK,MAAM,CAAC,aAAa,WAAW,SAAS;GAC3C,MAAM,oBAAoB,MAAM,iBAC9B,QACA,WACA,OACF;GAEA,IAAI;IACF,MAAM,aAAa,WAAW,mBAAmB,WAAW;GAC9D,SAAS,OAAO;IACd,YAAY;IACZ,SAAS,OAAO,WAAW;GAC7B;GAEA,IAAI,SAAS,UAAU,KAAA,GAAW;IAChC,MAAM,cAAc,SAAS,kBAAkB,MAAM,MAAM,IACvD,kBAAkB,MAAM,SACxB,KAAA;IAEJ,MAAM,aACJ,QAAQ,OACR,YAAY;KACV,cAAc;KACd,IAAI;MACF,MAAM,aAAa,WAAW,mBAAmB,WAAW;KAC9D,SAAS,OAAO;MACd,SAAS,OAAO,WAAW;KAC7B;KACA,IAAI,QAAQ,kBAAkB,gBAAgB,IAAI,GAChD,MAAM,IAAI,MACR,uBAAuB,gBAAgB,EAAE,yCAC3C;IAEJ,GACA,WACF;GACF;EACF;EAEA,IAAI,WACF,SAAS,mDA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