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 c}from"../../constants/common.js";import{ensureDir as x}from"../../utils/fs.js";import g from"../../utils/reporter/logger.js";const a=new Map;function O(i,t){const r=u.slice(1);try{for(const e of i){const{definition:s,relativePath:n,hash:f}=e;if(a.get(n)!==f){if(n.startsWith(c+"/")){const p=o.posix.extname(n);m({outDir:t,definitionFolder:".",relativePath:n.replace(c+"/",""),definitionString:p===".json"?JSON.stringify(s,null,2):d(s)}),a.set(n,f);continue}m({outDir:t,definitionFolder:r,relativePath:h(n,".json"),definitionString:JSON.stringify(s,null,2)}),a.set(n,f)}}}catch(e){g.error("failed to store definition bundles",e)}}function h(i,t){const r=o.posix.dirname(i),e=o.posix.basename(i,o.posix.extname(i))+t;return o.posix.join(r,e)}function m({outDir:i,definitionString:t,relativePath:r,definitionFolder:e}){l(x(o.resolve(i,`${e}/${r}`)),t,"utf8")}export{h as replaceFileExtension,O as storeDefinitionBundles};
