@eloqnt/cli 0.4.2 → 0.5.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 +13 -0
- package/dist/bin/eloqnt.mjs +1 -1
- package/dist/lint-EHLBXuQG.mjs +6 -0
- package/dist/{login-Cri7Zb15.mjs → login-CrJX7Rg7.mjs} +1 -1
- package/dist/{review-BZbZJcYs.mjs → review-DwtF6htB.mjs} +1 -1
- package/dist/source-HfmXUoKK.mjs +10 -0
- package/dist/stringWidth-Ba8f3rhS.mjs +1 -0
- package/package.json +2 -2
- package/dist/lint-BwKSOVgc.mjs +0 -4
- package/dist/source-BIRHLi05.mjs +0 -10
- package/dist/stringWidth-D46ajgdE.mjs +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @eloqnt/cli
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 0560a2f: Inside GitHub Actions, `eloqnt lint` now surfaces issues as file annotations on the pull request, including the call site's line for `undefined-key`.
|
|
8
|
+
- 0560a2f: `eloqnt lint` now distinguishes errors from warnings. Missing translations are warnings and no longer fail the run, so lint can gate CI without requiring translations on every commit. Pass `--strict` to treat warnings as errors.
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- 5877b8f: `eloqnt review` now notes in the diff when a fix was also synced to your source code (for `useExtracted`)
|
|
13
|
+
- Updated dependencies [0560a2f]
|
|
14
|
+
- @eloqnt/sdk@0.5.0
|
|
15
|
+
|
|
3
16
|
## 0.4.2
|
|
4
17
|
|
|
5
18
|
### 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-EHLBXuQG.mjs`)),review:r(()=>import(`../review-DwtF6htB.mjs`)),translate:r(()=>import(`../translate-BiFqwHuB.mjs`)),login:r(()=>import(`../login-CrJX7Rg7.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,6 @@
|
|
|
1
|
+
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{a as t,i as n,o as r,r as i,s as a,t as o}from"./stringWidth-Ba8f3rhS.mjs";import{t as s}from"./resolvePaths-Bc7dGH8a.mjs";import{lint as c}from"@eloqnt/sdk";import l from"node:process";import{basename as u,relative as d,resolve as f}from"node:path";import p from"picocolors";var m=e({meta:{name:`lint`,description:`Statically analyze your source code and messages for common problems.`},args:{strict:{type:`boolean`,description:`Exit with a non-zero code when warnings are found`,default:!1}},async execute({config:e,rootDir:t,args:n}){let{messages:r,srcPath:i}=e,a=await c({messagesPath:s(r.path,t),sourceLocale:r.sourceLocale,format:r.format,locales:r.locales,srcPath:i?s(i,t):void 0,cwd:t}),o=l.cwd();return{issues:a.map(e=>{let t=e;if(t.location&&(t={...t,location:{...t.location,file:d(o,t.location.file)}}),t.rule===`undefined-key`&&t.sourceReferences?.length){let e=t.sourceReferences.map(e=>({...e,path:d(o,e.path)})),n=e[0].line?`${e[0].path}:${e[0].line}`:e[0].path,r=e.length>1?` (+${e.length-1} more)`:``,i=t.location?u(t.location.file):`the source catalog`;t={...t,sourceReferences:e,message:`Used in ${n}${r} but not defined in ${i}`}}return t}),sourceLocale:r.sourceLocale,noSrcPath:!i,strict:!!n.strict}},render:({issues:e,sourceLocale:t,noSrcPath:n})=>{let r=h(e,t),i=n?`\n${p.dim("– Skipped source code analysis due to absent `srcPath`")}\n${r}`:r;return l.env.GITHUB_ACTIONS&&e.length>0?`${i}\n${_(e)}`:i},ok:({issues:e,strict:t})=>t?e.length===0:!e.some(e=>e.severity===`error`),json:({issues:e})=>e});function h(e,t){if(e.length===0)return`\n${p.green(`No issues found`)}\n`;let n=Object.groupBy(e,e=>e.location?.file??e.locale),r=x(Object.entries(n),t).map(([e,n])=>S(e,n,n[0].locale===t)),i=e.filter(e=>e.severity===`error`).length,a=e.length-i,o=[i>0&&p.bold(p.red(`✗ ${g(i,`error`)}`)),a>0&&p.bold(p.yellow(`! ${g(a,`warning`)}`))].filter(Boolean).join(`
|
|
2
|
+
`),s=e.filter(e=>e.rule===`missing-translation`).length,c=s?p.dim(`→ Run \`eloqnt translate\` to fill in ${s} missing ${s===1?`translation`:`translations`}`):void 0;return`\n${[...r,o,c].filter(Boolean).join(`
|
|
3
|
+
|
|
4
|
+
`)}\n`}function g(e,t){return`${e} ${e===1?t:`${t}s`}`}function _(e){return e.map(e=>{let t=e.rule===`undefined-key`&&e.sourceReferences?.length?e.sourceReferences[0]:void 0,n=t?.path??e.location?.file,r=[n&&`file=${b(v(n))}`,t?.line&&`line=${t.line}`,`title=${b(e.rule)}`].filter(Boolean).join(`,`),i=y(`"${e.key}": ${e.message}`);return`::${e.severity} ${r}::${i}`}).join(`
|
|
5
|
+
`)}function v(e){let t=l.env.GITHUB_WORKSPACE;return t?d(t,f(e)):e}function y(e){return e.replace(/%/g,`%25`).replace(/\r/g,`%0D`).replace(/\n/g,`%0A`)}function b(e){return y(e).replace(/:/g,`%3A`).replace(/,/g,`%2C`)}function x(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 S(e,t,n){let i=[n?`${p.cyan(e)} ${p.dim(`(source locale)`)}`:p.cyan(e)];for(let e of t){i.push(p.dim(`│`));let{content:t,span:n}=C(e);i.push(r(t)),i.push(...T(n,e))}return i.join(`
|
|
6
|
+
`)}function C(e){let n=`"${e.key}"`,r=e.targetMessage??e.sourceMessage,o=w(n),s=e.highlight?.type===`value`||e.highlight?.type===`argument`,c=s?p.dim(n):n,l=p.dim(`: `),u=i(n);if(r!==void 0&&e.highlight?.type===`argument`){let t=a(r),n=e.highlight.token,s=t.indexOf(n);if(s>=0){let{inner:e,offset:r}=E(t,s,n.length,o);return{content:`${c}${l}"${e}"`,span:{column:u+3+r,length:i(n)}}}}let d=r===void 0?`"…"`:`"${t(a(r),o)}"`,f=`${c}${l}${s?d:p.dim(d)}`;return r!==void 0&&e.highlight?.type===`value`?{content:f,span:{column:u+2,length:i(d)}}:{content:f,span:{column:0,length:u}}}function w(e){let t=3+i(e)+2+2;return Math.max(24,Math.min(48,n()-t))}function T(e,t){let n=t.severity===`error`?p.red:p.yellow,i=Math.min(1,e.length-1),a=`─`.repeat(i)+`┬`+`─`.repeat(e.length-1-i),o=`${t.message} ${p.dim(`(${t.rule})`)}`;return[r(` `.repeat(e.column)+n(a)),r(`${` `.repeat(e.column+i)}${n(`╰─`)} ${o}`)]}function E(e,t,n,r){let i=o(e),a=i.reduce((e,t)=>e+t.width,0),s=D(i,t),c=D(i,t+n);if(a<=r)return{inner:e,offset:O(i,0,s)};let l=Math.max(O(i,s,c),r-2),u=s,d=0;for(;u>0&&d+i[u-1].width<=16;)u--,d+=i[u].width;let f=s;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:O(i,u,s)+p.length}}function D(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 O(e,t,n){let r=0;for(let i=t;i<n;i++)r+=e[i].width;return r}export{m as default,_ as formatGithubAnnotations,h 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.5.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};
|
|
@@ -1 +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 (defaults to the `source` subcommand)."},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 before translation and fix issues in place (defaults to the `source` subcommand)."},setup({rawArgs:e}){e.find(e=>!e.startsWith(`-`))!==`source`&&e.unshift(`source`)},subCommands:{source:()=>import(`./source-HfmXUoKK.mjs`).then(e=>e.default)}});export{t as default};
|
|
@@ -0,0 +1,10 @@
|
|
|
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{basename as _,dirname as v,relative as y}from"node:path";import b from"picocolors";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 (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:i}=e,a=s(r.path,t),o=i?s(i,t):void 0,p=await x({cwd:t}),_=d(p,[r.sourceLocale]),v=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(b.dim(`Context enrichment running …
|
|
3
|
+
`))):e.state===`completed`?(C?.clear(),C=void 0,m(b.green(`✔`),`Context enrichment complete`)):(g.stderr.write(`
|
|
4
|
+
`),m(b.dim(`–`),"Skipped source code analysis due to absent `srcPath`"));return}e.state===`started`?(_?m(b.green(`✔`),_):m(b.dim(`–`),`No styleguides found`),S?(C=u({withGuide:!1}),C.start(`Reviewing source strings via ${v}`)):g.stderr.write(b.dim(`Reviewing source strings via ${v} …\n`))):(C?.clear(),C=void 0,m(b.green(`✔`),`Reviewed source strings via ${v}`))}}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:y(E,e.file)})),findings:T.findings.map(e=>({...e,file:e.file?y(E,e.file):void 0,sourceFiles:e.sourceFiles.map(e=>y(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=[`${b.cyan(e)} ${b.dim(`(source locale)`)}`];for(let e of n)r.push(b.dim(`│`)),r.push(...w(e,t));s.push(r.join(`
|
|
5
|
+
`))}let l=O(r,e.sourceLocale),u=Object.groupBy(e.files,e=>v(e.file)),d=Object.entries(u).map(([e,t=[]])=>{let n=Math.max(0,...t.map(e=>_(e.file).length)),r=t.map(e=>{let t=_(e.file).padEnd(n),r=l.get(e.file);return` ${t} ${k(e.reviewed,r?.fixed??0,r?.reported??0,o!==void 0)}`});return[b.dim(`${e}/`),...r].join(`
|
|
6
|
+
`)}).join(`
|
|
7
|
+
|
|
8
|
+
`);s.push(d),o&&s.push(b.yellow(`! Monthly included usage exhausted, reviewed as much as possible. Resets ${p(o.resetsAt)}`));let f=i===0?b.dim(`→ Add new strings for the source locale to review them before translation`):a>0?b.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(`${b.red(`-`)} ${b.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(`${b.green(`+`)} ${u}${r?b.dim(r):``}`))}else{let t=e.sourceFiles[0],o;if(t){let e=[t,D(t),_(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(`${b.yellow(`!`)} ${u}${b.dim(o)}`))}let d=Math.min(a(u)+2,t-3);return l.push(i(b.yellow(`─┬${`─`.repeat(Math.max(0,d-2))}`))),l.push(i(` ${b.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])})`,`(${_(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 b.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?b.yellow(a):r?b.dim(a):b.green(a)}export{S as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"node:process";import t from"picocolors";function n(e){return t.dim(`│ `)+e}const r=RegExp(`[\0--]`,`g`);function i(e){return e.replace(/\s+/g,` `).replace(r,``).trim()}const a=new Intl.Segmenter,o=[[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 s(e){let t=[];for(let{segment:n}of a.segment(e))t.push({text:n,width:f(n)});return t}function c(e){let t=0;for(let{segment:n}of a.segment(e))t+=f(n);return t}function l(t=80){let{columns:n,isTTY:r}=e.stdout;return!r||!n?t:Math.max(40,n)}function u(e,t){if(c(e)<=t)return e;let n=``,r=0;for(let i of s(e)){if(r+i.width>t-1)break;n+=i.text,r+=i.width}return`${n}…`}function d(e,t){return t.find(t=>c(t)<=e)??``}function f(e){let t=e.codePointAt(0)??0;return p(t)?0:o.some(([e,n])=>t>=e&&t<=n)?2:1}function p(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{u as a,l as i,d as n,n as o,c as r,i as s,s as t};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eloqnt/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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.5.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "^25.9.1"
|
package/dist/lint-BwKSOVgc.mjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
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?u.dim(`→ Run \`eloqnt translate\` to fill in ${o} missing ${o===1?`translation`:`translations`}`):void 0;return`\n${[...r,a,s].filter(Boolean).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};
|
package/dist/source-BIRHLi05.mjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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};
|
|
@@ -1 +0,0 @@
|
|
|
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};
|