@eloqnt/cli 0.0.6 → 0.0.8
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 +14 -0
- package/dist/bin/eloqnt.mjs +1 -1
- package/dist/createSpinner-eJF8xlU7.mjs +1 -0
- package/dist/lint-DJ_-UKqz.mjs +4 -0
- package/dist/{login-I-q8XlUT.mjs → login-CDByiLM7.mjs} +1 -1
- package/dist/resolvePaths-Bc7dGH8a.mjs +1 -0
- package/dist/translate-MMptm6YR.mjs +7 -0
- package/dist/whoami-VnvhpU5y.mjs +2 -0
- package/package.json +2 -2
- package/dist/createSpinner-CqLPjqnr.mjs +0 -1
- package/dist/lint-EEWge-v7.mjs +0 -4
- package/dist/translate-BjGIVueO.mjs +0 -4
- package/dist/whoami-BO35bAgR.mjs +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @eloqnt/cli
|
|
2
2
|
|
|
3
|
+
## 0.0.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- cae3873: Consume AST context for `.json` formats, output file reference for `undefined-key` rule
|
|
8
|
+
- Updated dependencies [cae3873]
|
|
9
|
+
- @eloqnt/sdk@0.0.7
|
|
10
|
+
|
|
11
|
+
## 0.0.7
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 62f3f06: `eloqnt whoami` now shows included usage and when it resets.
|
|
16
|
+
|
|
3
17
|
## 0.0.6
|
|
4
18
|
|
|
5
19
|
### 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-DJ_-UKqz.mjs`)),translate:r(()=>import(`../translate-MMptm6YR.mjs`)),login:r(()=>import(`../login-CDByiLM7.mjs`)),logout:r(()=>import(`../logout-BI-HnLL5.mjs`)),whoami:r(()=>import(`../whoami-VnvhpU5y.mjs`))}}));function r(e){return()=>e().then(e=>e.default)}export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"picocolors";import{spinner as t}from"@clack/prompts";function n({withGuide:n=!0}={}){return t({styleFrame:t=>e.cyan(t),withGuide:n})}export{n as t};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{t as e}from"./defineEloqntCommand-BEnYhPuF.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,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./withErrorFormatting-BzsnYkDV.mjs";import{a as t,t as n}from"./urls-DdV5qJFG.mjs";import{t as r}from"./createSpinner-
|
|
1
|
+
import{t as e}from"./withErrorFormatting-BzsnYkDV.mjs";import{a as t,t as n}from"./urls-DdV5qJFG.mjs";import{t as r}from"./createSpinner-eJF8xlU7.mjs";import{EloqntSdkError as i}from"@eloqnt/sdk";import a from"node:process";import{defineCommand as o}from"citty";import s from"picocolors";import{setTimeout as c}from"node:timers/promises";import{outro as l}from"@clack/prompts";import u from"open";function d(e){u(e).catch(()=>{})}const f=`eloqnt-cli`;var p=o({meta:{name:`login`,description:`Authenticates the CLI by storing an auth token locally.`},run:()=>e(async()=>{let e=n(),o=await fetch(`${e}/device/code`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({client_id:f})});if(!o.ok)throw new i(`ENGINE_UNREACHABLE`,`Couldn't start the login flow`,{details:`The auth server responded with ${o.status}.`,hint:`Check your connection and run eloqnt login again.`});let c=await o.json();a.stderr.write(`\n${s.cyan(`Log in to eloqnt studio`)}\n`),a.stderr.write(s.dim(`${c.verification_uri_complete}\n\n`)),d(c.verification_uri_complete);let u=a.stderr.isTTY?r():void 0;u?u.start(`Waiting for approval in the browser`):a.stderr.write(s.dim(`Waiting for approval in the browser …
|
|
2
2
|
`));let p=await m(e,c);if(!p.access_token)throw u?.stop(s.dim(`Login cancelled`)),new i(`NOT_AUTHENTICATED`,p.error_description??`Login failed`,{hint:`Run eloqnt login to try again.`});await t(p.access_token),u?(u.stop(s.dim(`Approved in the browser`)),l(s.green(`Logged in`))):a.stdout.write(`${s.green(`Logged in`)}\n`)})});async function m(e,t){let n=Date.now()+t.expires_in*1e3,r=t.interval;for(;Date.now()<n;){await c(r*1e3);let n=await(await fetch(`${e}/device/token`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({grant_type:`urn:ietf:params:oauth:grant-type:device_code`,device_code:t.device_code,client_id:f})})).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{p as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{resolve as e}from"node:path";function t(t,n){return(Array.isArray(t)?t:[t]).map(t=>e(n,t))}export{t};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{t as e}from"./defineEloqntCommand-BEnYhPuF.mjs";import{t}from"./resolvePaths-Bc7dGH8a.mjs";import{i as n,n as r}from"./urls-DdV5qJFG.mjs";import{t as i}from"./createSpinner-eJF8xlU7.mjs";import{loadStyleguide as a,translate as o}from"@eloqnt/sdk";import s from"node:process";import{basename as c,dirname as l,relative as u}from"node:path";import d from"picocolors";function f(e,t={month:`short`,day:`numeric`}){return new Date(e).toLocaleDateString(`en-US`,t)}function p(e,t){s.stderr.write(`${e} ${d.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:c,args:l}){let{messages:f,srcPath:m}=e,h=t(f.path,c),g=m?t(m,c):void 0,_=await a({cwd:c}),v=e.model?`local eloqnt/engine running ${typeof e.model==`string`?e.model:e.model.modelId}`:`hosted eloqnt/engine`,y=typeof l.locale==`string`?l.locale.split(`,`):Array.isArray(f.locales)?f.locales.filter(e=>e!==f.sourceLocale):void 0,b=`${y?.length?`${y.join(`, `)} `:``}via ${v}`,x=s.stderr.isTTY&&!l.json,S;function C(e){if(!l.json){if(e.phase===`source-scan`){e.state===`started`?(s.stderr.write(`
|
|
2
|
+
`),x?(S=i({withGuide:!1}),S.start(`Enriching context from source code`)):s.stderr.write(d.dim(`Enriching context from source code …
|
|
3
|
+
`))):e.state===`completed`?(S?.clear(),S=void 0,p(d.green(`✔`),`Enriched context from source code`)):(s.stderr.write(`
|
|
4
|
+
`),p(d.dim(`–`),"Skipped context enrichment — set `srcPath` to enable"));return}e.state===`started`?x?(S=i({withGuide:!1}),S.start(`Translating ${b}`)):s.stderr.write(d.dim(`Translating ${b} …\n`)):(S?.clear(),S=void 0,p(d.green(`✔`),`Translated ${b}`))}}let w;try{w=await o({messagesPath:h,sourceLocale:f.sourceLocale,format:f.format,locales:f.locales,cwd:c,engineUrl:r(),languageModel:e.model,providerOptions:e.providerOptions,authToken:await n(),styleguide:_,ids:typeof l.id==`string`?l.id.split(`,`):void 0,onlyLocales:typeof l.locale==`string`?l.locale.split(`,`):void 0,srcPath:g,onProgress:C})}catch(e){throw S?.clear(),e}let T=s.cwd(),E=w.targets.flatMap(e=>e.files.map(e=>({file:u(T,e.file),count:e.translated.length})));return{result:w,rows:E,complete:w.complete}},render({result:e,rows:t,complete:n}){let r=Object.groupBy(t,e=>l(e.file));return`\n${Object.entries(r).map(([e,t=[]])=>{let n=Math.max(0,...t.map(e=>c(e.file).length)),r=t.map(e=>` ${c(e.file).padEnd(n)} ${e.count===0?d.dim(`Nothing to translate`):d.green(`${e.count} translated`)}`);return[d.dim(`${e}/`),...r].join(`
|
|
5
|
+
`)}).join(`
|
|
6
|
+
|
|
7
|
+
`)}\n\n${n?d.green(`✔ Project fully translated`):e.quota?d.yellow(`! Monthly included usage exhausted, translated as much as possible. Resets ${f(e.quota.resetsAt)}`):d.dim(`✗ Partially translated, run eloqnt lint to see what's left`)}`},json:({result:e})=>e});export{m as default};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{t as e}from"./defineEloqntCommand-BEnYhPuF.mjs";import{i as t,n}from"./urls-DdV5qJFG.mjs";import{EloqntSdkError as r,getAuthHeaders as i}from"@eloqnt/sdk";import a from"picocolors";function o(e){return a.dim(e.padEnd(14))}var s=e({meta:{name:`whoami`,description:`Shows the logged-in user account.`},requiresConfig:!1,async execute(){let e=await t();if(!e)throw new r(`NOT_AUTHENTICATED`,`Not logged in`,{hint:`Run eloqnt login to authenticate.`});let a=await fetch(new URL(`/api/engine/me`,n()),{headers:i(e)});if(a.status===401)throw new r(`NOT_AUTHENTICATED`,`Your session has expired`,{hint:`Run eloqnt login to sign in again.`});if(!a.ok)throw new r(`ENGINE_ERROR`,`Sorry, we couldn't load your account`,{details:`The studio API responded with ${a.status}.`,hint:`This is on our end. Try again in a few minutes.`});let o=await a.json();return{email:o.user.email,subscription:o.subscription.status,usage:o.usage}},render:({email:e,subscription:t,usage:r})=>{let i=[`${o(`Email:`)}${e}`,`${o(`Subscription:`)}${c(t)}`];return r&&i.push(`${o(`Quota used:`)}${l(r)}`),t===`none`&&i.push(``,a.cyan(`→ Subscribe at ${n()}/app`)),i.join(`
|
|
2
|
+
`)},json:e=>e});function c(e){return e===`active`?a.green(`active`):e===`trialing`?a.yellow(`trialing`):e}function l({usedPercent:e,resetsAt:t}){let n=`${e}%`;return`${e>=100?a.red(n):e>=80?a.yellow(n):a.green(n)} (resets ${new Intl.DateTimeFormat(`en-US`,{month:`short`,day:`numeric`}).format(new Date(t))})`}export{s as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eloqnt/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
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.0.
|
|
33
|
+
"@eloqnt/sdk": "0.0.7"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "^25.9.1"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"picocolors";import{spinner as t}from"@clack/prompts";function n(){return t({styleFrame:t=>e.cyan(t)})}export{n as t};
|
package/dist/lint-EEWge-v7.mjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./defineEloqntCommand-BEnYhPuF.mjs";import{lint as t}from"@eloqnt/sdk";import n from"node:process";import{relative as r,resolve as i}from"node:path";import a from"picocolors";const o=new Intl.Segmenter,s=[[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 c(e){let t=[];for(let{segment:n}of o.segment(e))t.push({text:n,width:u(n)});return t}function l(e){let t=0;for(let{segment:n}of o.segment(e))t+=u(n);return t}function u(e){let t=e.codePointAt(0)??0;return d(t)?0:s.some(([e,n])=>t>=e&&t<=n)?2:1}function d(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 f=e({meta:{name:`lint`,description:`Statically analyze your source code and messages for common problems.`},async execute({config:e,rootDir:a}){let{messages:o,srcPath:s}=e;function c(e){return(Array.isArray(e)?e:[e]).map(e=>i(a,e))}let l=await t({messagesPath:c(o.path),sourceLocale:o.sourceLocale,format:o.format,locales:o.locales,srcPath:s?c(s):void 0,cwd:a}),u=n.cwd();return{issues:l.map(e=>e.location?{...e,location:{...e.location,file:r(u,e.location.file)}}:e),sourceLocale:o.sourceLocale}},render:({issues:e,sourceLocale:t})=>p(e,t),ok:({issues:e})=>e.length===0,json:({issues:e})=>e});function p(e,t){if(e.length===0)return`\n${a.green(`No issues found`)}\n`;let n=Object.groupBy(e,e=>e.location?.file??e.locale),r=m(Object.entries(n),t).map(([e,n])=>h(e,n,n[0].locale===t)),i=`${e.length} ${e.length===1?`issue`:`issues`}`,o=a.bold(a.red(`✗ ${i} found`)),s=e.filter(e=>e.rule===`missing-translation`).length,c=s?`${o}\n${a.dim(`→ Run \`eloqnt translate\` to fill in ${s} missing ${s===1?`translation`:`translations`}`)}`:o;return`\n${[...r,c].join(`
|
|
2
|
-
|
|
3
|
-
`)}\n`}function m(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 h(e,t,n){let r=[n?`${a.cyan(e)} ${a.dim(`(source locale)`)}`:a.cyan(e)];for(let e of t){r.push(a.dim(`│`));let{content:t,span:n}=g(e);r.push(y(t)),r.push(...v(n,e.message,e.rule))}return r.join(`
|
|
4
|
-
`)}function g(e){let t=`"${e.key}"`,n=e.targetMessage??e.sourceMessage,r=_(t),i=e.highlight?.type===`value`||e.highlight?.type===`argument`,o=i?a.dim(t):t,s=a.dim(`: `),c=l(t);if(n!==void 0&&e.highlight?.type===`argument`){let t=w(n),i=e.highlight.token,a=t.indexOf(i);if(a>=0){let{inner:e,offset:n}=b(t,a,i.length,r);return{content:`${o}${s}"${e}"`,span:{column:c+3+n,length:l(i)}}}}let u=n===void 0?`"…"`:`"${T(w(n),r)}"`,d=`${o}${s}${i?u:a.dim(u)}`;return n!==void 0&&e.highlight?.type===`value`?{content:d,span:{column:c+2,length:l(u)}}:{content:d,span:{column:0,length:c}}}function _(e){let t=3+l(e)+2+2;return Math.max(24,Math.min(48,80-t))}function v(e,t,n){let r=Math.min(1,e.length-1),i=`─`.repeat(r)+`┬`+`─`.repeat(e.length-1-r),o=`${t} ${a.dim(`(${n})`)}`;return[y(` `.repeat(e.column)+a.yellow(i)),y(`${` `.repeat(e.column+r)}${a.yellow(`╰─`)} ${o}`)]}function y(e){return a.dim(`│ `)+e}function b(e,t,n,r){let i=c(e),a=i.reduce((e,t)=>e+t.width,0),o=x(i,t),s=x(i,t+n);if(a<=r)return{inner:e,offset:S(i,0,o)};let l=Math.max(S(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<=l;)d+=i[f].width,f++;for(;u>0&&d+i[u-1].width<=l;)u--,d+=i[u].width;let p=u>0?`…`:``,m=f<i.length?`…`:``;return{inner:p+i.slice(u,f).map(e=>e.text).join(``)+m,offset:S(i,u,o)+p.length}}function x(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 S(e,t,n){let r=0;for(let i=t;i<n;i++)r+=e[i].width;return r}const C=RegExp(`[\0--]`,`g`);function w(e){return e.replace(/\s+/g,` `).replace(C,``).trim()}function T(e,t){if(l(e)<=t)return e;let n=``,r=0;for(let i of c(e)){if(r+i.width>t-1)break;n+=i.text,r+=i.width}return`${n}…`}export{f as default,p as formatLint};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./defineEloqntCommand-BEnYhPuF.mjs";import{i as t,n}from"./urls-DdV5qJFG.mjs";import{t as r}from"./createSpinner-CqLPjqnr.mjs";import{loadStyleguide as i,translate as a}from"@eloqnt/sdk";import o from"node:process";import{basename as s,dirname as c,relative as l,resolve as u}from"node:path";import d from"picocolors";function f(e,t={month:`short`,day:`numeric`}){return new Date(e).toLocaleDateString(`en-US`,t)}var p=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}=e,p=(Array.isArray(f.path)?f.path:[f.path]).map(e=>u(s,e)),m=await i({cwd:s}),h=e.model?`local eloqnt/engine running ${typeof e.model==`string`?e.model:e.model.modelId}`:`hosted eloqnt/engine`,g=typeof c.locale==`string`?c.locale.split(`,`):Array.isArray(f.locales)?f.locales.filter(e=>e!==f.sourceLocale):void 0,_=`${g?.length?`${g.join(`, `)} `:``}via ${h}`,v=o.stderr.isTTY&&!c.json?r():void 0;v?v.start(`Translating ${_}`):c.json||o.stderr.write(d.dim(`\nTranslating ${_} …\n`));let y;try{y=await a({messagesPath:p,sourceLocale:f.sourceLocale,format:f.format,locales:f.locales,cwd:s,engineUrl:n(),languageModel:e.model,providerOptions:e.providerOptions,authToken:await t(),styleguide:m,ids:typeof c.id==`string`?c.id.split(`,`):void 0,onlyLocales:typeof c.locale==`string`?c.locale.split(`,`):void 0})}catch(e){throw v?.clear(),e}v?.stop(d.dim(`Translated ${_}`));let b=o.cwd(),x=y.targets.flatMap(e=>e.files.map(e=>({file:l(b,e.file),count:e.translated.length})));return{result:y,rows:x,complete:y.complete}},render({result:e,rows:t,complete:n}){let r=Object.groupBy(t,e=>c(e.file));return`\n${Object.entries(r).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?d.dim(`Nothing to translate`):d.green(`${e.count} translated`)}`);return[d.dim(`${e}/`),...r].join(`
|
|
2
|
-
`)}).join(`
|
|
3
|
-
|
|
4
|
-
`)}\n\n${n?d.green(`✔ Fully translated`):e.quota?d.yellow(`! Monthly included usage exhausted, translated as much as possible. Resets ${f(e.quota.resetsAt)}`):d.dim(`✗ Partially translated, run eloqnt lint to see what's left`)}`},json:({result:e})=>e});export{p as default};
|
package/dist/whoami-BO35bAgR.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./defineEloqntCommand-BEnYhPuF.mjs";import{i as t,n}from"./urls-DdV5qJFG.mjs";import{EloqntSdkError as r,getAuthHeaders as i}from"@eloqnt/sdk";import a from"picocolors";var o=e({meta:{name:`whoami`,description:`Shows the logged-in user account.`},requiresConfig:!1,async execute(){let e=await t();if(!e)throw new r(`NOT_AUTHENTICATED`,`Not logged in`,{hint:`Run eloqnt login to authenticate.`});let a=await fetch(new URL(`/api/engine/me`,n()),{headers:i(e)});if(a.status===401)throw new r(`NOT_AUTHENTICATED`,`Your session has expired`,{hint:`Run eloqnt login to sign in again.`});if(!a.ok)throw new r(`ENGINE_ERROR`,`Sorry, we couldn't load your account`,{details:`The studio API responded with ${a.status}.`,hint:`This is on our end. Try again in a few minutes.`});let o=await a.json();return{email:o.user.email,subscription:o.subscription.status}},render:({email:e,subscription:t})=>`Email: ${a.green(e)}\nSubscription: ${s(t)}`,json:e=>e});function s(e){return e===`active`?a.green(`active`):e===`trialing`?a.yellow(`trialing`):e===`none`?a.yellow(`none (subscribe at ${n()}/app)`):a.yellow(e)}export{o as default};
|