@eloqnt/cli 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @eloqnt/cli
2
2
 
3
+ ## 0.5.4
4
+
5
+ ### Patch Changes
6
+
7
+ - e78663d: Add `eloqnt crowdin` commands for syncing messages with a Crowdin project via `crowdin.yml`: `upload sources`, `upload translations`, and `download translations`.
8
+ - Updated dependencies [e78663d]
9
+ - @eloqnt/sdk@0.5.2
10
+
11
+ ## 0.5.3
12
+
13
+ ### Patch Changes
14
+
15
+ - 5cbbc66: Link each command's docs page from `--help` output, with command descriptions kept to one line.
16
+
3
17
  ## 0.5.2
4
18
 
5
19
  ### Patch Changes
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import e from"node:process";import{defineCommand as t,runMain as n}from"citty";var r=`0.5.2`;try{e.loadEnvFile()}catch{}const i=t({meta:{name:`eloqnt`,version:r,description:`AI-powered translations for developers`},subCommands:{lint:o(()=>import(`../lint-EHLBXuQG.mjs`)),review:o(()=>import(`../review-DwtF6htB.mjs`)),translate:o(()=>import(`../translate-BiFqwHuB.mjs`)),login:o(()=>import(`../login-DcFAwS1Z.mjs`)),logout:o(()=>import(`../logout-BjdvLusP.mjs`)),whoami:o(()=>import(`../whoami-CTueGAHT.mjs`))}}),a=e.argv.slice(2);n(i,{rawArgs:a.length===1&&a[0]===`-v`?[`--version`]:a});function o(e){return()=>e().then(e=>e.default)}export{r as t};
2
+ import e from"node:process";import{defineCommand as t,renderUsage as n,runMain as r}from"citty";import i from"picocolors";var a=`0.5.4`;try{e.loadEnvFile()}catch{}const o=t({meta:{name:`eloqnt`,version:a,description:`AI-powered translations for developers`},subCommands:{lint:d(()=>import(`../lint-C_GvlHIh.mjs`)),review:d(()=>import(`../review-C_Op7_7I.mjs`)),translate:d(()=>import(`../translate-0d7JNq0l.mjs`)),crowdin:d(()=>import(`../crowdin-BXlNSsuT.mjs`)),login:d(()=>import(`../login-DkoUYP1R.mjs`)),logout:d(()=>import(`../logout-BjdvLusP.mjs`)),whoami:d(()=>import(`../whoami-CTueGAHT.mjs`))}}),s=e.argv.slice(2);r(o,{rawArgs:s.length===1&&s[0]===`-v`?[`--version`]:s,async showUsage(e,t){console.log(await n(e,t)),console.log(i.dim(`Docs: ${await c(e,t)}`))}});async function c(e,t){let n=(await u(e.meta))?.name,r=(await u(t?.meta))?.name,i=r===void 0||r===`eloqnt`?n:r;return i===void 0||i===`eloqnt`?`https://studio.eloqnt.dev/docs`:`https://studio.eloqnt.dev/docs/cli/${await l(i)}`}async function l(e){let t=o.subCommands??{};if(e in t)return e;for(let[n,r]of Object.entries(t)){let t=(await u(r))?.subCommands;if(t&&e in t)return n}return e}function u(e){return typeof e==`function`?e():e}function d(e){return()=>e().then(e=>e.default)}export{a as t};
@@ -0,0 +1 @@
1
+ import{defineCommand as e}from"citty";var t=e({meta:{name:`crowdin`,description:`Sync messages with a Crowdin project (uses crowdin.yml).`},subCommands:{upload:()=>import(`./upload-BDnaUB4y.mjs`).then(e=>e.default),download:()=>import(`./download-BuHS-69H.mjs`).then(e=>e.default)}});export{t as default};
@@ -0,0 +1 @@
1
+ import{defineCommand as e}from"citty";var t=e({meta:{name:`download`,description:`Download translations from your Crowdin project.`},subCommands:{translations:()=>import(`./translations-fTIBanLm.mjs`).then(e=>e.default)}});export{t as default};
@@ -1,6 +1,6 @@
1
- import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{a as t,i as n,o as r,r as i,s as a,t as o}from"./stringWidth-Ba8f3rhS.mjs";import{t as s}from"./resolvePaths-Bc7dGH8a.mjs";import{lint as c}from"@eloqnt/sdk";import l from"node:process";import{basename as u,relative as d,resolve as f}from"node:path";import p from"picocolors";var m=e({meta:{name:`lint`,description:`Statically analyze your source code and messages for common problems.`},args:{strict:{type:`boolean`,description:`Exit with a non-zero code when warnings are found`,default:!1}},async execute({config:e,rootDir:t,args:n}){let{messages:r,srcPath:i}=e,a=await c({messagesPath:s(r.path,t),sourceLocale:r.sourceLocale,format:r.format,locales:r.locales,srcPath:i?s(i,t):void 0,cwd:t}),o=l.cwd();return{issues:a.map(e=>{let t=e;if(t.location&&(t={...t,location:{...t.location,file:d(o,t.location.file)}}),t.rule===`undefined-key`&&t.sourceReferences?.length){let e=t.sourceReferences.map(e=>({...e,path:d(o,e.path)})),n=e[0].line?`${e[0].path}:${e[0].line}`:e[0].path,r=e.length>1?` (+${e.length-1} more)`:``,i=t.location?u(t.location.file):`the source catalog`;t={...t,sourceReferences:e,message:`Used in ${n}${r} but not defined in ${i}`}}return t}),sourceLocale:r.sourceLocale,noSrcPath:!i,strict:!!n.strict}},render:({issues:e,sourceLocale:t,noSrcPath:n})=>{let r=h(e,t),i=n?`\n${p.dim("– Skipped source code analysis due to absent `srcPath`")}\n${r}`:r;return l.env.GITHUB_ACTIONS&&e.length>0?`${i}\n${_(e)}`:i},ok:({issues:e,strict:t})=>t?e.length===0:!e.some(e=>e.severity===`error`),json:({issues:e})=>e});function h(e,t){if(e.length===0)return`\n${p.green(`No issues found`)}\n`;let n=Object.groupBy(e,e=>e.location?.file??e.locale),r=x(Object.entries(n),t).map(([e,n])=>S(e,n,n[0].locale===t)),i=e.filter(e=>e.severity===`error`).length,a=e.length-i,o=[i>0&&p.bold(p.red(`✗ ${g(i,`error`)}`)),a>0&&p.bold(p.yellow(`! ${g(a,`warning`)}`))].filter(Boolean).join(`
2
- `),s=e.filter(e=>e.rule===`missing-translation`).length,c=s?p.dim(`→ Run \`eloqnt translate\` to fill in ${s} missing ${s===1?`translation`:`translations`}`):void 0;return`\n${[...r,o,c].filter(Boolean).join(`
1
+ import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{a as t,i as n,o as r,r as i,s as a,t as o}from"./stringWidth-Ba8f3rhS.mjs";import{t as s}from"./resolvePaths-Bc7dGH8a.mjs";import{lint as c}from"@eloqnt/sdk";import l from"node:process";import u from"picocolors";import{basename as d,relative as f,resolve as p}from"node:path";var m=e({meta:{name:`lint`,description:`Statically analyze your source code and messages for common problems.`},args:{strict:{type:`boolean`,description:`Exit with a non-zero code when warnings are found`,default:!1}},async execute({config:e,rootDir:t,args:n}){let{messages:r,srcPath:i}=e,a=await c({messagesPath:s(r.path,t),sourceLocale:r.sourceLocale,format:r.format,locales:r.locales,srcPath:i?s(i,t):void 0,cwd:t}),o=l.cwd();return{issues:a.map(e=>{let t=e;if(t.location&&(t={...t,location:{...t.location,file:f(o,t.location.file)}}),t.rule===`undefined-key`&&t.sourceReferences?.length){let e=t.sourceReferences.map(e=>({...e,path:f(o,e.path)})),n=e[0].line?`${e[0].path}:${e[0].line}`:e[0].path,r=e.length>1?` (+${e.length-1} more)`:``,i=t.location?d(t.location.file):`the source catalog`;t={...t,sourceReferences:e,message:`Used in ${n}${r} but not defined in ${i}`}}return t}),sourceLocale:r.sourceLocale,noSrcPath:!i,strict:!!n.strict}},render:({issues:e,sourceLocale:t,noSrcPath:n})=>{let r=h(e,t),i=n?`\n${u.dim("– Skipped source code analysis due to absent `srcPath`")}\n${r}`:r;return l.env.GITHUB_ACTIONS&&e.length>0?`${i}\n${_(e)}`:i},ok:({issues:e,strict:t})=>t?e.length===0:!e.some(e=>e.severity===`error`),json:({issues:e})=>e});function h(e,t){if(e.length===0)return`\n${u.green(`No issues found`)}\n`;let n=Object.groupBy(e,e=>e.location?.file??e.locale),r=x(Object.entries(n),t).map(([e,n])=>S(e,n,n[0].locale===t)),i=e.filter(e=>e.severity===`error`).length,a=e.length-i,o=[i>0&&u.bold(u.red(`✗ ${g(i,`error`)}`)),a>0&&u.bold(u.yellow(`! ${g(a,`warning`)}`))].filter(Boolean).join(`
2
+ `),s=e.filter(e=>e.rule===`missing-translation`).length,c=s?u.dim(`→ Run \`eloqnt translate\` to fill in ${s} missing ${s===1?`translation`:`translations`}`):void 0;return`\n${[...r,o,c].filter(Boolean).join(`
3
3
 
4
4
  `)}\n`}function g(e,t){return`${e} ${e===1?t:`${t}s`}`}function _(e){return e.map(e=>{let t=e.rule===`undefined-key`&&e.sourceReferences?.length?e.sourceReferences[0]:void 0,n=t?.path??e.location?.file,r=[n&&`file=${b(v(n))}`,t?.line&&`line=${t.line}`,`title=${b(e.rule)}`].filter(Boolean).join(`,`),i=y(`"${e.key}": ${e.message}`);return`::${e.severity} ${r}::${i}`}).join(`
5
- `)}function v(e){let t=l.env.GITHUB_WORKSPACE;return t?d(t,f(e)):e}function y(e){return e.replace(/%/g,`%25`).replace(/\r/g,`%0D`).replace(/\n/g,`%0A`)}function b(e){return y(e).replace(/:/g,`%3A`).replace(/,/g,`%2C`)}function x(e,t){let n=e.findIndex(([,e])=>e[0].locale===t);if(n<=0)return e;let r=[...e],[i]=r.splice(n,1);return[i,...r]}function S(e,t,n){let i=[n?`${p.cyan(e)} ${p.dim(`(source locale)`)}`:p.cyan(e)];for(let e of t){i.push(p.dim(`│`));let{content:t,span:n}=C(e);i.push(r(t)),i.push(...T(n,e))}return i.join(`
6
- `)}function C(e){let n=`"${e.key}"`,r=e.targetMessage??e.sourceMessage,o=w(n),s=e.highlight?.type===`value`||e.highlight?.type===`argument`,c=s?p.dim(n):n,l=p.dim(`: `),u=i(n);if(r!==void 0&&e.highlight?.type===`argument`){let t=a(r),n=e.highlight.token,s=t.indexOf(n);if(s>=0){let{inner:e,offset:r}=E(t,s,n.length,o);return{content:`${c}${l}"${e}"`,span:{column:u+3+r,length:i(n)}}}}let d=r===void 0?`"…"`:`"${t(a(r),o)}"`,f=`${c}${l}${s?d:p.dim(d)}`;return r!==void 0&&e.highlight?.type===`value`?{content:f,span:{column:u+2,length:i(d)}}:{content:f,span:{column:0,length:u}}}function w(e){let t=3+i(e)+2+2;return Math.max(24,Math.min(48,n()-t))}function T(e,t){let n=t.severity===`error`?p.red:p.yellow,i=Math.min(1,e.length-1),a=`─`.repeat(i)+`┬`+`─`.repeat(e.length-1-i),o=`${t.message} ${p.dim(`(${t.rule})`)}`;return[r(` `.repeat(e.column)+n(a)),r(`${` `.repeat(e.column+i)}${n(`╰─`)} ${o}`)]}function E(e,t,n,r){let i=o(e),a=i.reduce((e,t)=>e+t.width,0),s=D(i,t),c=D(i,t+n);if(a<=r)return{inner:e,offset:O(i,0,s)};let l=Math.max(O(i,s,c),r-2),u=s,d=0;for(;u>0&&d+i[u-1].width<=16;)u--,d+=i[u].width;let f=s;for(;f<i.length&&d+i[f].width<=l;)d+=i[f].width,f++;for(;u>0&&d+i[u-1].width<=l;)u--,d+=i[u].width;let p=u>0?`…`:``,m=f<i.length?`…`:``;return{inner:p+i.slice(u,f).map(e=>e.text).join(``)+m,offset:O(i,u,s)+p.length}}function D(e,t){let n=0;for(let r=0;r<e.length;r++){if(n>=t)return r;n+=e[r].text.length}return e.length}function O(e,t,n){let r=0;for(let i=t;i<n;i++)r+=e[i].width;return r}export{m as default,_ as formatGithubAnnotations,h as formatLint};
5
+ `)}function v(e){let t=l.env.GITHUB_WORKSPACE;return t?f(t,p(e)):e}function y(e){return e.replace(/%/g,`%25`).replace(/\r/g,`%0D`).replace(/\n/g,`%0A`)}function b(e){return y(e).replace(/:/g,`%3A`).replace(/,/g,`%2C`)}function x(e,t){let n=e.findIndex(([,e])=>e[0].locale===t);if(n<=0)return e;let r=[...e],[i]=r.splice(n,1);return[i,...r]}function S(e,t,n){let i=[n?`${u.cyan(e)} ${u.dim(`(source locale)`)}`:u.cyan(e)];for(let e of t){i.push(u.dim(`│`));let{content:t,span:n}=C(e);i.push(r(t)),i.push(...T(n,e))}return i.join(`
6
+ `)}function C(e){let n=`"${e.key}"`,r=e.targetMessage??e.sourceMessage,o=w(n),s=e.highlight?.type===`value`||e.highlight?.type===`argument`,c=s?u.dim(n):n,l=u.dim(`: `),d=i(n);if(r!==void 0&&e.highlight?.type===`argument`){let t=a(r),n=e.highlight.token,s=t.indexOf(n);if(s>=0){let{inner:e,offset:r}=E(t,s,n.length,o);return{content:`${c}${l}"${e}"`,span:{column:d+3+r,length:i(n)}}}}let f=r===void 0?`"…"`:`"${t(a(r),o)}"`,p=`${c}${l}${s?f:u.dim(f)}`;return r!==void 0&&e.highlight?.type===`value`?{content:p,span:{column:d+2,length:i(f)}}:{content:p,span:{column:0,length:d}}}function w(e){let t=3+i(e)+2+2;return Math.max(24,Math.min(48,n()-t))}function T(e,t){let n=t.severity===`error`?u.red:u.yellow,i=Math.min(1,e.length-1),a=`─`.repeat(i)+`┬`+`─`.repeat(e.length-1-i),o=`${t.message} ${u.dim(`(${t.rule})`)}`;return[r(` `.repeat(e.column)+n(a)),r(`${` `.repeat(e.column+i)}${n(`╰─`)} ${o}`)]}function E(e,t,n,r){let i=o(e),a=i.reduce((e,t)=>e+t.width,0),s=D(i,t),c=D(i,t+n);if(a<=r)return{inner:e,offset:O(i,0,s)};let l=Math.max(O(i,s,c),r-2),u=s,d=0;for(;u>0&&d+i[u-1].width<=16;)u--,d+=i[u].width;let f=s;for(;f<i.length&&d+i[f].width<=l;)d+=i[f].width,f++;for(;u>0&&d+i[u-1].width<=l;)u--,d+=i[u].width;let p=u>0?`…`:``,m=f<i.length?`…`:``;return{inner:p+i.slice(u,f).map(e=>e.text).join(``)+m,offset:O(i,u,s)+p.length}}function D(e,t){let n=0;for(let r=0;r<e.length;r++){if(n>=t)return r;n+=e[r].text.length}return e.length}function O(e,t,n){let r=0;for(let i=t;i<n;i++)r+=e[i].width;return r}export{m as default,_ as formatGithubAnnotations,h as formatLint};
@@ -0,0 +1,2 @@
1
+ import{t as e}from"./bin/eloqnt.mjs";import{t}from"./withErrorFormatting-CnMLjXSn.mjs";import{t as n}from"./createSpinner-BBkrpcrh.mjs";import{a as r,i,n as a,t as o}from"./urls-BrJoRsYB.mjs";import s from"node:process";import{defineCommand as c}from"citty";import l from"picocolors";import{EloqntSdkError as u,getAuthHeaders as d}from"@eloqnt/sdk/_internal";import{outro as f}from"@clack/prompts";import{hostname as p}from"node:os";import{setTimeout as m}from"node:timers/promises";import h from"open";function g(e){h(e).catch(()=>{})}const _=`eloqnt-cli`,v=`eloqnt-cli/${e} (${p()}; ${s.platform} ${s.arch}; node ${s.version})`;var y=c({meta:{name:`login`,description:`Authenticates the CLI by storing an auth token locally.`},run:()=>t(async()=>{let e=o(),t=await i();t&&await fetch(`${e}/revoke-session`,{method:`POST`,headers:{authorization:`Bearer ${t}`,"content-type":`application/json`,"user-agent":v},body:JSON.stringify({token:t})}).catch(()=>{});let c=await fetch(`${e}/device/code`,{method:`POST`,headers:{"content-type":`application/json`,"user-agent":v},body:JSON.stringify({client_id:_})});if(!c.ok)throw new u(`ENGINE_UNREACHABLE`,`Couldn't start the login flow`,{details:`The auth server responded with ${c.status}.`,hint:`Check your connection and run eloqnt login again.`});let d=await c.json();s.stderr.write(`\n${l.cyan(`Log in to eloqnt studio`)}\n`),s.stderr.write(l.dim(`${d.verification_uri_complete}\n\n`)),g(d.verification_uri_complete);let p=s.stderr.isTTY?n():void 0;p?p.start(`Waiting for approval in the browser`):s.stderr.write(l.dim(`Waiting for approval in the browser …
2
+ `));let m=await x(e,d);if(!m.access_token)throw p?.stop(l.dim(`Login cancelled`)),new u(`NOT_AUTHENTICATED`,m.error_description??`Login failed`,{hint:`Run eloqnt login to try again.`});await r(m.access_token),p?(p.stop(l.dim(`Approved in the browser`)),f(l.green(`Logged in`))):s.stdout.write(`${l.green(`Logged in`)}\n`),await b(m.access_token)&&s.stderr.write(`\n${l.cyan(`→ Choose a plan at ${a()}/plans`)}\n`)})});async function b(e){try{let t=await fetch(new URL(`/api/engine/me`,a()),{headers:d(e)});if(!t.ok)return!1;let n=await t.json();return Array.isArray(n.plans)&&n.plans.length===0}catch{return!1}}async function x(e,t){let n=Date.now()+t.expires_in*1e3,r=t.interval;for(;Date.now()<n;){await m(r*1e3);let n=await(await fetch(`${e}/device/token`,{method:`POST`,headers:{"content-type":`application/json`,"user-agent":v},body:JSON.stringify({grant_type:`urn:ietf:params:oauth:grant-type:device_code`,device_code:t.device_code,client_id:_})})).json();if(n.access_token)return n;if(n.error!==`authorization_pending`){if(n.error===`slow_down`){r+=5;continue}return n}}return{error:`expired_token`,error_description:`The login request expired`}}export{y as default};
@@ -0,0 +1 @@
1
+ function e(e){if(e!==void 0)return(Array.isArray(e)?e:[e]).flatMap(e=>String(e).split(`,`).map(e=>e.trim()).filter(e=>e.length>0))}export{e as t};
@@ -0,0 +1 @@
1
+ import{defineCommand as e}from"citty";var t=e({meta:{name:`review`,description:`Review source strings and fix issues in place.`},setup({rawArgs:e}){e.find(e=>!e.startsWith(`-`))!==`source`&&e.unshift(`source`)},subCommands:{source:()=>import(`./source-DxyjecuV.mjs`).then(e=>e.default)}});export{t as default};
@@ -0,0 +1,10 @@
1
+ import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{t}from"./parseListArg-p5H1s5JC.mjs";import{t as n}from"./createSpinner-BBkrpcrh.mjs";import{a as r,i,n as a,o,r as s,s as c}from"./stringWidth-Ba8f3rhS.mjs";import{t as l}from"./resolvePaths-Bc7dGH8a.mjs";import{i as u,n as d}from"./urls-BrJoRsYB.mjs";import{n as f,r as p,t as m}from"./writeStep-CerCYWGN.mjs";import{reviewSource as h}from"@eloqnt/sdk";import g from"node:process";import _ from"picocolors";import{basename as v,dirname as y,relative as b}from"node:path";import{loadStyleguide as x}from"@eloqnt/sdk/_internal";var S=e({meta:{name:`source`,description:`Review source strings for errors and fix them in place.`,requiresLogin:!0},args:{id:{type:`string`,description:`(Re-)review these message ids (comma-separated)`}},async execute({config:e,rootDir:r,args:i}){let{messages:a,srcPath:o}=e,s=l(a.path,r),c=o?l(o,r):void 0,f=await x({cwd:r}),v=p(f,[a.sourceLocale]),y=e.model?`eloqnt/engine (${typeof e.model==`string`?e.model:e.model.modelId})`:`eloqnt/engine (hosted)`,S=g.stderr.isTTY&&!i.json,C;function w(e){if(!i.json){if(e.phase===`context-enrichment`){e.state===`started`?(g.stderr.write(`
2
+ `),S?(C=n({withGuide:!1}),C.start(`Context enrichment running`)):g.stderr.write(_.dim(`Context enrichment running …
3
+ `))):e.state===`completed`?(C?.clear(),C=void 0,m(_.green(`✔`),`Context enrichment complete`)):(g.stderr.write(`
4
+ `),m(_.dim(`–`),"Skipped source code analysis due to absent `srcPath`"));return}e.state===`started`?(v?m(_.green(`✔`),v):m(_.dim(`–`),`No styleguides found`),S?(C=n({withGuide:!1}),C.start(`Reviewing source strings via ${y}`)):g.stderr.write(_.dim(`Reviewing source strings via ${y} …\n`))):(C?.clear(),C=void 0,m(_.green(`✔`),`Reviewed source strings via ${y}`))}}let T;try{T=await h({messagesPath:s,sourceLocale:a.sourceLocale,format:a.format,locales:a.locales,cwd:r,engineUrl:d(),languageModel:e.model,authToken:await u(),styleguide:f,ids:t(i.id),srcPath:c,onProgress:w})}catch(e){throw C?.clear(),e}let E=g.cwd();return{result:{...T,files:T.files.map(e=>({...e,file:b(E,e.file)})),findings:T.findings.map(e=>({...e,file:e.file?b(E,e.file):void 0,sourceFiles:e.sourceFiles.map(e=>b(E,e))}))}}},render:({result:e})=>C(e),ok:({result:e})=>e.findings.every(e=>e.status===`fixed`),json:({result:e})=>e});function C(e,t=i()){let{findings:n,reviewed:r,missingTranslations:a,quota:o}=e,s=[],c=new Map;for(let t of n){let n=t.file??e.sourceLocale,r=c.get(n)??[];r.push(t),c.set(n,r)}for(let[e,n]of c){let r=[`${_.cyan(e)} ${_.dim(`(source locale)`)}`];for(let e of n)r.push(_.dim(`│`)),r.push(...w(e,t));s.push(r.join(`
5
+ `))}let l=O(n,e.sourceLocale),u=Object.groupBy(e.files,e=>y(e.file)),d=Object.entries(u).map(([e,t=[]])=>{let n=Math.max(0,...t.map(e=>v(e.file).length)),r=t.map(e=>{let t=v(e.file).padEnd(n),r=l.get(e.file);return` ${t} ${k(e.reviewed,r?.fixed??0,r?.reported??0,o!==void 0)}`});return[_.dim(`${e}/`),...r].join(`
6
+ `)}).join(`
7
+
8
+ `);s.push(d),o&&s.push(_.yellow(`! Monthly included usage exhausted, reviewed as much as possible. Resets ${f(o.resetsAt)}`));let p=r===0?_.dim(`→ Add new strings for the source locale to review them before translation`):a>0?_.dim("→ Run `eloqnt translate` to translate"):void 0;return`\n${s.join(`
9
+
10
+ `)}${p?`\n\n${p}`:``}\n`}function w(e,t){let n=t-3-2,r=e.newId??e.id,i=T(e.id,e.before,n),l=[o(`${_.red(`-`)} ${_.dim(i)}`)],u;if(e.status===`fixed`){let t=T(r,e.after,n),i=E(e.via,e.sourceFiles,n-s(t));u=i?T(r,e.after,n-s(i)):t,l.push(o(`${_.green(`+`)} ${u}${i?_.dim(i):``}`))}else{let t=e.sourceFiles[0],i;if(t){let e=[t,D(t),v(t)].map(e=>` (apply manually in ${e})`);i=a(n,e)||e.at(-1)}else i=` (apply manually)`;u=T(r,e.after,n-s(i)),l.push(o(`${_.yellow(`!`)} ${u}${_.dim(i)}`))}let d=Math.min(s(u)+2,t-3);return l.push(o(_.yellow(`─┬${`─`.repeat(Math.max(0,d-2))}`))),l.push(o(` ${_.yellow(`╰─`)} ${c(e.note)}`)),l}function T(e,t,n){let i=s(`"${e}": ""`);return`"${e}": "${r(c(t),Math.max(0,n-i))}"`}function E(e,t,n){if(e!==`code`||t.length===0)return``;let r=t.length>1?[`(${t.length} call sites)`]:[`(${t[0]})`,`(${D(t[0])})`,`(${v(t[0])})`],i=a(n-1,r);return i?` ${i}`:``}function D(e){let t=e.split(`/`);return t.length<=2?e:`${t[0]}/…/${t.at(-1)}`}function O(e,t){let n=new Map;for(let r of e){let e=r.file??t,i=n.get(e)??{fixed:0,reported:0};i[r.status===`fixed`?`fixed`:`reported`]++,n.set(e,i)}return n}function k(e,t,n,r){if(e===0)return _.dim(`Nothing to review`);let i=[`${e} reviewed`];t===0&&n===0&&!r&&i.push(`no fixes needed`),t>0&&i.push(`${t} fixed`),n>0&&i.push(`${n} ${n===1?`needs`:`need`} a manual edit`);let a=i.join(`, `);return n>0?_.yellow(a):r?_.dim(a):_.green(a)}export{S as default};
@@ -0,0 +1,3 @@
1
+ import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{n as t,r as n,t as r}from"./withSpinner-CeQSfolX.mjs";import i from"node:process";import a from"picocolors";import{relative as o}from"node:path";import{uploadCrowdinSources as s}from"@eloqnt/sdk/_internal";var c=e({meta:{name:`sources`,description:`Upload source files to your Crowdin project.`},requiresConfig:!1,args:{branch:{type:`string`,description:`Sync with this branch of the Crowdin project (created when missing)`}},async execute({rootDir:e,args:t}){let n=await r({label:`Uploading sources to Crowdin`,json:!!t.json,task:()=>s({cwd:e,branch:t.branch})}),a=i.cwd();return{result:{...n,files:n.files.map(e=>({...e,file:o(a,e.file)}))}}},render({result:e}){let r=e.files.map(e=>({file:e.file,detail:a.green(e.action===`created`?`Created`:`Updated`)})),i=e.files.length,o=a.green(`✔ Uploaded ${i} source ${i===1?`file`:`files`} to ${e.project.name}`)+(e.branch?` ${a.dim(`(${e.branch})`)}`:``);return`\n${[...e.createdBranch?[a.green(`✔ Created the branch ${e.createdBranch}`)]:[],t(r),...n(e.warnings),o].join(`
2
+
3
+ `)}`},json:({result:e})=>e});export{c as default};
@@ -0,0 +1,8 @@
1
+ import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{t}from"./parseListArg-p5H1s5JC.mjs";import{t as n}from"./createSpinner-BBkrpcrh.mjs";import{t as r}from"./resolvePaths-Bc7dGH8a.mjs";import{i,n as a}from"./urls-BrJoRsYB.mjs";import{n as o,r as s,t as c}from"./writeStep-CerCYWGN.mjs";import{translate as l}from"@eloqnt/sdk";import u from"node:process";import d from"picocolors";import{basename as f,dirname as p,relative as m}from"node:path";import{loadStyleguide as h}from"@eloqnt/sdk/_internal";var g=e({meta:{name:`translate`,description:`Translate strings to target locales (defaults to missing ones).`,requiresLogin:!0},args:{id:{type:`string`,description:`(Re-)translate these message ids (comma-separated)`},locale:{type:`string`,description:`Restrict to these target locales (comma-separated)`}},async execute({config:e,rootDir:o,args:f}){let{messages:p,srcPath:g}=e,_=r(p.path,o),v=g?r(g,o):void 0,y=await h({cwd:o}),b=e.model?`eloqnt/engine (${typeof e.model==`string`?e.model:e.model.modelId})`:`eloqnt/engine (hosted)`,x=t(f.locale),S=x??(Array.isArray(p.locales)?p.locales.filter(e=>e!==p.sourceLocale):void 0),C=`${S?.length?`${S.join(`, `)} `:``}via ${b}`,w=s(y,S??Object.keys(y.byLocale)),T=u.stderr.isTTY&&!f.json,E;function D(e){if(!f.json){if(e.phase===`context-enrichment`){e.state===`started`?(u.stderr.write(`
2
+ `),T?(E=n({withGuide:!1}),E.start(`Context enrichment running`)):u.stderr.write(d.dim(`Context enrichment running …
3
+ `))):e.state===`completed`?(E?.clear(),E=void 0,c(d.green(`✔`),`Context enrichment complete`)):(u.stderr.write(`
4
+ `),c(d.dim(`–`),"Skipped context enrichment due to absent `srcPath`"));return}if(e.phase===`translate`){e.state===`started`?(w?c(d.green(`✔`),w):c(d.dim(`–`),`No styleguides found`),T?(E=n({withGuide:!1}),E.start(`Translating ${C}`)):u.stderr.write(d.dim(`Translating ${C} …\n`))):(E?.clear(),E=void 0,c(d.green(`✔`),`Translated ${C}`));return}e.state===`started`?T?(E=n({withGuide:!1}),E.start(`Post-translation checks running`)):u.stderr.write(d.dim(`Post-translation checks running …
5
+ `)):(E?.clear(),E=void 0,c(d.green(`✔`),`Post-translation checks done`))}}let O;try{O=await l({messagesPath:_,sourceLocale:p.sourceLocale,format:p.format,locales:p.locales,cwd:o,engineUrl:a(),languageModel:e.model,authToken:await i(),styleguide:y,ids:t(f.id),onlyLocales:x,srcPath:v,onProgress:D})}catch(e){throw E?.clear(),e}let k=u.cwd(),A=O.targets.flatMap(e=>e.files.map(e=>({file:m(k,e.file),count:e.translated.length})));return{result:O,rows:A,complete:O.complete,noStyleguides:!w}},render({result:e,rows:t,complete:n,noStyleguides:r}){let i=Object.groupBy(t,e=>p(e.file));return`\n${Object.entries(i).map(([e,t=[]])=>{let n=Math.max(0,...t.map(e=>f(e.file).length)),r=t.map(e=>` ${f(e.file).padEnd(n)} ${e.count===0?d.dim(`Nothing to translate`):d.green(`${e.count} translated`)}`);return[d.dim(`${e}/`),...r].join(`
6
+ `)}).join(`
7
+
8
+ `)}\n\n${n?d.green(`✔ Project fully translated`):e.quota?d.yellow(`! Monthly included usage exhausted, translated as much as possible. Resets ${o(e.quota.resetsAt)}`):d.dim(`✗ Partially translated, run eloqnt lint to see what's left`)}${r?`\n\n${d.dim(`→ Add a styleguide to improve your translation quality`)}\n${d.dim(` ${a()}/docs#styleguides`)}`:``}`},json:({result:e})=>e});export{g as default};
@@ -0,0 +1,3 @@
1
+ import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{n as t,r as n,t as r}from"./withSpinner-CeQSfolX.mjs";import{t as i}from"./parseListArg-p5H1s5JC.mjs";import a from"node:process";import o from"picocolors";import{relative as s}from"node:path";import{uploadCrowdinTranslations as c}from"@eloqnt/sdk/_internal";var l=e({meta:{name:`translations`,description:`Upload existing local translations to your Crowdin project (they arrive unapproved).`},requiresConfig:!1,args:{branch:{type:`string`,description:`Sync with this branch of the Crowdin project`},locale:{type:`string`,description:`Restrict to these target languages (comma-separated)`}},async execute({rootDir:e,args:t}){let n=await r({label:`Uploading translations to Crowdin`,json:!!t.json,task:()=>c({cwd:e,branch:t.branch,onlyLocales:i(t.locale)})}),o=a.cwd();return{result:{...n,files:n.files.map(e=>({...e,file:s(o,e.file)}))}}},render({result:e}){let r=e.files.map(e=>({file:e.file,detail:e.status===`uploaded`?o.green(`Uploaded`):o.dim(`No local file`)})),i=e.files.filter(e=>e.status===`uploaded`).length,a=i===0?o.dim(`Nothing to upload`):o.green(`✔ Uploaded ${i} translation ${i===1?`file`:`files`} to ${e.project.name}`)+(e.branch?` ${o.dim(`(${e.branch})`)}`:``);return`\n${[t(r),...n(e.warnings),a].join(`
2
+
3
+ `)}`},json:({result:e})=>e});export{l as default};
@@ -0,0 +1,3 @@
1
+ import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{n as t,r as n,t as r}from"./withSpinner-CeQSfolX.mjs";import{t as i}from"./parseListArg-p5H1s5JC.mjs";import a from"node:process";import o from"picocolors";import{relative as s}from"node:path";import{downloadCrowdinTranslations as c}from"@eloqnt/sdk/_internal";var l=e({meta:{name:`translations`,description:`Download translations from your Crowdin project into your local messages files.`},requiresConfig:!1,args:{branch:{type:`string`,description:`Sync with this branch of the Crowdin project`},locale:{type:`string`,description:`Restrict to these target languages (comma-separated)`}},async execute({rootDir:e,args:t}){let n=await r({label:`Downloading translations from Crowdin`,json:!!t.json,task:()=>c({cwd:e,branch:t.branch,onlyLocales:i(t.locale)})}),o=a.cwd();return{result:{...n,files:n.files.map(e=>({...e,file:s(o,e.file)}))}}},render({result:e}){let r=e.files.map(e=>({file:e.file,detail:e.status===`updated`?o.green(`Updated`):o.dim(`Nothing translated yet`)})),i=e.files.filter(e=>e.status===`updated`).length,a=i===0?o.dim(`Nothing to download yet`):o.green(`✔ Downloaded ${i} translation ${i===1?`file`:`files`} from ${e.project.name}`)+(e.branch?` ${o.dim(`(${e.branch})`)}`:``);return`\n${[t(r),...n(e.warnings),a].join(`
2
+
3
+ `)}`},json:({result:e})=>e});export{l as default};
@@ -0,0 +1 @@
1
+ import{defineCommand as e}from"citty";var t=e({meta:{name:`upload`,description:`Upload sources or translations to your Crowdin project.`},subCommands:{sources:()=>import(`./sources-D2CmEsFc.mjs`).then(e=>e.default),translations:()=>import(`./translations-5dIUqhdZ.mjs`).then(e=>e.default)}});export{t as default};
@@ -0,0 +1,5 @@
1
+ import{t as e}from"./createSpinner-BBkrpcrh.mjs";import t from"node:process";import n from"picocolors";import{basename as r,dirname as i}from"node:path";function a(e){let t=Object.groupBy(e,e=>i(e.file));return Object.entries(t).map(([e,t=[]])=>{let i=Math.max(0,...t.map(e=>r(e.file).length)),a=t.map(e=>` ${r(e.file).padEnd(i)} ${e.detail}`);return[n.dim(`${e}/`),...a].join(`
2
+ `)}).join(`
3
+
4
+ `)}function o(e){return e.length===0?[]:[e.map(e=>n.yellow(`! ${e}`)).join(`
5
+ `)]}async function s(r){if(r.json)return r.task();let i=t.stderr.isTTY?e({withGuide:!1}):void 0;i?i.start(r.label):t.stderr.write(`\n${n.dim(`${r.label} …\n`)}`);try{return await r.task()}finally{i?.clear()}}export{a as n,o as r,s as t};
@@ -1 +1 @@
1
- import e from"node:process";import t from"picocolors";function n(e,t){let n=[...e.global?[`global`]:[],...t.filter(t=>e.byLocale[t])];if(n.length!==0)return`${n.length===1?`Styleguide`:`Styleguides`} loaded (${n.join(`, `)})`}function r(e,t={month:`short`,day:`numeric`}){return new Date(e).toLocaleDateString(`en-US`,t)}function i(e){if(e!==void 0)return(Array.isArray(e)?e:[e]).flatMap(e=>String(e).split(`,`).map(e=>e.trim()).filter(e=>e.length>0))}function a(n,r){e.stderr.write(`${n} ${t.dim(r)}\n`)}export{n as i,i as n,r,a as t};
1
+ import e from"node:process";import t from"picocolors";function n(e,t){let n=[...e.global?[`global`]:[],...t.filter(t=>e.byLocale[t])];if(n.length!==0)return`${n.length===1?`Styleguide`:`Styleguides`} loaded (${n.join(`, `)})`}function r(e,t={month:`short`,day:`numeric`}){return new Date(e).toLocaleDateString(`en-US`,t)}function i(n,r){e.stderr.write(`${n} ${t.dim(r)}\n`)}export{r as n,n as r,i as t};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eloqnt/cli",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "CLI for eloqnt/studio",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,7 +30,7 @@
30
30
  "citty": "^0.1.6",
31
31
  "open": "^11.0.0",
32
32
  "picocolors": "^1.1.1",
33
- "@eloqnt/sdk": "0.5.1"
33
+ "@eloqnt/sdk": "0.5.2"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "^25.9.1"
@@ -1,2 +0,0 @@
1
- import{t as e}from"./bin/eloqnt.mjs";import{t}from"./withErrorFormatting-CnMLjXSn.mjs";import{a as n,i as r,n as i,t as a}from"./urls-BrJoRsYB.mjs";import{t as o}from"./createSpinner-BBkrpcrh.mjs";import s from"node:process";import{defineCommand as c}from"citty";import l from"picocolors";import{EloqntSdkError as u,getAuthHeaders as d}from"@eloqnt/sdk/_internal";import{hostname as f}from"node:os";import{setTimeout as p}from"node:timers/promises";import{outro as m}from"@clack/prompts";import h from"open";function g(e){h(e).catch(()=>{})}const _=`eloqnt-cli`,v=`eloqnt-cli/${e} (${f()}; ${s.platform} ${s.arch}; node ${s.version})`;var y=c({meta:{name:`login`,description:`Authenticates the CLI by storing an auth token locally.`},run:()=>t(async()=>{let e=a(),t=await r();t&&await fetch(`${e}/revoke-session`,{method:`POST`,headers:{authorization:`Bearer ${t}`,"content-type":`application/json`,"user-agent":v},body:JSON.stringify({token:t})}).catch(()=>{});let c=await fetch(`${e}/device/code`,{method:`POST`,headers:{"content-type":`application/json`,"user-agent":v},body:JSON.stringify({client_id:_})});if(!c.ok)throw new u(`ENGINE_UNREACHABLE`,`Couldn't start the login flow`,{details:`The auth server responded with ${c.status}.`,hint:`Check your connection and run eloqnt login again.`});let d=await c.json();s.stderr.write(`\n${l.cyan(`Log in to eloqnt studio`)}\n`),s.stderr.write(l.dim(`${d.verification_uri_complete}\n\n`)),g(d.verification_uri_complete);let f=s.stderr.isTTY?o():void 0;f?f.start(`Waiting for approval in the browser`):s.stderr.write(l.dim(`Waiting for approval in the browser …
2
- `));let p=await x(e,d);if(!p.access_token)throw f?.stop(l.dim(`Login cancelled`)),new u(`NOT_AUTHENTICATED`,p.error_description??`Login failed`,{hint:`Run eloqnt login to try again.`});await n(p.access_token),f?(f.stop(l.dim(`Approved in the browser`)),m(l.green(`Logged in`))):s.stdout.write(`${l.green(`Logged in`)}\n`),await b(p.access_token)&&s.stderr.write(`\n${l.cyan(`→ Choose a plan at ${i()}/plans`)}\n`)})});async function b(e){try{let t=await fetch(new URL(`/api/engine/me`,i()),{headers:d(e)});if(!t.ok)return!1;let n=await t.json();return Array.isArray(n.plans)&&n.plans.length===0}catch{return!1}}async function x(e,t){let n=Date.now()+t.expires_in*1e3,r=t.interval;for(;Date.now()<n;){await p(r*1e3);let n=await(await fetch(`${e}/device/token`,{method:`POST`,headers:{"content-type":`application/json`,"user-agent":v},body:JSON.stringify({grant_type:`urn:ietf:params:oauth:grant-type:device_code`,device_code:t.device_code,client_id:_})})).json();if(n.access_token)return n;if(n.error!==`authorization_pending`){if(n.error===`slow_down`){r+=5;continue}return n}}return{error:`expired_token`,error_description:`The login request expired`}}export{y as default};
@@ -1 +0,0 @@
1
- import{defineCommand as e}from"citty";var t=e({meta:{name:`review`,description:"Review source strings before translation and fix issues in place (defaults to the `source` subcommand)."},setup({rawArgs:e}){e.find(e=>!e.startsWith(`-`))!==`source`&&e.unshift(`source`)},subCommands:{source:()=>import(`./source-HfmXUoKK.mjs`).then(e=>e.default)}});export{t as default};
@@ -1,10 +0,0 @@
1
- import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{a as t,i as n,n as r,o as i,r as a,s as o}from"./stringWidth-Ba8f3rhS.mjs";import{t as s}from"./resolvePaths-Bc7dGH8a.mjs";import{i as c,n as l}from"./urls-BrJoRsYB.mjs";import{t as u}from"./createSpinner-BBkrpcrh.mjs";import{i as d,n as f,r as p,t as m}from"./writeStep-f1jYLsuV.mjs";import{reviewSource as h}from"@eloqnt/sdk";import g from"node:process";import{basename as _,dirname as v,relative as y}from"node:path";import b from"picocolors";import{loadStyleguide as x}from"@eloqnt/sdk/_internal";var S=e({meta:{name:`source`,description:"Review source strings for errors and fix them in place (defaults to strings with missing translations). When using `srcPath`, changes will sync to your source code as well.",requiresLogin:!0},args:{id:{type:`string`,description:`(Re-)review these message ids (comma-separated)`}},async execute({config:e,rootDir:t,args:n}){let{messages:r,srcPath:i}=e,a=s(r.path,t),o=i?s(i,t):void 0,p=await x({cwd:t}),_=d(p,[r.sourceLocale]),v=e.model?`eloqnt/engine (${typeof e.model==`string`?e.model:e.model.modelId})`:`eloqnt/engine (hosted)`,S=g.stderr.isTTY&&!n.json,C;function w(e){if(!n.json){if(e.phase===`context-enrichment`){e.state===`started`?(g.stderr.write(`
2
- `),S?(C=u({withGuide:!1}),C.start(`Context enrichment running`)):g.stderr.write(b.dim(`Context enrichment running …
3
- `))):e.state===`completed`?(C?.clear(),C=void 0,m(b.green(`✔`),`Context enrichment complete`)):(g.stderr.write(`
4
- `),m(b.dim(`–`),"Skipped source code analysis due to absent `srcPath`"));return}e.state===`started`?(_?m(b.green(`✔`),_):m(b.dim(`–`),`No styleguides found`),S?(C=u({withGuide:!1}),C.start(`Reviewing source strings via ${v}`)):g.stderr.write(b.dim(`Reviewing source strings via ${v} …\n`))):(C?.clear(),C=void 0,m(b.green(`✔`),`Reviewed source strings via ${v}`))}}let T;try{T=await h({messagesPath:a,sourceLocale:r.sourceLocale,format:r.format,locales:r.locales,cwd:t,engineUrl:l(),languageModel:e.model,authToken:await c(),styleguide:p,ids:f(n.id),srcPath:o,onProgress:w})}catch(e){throw C?.clear(),e}let E=g.cwd();return{result:{...T,files:T.files.map(e=>({...e,file:y(E,e.file)})),findings:T.findings.map(e=>({...e,file:e.file?y(E,e.file):void 0,sourceFiles:e.sourceFiles.map(e=>y(E,e))}))}}},render:({result:e})=>C(e),ok:({result:e})=>e.findings.every(e=>e.status===`fixed`),json:({result:e})=>e});function C(e,t=n()){let{findings:r,reviewed:i,missingTranslations:a,quota:o}=e,s=[],c=new Map;for(let t of r){let n=t.file??e.sourceLocale,r=c.get(n)??[];r.push(t),c.set(n,r)}for(let[e,n]of c){let r=[`${b.cyan(e)} ${b.dim(`(source locale)`)}`];for(let e of n)r.push(b.dim(`│`)),r.push(...w(e,t));s.push(r.join(`
5
- `))}let l=O(r,e.sourceLocale),u=Object.groupBy(e.files,e=>v(e.file)),d=Object.entries(u).map(([e,t=[]])=>{let n=Math.max(0,...t.map(e=>_(e.file).length)),r=t.map(e=>{let t=_(e.file).padEnd(n),r=l.get(e.file);return` ${t} ${k(e.reviewed,r?.fixed??0,r?.reported??0,o!==void 0)}`});return[b.dim(`${e}/`),...r].join(`
6
- `)}).join(`
7
-
8
- `);s.push(d),o&&s.push(b.yellow(`! Monthly included usage exhausted, reviewed as much as possible. Resets ${p(o.resetsAt)}`));let f=i===0?b.dim(`→ Add new strings for the source locale to review them before translation`):a>0?b.dim("→ Run `eloqnt translate` to translate"):void 0;return`\n${s.join(`
9
-
10
- `)}${f?`\n\n${f}`:``}\n`}function w(e,t){let n=t-3-2,s=e.newId??e.id,c=T(e.id,e.before,n),l=[i(`${b.red(`-`)} ${b.dim(c)}`)],u;if(e.status===`fixed`){let t=T(s,e.after,n),r=E(e.via,e.sourceFiles,n-a(t));u=r?T(s,e.after,n-a(r)):t,l.push(i(`${b.green(`+`)} ${u}${r?b.dim(r):``}`))}else{let t=e.sourceFiles[0],o;if(t){let e=[t,D(t),_(t)].map(e=>` (apply manually in ${e})`);o=r(n,e)||e.at(-1)}else o=` (apply manually)`;u=T(s,e.after,n-a(o)),l.push(i(`${b.yellow(`!`)} ${u}${b.dim(o)}`))}let d=Math.min(a(u)+2,t-3);return l.push(i(b.yellow(`─┬${`─`.repeat(Math.max(0,d-2))}`))),l.push(i(` ${b.yellow(`╰─`)} ${o(e.note)}`)),l}function T(e,n,r){let i=a(`"${e}": ""`);return`"${e}": "${t(o(n),Math.max(0,r-i))}"`}function E(e,t,n){if(e!==`code`||t.length===0)return``;let i=t.length>1?[`(${t.length} call sites)`]:[`(${t[0]})`,`(${D(t[0])})`,`(${_(t[0])})`],a=r(n-1,i);return a?` ${a}`:``}function D(e){let t=e.split(`/`);return t.length<=2?e:`${t[0]}/…/${t.at(-1)}`}function O(e,t){let n=new Map;for(let r of e){let e=r.file??t,i=n.get(e)??{fixed:0,reported:0};i[r.status===`fixed`?`fixed`:`reported`]++,n.set(e,i)}return n}function k(e,t,n,r){if(e===0)return b.dim(`Nothing to review`);let i=[`${e} reviewed`];t===0&&n===0&&!r&&i.push(`no fixes needed`),t>0&&i.push(`${t} fixed`),n>0&&i.push(`${n} ${n===1?`needs`:`need`} a manual edit`);let a=i.join(`, `);return n>0?b.yellow(a):r?b.dim(a):b.green(a)}export{S as default};
@@ -1,8 +0,0 @@
1
- import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{t}from"./resolvePaths-Bc7dGH8a.mjs";import{i as n,n as r}from"./urls-BrJoRsYB.mjs";import{t as i}from"./createSpinner-BBkrpcrh.mjs";import{i as a,n as o,r as s,t as c}from"./writeStep-f1jYLsuV.mjs";import{translate as l}from"@eloqnt/sdk";import u from"node:process";import{basename as d,dirname as f,relative as p}from"node:path";import m from"picocolors";import{loadStyleguide as h}from"@eloqnt/sdk/_internal";var g=e({meta:{name:`translate`,description:`Translate strings to target locales (defaults to missing ones).`,requiresLogin:!0},args:{id:{type:`string`,description:`(Re-)translate these message ids (comma-separated)`},locale:{type:`string`,description:`Restrict to these target locales (comma-separated)`}},async execute({config:e,rootDir:s,args:d}){let{messages:f,srcPath:g}=e,_=t(f.path,s),v=g?t(g,s):void 0,y=await h({cwd:s}),b=e.model?`eloqnt/engine (${typeof e.model==`string`?e.model:e.model.modelId})`:`eloqnt/engine (hosted)`,x=o(d.locale),S=x??(Array.isArray(f.locales)?f.locales.filter(e=>e!==f.sourceLocale):void 0),C=`${S?.length?`${S.join(`, `)} `:``}via ${b}`,w=a(y,S??Object.keys(y.byLocale)),T=u.stderr.isTTY&&!d.json,E;function D(e){if(!d.json){if(e.phase===`context-enrichment`){e.state===`started`?(u.stderr.write(`
2
- `),T?(E=i({withGuide:!1}),E.start(`Context enrichment running`)):u.stderr.write(m.dim(`Context enrichment running …
3
- `))):e.state===`completed`?(E?.clear(),E=void 0,c(m.green(`✔`),`Context enrichment complete`)):(u.stderr.write(`
4
- `),c(m.dim(`–`),"Skipped context enrichment due to absent `srcPath`"));return}if(e.phase===`translate`){e.state===`started`?(w?c(m.green(`✔`),w):c(m.dim(`–`),`No styleguides found`),T?(E=i({withGuide:!1}),E.start(`Translating ${C}`)):u.stderr.write(m.dim(`Translating ${C} …\n`))):(E?.clear(),E=void 0,c(m.green(`✔`),`Translated ${C}`));return}e.state===`started`?T?(E=i({withGuide:!1}),E.start(`Post-translation checks running`)):u.stderr.write(m.dim(`Post-translation checks running …
5
- `)):(E?.clear(),E=void 0,c(m.green(`✔`),`Post-translation checks done`))}}let O;try{O=await l({messagesPath:_,sourceLocale:f.sourceLocale,format:f.format,locales:f.locales,cwd:s,engineUrl:r(),languageModel:e.model,authToken:await n(),styleguide:y,ids:o(d.id),onlyLocales:x,srcPath:v,onProgress:D})}catch(e){throw E?.clear(),e}let k=u.cwd(),A=O.targets.flatMap(e=>e.files.map(e=>({file:p(k,e.file),count:e.translated.length})));return{result:O,rows:A,complete:O.complete,noStyleguides:!w}},render({result:e,rows:t,complete:n,noStyleguides:i}){let a=Object.groupBy(t,e=>f(e.file));return`\n${Object.entries(a).map(([e,t=[]])=>{let n=Math.max(0,...t.map(e=>d(e.file).length)),r=t.map(e=>` ${d(e.file).padEnd(n)} ${e.count===0?m.dim(`Nothing to translate`):m.green(`${e.count} translated`)}`);return[m.dim(`${e}/`),...r].join(`
6
- `)}).join(`
7
-
8
- `)}\n\n${n?m.green(`✔ Project fully translated`):e.quota?m.yellow(`! Monthly included usage exhausted, translated as much as possible. Resets ${s(e.quota.resetsAt)}`):m.dim(`✗ Partially translated, run eloqnt lint to see what's left`)}${i?`\n\n${m.dim(`→ Add a styleguide to improve your translation quality`)}\n${m.dim(` ${r()}/docs#styleguides`)}`:``}`},json:({result:e})=>e});export{g as default};