import{existsSync as p}from"fs";import*as i from"path";import{cliCommandNames as o}from"../../constants/index.js";import{PUBLIC_STATIC_FOLDER as s}from"../constants/common.js";import{loadEnvironmentVariables as a}from"../../shared/env.js";import{copyFolderRecursiveSync as c}from"./fs.js";import n from"./reporter/logger.js";import{validateInstalledVersion as f}from"./validate-installed-version.js";import{blue as l,gray as u}from"./reporter/colors.js";import{PACKAGE_NAME as E}from"../../config/product-gates.js";import{PORTAL_VERSION as P}from"../version.js";function R(e){return e?"true":"false"}function v(e){return e?"true":"false"}function O(e){return p(i.resolve(e))?!0:(n.warn("The specified HTML Template does not exist at %rp: ",e),!1)}function d(e,r){const t=e.htmlTemplate;t&&O(t)&&r.setCliOptions({customHtmlTemplate:t}),process.env.REPORTER_VERBOSE=R(e.verbose),process.env.INSPECT_MODE=v(e.inspect),e.pathPrefix&&(process.env.REDOCLY_PREFIX_PATHS=e.pathPrefix)}function C({contentDir:e,outdir:r}){c(i.join(e,s),i.join(r,s))}async function V(e,r,t){a(r["project-dir"]),process.env.REDOCLY_RUNNING_COMMAND=e;const m=e===o.DEVELOP?"  Previewing with":"Building with";switch(n.logSticky("product",`${m} ${l(`${E}@${P}`)}`),n.logSticky("server",`  \u{1F310} Preview URL: ${u("server starting...")}`),e){case o.DEVELOP:case o.BUILD:case o.PREPARE:d(r,t);break;default:break}await f(),C(t)}export{V as beforeCommand};
