import m from"path";import{DEFAULT_LOCALE_PLACEHOLDER as s,TRANSLATIONS_FILE_NAME as u}from"../../constants/index.js";import{exit as T}from"../../server/utils/process.js";import{confirmPrompt as E}from"../generate/prompt.js";import{blue as d}from"../../server/utils/reporter/colors.js";import{splitArrayAsync as P}from"../../shared/jsUtils.js";import{updateTranslations as _}from"./update-translations.js";import{logger as n}from"../../server/utils/index.js";import{initPlugins as D}from"../../server/plugins/lifecycle.js";const F="default",q=async r=>{const i=r._||[];if(i.length===0)return n.panicOnContentError("Locale is required but was not provided.");const L=m.resolve(r["project-dir"]),{lifecycleContext:e}=await D({outdir:"",contentDir:L,setGlobalConfig:()=>null}),h=(await e.getConfig()).l10n?.defaultLocale?.toLowerCase()||s,a=[s,...e.fs.localeFolders],l=(i[0]==="all"?a:i).map(t=>{const p=t.toLocaleLowerCase()===h||t===F?s:t.toLowerCase(),C=a.find(A=>A.toLocaleLowerCase()===t)||t,w=p===s?u:m.join(e.fs.localizationFolder,C,u);return{systemName:p,providedName:t,filePath:w}}),[c,f]=await P(l,t=>e.fs.exists(t.filePath)),o=["Confirm the following actions:",""];f.length>0&&(o.push("Create new files with translations stubs:"),o.push(...f.map(t=>` - ${d(t.filePath)}`)),o.push("")),c.length>0&&(o.push("Update translations files with missing phrases (this doesn't rewrite existing data values):"),o.push(...c.map(t=>` - ${d(t.filePath)}`)),o.push("")),o.push("Continue? ");const{confirm:g}=await E(o.join(`
`));if(g){const t=n.startTiming();await _(e,l),n.successTime(t,"Success!")}T(0)};export{q as generateTranslations};
