@eloqnt/cli 0.3.1 → 0.3.2
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 +7 -0
- package/dist/bin/eloqnt.mjs +1 -1
- package/dist/{lint-DJ-RHUGB.mjs → lint-Cjz1kbgw.mjs} +1 -1
- package/dist/{login-Ceywjhs3.mjs → login-D0z9fCkZ.mjs} +1 -1
- package/dist/{translate-DPkpSc4M.mjs → translate-DJt4zE4s.mjs} +1 -1
- package/dist/{whoami-Z3z2RxwG.mjs → whoami-CTueGAHT.mjs} +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @eloqnt/cli
|
|
2
2
|
|
|
3
|
+
## 0.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8fcd1bf: Note in `eloqnt lint` when source code analysis is skipped due to an absent `srcPath`, and reword the equivalent note in `eloqnt translate`.
|
|
8
|
+
- 26db6a9: `eloqnt whoami` now notes that a trial includes 1/4 of the regular monthly usage.
|
|
9
|
+
|
|
3
10
|
## 0.3.1
|
|
4
11
|
|
|
5
12
|
### 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-Cjz1kbgw.mjs`)),translate:r(()=>import(`../translate-DJt4zE4s.mjs`)),login:r(()=>import(`../login-D0z9fCkZ.mjs`)),logout:r(()=>import(`../logout-BjdvLusP.mjs`)),whoami:r(()=>import(`../whoami-CTueGAHT.mjs`))}}));function r(e){return()=>e().then(e=>e.default)}export{};
|
|
@@ -1,4 +1,4 @@
|
|
|
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(`
|
|
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,noSrcPath:!c}},render:({issues:e,sourceLocale:t,noSrcPath:n})=>{let r=m(e,t);return n?`\n${o.dim("– Skipped source code analysis due to absent `srcPath`")}\n${r}`:r},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
2
|
|
|
3
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
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,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.3.
|
|
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.3.2`;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};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
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
2
|
`),C?(w=i({withGuide:!1}),w.start(`Context enrichment running`)):o.stderr.write(u.dim(`Context enrichment running …
|
|
3
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
|
|
4
|
+
`),p(u.dim(`–`),"Skipped context enrichment due to absent `srcPath`"));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
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
6
|
`)}).join(`
|
|
7
7
|
|
|
@@ -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};
|