import{writeFileSync as l}from"fs";import o from"path";import{dump as d}from"js-yaml";import{PUBLIC_API_DEFINITIONS_FOLDER as u,PUBLIC_STATIC_FOLDER as m}from"../../constants/common.js";import{logger as x}from"../../tools/notifiers/logger.js";import{ensureDir as g}from"../../utils/fs.js";const c=new Map;function _(e,t,i){const r=u.slice(1);try{for(const s of e){const{documentWithReferences:f,relativePath:n}=s;if(c.get(n)!==i){if(n.startsWith(m+"/")){const a=o.posix.extname(n);p({outDir:t,definitionFolder:".",relativePath:n.replace(m+"/",""),definitionString:a===".json"?JSON.stringify(f,null,2):d(f)}),c.set(n,i);continue}p({outDir:t,definitionFolder:r,relativePath:F(n,".json"),definitionString:JSON.stringify(f,null,2)}),c.set(n,i)}}}catch(s){x.error("failed to store definition bundles",s)}}function F(e,t){const i=o.posix.dirname(e),r=o.posix.basename(e,o.posix.extname(e))+t;return o.posix.join(i,r)}function p({outDir:e,definitionString:t,relativePath:i,definitionFolder:r}){l(g(o.resolve(e,`${r}/${i}`)),t,"utf8")}export{F as replaceFileExtension,_ as storeDefinitionBundles};
