@eloqnt/cli 0.3.1 → 0.4.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 +18 -0
- package/dist/bin/eloqnt.mjs +1 -1
- package/dist/lint-6H7VNJC2.mjs +4 -0
- package/dist/{login-Ceywjhs3.mjs → login-nkMnzEjE.mjs} +1 -1
- package/dist/review-BPDZscRV.mjs +1 -0
- package/dist/source-BIRHLi05.mjs +10 -0
- package/dist/stringWidth-D46ajgdE.mjs +1 -0
- package/dist/translate-BiFqwHuB.mjs +8 -0
- package/dist/{whoami-Z3z2RxwG.mjs → whoami-CTueGAHT.mjs} +2 -2
- package/dist/writeStep-f1jYLsuV.mjs +1 -0
- package/package.json +2 -2
- package/dist/lint-DJ-RHUGB.mjs +0 -4
- package/dist/translate-DPkpSc4M.mjs +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @eloqnt/cli
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 447e82d: Added `eloqnt review source`: Reviews source strings for typos and grammatical errors and fixes them in place.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [447e82d]
|
|
12
|
+
- @eloqnt/sdk@0.4.0
|
|
13
|
+
|
|
14
|
+
## 0.3.2
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 8fcd1bf: Note in `eloqnt lint` when source code analysis is skipped due to an absent `srcPath`, and reword the equivalent note in `eloqnt translate`.
|
|
19
|
+
- 26db6a9: `eloqnt whoami` now notes that a trial includes 1/4 of the regular monthly usage.
|
|
20
|
+
|
|
3
21
|
## 0.3.1
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
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,runMain as n}from"citty";try{e.loadEnvFile()}catch{}n(t({meta:{name:`eloqnt`,description:`AI-powered translations for developers`},subCommands:{lint:r(()=>import(`../lint-
|
|
2
|
+
import e from"node:process";import{defineCommand as t,runMain as n}from"citty";try{e.loadEnvFile()}catch{}n(t({meta:{name:`eloqnt`,description:`AI-powered translations for developers`},subCommands:{lint:r(()=>import(`../lint-6H7VNJC2.mjs`)),review:r(()=>import(`../review-BPDZscRV.mjs`)),translate:r(()=>import(`../translate-BiFqwHuB.mjs`)),login:r(()=>import(`../login-nkMnzEjE.mjs`)),logout:r(()=>import(`../logout-BjdvLusP.mjs`)),whoami:r(()=>import(`../whoami-CTueGAHT.mjs`))}}));function r(e){return()=>e().then(e=>e.default)}export{};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{i as t,n,r,t as i}from"./stringWidth-D46ajgdE.mjs";import{t as a}from"./resolvePaths-Bc7dGH8a.mjs";import{lint as o}from"@eloqnt/sdk";import s from"node:process";import{basename as c,relative as l}from"node:path";import u from"picocolors";var d=e({meta:{name:`lint`,description:`Statically analyze your source code and messages for common problems.`},async execute({config:e,rootDir:t}){let{messages:n,srcPath:r}=e,i=await o({messagesPath:a(n.path,t),sourceLocale:n.sourceLocale,format:n.format,locales:n.locales,srcPath:r?a(r,t):void 0,cwd:t}),u=s.cwd();return{issues:i.map(e=>{let t=e;if(t.location&&(t={...t,location:{...t.location,file:l(u,t.location.file)}}),t.rule===`undefined-key`&&t.sourceReferences?.length){let e=t.sourceReferences.map(e=>({path:l(u,e.path)})),n=e.length>1?` (+${e.length-1} more)`:``,r=t.location?c(t.location.file):`the source catalog`;t={...t,sourceReferences:e,message:`Used in ${e[0].path}${n} but not defined in ${r}`}}return t}),sourceLocale:n.sourceLocale,noSrcPath:!r}},render:({issues:e,sourceLocale:t,noSrcPath:n})=>{let r=f(e,t);return n?`\n${u.dim("– Skipped source code analysis due to absent `srcPath`")}\n${r}`:r},ok:({issues:e})=>e.length===0,json:({issues:e})=>e});function f(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=p(Object.entries(n),t).map(([e,n])=>m(e,n,n[0].locale===t)),i=`${e.length} ${e.length===1?`issue`:`issues`}`,a=u.bold(u.red(`✗ ${i} found`)),o=e.filter(e=>e.rule===`missing-translation`).length,s=o?`${a}\n${u.dim(`→ Run \`eloqnt translate\` to fill in ${o} missing ${o===1?`translation`:`translations`}`)}`:a;return`\n${[...r,s].join(`
|
|
2
|
+
|
|
3
|
+
`)}\n`}function p(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 m(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}=h(e);i.push(r(t)),i.push(..._(n,e.message,e.rule))}return i.join(`
|
|
4
|
+
`)}function h(e){let r=`"${e.key}"`,i=e.targetMessage??e.sourceMessage,a=g(r),o=e.highlight?.type===`value`||e.highlight?.type===`argument`,s=o?u.dim(r):r,c=u.dim(`: `),l=n(r);if(i!==void 0&&e.highlight?.type===`argument`){let r=t(i),o=e.highlight.token,u=r.indexOf(o);if(u>=0){let{inner:e,offset:t}=v(r,u,o.length,a);return{content:`${s}${c}"${e}"`,span:{column:l+3+t,length:n(o)}}}}let d=i===void 0?`"…"`:`"${x(t(i),a)}"`,f=`${s}${c}${o?d:u.dim(d)}`;return i!==void 0&&e.highlight?.type===`value`?{content:f,span:{column:l+2,length:n(d)}}:{content:f,span:{column:0,length:l}}}function g(e){let t=3+n(e)+2+2;return Math.max(24,Math.min(48,80-t))}function _(e,t,n){let i=Math.min(1,e.length-1),a=`─`.repeat(i)+`┬`+`─`.repeat(e.length-1-i),o=`${t} ${u.dim(`(${n})`)}`;return[r(` `.repeat(e.column)+u.yellow(a)),r(`${` `.repeat(e.column+i)}${u.yellow(`╰─`)} ${o}`)]}function v(e,t,n,r){let a=i(e),o=a.reduce((e,t)=>e+t.width,0),s=y(a,t),c=y(a,t+n);if(o<=r)return{inner:e,offset:b(a,0,s)};let l=Math.max(b(a,s,c),r-2),u=s,d=0;for(;u>0&&d+a[u-1].width<=16;)u--,d+=a[u].width;let f=s;for(;f<a.length&&d+a[f].width<=l;)d+=a[f].width,f++;for(;u>0&&d+a[u-1].width<=l;)u--,d+=a[u].width;let p=u>0?`…`:``,m=f<a.length?`…`:``;return{inner:p+a.slice(u,f).map(e=>e.text).join(``)+m,offset:b(a,u,s)+p.length}}function y(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 b(e,t,n){let r=0;for(let i=t;i<n;i++)r+=e[i].width;return r}function x(e,t){if(n(e)<=t)return e;let r=``,a=0;for(let n of i(e)){if(a+n.width>t-1)break;r+=n.text,a+=n.width}return`${r}…`}export{d as default,f as formatLint};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./withErrorFormatting-CnMLjXSn.mjs";import{a as t,i as n,n as r,t as i}from"./urls-BrJoRsYB.mjs";import{t as a}from"./createSpinner-BBkrpcrh.mjs";import o from"node:process";import{defineCommand as s}from"citty";import c from"picocolors";import{EloqntSdkError as l,getAuthHeaders as u}from"@eloqnt/sdk/_internal";import{hostname as d}from"node:os";import{setTimeout as f}from"node:timers/promises";import{outro as p}from"@clack/prompts";import m from"open";var h=`0.
|
|
1
|
+
import{t as e}from"./withErrorFormatting-CnMLjXSn.mjs";import{a as t,i as n,n as r,t as i}from"./urls-BrJoRsYB.mjs";import{t as a}from"./createSpinner-BBkrpcrh.mjs";import o from"node:process";import{defineCommand as s}from"citty";import c from"picocolors";import{EloqntSdkError as l,getAuthHeaders as u}from"@eloqnt/sdk/_internal";import{hostname as d}from"node:os";import{setTimeout as f}from"node:timers/promises";import{outro as p}from"@clack/prompts";import m from"open";var h=`0.4.0`;function g(e){m(e).catch(()=>{})}const _=`eloqnt-cli`,v=`eloqnt-cli/${h} (${d()}; ${o.platform} ${o.arch}; node ${o.version})`;var y=s({meta:{name:`login`,description:`Authenticates the CLI by storing an auth token locally.`},run:()=>e(async()=>{let e=i(),s=await n();s&&await fetch(`${e}/revoke-session`,{method:`POST`,headers:{authorization:`Bearer ${s}`,"content-type":`application/json`,"user-agent":v},body:JSON.stringify({token:s})}).catch(()=>{});let u=await fetch(`${e}/device/code`,{method:`POST`,headers:{"content-type":`application/json`,"user-agent":v},body:JSON.stringify({client_id:_})});if(!u.ok)throw new l(`ENGINE_UNREACHABLE`,`Couldn't start the login flow`,{details:`The auth server responded with ${u.status}.`,hint:`Check your connection and run eloqnt login again.`});let d=await u.json();o.stderr.write(`\n${c.cyan(`Log in to eloqnt studio`)}\n`),o.stderr.write(c.dim(`${d.verification_uri_complete}\n\n`)),g(d.verification_uri_complete);let f=o.stderr.isTTY?a():void 0;f?f.start(`Waiting for approval in the browser`):o.stderr.write(c.dim(`Waiting for approval in the browser …
|
|
2
2
|
`));let m=await x(e,d);if(!m.access_token)throw f?.stop(c.dim(`Login cancelled`)),new l(`NOT_AUTHENTICATED`,m.error_description??`Login failed`,{hint:`Run eloqnt login to try again.`});await t(m.access_token),f?(f.stop(c.dim(`Approved in the browser`)),p(c.green(`Logged in`))):o.stdout.write(`${c.green(`Logged in`)}\n`),await b(m.access_token)&&o.stderr.write(`\n${c.cyan(`→ Choose a plan at ${r()}/plans`)}\n`)})});async function b(e){try{let t=await fetch(new URL(`/api/engine/me`,r()),{headers:u(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 f(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
|
+
import{defineCommand as e}from"citty";var t=e({meta:{name:`review`,description:`Review source strings before translation and fix issues in place.`},subCommands:{source:()=>import(`./source-BIRHLi05.mjs`).then(e=>e.default)}});export{t as default};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{i as t,n,r}from"./stringWidth-D46ajgdE.mjs";import{t as i}from"./resolvePaths-Bc7dGH8a.mjs";import{i as a,n as o}from"./urls-BrJoRsYB.mjs";import{t as s}from"./createSpinner-BBkrpcrh.mjs";import{i as c,n as l,r as u,t as d}from"./writeStep-f1jYLsuV.mjs";import{reviewSource as f}from"@eloqnt/sdk";import p from"node:process";import{basename as m,dirname as h,relative as g}from"node:path";import _ from"picocolors";import{loadStyleguide as v}from"@eloqnt/sdk/_internal";var y=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:u}=e,m=i(r.path,t),h=u?i(u,t):void 0,y=await v({cwd:t}),b=c(y,[r.sourceLocale]),x=e.model?`eloqnt/engine (${typeof e.model==`string`?e.model:e.model.modelId})`:`eloqnt/engine (hosted)`,S=p.stderr.isTTY&&!n.json,C;function w(e){if(!n.json){if(e.phase===`context-enrichment`){e.state===`started`?(p.stderr.write(`
|
|
2
|
+
`),S?(C=s({withGuide:!1}),C.start(`Context enrichment running`)):p.stderr.write(_.dim(`Context enrichment running …
|
|
3
|
+
`))):e.state===`completed`?(C?.clear(),C=void 0,d(_.green(`✔`),`Context enrichment complete`)):(p.stderr.write(`
|
|
4
|
+
`),d(_.dim(`–`),"Skipped source code analysis due to absent `srcPath`"));return}e.state===`started`?(b?d(_.green(`✔`),b):d(_.dim(`–`),`No styleguides found`),S?(C=s({withGuide:!1}),C.start(`Reviewing source strings via ${x}`)):p.stderr.write(_.dim(`Reviewing source strings via ${x} …\n`))):(C?.clear(),C=void 0,d(_.green(`✔`),`Reviewed source strings via ${x}`))}}let T;try{T=await f({messagesPath:m,sourceLocale:r.sourceLocale,format:r.format,locales:r.locales,cwd:t,engineUrl:o(),languageModel:e.model,authToken:await a(),styleguide:y,ids:l(n.id),srcPath:h,onProgress:w})}catch(e){throw C?.clear(),e}let E=p.cwd();return{result:{...T,files:T.files.map(e=>({...e,file:g(E,e.file)})),findings:T.findings.map(e=>({...e,file:e.file?g(E,e.file):void 0,sourceFiles:e.sourceFiles.map(e=>g(E,e))}))}}},render:({result:e})=>b(e),ok:({result:e})=>e.findings.every(e=>e.status===`fixed`),json:({result:e})=>e});function b(e){let{findings:t,reviewed:n,missingTranslations:r,quota:i}=e,a=[],o=new Map;for(let n of t){let t=n.file??e.sourceLocale,r=o.get(t)??[];r.push(n),o.set(t,r)}for(let[e,t]of o){let n=[`${_.cyan(e)} ${_.dim(`(source locale)`)}`];for(let e of t)n.push(_.dim(`│`)),n.push(...x(e));a.push(n.join(`
|
|
5
|
+
`))}let s=S(t,e.sourceLocale),c=Object.groupBy(e.files,e=>h(e.file)),l=Object.entries(c).map(([e,t=[]])=>{let n=Math.max(0,...t.map(e=>m(e.file).length)),r=t.map(e=>{let t=m(e.file).padEnd(n),r=s.get(e.file);return` ${t} ${C(e.reviewed,r?.fixed??0,r?.reported??0,i!==void 0)}`});return[_.dim(`${e}/`),...r].join(`
|
|
6
|
+
`)}).join(`
|
|
7
|
+
|
|
8
|
+
`);a.push(l),i&&a.push(_.yellow(`! Monthly included usage exhausted, reviewed as much as possible. Resets ${u(i.resetsAt)}`));let d=n===0?_.dim(`→ Add new strings for the source locale to review them before translation`):r>0?_.dim("→ Run `eloqnt translate` to translate"):void 0;return`\n${a.join(`
|
|
9
|
+
|
|
10
|
+
`)}${d?`\n\n${d}`:``}\n`}function x(e){let i=`"${e.id}": "${t(e.before)}"`,a=`"${e.newId??e.id}": "${t(e.after)}"`,o=[r(`${_.red(`-`)} ${_.dim(i)}`)];if(e.status===`fixed`)o.push(r(`${_.green(`+`)} ${a}`));else{let t=e.sourceFiles[0];o.push(r(`${_.yellow(`!`)} ${a} ${_.dim(`(apply manually${t?` in ${t}`:``})`)}`))}let s=Math.min(n(`+ ${a}`),74);return o.push(r(_.yellow(`─┬${`─`.repeat(Math.max(0,s-2))}`))),o.push(r(` ${_.yellow(`╰─`)} ${t(e.note)}`)),o}function S(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 C(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{y as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"picocolors";function t(t){return e.dim(`│ `)+t}const n=RegExp(`[\0--]`,`g`);function r(e){return e.replace(/\s+/g,` `).replace(n,``).trim()}const i=new Intl.Segmenter,a=[[4352,4447],[9001,9002],[11904,12350],[12353,13311],[13312,19903],[19968,40959],[40960,42191],[44032,55203],[63744,64255],[65040,65049],[65072,65135],[65280,65376],[65504,65510],[126976,127743],[127744,129791],[131072,262141]];function o(e){let t=[];for(let{segment:n}of i.segment(e))t.push({text:n,width:c(n)});return t}function s(e){let t=0;for(let{segment:n}of i.segment(e))t+=c(n);return t}function c(e){let t=e.codePointAt(0)??0;return l(t)?0:a.some(([e,n])=>t>=e&&t<=n)?2:1}function l(e){return e<=31||e>=127&&e<=159||e>=768&&e<=879||e>=8203&&e<=8207||e>=8232&&e<=8238||e>=8288&&e<=8292||e===65279}export{r as i,s as n,t as r,o as t};
|
|
@@ -0,0 +1,8 @@
|
|
|
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};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{i as t,n}from"./urls-BrJoRsYB.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)}`];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){if(e.length===0)return r.yellow(`none`);let
|
|
1
|
+
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{i as t,n}from"./urls-BrJoRsYB.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};
|
|
@@ -0,0 +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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eloqnt/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
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.
|
|
33
|
+
"@eloqnt/sdk": "0.4.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "^25.9.1"
|
package/dist/lint-DJ-RHUGB.mjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{t}from"./resolvePaths-Bc7dGH8a.mjs";import{lint as n}from"@eloqnt/sdk";import r from"node:process";import{basename as i,relative as a}from"node:path";import o from"picocolors";const s=new Intl.Segmenter,c=[[4352,4447],[9001,9002],[11904,12350],[12353,13311],[13312,19903],[19968,40959],[40960,42191],[44032,55203],[63744,64255],[65040,65049],[65072,65135],[65280,65376],[65504,65510],[126976,127743],[127744,129791],[131072,262141]];function l(e){let t=[];for(let{segment:n}of s.segment(e))t.push({text:n,width:d(n)});return t}function u(e){let t=0;for(let{segment:n}of s.segment(e))t+=d(n);return t}function d(e){let t=e.codePointAt(0)??0;return f(t)?0:c.some(([e,n])=>t>=e&&t<=n)?2:1}function f(e){return e<=31||e>=127&&e<=159||e>=768&&e<=879||e>=8203&&e<=8207||e>=8232&&e<=8238||e>=8288&&e<=8292||e===65279}var p=e({meta:{name:`lint`,description:`Statically analyze your source code and messages for common problems.`},async execute({config:e,rootDir:o}){let{messages:s,srcPath:c}=e,l=await n({messagesPath:t(s.path,o),sourceLocale:s.sourceLocale,format:s.format,locales:s.locales,srcPath:c?t(c,o):void 0,cwd:o}),u=r.cwd();return{issues:l.map(e=>{let t=e;if(t.location&&(t={...t,location:{...t.location,file:a(u,t.location.file)}}),t.rule===`undefined-key`&&t.sourceReferences?.length){let e=t.sourceReferences.map(e=>({path:a(u,e.path)})),n=e.length>1?` (+${e.length-1} more)`:``,r=t.location?i(t.location.file):`the source catalog`;t={...t,sourceReferences:e,message:`Used in ${e[0].path}${n} but not defined in ${r}`}}return t}),sourceLocale:s.sourceLocale}},render:({issues:e,sourceLocale:t})=>m(e,t),ok:({issues:e})=>e.length===0,json:({issues:e})=>e});function m(e,t){if(e.length===0)return`\n${o.green(`No issues found`)}\n`;let n=Object.groupBy(e,e=>e.location?.file??e.locale),r=h(Object.entries(n),t).map(([e,n])=>g(e,n,n[0].locale===t)),i=`${e.length} ${e.length===1?`issue`:`issues`}`,a=o.bold(o.red(`✗ ${i} found`)),s=e.filter(e=>e.rule===`missing-translation`).length,c=s?`${a}\n${o.dim(`→ Run \`eloqnt translate\` to fill in ${s} missing ${s===1?`translation`:`translations`}`)}`:a;return`\n${[...r,c].join(`
|
|
2
|
-
|
|
3
|
-
`)}\n`}function h(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 g(e,t,n){let r=[n?`${o.cyan(e)} ${o.dim(`(source locale)`)}`:o.cyan(e)];for(let e of t){r.push(o.dim(`│`));let{content:t,span:n}=_(e);r.push(b(t)),r.push(...y(n,e.message,e.rule))}return r.join(`
|
|
4
|
-
`)}function _(e){let t=`"${e.key}"`,n=e.targetMessage??e.sourceMessage,r=v(t),i=e.highlight?.type===`value`||e.highlight?.type===`argument`,a=i?o.dim(t):t,s=o.dim(`: `),c=u(t);if(n!==void 0&&e.highlight?.type===`argument`){let t=T(n),i=e.highlight.token,o=t.indexOf(i);if(o>=0){let{inner:e,offset:n}=x(t,o,i.length,r);return{content:`${a}${s}"${e}"`,span:{column:c+3+n,length:u(i)}}}}let l=n===void 0?`"…"`:`"${E(T(n),r)}"`,d=`${a}${s}${i?l:o.dim(l)}`;return n!==void 0&&e.highlight?.type===`value`?{content:d,span:{column:c+2,length:u(l)}}:{content:d,span:{column:0,length:c}}}function v(e){let t=3+u(e)+2+2;return Math.max(24,Math.min(48,80-t))}function y(e,t,n){let r=Math.min(1,e.length-1),i=`─`.repeat(r)+`┬`+`─`.repeat(e.length-1-r),a=`${t} ${o.dim(`(${n})`)}`;return[b(` `.repeat(e.column)+o.yellow(i)),b(`${` `.repeat(e.column+r)}${o.yellow(`╰─`)} ${a}`)]}function b(e){return o.dim(`│ `)+e}function x(e,t,n,r){let i=l(e),a=i.reduce((e,t)=>e+t.width,0),o=S(i,t),s=S(i,t+n);if(a<=r)return{inner:e,offset:C(i,0,o)};let c=Math.max(C(i,o,s),r-2),u=o,d=0;for(;u>0&&d+i[u-1].width<=16;)u--,d+=i[u].width;let f=o;for(;f<i.length&&d+i[f].width<=c;)d+=i[f].width,f++;for(;u>0&&d+i[u-1].width<=c;)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:C(i,u,o)+p.length}}function S(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 C(e,t,n){let r=0;for(let i=t;i<n;i++)r+=e[i].width;return r}const w=RegExp(`[\0--]`,`g`);function T(e){return e.replace(/\s+/g,` `).replace(w,``).trim()}function E(e,t){if(u(e)<=t)return e;let n=``,r=0;for(let i of l(e)){if(r+i.width>t-1)break;n+=i.text,r+=i.width}return`${n}…`}export{p as default,m as formatLint};
|
|
@@ -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{translate as a}from"@eloqnt/sdk";import o from"node:process";import{basename as s,dirname as c,relative as l}from"node:path";import u from"picocolors";import{loadStyleguide as d}from"@eloqnt/sdk/_internal";function f(e,t={month:`short`,day:`numeric`}){return new Date(e).toLocaleDateString(`en-US`,t)}function p(e,t){o.stderr.write(`${e} ${u.dim(t)}\n`)}var m=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:c}){let{messages:f,srcPath:m}=e,h=t(f.path,s),g=m?t(m,s):void 0,_=await d({cwd:s}),v=+!!_.base+Object.keys(_.byLocale).length,y=v===0,b=e.model?`eloqnt/engine (${typeof e.model==`string`?e.model:e.model.modelId})`:`eloqnt/engine (hosted)`,x=typeof c.locale==`string`?c.locale.split(`,`):Array.isArray(f.locales)?f.locales.filter(e=>e!==f.sourceLocale):void 0,S=`${x?.length?`${x.join(`, `)} `:``}via ${b}`,C=o.stderr.isTTY&&!c.json,w;function T(e){if(!c.json){if(e.phase===`context-enrichment`){e.state===`started`?(o.stderr.write(`
|
|
2
|
-
`),C?(w=i({withGuide:!1}),w.start(`Context enrichment running`)):o.stderr.write(u.dim(`Context enrichment running …
|
|
3
|
-
`))):e.state===`completed`?(w?.clear(),w=void 0,p(u.green(`✔`),`Context enrichment complete`)):(o.stderr.write(`
|
|
4
|
-
`),p(u.dim(`–`),"Skipped context enrichment — set `srcPath` to enable"));return}if(e.phase===`translate`){e.state===`started`?(y?p(u.dim(`–`),`No styleguides found`):p(u.green(`✔`),v===1?`Styleguide loaded`:`Styleguides loaded`),C?(w=i({withGuide:!1}),w.start(`Translating ${S}`)):o.stderr.write(u.dim(`Translating ${S} …\n`))):(w?.clear(),w=void 0,p(u.green(`✔`),`Translated ${S}`));return}e.state===`started`?C?(w=i({withGuide:!1}),w.start(`Post-translation checks running`)):o.stderr.write(u.dim(`Post-translation checks running …
|
|
5
|
-
`)):(w?.clear(),w=void 0,p(u.green(`✔`),`Post-translation checks done`))}}let E;try{E=await a({messagesPath:h,sourceLocale:f.sourceLocale,format:f.format,locales:f.locales,cwd:s,engineUrl:r(),languageModel:e.model,authToken:await n(),styleguide:_,ids:typeof c.id==`string`?c.id.split(`,`):void 0,onlyLocales:typeof c.locale==`string`?c.locale.split(`,`):void 0,srcPath:g,onProgress:T})}catch(e){throw w?.clear(),e}let D=o.cwd(),O=E.targets.flatMap(e=>e.files.map(e=>({file:l(D,e.file),count:e.translated.length})));return{result:E,rows:O,complete:E.complete,noStyleguides:y}},render({result:e,rows:t,complete:n,noStyleguides:i}){let a=Object.groupBy(t,e=>c(e.file));return`\n${Object.entries(a).map(([e,t=[]])=>{let n=Math.max(0,...t.map(e=>s(e.file).length)),r=t.map(e=>` ${s(e.file).padEnd(n)} ${e.count===0?u.dim(`Nothing to translate`):u.green(`${e.count} translated`)}`);return[u.dim(`${e}/`),...r].join(`
|
|
6
|
-
`)}).join(`
|
|
7
|
-
|
|
8
|
-
`)}\n\n${n?u.green(`✔ Project fully translated`):e.quota?u.yellow(`! Monthly included usage exhausted, translated as much as possible. Resets ${f(e.quota.resetsAt)}`):u.dim(`✗ Partially translated, run eloqnt lint to see what's left`)}${i?`\n\n${u.dim(`→ Add a styleguide to improve your translation quality`)}\n${u.dim(` ${r()}/docs#styleguides`)}`:``}`},json:({result:e})=>e});export{m as default};
|