@eloqnt/cli 0.0.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.
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,2 @@
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:{status:r(()=>import(`../status-BlndPEOf.mjs`)),lint:r(()=>import(`../lint-D7191wzi.mjs`)),translate:r(()=>import(`../translate-1gUfH1xf.mjs`)),login:r(()=>import(`../login-qJXHaxC9.mjs`)),logout:r(()=>import(`../logout-Dv-YLq8P.mjs`)),whoami:r(()=>import(`../whoami-CR34U7uT.mjs`))}}));function r(e){return()=>e().then(e=>e.default)}export{};
@@ -0,0 +1 @@
1
+ import{EloqntSdkError as e,loadConfig as t}from"@eloqnt/sdk";import n from"node:process";import{defineCommand as r}from"citty";function i(i){return r({meta:i.meta,args:{config:{type:`string`,description:`Path to the eloqnt config file (defaults to .eloqnt/config.{ts,js,mjs})`},json:{type:`boolean`,description:`Output the result as JSON`,default:!1},...i.args},async run({args:r}){try{let{config:e,rootDir:a}=await t({configPath:r.config}),o=await i.execute({config:e,rootDir:a,args:r}),s=r.json?JSON.stringify(i.json?i.json(o):o,null,2):i.render(o);n.stdout.write(`${s}\n`),i.ok&&!i.ok(o)&&(n.exitCode=1)}catch(t){if(t instanceof e){n.stderr.write(`error (${t.code}): ${t.message}\n`),n.exitCode=1;return}throw t}}})}export{i as t};
@@ -0,0 +1,2 @@
1
+ import { defineCodec, defineConfig } from "@eloqnt/sdk";
2
+ export { defineCodec, defineConfig };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import{defineCodec as e,defineConfig as t}from"@eloqnt/sdk";export{e as defineCodec,t as defineConfig};
@@ -0,0 +1,4 @@
1
+ import{t as e}from"./defineEloqntCommand-BrLGrJ7d.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:`Check for missing translations, unused messages, undefined or superfluous keys, and inconsistent usage of ICU arguments.`},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:c(s),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`)}`;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`));return`\n${[...r,o].join(`
2
+
3
+ `)}`}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.name}}`,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};
@@ -0,0 +1 @@
1
+ import{a as e,t}from"./urls-DdV5qJFG.mjs";import n from"node:process";import{defineCommand as r}from"citty";import i from"picocolors";import{setTimeout as a}from"node:timers/promises";import{spinner as o}from"@clack/prompts";import s from"open";function c(e){s(e).catch(()=>{})}const l=`eloqnt-cli`;var u=r({meta:{name:`login`,description:`Authenticates the CLI by storing an auth token locally.`},async run(){let r=t(),a=await fetch(`${r}/device/code`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({client_id:l})});if(!a.ok){n.stderr.write(i.red(`Could not start the login flow (${a.status})\n`)),n.exitCode=1;return}let s=await a.json();n.stderr.write(`\n${i.cyan(`Log in to eloqnt studio`)}\n`),n.stderr.write(i.dim(`${s.verification_uri_complete}\n\n`)),c(s.verification_uri_complete);let u=o();u.start(`Waiting for approval in the browser`);let f=await d(r,s);if(!f.access_token){u.stop(i.red(f.error_description??`Login failed`)),n.exitCode=1;return}await e(f.access_token),u.stop(i.green(`Logged in`))}});async function d(e,t){let n=Date.now()+t.expires_in*1e3,r=t.interval;for(;Date.now()<n;){await a(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:l})})).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 — run eloqnt login again`}}export{u as default};
@@ -0,0 +1 @@
1
+ import{i as e,r as t,t as n}from"./urls-DdV5qJFG.mjs";import r from"node:process";import{defineCommand as i}from"citty";import a from"picocolors";var o=i({meta:{name:`logout`,description:`Logs out of eloqnt studio by removing a local auth token.`},async run(){let i=await e();i&&await fetch(`${n()}/sign-out`,{method:`POST`,headers:{authorization:`Bearer ${i}`}}).catch(()=>{});let o=await t();r.stdout.write(o||i?`${a.green(`Logged out`)}\n`:`${a.dim(`Not logged in`)}\n`)}});export{o as default};
@@ -0,0 +1,2 @@
1
+ import{t as e}from"./defineEloqntCommand-BrLGrJ7d.mjs";import{getStatus as t}from"@eloqnt/sdk";import{resolve as n}from"node:path";import r from"picocolors";var i=e({meta:{name:`status`,description:`Report translation completeness per locale.`},async execute({config:e,rootDir:r}){let{messages:i}=e;return await t({messagesPath:(Array.isArray(i.path)?i.path:[i.path]).map(e=>n(r,e)),sourceLocale:i.sourceLocale,format:i.format,locales:i.locales,cwd:r})},render(e){let{source:t,targets:n}=e,i=Math.max(t.locale.length,...n.map(e=>e.locale.length)),a=`${t.totalMessages} ${t.totalMessages===1?`message`:`messages`}`,o=[`${r.bold(t.locale.padEnd(i))} ${r.dim(a)}`];for(let e of n){let t=r.bold(e.locale.padEnd(i)),n=e.missing.length===0?r.green(`complete`):r.yellow(`${e.missing.length} missing`);o.push(`${t} ${n}`)}return o.join(`
2
+ `)}});export{i as default};
@@ -0,0 +1,4 @@
1
+ import{t as e}from"./defineEloqntCommand-BrLGrJ7d.mjs";import{i as t,n}from"./urls-DdV5qJFG.mjs";import{loadStyleguide as r,translate as i}from"@eloqnt/sdk";import a from"node:process";import{basename as o,dirname as s,relative as c,resolve as l}from"node:path";import u from"picocolors";function d(e,t={month:`short`,day:`numeric`}){return new Date(e).toLocaleDateString(`en-US`,t)}var f=e({meta:{name:`translate`,description:`Translate strings to target locales (defaults to missing ones).`,requiresLogin:!0},args:{id:{type:`string`,description:`(Re-)translate these message ids (comma-separated)`},locale:{type:`string`,description:`Restrict to these target locales (comma-separated)`}},async execute({config:e,rootDir:o,args:s}){let{messages:d}=e,f=(Array.isArray(d.path)?d.path:[d.path]).map(e=>l(o,e)),p=await r({cwd:o});a.stderr.write(u.dim(`\nTranslating via ${e.model?`your model`:`eloqnt/engine`} …\n\n`));let m=await i({messagesPath:f,sourceLocale:d.sourceLocale,format:d.format,locales:d.locales,cwd:o,engineUrl:n(),languageModel:e.model,authToken:await t(),styleguide:p,ids:typeof s.id==`string`?s.id.split(`,`):void 0,onlyLocales:typeof s.locale==`string`?s.locale.split(`,`):void 0}),h=a.cwd();return{result:m,rows:m.targets.map(e=>({file:c(h,e.file),count:e.translated.length})),complete:m.complete}},render({result:e,rows:t,complete:n}){let r=Object.groupBy(t,e=>s(e.file));return`${Object.entries(r).map(([e,t=[]])=>{let n=Math.max(0,...t.map(e=>o(e.file).length)),r=t.map(e=>` ${o(e.file).padEnd(n)} ${e.count===0?u.dim(`Nothing to translate`):u.green(`${e.count} translated`)}`);return[u.dim(`${e}/`),...r].join(`
2
+ `)}).join(`
3
+
4
+ `)}\n\n${n?u.green(`✔ Fully translated`):e.quota?u.yellow(`✗ Monthly included usage exhausted — translated as much as possible, resets ${d(e.quota.resetsAt)}`):u.dim(`✗ Partially translated, run eloqnt lint to see what's left`)}`},json:({result:e})=>e});export{f as default};
@@ -0,0 +1 @@
1
+ import e from"node:process";import{dirname as t,join as n}from"node:path";import{mkdir as r,readFile as i,rm as a,writeFile as o}from"node:fs/promises";import{homedir as s}from"node:os";function c(){return n(e.env.XDG_CONFIG_HOME??n(s(),`.config`),`eloqnt`,`credentials.json`)}async function l(){if(e.env.ELOQNT_TOKEN)return e.env.ELOQNT_TOKEN;try{let e=await i(c(),`utf8`),t=JSON.parse(e);return typeof t.token==`string`?t.token:void 0}catch{return}}async function u(e){let n=c();return await r(t(n),{recursive:!0}),await o(n,`${JSON.stringify({token:e},null,2)}\n`,{mode:384}),n}async function d(){try{return await a(c()),!0}catch{return!1}}function f(){return e.env.ELOQNT_STUDIO_URL??`https://studio.eloqnt.dev`}function p(){return`${f()}/api/auth`}export{u as a,l as i,f as n,d as r,p as t};
@@ -0,0 +1 @@
1
+ import{i as e,n as t}from"./urls-DdV5qJFG.mjs";import{getAuthHeaders as n}from"@eloqnt/sdk";import r from"node:process";import{defineCommand as i}from"citty";import a from"picocolors";var o=i({meta:{name:`whoami`,description:`Shows the logged-in user account.`},async run(){let i=await e();if(!i){r.stderr.write(`${a.dim(`Not logged in — run eloqnt login`)}\n`),r.exitCode=1;return}let o=await fetch(new URL(`/api/engine/me`,t()),{headers:n(i)});if(o.status===401){r.stderr.write(`${a.dim(`Session expired — run eloqnt login`)}\n`),r.exitCode=1;return}if(!o.ok){r.stderr.write(a.red(`Could not load the account (${o.status})\n`)),r.exitCode=1;return}let c=await o.json();r.stdout.write(`Email: ${a.green(c.user.email)}\nSubscription: ${s(c.subscription.status)}\n`)}});function s(e){return e===`active`?a.green(`active`):e===`trialing`?a.yellow(`trialing`):e===`none`?a.yellow(`none — subscribe at ${t()}/app`):a.yellow(e)}export{o as default};
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@eloqnt/cli",
3
+ "version": "0.0.0",
4
+ "description": "eloqnt CLI",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/eloqnt/studio.git",
8
+ "directory": "packages/cli"
9
+ },
10
+ "bin": {
11
+ "eloqnt": "./dist/bin/eloqnt.mjs"
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "!dist/**/*.map"
16
+ ],
17
+ "type": "module",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.mts",
21
+ "import": "./dist/index.mjs"
22
+ }
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "dependencies": {
28
+ "@clack/prompts": "^1.5.1",
29
+ "@eloqnt/sdk": "0.0.0",
30
+ "citty": "^0.1.6",
31
+ "open": "^11.0.0",
32
+ "picocolors": "^1.1.1"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "^25.9.1"
36
+ },
37
+ "scripts": {
38
+ "build": "vp pack --minify src/index.ts src/bin/eloqnt.ts"
39
+ }
40
+ }