import{readdir as v,access as h,copyFile as w,constants as g}from"fs/promises";import{join as i,relative as $}from"node:path";async function F(c={}){let{testResultsDir:a="test-results",testsDir:o="tests",projectRoot:t=process.cwd(),verbose:s=!0}=c;s&&console.log(`\u{1F3A5} Organizing test videos...
`);let r=i(t,a),l=i(t,o);try{let e=await v(r),f=0;for(let n of e){if(n.startsWith("."))continue;let u=i(r,n,"video.webm");try{await h(u,g.F_OK)}catch{continue}let m=n.replace(/-chromium$/,"").replace(/-firefox$/,"").replace(/-webkit$/,""),d=await P(l,m);if(d){let p=d.replace(/\.spec\.(js|ts)$/,".spec.webm");await w(u,p),s&&console.log(`\u2705 ${$(t,p)}`),f++}else s&&console.log(`\u26A0\uFE0F  Could not find test file for: ${n}`)}return s&&(console.log(`
\u{1F3AC} Organized ${f} video(s)`),console.log(`\u{1F4C2} Videos are now next to their test files in ${o}/`)),{movedCount:f,success:!0}}catch(e){return s&&console.error("\u274C Error organizing videos:",e.message),{movedCount:0,success:!1,error:e.message}}}async function P(c,a){let o=a.split("-");for(let t=o.length;t>0;t--){let r=o.slice(0,t).join("/");for(let l of["js","ts"]){let e=i(c,`${r}.spec.${l}`);try{return await h(e,g.F_OK),e}catch{}}}return null}export{F as organizeVideos};
