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 _(i,t,e){const r=u.slice(1);try{for(const s of i){const{document:f,relativePath:n}=s;if(c.get(n)!==e){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,e);continue}p({outDir:t,definitionFolder:r,relativePath:F(n,".json"),definitionString:JSON.stringify(f,null,2)}),c.set(n,e)}}}catch(s){x.error("failed to store definition bundles",s)}}function F(i,t){const e=o.posix.dirname(i),r=o.posix.basename(i,o.posix.extname(i))+t;return o.posix.join(e,r)}function p({outDir:i,definitionString:t,relativePath:e,definitionFolder:r}){l(g(o.resolve(i,`${r}/${e}`)),t,"utf8")}export{F as replaceFileExtension,_ as storeDefinitionBundles};
