import t from"node:path";import{copyFileSync as v,existsSync as s,mkdirSync as u}from"node:fs";import{envConfig as c}from"../../server/config/env-config.js";import{logger as a}from"../../server/tools/notifiers/logger.js";import{sanitizeBranchName as l}from"../../server/utils/envs/sanitize-branch-name.js";const F=n=>{const i=f();s(n.serverOutDir)||u(n.serverOutDir,{recursive:!0});const e=[];for(const o of i){const r=t.join(n.contentDir,o);if(!s(r))continue;const p=t.join(n.serverOutDir,o);v(r,p),e.push(o)}e.length>0&&a.info(`Env files included in bundle: ${e.map(()=>"%rp").join(", ")}`,...e)},f=()=>{const n=c.REDOCLY_ENV,i=c.PUBLIC_REDOCLY_BRANCH_NAME,e=[".env"];switch(i&&e.push(`.env.branch.${l(i)}`),n){case"production":e.push(".env.production");break;case"preview":e.push(".env.preview");break;default:e.push(".env.development");break}return e};export{F as copyEnvFiles};
