@eloqnt/cli 0.5.3 → 0.6.0
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 +23 -0
- package/README.md +1 -1
- package/dist/bin/eloqnt.mjs +1 -1
- package/dist/crowdin-BXlNSsuT.mjs +1 -0
- package/dist/download-BuHS-69H.mjs +1 -0
- package/dist/login-DkoUYP1R.mjs +2 -0
- package/dist/parseListArg-p5H1s5JC.mjs +1 -0
- package/dist/{review-_kko2HqL.mjs → review-C_Op7_7I.mjs} +1 -1
- package/dist/source-DxyjecuV.mjs +10 -0
- package/dist/sources-D2CmEsFc.mjs +3 -0
- package/dist/translate-0d7JNq0l.mjs +8 -0
- package/dist/translations-5dIUqhdZ.mjs +3 -0
- package/dist/translations-fTIBanLm.mjs +3 -0
- package/dist/upload-BDnaUB4y.mjs +1 -0
- package/dist/withSpinner-CeQSfolX.mjs +5 -0
- package/dist/{writeStep-f1jYLsuV.mjs → writeStep-CerCYWGN.mjs} +1 -1
- package/package.json +3 -7
- package/dist/login-DcFAwS1Z.mjs +0 -2
- package/dist/source-BzUAldmM.mjs +0 -10
- package/dist/translate-BZX3KTIl.mjs +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @eloqnt/cli
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 640779c: Add an `inconsistent-plurals` lint rule that reports plural cases which don't match the target locale's CLDR categories.
|
|
8
|
+
- 640779c: Locales that aren't recognised now fail loudly instead of being silently treated as the default locale. A new `invalid-locale` lint rule reports them, and `eloqnt translate` stops before spending inference on one.
|
|
9
|
+
- 640779c: `eloqnt translate` now reads CLDR data so `plural` and `selectordinal` statements are guaranteed to be adjusted for target locales.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [640779c]
|
|
14
|
+
- Updated dependencies [640779c]
|
|
15
|
+
- Updated dependencies [640779c]
|
|
16
|
+
- @eloqnt/sdk@0.6.0
|
|
17
|
+
|
|
18
|
+
## 0.5.4
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- e78663d: Add `eloqnt crowdin` commands for syncing messages with a Crowdin project via `crowdin.yml`: `upload sources`, `upload translations`, and `download translations`.
|
|
23
|
+
- Updated dependencies [e78663d]
|
|
24
|
+
- @eloqnt/sdk@0.5.2
|
|
25
|
+
|
|
3
26
|
## 0.5.3
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
package/README.md
CHANGED
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.
|
|
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.0`;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};
|
|
@@ -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};
|
|
@@ -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-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(
|
|
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,12 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eloqnt/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "CLI for eloqnt/studio",
|
|
5
|
-
"
|
|
6
|
-
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/eloqnt/studio.git",
|
|
8
|
-
"directory": "packages/cli"
|
|
9
|
-
},
|
|
5
|
+
"homepage": "https://studio.eloqnt.dev",
|
|
10
6
|
"bin": {
|
|
11
7
|
"eloqnt": "./dist/bin/eloqnt.mjs"
|
|
12
8
|
},
|
|
@@ -30,7 +26,7 @@
|
|
|
30
26
|
"citty": "^0.1.6",
|
|
31
27
|
"open": "^11.0.0",
|
|
32
28
|
"picocolors": "^1.1.1",
|
|
33
|
-
"@eloqnt/sdk": "0.
|
|
29
|
+
"@eloqnt/sdk": "0.6.0"
|
|
34
30
|
},
|
|
35
31
|
"devDependencies": {
|
|
36
32
|
"@types/node": "^25.9.1"
|
package/dist/login-DcFAwS1Z.mjs
DELETED
|
@@ -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};
|
package/dist/source-BzUAldmM.mjs
DELETED
|
@@ -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 _ 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: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}),v=d(p,[r.sourceLocale]),y=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(_.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=u({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: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: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=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=[`${_.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(r,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 ${p(o.resetsAt)}`));let f=i===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
|
-
`)}${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(`${_.red(`-`)} ${_.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(`${_.green(`+`)} ${u}${r?_.dim(r):``}`))}else{let t=e.sourceFiles[0],o;if(t){let e=[t,D(t),v(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(`${_.yellow(`!`)} ${u}${_.dim(o)}`))}let d=Math.min(a(u)+2,t-3);return l.push(i(_.yellow(`─┬${`─`.repeat(Math.max(0,d-2))}`))),l.push(i(` ${_.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])})`,`(${v(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 _.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};
|
|
@@ -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 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:s,args:f}){let{messages:p,srcPath:g}=e,_=t(p.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(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=a(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=i({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=i({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=i({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:s,engineUrl:r(),languageModel:e.model,authToken:await n(),styleguide:y,ids:o(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:i}){let a=Object.groupBy(t,e=>p(e.file));return`\n${Object.entries(a).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 ${s(e.quota.resetsAt)}`):d.dim(`✗ Partially translated, run eloqnt lint to see what's left`)}${i?`\n\n${d.dim(`→ Add a styleguide to improve your translation quality`)}\n${d.dim(` ${r()}/docs#styleguides`)}`:``}`},json:({result:e})=>e});export{g as default};
|