@eloqnt/cli 0.6.13 → 0.6.14
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 +9 -0
- package/README.md +6 -6
- package/dist/bin/eloqnt.mjs +1 -1
- package/dist/{lint-SaT4fq-x.mjs → lint-Wu02Ge85.mjs} +1 -1
- package/dist/login-BpNU31ln.mjs +2 -0
- package/dist/{logout-BCLs2gQ-.mjs → logout-DSYs8Q7s.mjs} +1 -1
- package/dist/{review-XgxtI6Gm.mjs → review-Jq5qfN92.mjs} +1 -1
- package/dist/{source-WF-vkuKU.mjs → source-CqF_hqe4.mjs} +1 -1
- package/dist/translate-CxX0Zpzp.mjs +8 -0
- package/dist/{urls-F6fkAWuj.mjs → urls-C1kSCAFx.mjs} +1 -1
- package/dist/whoami-CL3FnZLb.mjs +2 -0
- package/package.json +4 -4
- package/dist/login-W60UmKbD.mjs +0 -2
- package/dist/translate-DkSTqtOF.mjs +0 -8
- package/dist/whoami-bo3bXioJ.mjs +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @eloqnt/cli
|
|
2
2
|
|
|
3
|
+
## 0.6.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4f59c9f: `studio.eloqnt.dev` was renamed to `engine.eloqnt.dev`, with CLI docs remaining at `cli.eloqnt.dev`.
|
|
8
|
+
- Updated dependencies [4f59c9f]
|
|
9
|
+
- Updated dependencies [e26637a]
|
|
10
|
+
- @eloqnt/sdk@0.6.13
|
|
11
|
+
|
|
3
12
|
## 0.6.13
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
An AI-based toolchain that helps you ship high-quality translations.
|
|
4
4
|
|
|
5
|
-
[Documentation](https://
|
|
5
|
+
[Documentation](https://cli.eloqnt.dev/docs) · [Configuration](https://cli.eloqnt.dev/docs/configuration)
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -63,7 +63,7 @@ export default defineConfig({
|
|
|
63
63
|
});
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
All paths are relative to your project root. For more sophisticated setups like monorepos or when not using `next-intl`, see the [configuration docs](https://
|
|
66
|
+
All paths are relative to your project root. For more sophisticated setups like monorepos or when not using `next-intl`, see the [configuration docs](https://cli.eloqnt.dev/docs/configuration).
|
|
67
67
|
|
|
68
68
|
### 3. Lint your source code and messages
|
|
69
69
|
|
|
@@ -71,11 +71,11 @@ All paths are relative to your project root. For more sophisticated setups like
|
|
|
71
71
|
npx eloqnt lint
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
See [`eloqnt lint`](https://
|
|
74
|
+
See [`eloqnt lint`](https://cli.eloqnt.dev/docs/cli/lint) for details.
|
|
75
75
|
|
|
76
76
|
## Start translating
|
|
77
77
|
|
|
78
|
-
Once linting works, you can optionally use [`eloqnt translate`](https://
|
|
78
|
+
Once linting works, you can optionally use [`eloqnt translate`](https://cli.eloqnt.dev/docs/cli/translate) to fill in any missing translations:
|
|
79
79
|
|
|
80
80
|
```console
|
|
81
81
|
$ eloqnt translate
|
|
@@ -92,6 +92,6 @@ messages/
|
|
|
92
92
|
✔ Project fully translated
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
-
Source strings are enriched with context from their call sites, [styleguides](https://
|
|
95
|
+
Source strings are enriched with context from their call sites, [styleguides](https://cli.eloqnt.dev/docs/styleguides) steer tone and terminology, and post-translation checks retry anything that comes back wrong.
|
|
96
96
|
|
|
97
|
-
To get started with translating, [log into eloqnt/
|
|
97
|
+
To get started with translating, [log into eloqnt/engine](https://engine.eloqnt.dev) first.
|
package/dist/bin/eloqnt.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
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.6.
|
|
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.6.14`;try{e.loadEnvFile()}catch{}const o=t({meta:{name:`eloqnt`,version:a,description:`AI-powered translations for developers`},subCommands:{lint:d(()=>import(`../lint-Wu02Ge85.mjs`)),review:d(()=>import(`../review-Jq5qfN92.mjs`)),translate:d(()=>import(`../translate-CxX0Zpzp.mjs`)),crowdin:d(()=>import(`../crowdin-DdfREp0-.mjs`)),login:d(()=>import(`../login-BpNU31ln.mjs`)),logout:d(()=>import(`../logout-DSYs8Q7s.mjs`)),whoami:d(()=>import(`../whoami-CL3FnZLb.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://cli.eloqnt.dev/docs`:`https://cli.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};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{n as t,t as n}from"./report-CEfrIjER.mjs";import{a as r,i,o as a,r as o,t as s}from"./stringWidth-DvyI3S_b.mjs";import{lint as c}from"@eloqnt/sdk";import l from"node:process";import u from"picocolors";import{relative as d,resolve as f}from"node:path";var p=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,o=await c({messagesPath:a(r.path,t),sourceLocale:r.sourceLocale,format:r.format,locales:r.locales,codes:r.codes,srcPath:i?a(i,t):void 0,rules:e.lint?.rules,overrides:e.lint?.overrides,rootDir:t}),s=l.cwd();return{issues:o.map(e=>{let t=e;if(t.location&&(t={...t,location:{...t.location,file:d(s,t.location.file)}}),t.rule===`undefined-key`&&t.sourceReferences?.length){let e=t.sourceReferences.map(e=>({...e,path:d(s,e.path)})),n=e[0].line?`${e[0].path}:${e[0].line}`:e[0].path,i=e.length>1?` (+${e.length-1} more)`:``;t={...t,sourceReferences:e,message:`Used in ${n}${i} but not defined for ${r.sourceLocale}`}}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.map(e=>({...e,docsUrl:m(e.rule)}))});function m(e){return`https://
|
|
1
|
+
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{n as t,t as n}from"./report-CEfrIjER.mjs";import{a as r,i,o as a,r as o,t as s}from"./stringWidth-DvyI3S_b.mjs";import{lint as c}from"@eloqnt/sdk";import l from"node:process";import u from"picocolors";import{relative as d,resolve as f}from"node:path";var p=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,o=await c({messagesPath:a(r.path,t),sourceLocale:r.sourceLocale,format:r.format,locales:r.locales,codes:r.codes,srcPath:i?a(i,t):void 0,rules:e.lint?.rules,overrides:e.lint?.overrides,rootDir:t}),s=l.cwd();return{issues:o.map(e=>{let t=e;if(t.location&&(t={...t,location:{...t.location,file:d(s,t.location.file)}}),t.rule===`undefined-key`&&t.sourceReferences?.length){let e=t.sourceReferences.map(e=>({...e,path:d(s,e.path)})),n=e[0].line?`${e[0].path}:${e[0].line}`:e[0].path,i=e.length>1?` (+${e.length-1} more)`:``;t={...t,sourceReferences:e,message:`Used in ${n}${i} but not defined for ${r.sourceLocale}`}}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.map(e=>({...e,docsUrl:m(e.rule)}))});function m(e){return`https://cli.eloqnt.dev/docs/lint-rules/${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
2
|
`),s=e.filter(e=>e.rule===`missing-translation`).length,c=[e.some(e=>e.rule!==`missing-translation`)&&u.dim(`→ Rule details: ${m(`<rule>`)}`),s>0&&u.dim(`→ Run \`eloqnt translate\` to fill in ${s} missing ${s===1?`translation`:`translations`}`)].filter(Boolean).join(`
|
|
3
3
|
`);return`\n${[...r,o,c].filter(Boolean).join(`
|
|
4
4
|
|
|
@@ -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,n as i,o as a,r as o}from"./urls-C1kSCAFx.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=i(),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/engine`)}\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 canceled`)),new u(`NOT_AUTHENTICATED`,m.error_description??`Login failed`,{hint:`Run eloqnt login to try again.`});await a(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 ${o()}/plans`)}\n`)})});async function b(e){try{let t=await fetch(new URL(`/api/engine/me`,o()),{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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./withErrorFormatting-CnMLjXSn.mjs";import{
|
|
1
|
+
import{t as e}from"./withErrorFormatting-CnMLjXSn.mjs";import{a as t,i as n,n as r}from"./urls-C1kSCAFx.mjs";import i from"node:process";import{defineCommand as a}from"citty";import o from"picocolors";var s=a({meta:{name:`logout`,description:`Logs out of eloqnt/engine by removing a local auth token.`},run:()=>e(async()=>{let e=await t();e&&await fetch(`${r()}/revoke-session`,{method:`POST`,headers:{authorization:`Bearer ${e}`,"content-type":`application/json`},body:JSON.stringify({token:e})}).catch(()=>{});let a=await n();i.stdout.write(`${a||e?o.green(`Logged out`):o.dim(`Not logged in`)}\n`)})});export{s as default};
|
|
@@ -1 +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-
|
|
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-CqF_hqe4.mjs`).then(e=>e.default)}});export{t as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{t}from"./parseListArg-p5H1s5JC.mjs";import{t as n}from"./createSpinner-BBkrpcrh.mjs";import{n as r,t as i}from"./report-CEfrIjER.mjs";import{a,i as o,n as s,o as c,r as l}from"./stringWidth-DvyI3S_b.mjs";import{
|
|
1
|
+
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{t}from"./parseListArg-p5H1s5JC.mjs";import{t as n}from"./createSpinner-BBkrpcrh.mjs";import{n as r,t as i}from"./report-CEfrIjER.mjs";import{a,i as o,n as s,o as c,r as l}from"./stringWidth-DvyI3S_b.mjs";import{a as u,r as d}from"./urls-C1kSCAFx.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=c(a.path,r),l=o?c(o,r):void 0,f=await x({rootDir:r,path:e.styleguides}),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
2
|
`),S?(C=n({withGuide:!1}),C.start(`Context enrichment running`)):g.stderr.write(_.dim(`Context enrichment running …
|
|
3
3
|
`))):e.state===`completed`?(C?.clear(),C=void 0,m(_.green(`✔`),`Context enrichment complete`)):(g.stderr.write(`
|
|
4
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,codes:a.codes,rootDir:r,engineUrl:d(),languageModel:e.model,authToken:await u(),styleguide:f,ids:t(i.id),srcPath:l,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=o()){let{findings:n,reviewed:r,missingTranslations:i,quota:a}=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(`
|
|
@@ -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{a as r,i,n as a,o}from"./stringWidth-DvyI3S_b.mjs";import{a as s,r as c,t as l}from"./urls-C1kSCAFx.mjs";import{n as u,r as d,t as f}from"./writeStep-CerCYWGN.mjs";import{translate as p}from"@eloqnt/sdk";import m from"node:process";import h from"picocolors";import{basename as g,dirname as _,relative as v}from"node:path";import{loadStyleguide as y}from"@eloqnt/sdk/_internal";var b=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:l,args:u}){let{messages:g,srcPath:_}=e,b=o(g.path,l),x=_?o(_,l):void 0,S=await y({rootDir:l,path:e.styleguides}),C=e.model?`eloqnt/engine (${typeof e.model==`string`?e.model:e.model.modelId})`:`eloqnt/engine (hosted)`,w=t(u.locale),T=w??(Array.isArray(g.locales)?g.locales.filter(e=>e!==g.sourceLocale):void 0),E=`${T?.length?`${T.join(`, `)} `:``}via ${C}`,D=d(S,T??Object.keys(S.byLocale)),O=m.stderr.isTTY&&!u.json,k;function A(e,t,n){let o=`(${t}/${n})`,s=i()-4,c=`Translating ${e}% done`;return a(s,[`Translating ${E} · ${e}% done ${o}`,`Translating ${E} · ${e}% done`,`Translating ${e}% done ${o}`,c])||r(c,s)}let j=0;function M(e){if(!u.json){if(e.phase===`context-enrichment`){e.state===`started`?(m.stderr.write(`
|
|
2
|
+
`),O?(k=n({withGuide:!1}),k.start(`Context enrichment running`)):m.stderr.write(h.dim(`Context enrichment running …
|
|
3
|
+
`))):e.state===`completed`?(k?.clear(),k=void 0,f(h.green(`✔`),`Context enrichment complete`)):(m.stderr.write(`
|
|
4
|
+
`),f(h.dim(`–`),"Skipped context enrichment (no `srcPath` set)"));return}if(e.phase===`translate`){if(e.state===`started`)D?f(h.green(`✔`),D):f(h.dim(`–`),`No styleguides found`),O?(k=n({withGuide:!1}),k.start(`Translating ${E}`)):m.stderr.write(h.dim(`Translating ${E} …\n`));else if(e.state===`progress`){let t=Math.floor(e.completedStrings/e.totalStrings*100);if(O)k?.message(A(t,e.completedStrings,e.totalStrings));else{let n=Math.floor(t/25);n>j&&n<4&&(j=n,m.stderr.write(h.dim(`Translating ${t}% done (${e.completedStrings}/${e.totalStrings}) …\n`)))}}else e.state===`stopped`?(k?.clear(),k=void 0):(k?.clear(),k=void 0,f(h.green(`✔`),`Translated ${E}`));return}e.state===`started`?O?(k=n({withGuide:!1}),k.start(`Post-translation checks running`)):m.stderr.write(h.dim(`Post-translation checks running …
|
|
5
|
+
`)):(k?.clear(),k=void 0,f(h.green(`✔`),`Post-translation checks done`))}}let N;try{N=await p({messagesPath:b,sourceLocale:g.sourceLocale,format:g.format,locales:g.locales,codes:g.codes,rootDir:l,engineUrl:c(),languageModel:e.model,authToken:await s(),styleguide:S,ids:t(u.id),onlyLocales:w,srcPath:x,onProgress:M})}catch(e){throw k?.clear(),e}let P=m.cwd(),F=N.targets.flatMap(e=>e.files.map(t=>({file:v(P,t.file),locale:e.locale,count:t.translated.length})));return{result:N,rows:F,complete:N.complete,noStyleguides:!D}},render({result:e,rows:t,complete:n,noStyleguides:r}){let i=Object.groupBy(t,e=>_(e.file));return`\n${Object.entries(i).map(([e,t=[]])=>{let n=Math.max(0,...t.map(e=>g(e.file).length)),r=t.map(e=>g(e.file)),i=r.length!==new Set(r).size,a=Math.max(0,...t.map(e=>e.locale.length)),o=t.map(e=>` ${g(e.file).padEnd(n)} ${i?`${h.dim(e.locale.padEnd(a))} `:``}${e.count===0?h.dim(`Nothing to translate`):h.green(`${e.count} translated`)}`);return[h.dim(`${e}/`),...o].join(`
|
|
6
|
+
`)}).join(`
|
|
7
|
+
|
|
8
|
+
`)}\n\n${n?h.green(`✔ Project fully translated`):e.quota?h.yellow(`! Monthly included usage exhausted, translated as much as possible. Resets ${u(e.quota.resetsAt)}`):h.dim(`✗ Partially translated, run eloqnt lint to see what's left`)}${r?`\n\n${h.dim(`→ Add a styleguide to improve your translation quality`)}\n${h.dim(` ${l}/docs#styleguides`)}`:``}`},json:({result:e})=>e});export{b as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"node:process";import{dirname as t,join as n}from"node:path";import{homedir as r}from"node:os";import{mkdir as i,readFile as a,rm as o,writeFile as s}from"node:fs/promises";function c(){let t=e.env.XDG_CONFIG_HOME??n(r(),`.config`);return n(t,`eloqnt`,`credentials.json`)}async function l(){if(e.env.ELOQNT_TOKEN)return e.env.ELOQNT_TOKEN;try{let e=await a(c(),`utf8`),t=JSON.parse(e);return typeof t.token==`string`?t.token:void 0}catch{return}}async function u(e){let n=c();return await i(t(n),{recursive:!0}),await s(n,`${JSON.stringify({token:e},null,2)}\n`,{mode:384}),n}async function d(){try{return await o(c()),!0}catch{return!1}}function f(){return e.env.ELOQNT_STUDIO_URL??`https://
|
|
1
|
+
import e from"node:process";import{dirname as t,join as n}from"node:path";import{homedir as r}from"node:os";import{mkdir as i,readFile as a,rm as o,writeFile as s}from"node:fs/promises";function c(){let t=e.env.XDG_CONFIG_HOME??n(r(),`.config`);return n(t,`eloqnt`,`credentials.json`)}async function l(){if(e.env.ELOQNT_TOKEN)return e.env.ELOQNT_TOKEN;try{let e=await a(c(),`utf8`),t=JSON.parse(e);return typeof t.token==`string`?t.token:void 0}catch{return}}async function u(e){let n=c();return await i(t(n),{recursive:!0}),await s(n,`${JSON.stringify({token:e},null,2)}\n`,{mode:384}),n}async function d(){try{return await o(c()),!0}catch{return!1}}function f(){return e.env.ELOQNT_ENGINE_URL??e.env.ELOQNT_STUDIO_URL??`https://engine.eloqnt.dev`}function p(){return`${f()}/api/auth`}const m=`https://cli.eloqnt.dev`;export{l as a,d as i,p as n,u as o,f as r,m as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{a as t,r as n}from"./urls-C1kSCAFx.mjs";import r from"picocolors";import{EloqntSdkError as i,MeResponseSchema as a,getAuthHeaders as o}from"@eloqnt/sdk/_internal";function s(e){return r.dim(e.padEnd(12))}var c=e({meta:{name:`whoami`,description:`Shows the logged-in user account.`},requiresConfig:!1,async execute(){let e=await t();if(!e)throw new i(`NOT_AUTHENTICATED`,`Not logged in`,{hint:`Run eloqnt login to authenticate.`});let r=await fetch(new URL(`/api/engine/me`,n()),{headers:o(e)});if(r.status===401)throw new i(`NOT_AUTHENTICATED`,`Your session has expired`,{hint:`Run eloqnt login to sign in again.`});if(!r.ok)throw new i(`ENGINE_ERROR`,`Sorry, we couldn't load your account`,{details:`The studio API responded with ${r.status}.`,hint:`This is on our end. Try again in a few minutes.`});let s=a.safeParse(await r.json());if(!s.success)throw new i(`ENGINE_ERROR`,`Sorry, we couldn't load your account`,{details:`The studio API returned an unexpected shape.`,hint:`This is on our end. Try again in a few minutes.`});let{user:c,plans:l,hosted:u}=s.data;return{email:c.email,plans:l,hosted:u}},render:({email:e,plans:t,hosted:i})=>{let a=[`${s(`Email:`)}${e}`,`${s(`Plan:`)}${l(t,i)}`];return i&&a.push(`${s(`Quota used:`)}${u(i)}`),t.length===0&&a.push(``,r.cyan(`→ Choose a plan at ${n()}/plans`)),a.join(`
|
|
2
|
+
`)},json:e=>e});function l(e,t){if(e.length===0)return r.yellow(`none`);let n=e.map(e=>e===`hosted`?`Hosted model`:`Bring your own model`),i=t?.status===`trialing`?r.dim(` (trial, includes 1/4 of monthly usage)`):``;return r.green(n.join(` + `))+i}function u(e){let{usedPercent:t,resetsAt:n}=e,i=`${t}%`;return`${t>=100?r.red(i):t>=80?r.yellow(i):r.green(i)} (resets ${new Intl.DateTimeFormat(`en-US`,{month:`short`,day:`numeric`}).format(new Date(n))})`}export{c as default};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eloqnt/cli",
|
|
3
|
-
"version": "0.6.
|
|
4
|
-
"description": "
|
|
5
|
-
"homepage": "https://
|
|
3
|
+
"version": "0.6.14",
|
|
4
|
+
"description": "An AI-based toolchain that helps you ship high-quality translations.",
|
|
5
|
+
"homepage": "https://cli.eloqnt.dev",
|
|
6
6
|
"bin": {
|
|
7
7
|
"eloqnt": "./dist/bin/eloqnt.mjs"
|
|
8
8
|
},
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"citty": "^0.1.6",
|
|
27
27
|
"open": "^11.0.0",
|
|
28
28
|
"picocolors": "^1.1.1",
|
|
29
|
-
"@eloqnt/sdk": "0.6.
|
|
29
|
+
"@eloqnt/sdk": "0.6.13"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/node": "^25.9.5"
|
package/dist/login-W60UmKbD.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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-F6fkAWuj.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 canceled`)),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};
|
|
@@ -1,8 +0,0 @@
|
|
|
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}from"./stringWidth-DvyI3S_b.mjs";import{i as s,n as c}from"./urls-F6fkAWuj.mjs";import{n as l,r as u,t as d}from"./writeStep-CerCYWGN.mjs";import{translate as f}from"@eloqnt/sdk";import p from"node:process";import m from"picocolors";import{basename as h,dirname as g,relative as _}from"node:path";import{loadStyleguide as v}from"@eloqnt/sdk/_internal";var y=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:l,args:h}){let{messages:g,srcPath:y}=e,b=o(g.path,l),x=y?o(y,l):void 0,S=await v({rootDir:l,path:e.styleguides}),C=e.model?`eloqnt/engine (${typeof e.model==`string`?e.model:e.model.modelId})`:`eloqnt/engine (hosted)`,w=t(h.locale),T=w??(Array.isArray(g.locales)?g.locales.filter(e=>e!==g.sourceLocale):void 0),E=`${T?.length?`${T.join(`, `)} `:``}via ${C}`,D=u(S,T??Object.keys(S.byLocale)),O=p.stderr.isTTY&&!h.json,k;function A(e,t,n){let o=`(${t}/${n})`,s=i()-4,c=`Translating ${e}% done`;return a(s,[`Translating ${E} · ${e}% done ${o}`,`Translating ${E} · ${e}% done`,`Translating ${e}% done ${o}`,c])||r(c,s)}let j=0;function M(e){if(!h.json){if(e.phase===`context-enrichment`){e.state===`started`?(p.stderr.write(`
|
|
2
|
-
`),O?(k=n({withGuide:!1}),k.start(`Context enrichment running`)):p.stderr.write(m.dim(`Context enrichment running …
|
|
3
|
-
`))):e.state===`completed`?(k?.clear(),k=void 0,d(m.green(`✔`),`Context enrichment complete`)):(p.stderr.write(`
|
|
4
|
-
`),d(m.dim(`–`),"Skipped context enrichment (no `srcPath` set)"));return}if(e.phase===`translate`){if(e.state===`started`)D?d(m.green(`✔`),D):d(m.dim(`–`),`No styleguides found`),O?(k=n({withGuide:!1}),k.start(`Translating ${E}`)):p.stderr.write(m.dim(`Translating ${E} …\n`));else if(e.state===`progress`){let t=Math.floor(e.completedStrings/e.totalStrings*100);if(O)k?.message(A(t,e.completedStrings,e.totalStrings));else{let n=Math.floor(t/25);n>j&&n<4&&(j=n,p.stderr.write(m.dim(`Translating ${t}% done (${e.completedStrings}/${e.totalStrings}) …\n`)))}}else e.state===`stopped`?(k?.clear(),k=void 0):(k?.clear(),k=void 0,d(m.green(`✔`),`Translated ${E}`));return}e.state===`started`?O?(k=n({withGuide:!1}),k.start(`Post-translation checks running`)):p.stderr.write(m.dim(`Post-translation checks running …
|
|
5
|
-
`)):(k?.clear(),k=void 0,d(m.green(`✔`),`Post-translation checks done`))}}let N;try{N=await f({messagesPath:b,sourceLocale:g.sourceLocale,format:g.format,locales:g.locales,codes:g.codes,rootDir:l,engineUrl:c(),languageModel:e.model,authToken:await s(),styleguide:S,ids:t(h.id),onlyLocales:w,srcPath:x,onProgress:M})}catch(e){throw k?.clear(),e}let P=p.cwd(),F=N.targets.flatMap(e=>e.files.map(t=>({file:_(P,t.file),locale:e.locale,count:t.translated.length})));return{result:N,rows:F,complete:N.complete,noStyleguides:!D}},render({result:e,rows:t,complete:n,noStyleguides:r}){let i=Object.groupBy(t,e=>g(e.file));return`\n${Object.entries(i).map(([e,t=[]])=>{let n=Math.max(0,...t.map(e=>h(e.file).length)),r=t.map(e=>h(e.file)),i=r.length!==new Set(r).size,a=Math.max(0,...t.map(e=>e.locale.length)),o=t.map(e=>` ${h(e.file).padEnd(n)} ${i?`${m.dim(e.locale.padEnd(a))} `:``}${e.count===0?m.dim(`Nothing to translate`):m.green(`${e.count} translated`)}`);return[m.dim(`${e}/`),...o].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 ${l(e.quota.resetsAt)}`):m.dim(`✗ Partially translated, run eloqnt lint to see what's left`)}${r?`\n\n${m.dim(`→ Add a styleguide to improve your translation quality`)}\n${m.dim(` ${c()}/docs#styleguides`)}`:``}`},json:({result:e})=>e});export{y as default};
|
package/dist/whoami-bo3bXioJ.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{i as t,n}from"./urls-F6fkAWuj.mjs";import r from"picocolors";import{EloqntSdkError as i,MeResponseSchema as a,getAuthHeaders as o}from"@eloqnt/sdk/_internal";function s(e){return r.dim(e.padEnd(12))}var c=e({meta:{name:`whoami`,description:`Shows the logged-in user account.`},requiresConfig:!1,async execute(){let e=await t();if(!e)throw new i(`NOT_AUTHENTICATED`,`Not logged in`,{hint:`Run eloqnt login to authenticate.`});let r=await fetch(new URL(`/api/engine/me`,n()),{headers:o(e)});if(r.status===401)throw new i(`NOT_AUTHENTICATED`,`Your session has expired`,{hint:`Run eloqnt login to sign in again.`});if(!r.ok)throw new i(`ENGINE_ERROR`,`Sorry, we couldn't load your account`,{details:`The studio API responded with ${r.status}.`,hint:`This is on our end. Try again in a few minutes.`});let s=a.safeParse(await r.json());if(!s.success)throw new i(`ENGINE_ERROR`,`Sorry, we couldn't load your account`,{details:`The studio API returned an unexpected shape.`,hint:`This is on our end. Try again in a few minutes.`});let{user:c,plans:l,hosted:u}=s.data;return{email:c.email,plans:l,hosted:u}},render:({email:e,plans:t,hosted:i})=>{let a=[`${s(`Email:`)}${e}`,`${s(`Plan:`)}${l(t,i)}`];return i&&a.push(`${s(`Quota used:`)}${u(i)}`),t.length===0&&a.push(``,r.cyan(`→ Choose a plan at ${n()}/plans`)),a.join(`
|
|
2
|
-
`)},json:e=>e});function l(e,t){if(e.length===0)return r.yellow(`none`);let n=e.map(e=>e===`hosted`?`Hosted model`:`Bring your own model`),i=t?.status===`trialing`?r.dim(` (trial, includes 1/4 of monthly usage)`):``;return r.green(n.join(` + `))+i}function u(e){let{usedPercent:t,resetsAt:n}=e,i=`${t}%`;return`${t>=100?r.red(i):t>=80?r.yellow(i):r.green(i)} (resets ${new Intl.DateTimeFormat(`en-US`,{month:`short`,day:`numeric`}).format(new Date(n))})`}export{c as default};
|