@better-i18n/cli 0.4.0 → 0.6.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.
Files changed (74) hide show
  1. package/dist/analyzer/rules/string-variable.js +1 -1
  2. package/dist/analyzer/rules/string-variable.js.map +1 -1
  3. package/dist/analyzer/rules/translation-function.d.ts.map +1 -1
  4. package/dist/analyzer/rules/translation-function.js +9 -0
  5. package/dist/analyzer/rules/translation-function.js.map +1 -1
  6. package/dist/commands/content-types.d.ts.map +1 -1
  7. package/dist/commands/content-types.js +4 -2
  8. package/dist/commands/content-types.js.map +1 -1
  9. package/dist/commands/keys.d.ts +30 -0
  10. package/dist/commands/keys.d.ts.map +1 -0
  11. package/dist/commands/keys.js +193 -0
  12. package/dist/commands/keys.js.map +1 -0
  13. package/dist/commands/languages.d.ts +20 -0
  14. package/dist/commands/languages.d.ts.map +1 -0
  15. package/dist/commands/languages.js +87 -0
  16. package/dist/commands/languages.js.map +1 -0
  17. package/dist/commands/login.d.ts +17 -0
  18. package/dist/commands/login.d.ts.map +1 -0
  19. package/dist/commands/login.js +291 -0
  20. package/dist/commands/login.js.map +1 -0
  21. package/dist/commands/projects.d.ts +23 -0
  22. package/dist/commands/projects.d.ts.map +1 -0
  23. package/dist/commands/projects.js +78 -0
  24. package/dist/commands/projects.js.map +1 -0
  25. package/dist/commands/sync.d.ts +5 -0
  26. package/dist/commands/sync.d.ts.map +1 -1
  27. package/dist/commands/sync.js +142 -0
  28. package/dist/commands/sync.js.map +1 -1
  29. package/dist/commands/syncs.d.ts +38 -0
  30. package/dist/commands/syncs.d.ts.map +1 -0
  31. package/dist/commands/syncs.js +140 -0
  32. package/dist/commands/syncs.js.map +1 -0
  33. package/dist/commands/translate.d.ts +19 -0
  34. package/dist/commands/translate.d.ts.map +1 -0
  35. package/dist/commands/translate.js +135 -0
  36. package/dist/commands/translate.js.map +1 -0
  37. package/dist/context/detector.js +11 -5
  38. package/dist/context/detector.js.map +1 -1
  39. package/dist/index.d.ts +2 -2
  40. package/dist/index.js +114 -16
  41. package/dist/index.js.map +1 -1
  42. package/dist/reporters/doctor-eslint.d.ts.map +1 -1
  43. package/dist/reporters/doctor-eslint.js +1 -0
  44. package/dist/reporters/doctor-eslint.js.map +1 -1
  45. package/dist/reporters/eslint-style.d.ts +1 -1
  46. package/dist/reporters/eslint-style.d.ts.map +1 -1
  47. package/dist/reporters/eslint-style.js +1 -1
  48. package/dist/reporters/eslint-style.js.map +1 -1
  49. package/dist/rules/code/string-variable.js +1 -1
  50. package/dist/rules/code/string-variable.js.map +1 -1
  51. package/dist/rules/extraction/translation-function.d.ts.map +1 -1
  52. package/dist/rules/extraction/translation-function.js +9 -0
  53. package/dist/rules/extraction/translation-function.js.map +1 -1
  54. package/dist/utils/api-client.d.ts +34 -0
  55. package/dist/utils/api-client.d.ts.map +1 -0
  56. package/dist/utils/api-client.js +95 -0
  57. package/dist/utils/api-client.js.map +1 -0
  58. package/dist/utils/auth.d.ts +23 -0
  59. package/dist/utils/auth.d.ts.map +1 -0
  60. package/dist/utils/auth.js +59 -0
  61. package/dist/utils/auth.js.map +1 -0
  62. package/dist/utils/cdn-client.d.ts.map +1 -1
  63. package/dist/utils/cdn-client.js +9 -3
  64. package/dist/utils/cdn-client.js.map +1 -1
  65. package/dist/utils/json-keys.d.ts +2 -0
  66. package/dist/utils/json-keys.d.ts.map +1 -1
  67. package/dist/utils/key-comparison.d.ts.map +1 -1
  68. package/dist/utils/key-comparison.js +1 -0
  69. package/dist/utils/key-comparison.js.map +1 -1
  70. package/dist/utils/require-auth.d.ts +17 -0
  71. package/dist/utils/require-auth.d.ts.map +1 -0
  72. package/dist/utils/require-auth.js +31 -0
  73. package/dist/utils/require-auth.js.map +1 -0
  74. package/package.json +1 -1
@@ -0,0 +1,291 @@
1
+ import { createServer } from "node:http";
2
+ import { execFile } from "node:child_process";
3
+ import { URL } from "node:url";
4
+ import ora from "ora";
5
+ import { bold, cyan, dim, green, red, yellow } from "../utils/colors.js";
6
+ import { saveCredentials, loadCredentials, clearCredentials, getAuthFilePath, resolveAuth, } from "../utils/auth.js";
7
+ import { getSession } from "../utils/api-client.js";
8
+ const DEFAULT_API_URL = "https://dash.better-i18n.com";
9
+ const CALLBACK_PORT = 9876;
10
+ export async function loginCommand(options) {
11
+ const apiUrl = options.apiUrl || DEFAULT_API_URL;
12
+ if (options.apiKey) {
13
+ await loginWithApiKey(options.apiKey, apiUrl, options.json);
14
+ return;
15
+ }
16
+ await loginWithBrowser(apiUrl, options.json);
17
+ }
18
+ async function loginWithApiKey(apiKey, apiUrl, json) {
19
+ const spinner = json ? null : ora("Verifying API key...").start();
20
+ const result = await getSession(apiKey, apiUrl);
21
+ if (!result.ok || !result.data) {
22
+ spinner?.fail("Invalid API key");
23
+ if (json) {
24
+ console.log(JSON.stringify({ ok: false, error: "Invalid API key", code: "AUTH_FAILED" }));
25
+ }
26
+ else {
27
+ console.error(red(" Could not authenticate with the provided API key."));
28
+ console.error(dim(" Get your key from: https://dash.better-i18n.com/settings/api-keys"));
29
+ }
30
+ process.exit(1);
31
+ }
32
+ const { user } = result.data;
33
+ const creds = {
34
+ apiKey,
35
+ email: user.email,
36
+ userId: user.id,
37
+ apiUrl,
38
+ createdAt: new Date().toISOString(),
39
+ };
40
+ saveCredentials(creds);
41
+ if (json) {
42
+ console.log(JSON.stringify({ ok: true, data: { email: user.email, name: user.name } }));
43
+ }
44
+ else {
45
+ spinner?.succeed(`Logged in as ${bold(user.email)}`);
46
+ console.log(dim(` Credentials saved to ${getAuthFilePath()}`));
47
+ }
48
+ }
49
+ async function loginWithBrowser(apiUrl, json) {
50
+ const existing = loadCredentials();
51
+ if (existing) {
52
+ const check = await getSession(existing.apiKey, existing.apiUrl);
53
+ if (check.ok && check.data) {
54
+ if (json) {
55
+ console.log(JSON.stringify({
56
+ ok: true,
57
+ data: { email: check.data.user.email, name: check.data.user.name, alreadyLoggedIn: true },
58
+ }));
59
+ }
60
+ else {
61
+ console.log();
62
+ console.log(yellow(` Already logged in as ${bold(check.data.user.email)}`));
63
+ console.log(dim(` Run ${cyan("better-i18n logout")} first to switch accounts.`));
64
+ }
65
+ return;
66
+ }
67
+ }
68
+ if (json) {
69
+ console.log(JSON.stringify({ ok: false, error: "Browser login not available in JSON mode. Use --api-key.", code: "BROWSER_REQUIRED" }));
70
+ process.exit(1);
71
+ }
72
+ console.log();
73
+ console.log(bold(" Better i18n CLI Login"));
74
+ console.log();
75
+ const callbackUrl = `http://localhost:${CALLBACK_PORT}/callback`;
76
+ const loginUrl = `${apiUrl}/cli-auth?callback=${encodeURIComponent(callbackUrl)}`;
77
+ const apiKeyPromise = startCallbackServer();
78
+ console.log(` Opening browser to log in...`);
79
+ console.log();
80
+ console.log(dim(` If the browser doesn't open, visit:`));
81
+ console.log(cyan(` ${loginUrl}`));
82
+ console.log();
83
+ const openCmd = process.platform === "darwin"
84
+ ? "open"
85
+ : process.platform === "win32"
86
+ ? "cmd"
87
+ : "xdg-open";
88
+ const openArgs = process.platform === "win32" ? ["/c", "start", loginUrl] : [loginUrl];
89
+ execFile(openCmd, openArgs, () => { });
90
+ const spinner = ora("Waiting for authentication...").start();
91
+ try {
92
+ const apiKey = await apiKeyPromise;
93
+ spinner.text = "Verifying...";
94
+ const result = await getSession(apiKey, apiUrl);
95
+ if (!result.ok || !result.data) {
96
+ spinner.fail("Authentication failed");
97
+ console.error(red(" Received API key could not be verified."));
98
+ process.exit(1);
99
+ }
100
+ const { user } = result.data;
101
+ const creds = {
102
+ apiKey,
103
+ email: user.email,
104
+ userId: user.id,
105
+ apiUrl,
106
+ createdAt: new Date().toISOString(),
107
+ };
108
+ saveCredentials(creds);
109
+ spinner.succeed(`Logged in as ${bold(user.email)}`);
110
+ console.log(dim(` Credentials saved to ${getAuthFilePath()}`));
111
+ }
112
+ catch (err) {
113
+ spinner.fail("Authentication timed out or failed");
114
+ console.error(red(` ${err instanceof Error ? err.message : String(err)}`));
115
+ process.exit(1);
116
+ }
117
+ }
118
+ function startCallbackServer() {
119
+ return new Promise((resolve, reject) => {
120
+ const timeout = setTimeout(() => {
121
+ server.close();
122
+ reject(new Error("Login timed out after 5 minutes. Please try again."));
123
+ }, 5 * 60 * 1000);
124
+ const server = createServer((req, res) => {
125
+ const url = new URL(req.url || "/", `http://localhost:${CALLBACK_PORT}`);
126
+ if (url.pathname === "/callback") {
127
+ const apiKey = url.searchParams.get("api_key") || url.searchParams.get("token");
128
+ if (apiKey) {
129
+ res.writeHead(200, { "Content-Type": "text/html" });
130
+ res.end(renderCallbackPage("success"));
131
+ clearTimeout(timeout);
132
+ server.close();
133
+ resolve(apiKey);
134
+ }
135
+ else {
136
+ res.writeHead(400, { "Content-Type": "text/html" });
137
+ res.end(renderCallbackPage("error"));
138
+ }
139
+ }
140
+ else {
141
+ res.writeHead(404);
142
+ res.end();
143
+ }
144
+ });
145
+ server.listen(CALLBACK_PORT, "127.0.0.1");
146
+ server.on("error", (err) => {
147
+ clearTimeout(timeout);
148
+ if (err.code === "EADDRINUSE") {
149
+ reject(new Error(`Port ${CALLBACK_PORT} is in use. Close the other process and try again.`));
150
+ }
151
+ else {
152
+ reject(err);
153
+ }
154
+ });
155
+ });
156
+ }
157
+ export async function logoutCommand(options) {
158
+ const removed = clearCredentials();
159
+ if (options.json) {
160
+ console.log(JSON.stringify({ ok: true, data: { removed } }));
161
+ return;
162
+ }
163
+ if (removed) {
164
+ console.log();
165
+ console.log(green(" Logged out successfully."));
166
+ console.log(dim(` Credentials removed from ${getAuthFilePath()}`));
167
+ }
168
+ else {
169
+ console.log();
170
+ console.log(yellow(" Not logged in."));
171
+ }
172
+ }
173
+ export async function whoamiCommand(options) {
174
+ const auth = resolveAuth(options);
175
+ if (!auth) {
176
+ if (options.json) {
177
+ console.log(JSON.stringify({ ok: false, error: "Not logged in", code: "NOT_AUTHENTICATED" }));
178
+ }
179
+ else {
180
+ console.log();
181
+ console.log(yellow(" Not logged in."));
182
+ console.log(dim(` Run ${cyan("better-i18n login")} to authenticate.`));
183
+ }
184
+ process.exit(1);
185
+ }
186
+ const spinner = options.json ? null : ora("Checking session...").start();
187
+ const result = await getSession(auth.apiKey, auth.apiUrl);
188
+ if (!result.ok || !result.data) {
189
+ spinner?.fail("Session expired or invalid");
190
+ if (options.json) {
191
+ console.log(JSON.stringify({ ok: false, error: "Session expired", code: "SESSION_EXPIRED" }));
192
+ }
193
+ else {
194
+ console.error(dim(` Run ${cyan("better-i18n login")} to re-authenticate.`));
195
+ }
196
+ process.exit(1);
197
+ }
198
+ const { user, session } = result.data;
199
+ const creds = loadCredentials();
200
+ if (options.json) {
201
+ console.log(JSON.stringify({
202
+ ok: true,
203
+ data: {
204
+ email: user.email,
205
+ name: user.name,
206
+ userId: user.id,
207
+ source: auth.source,
208
+ expiresAt: session.expiresAt,
209
+ },
210
+ }));
211
+ return;
212
+ }
213
+ spinner?.stop();
214
+ console.log();
215
+ console.log(bold(" Better i18n CLI"));
216
+ console.log();
217
+ console.log(` ${dim("Email:")} ${user.email}`);
218
+ console.log(` ${dim("Name:")} ${user.name}`);
219
+ if (creds?.organizationName) {
220
+ console.log(` ${dim("Org:")} ${creds.organizationName}`);
221
+ }
222
+ console.log(` ${dim("Auth:")} ${auth.source === "credentials" ? "~/.better-i18n/auth.json" : auth.source === "env" ? "BETTER_I18N_API_KEY env" : auth.source}`);
223
+ console.log(` ${dim("API:")} ${auth.apiUrl}`);
224
+ console.log();
225
+ }
226
+ // ── Callback HTML ────────────────────────────────────────────────────
227
+ function renderCallbackPage(status) {
228
+ const isSuccess = status === "success";
229
+ return `<!DOCTYPE html>
230
+ <html lang="en">
231
+ <head>
232
+ <meta charset="utf-8" />
233
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
234
+ <title>Better i18n CLI</title>
235
+ <style>
236
+ * { margin: 0; padding: 0; box-sizing: border-box; }
237
+ body { font-family: system-ui, -apple-system, sans-serif; min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #fafafa; color: #111; }
238
+ @media (prefers-color-scheme: dark) { body { background: #0a0a0a; color: #fafafa; } }
239
+ .page { width: 480px; max-width: 100%; padding: 0 16px; text-align: center; }
240
+ .logos { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 20px; }
241
+ .logo-circle { width: 64px; height: 64px; border-radius: 50%; border: 1px solid #e5e5e5; background: #fff; display: flex; align-items: center; justify-content: center; }
242
+ @media (prefers-color-scheme: dark) { .logo-circle { border-color: #262626; background: #171717; } }
243
+ .arrow { color: #d1d5db; }
244
+ @media (prefers-color-scheme: dark) { .arrow { color: #404040; } }
245
+ h1 { font-size: 22px; font-weight: 600; margin-bottom: 24px; }
246
+ .card { overflow: hidden; border-radius: 12px; border: 1px solid #e5e5e5; background: #fff; text-align: center; }
247
+ @media (prefers-color-scheme: dark) { .card { border-color: #262626; background: #171717; } }
248
+ .card-body { padding: 28px 24px; }
249
+ .icon-wrap { width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 16px; }
250
+ .icon-success { background: #ecfdf5; color: #059669; }
251
+ @media (prefers-color-scheme: dark) { .icon-success { background: rgba(16,185,129,0.12); color: #34d399; } }
252
+ .icon-error { background: #fef2f2; color: #dc2626; }
253
+ @media (prefers-color-scheme: dark) { .icon-error { background: rgba(220,38,38,0.12); color: #f87171; } }
254
+ .title { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
255
+ .desc { font-size: 13px; color: #6b7280; line-height: 1.5; }
256
+ @media (prefers-color-scheme: dark) { .desc { color: #9ca3af; } }
257
+ .footer { padding: 0 24px 20px; text-align: center; font-size: 12px; color: #9ca3af; }
258
+ @media (prefers-color-scheme: dark) { .footer { color: #6b7280; } }
259
+ </style>
260
+ </head>
261
+ <body>
262
+ <div class="page">
263
+ <div class="logos">
264
+ <div class="logo-circle">
265
+ <svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" style="color:#525252"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg>
266
+ </div>
267
+ <svg width="55" height="11" viewBox="0 0 55 11" fill="none" class="arrow"><path fill-rule="evenodd" clip-rule="evenodd" d="M3.94 5.96H.005V4.96H3.94v1zm5.91 0H5.91V4.96h3.94v1zm5.91 0h-3.94V4.96h3.94v1zm5.9 0h-3.93V4.96h3.94v1zm5.91 0H23.63V4.96h3.94v1zm5.91 0h-3.94V4.96h3.94v1zm5.9 0h-3.93V4.96h3.94v1zm5.91 0h-3.94V4.96h3.94v1zm7.91 0h-5.94V4.96h5.94v1z" fill="currentColor"/><path fill-rule="evenodd" clip-rule="evenodd" d="M52.9 5.46l-3.88-3.88.71-.71 4.59 4.59-4.59 4.59-.71-.71 3.88-3.88z" fill="currentColor"/></svg>
268
+ <div class="logo-circle">
269
+ <svg width="28" height="28" viewBox="0 0 260 286" fill="none"><path fill-rule="evenodd" clip-rule="evenodd" d="M108 5.88c13.6-7.84 30.4-7.84 44 0l86 49.54c13.6 7.85 22 22.36 22 38.06v99.04c0 15.7-8.4 30.21-22 38.06l-86 49.54c-13.6 7.84-30.4 7.84-44 0l-86-49.55C8.39 222.73 0 208.22 0 192.52V93.48c0-15.7 8.39-30.21 22-38.06l86-49.54zm28.6 17.74c-4.95-2.86-11.05-2.86-16 0L54 62.07c-5.33 3.08-5.33 10.78 0 13.86l88.34 51c4.95 2.86 8 8.14 8 13.86v102c0 6.16 6.67 10.01 12 6.93l66.6-38.45c4.95-2.86 8-8.14 8-13.86V90.79c0-5.72-3.05-11-8-13.86l-92.34-53.31z" fill="currentColor"/></svg>
270
+ </div>
271
+ </div>
272
+
273
+ <h1>${isSuccess ? "CLI authenticated" : "Authentication failed"}</h1>
274
+
275
+ <div class="card">
276
+ <div class="card-body">
277
+ <div class="icon-wrap ${isSuccess ? "icon-success" : "icon-error"}">
278
+ ${isSuccess
279
+ ? '<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></svg>'
280
+ : '<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>'}
281
+ </div>
282
+ <p class="title">${isSuccess ? "You're all set" : "Something went wrong"}</p>
283
+ <p class="desc">${isSuccess ? "You can close this tab and return to the terminal." : "No API key was received. Please try running <code>better-i18n login</code> again."}</p>
284
+ </div>
285
+ <p class="footer">${isSuccess ? "A new API key was created for CLI access." : "If the problem persists, use <code>better-i18n login --api-key</code> instead."}</p>
286
+ </div>
287
+ </div>
288
+ </body>
289
+ </html>`;
290
+ }
291
+ //# sourceMappingURL=login.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EACL,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,WAAW,GAEZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,MAAM,eAAe,GAAG,8BAA8B,CAAC;AACvD,MAAM,aAAa,GAAG,IAAI,CAAC;AAU3B,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAqB;IACtD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,eAAe,CAAC;IAEjD,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC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iKey?: string;
3
+ apiUrl?: string;
4
+ json?: boolean;
5
+ }
6
+ export declare function projectsCommand(options: ProjectsOptions): Promise<void>;
7
+ export interface ProjectInfoOptions {
8
+ project?: string;
9
+ apiKey?: string;
10
+ apiUrl?: string;
11
+ json?: boolean;
12
+ dir?: string;
13
+ }
14
+ export declare function projectInfoCommand(options: ProjectInfoOptions): Promise<void>;
15
+ declare function resolveProject(options: {
16
+ project?: string;
17
+ dir?: string;
18
+ }): Promise<{
19
+ org: string;
20
+ slug: string;
21
+ }>;
22
+ export { resolveProject };
23
+ //# sourceMappingURL=projects.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projects.d.ts","sourceRoot":"","sources":["../../src/commands/projects.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,wBAAsB,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAoC7E;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CA6CnF;AAED,iBAAe,cAAc,CAAC,OAAO,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAmBjH;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -0,0 +1,78 @@
1
+ import ora from "ora";
2
+ import { bold, cyan, dim, green } from "../utils/colors.js";
3
+ import { requireAuth, handleError } from "../utils/require-auth.js";
4
+ export async function projectsCommand(options) {
5
+ const { trpc } = requireAuth(options);
6
+ const spinner = options.json ? null : ora("Fetching projects...").start();
7
+ const result = await trpc.query("mcp.listProjects");
8
+ if (!result.ok || !result.data) {
9
+ spinner?.fail("Failed to fetch projects");
10
+ handleError(result, options.json);
11
+ }
12
+ const { projects } = result.data;
13
+ if (options.json) {
14
+ console.log(JSON.stringify({ ok: true, data: result.data }));
15
+ return;
16
+ }
17
+ spinner?.stop();
18
+ console.log();
19
+ console.log(bold(` ${projects.length} project${projects.length !== 1 ? "s" : ""}`));
20
+ console.log();
21
+ for (const p of projects) {
22
+ const langCount = p.targetLanguages?.length || 0;
23
+ console.log(` ${green(p.slug)} ${dim(`${langCount} language${langCount !== 1 ? "s" : ""} · source: ${p.sourceLanguage}`)}`);
24
+ }
25
+ console.log();
26
+ }
27
+ export async function projectInfoCommand(options) {
28
+ const { trpc } = requireAuth(options);
29
+ const project = await resolveProject(options);
30
+ const spinner = options.json ? null : ora("Fetching project info...").start();
31
+ const result = await trpc.query("mcp.getProject", { orgSlug: project.org, projectSlug: project.slug });
32
+ if (!result.ok || !result.data) {
33
+ spinner?.fail("Failed to fetch project");
34
+ handleError(result, options.json);
35
+ }
36
+ if (options.json) {
37
+ console.log(JSON.stringify({ ok: true, data: result.data }));
38
+ return;
39
+ }
40
+ const d = result.data;
41
+ spinner?.stop();
42
+ console.log();
43
+ console.log(bold(` ${d.name}`));
44
+ console.log(` ${dim("Slug:")} ${d.slug}`);
45
+ console.log(` ${dim("Source:")} ${d.sourceLanguageCode}`);
46
+ console.log(` ${dim("Keys:")} ${d.keyCount}`);
47
+ console.log(` ${dim("Languages:")} ${d.languages.length}`);
48
+ console.log(` ${dim("Namespaces:")} ${d.namespaces.map(n => n.name).join(", ") || "default"}`);
49
+ console.log();
50
+ if (d.languages.length > 0) {
51
+ console.log(dim(" Languages:"));
52
+ for (const lang of d.languages) {
53
+ const bar = lang.coverage >= 100 ? green("█") : lang.coverage >= 50 ? cyan("▓") : dim("░");
54
+ console.log(` ${bar} ${lang.code.padEnd(8)} ${String(Math.round(lang.coverage)).padStart(3)}% ${dim(lang.name)}`);
55
+ }
56
+ console.log();
57
+ }
58
+ }
59
+ async function resolveProject(options) {
60
+ if (options.project) {
61
+ const [org, slug] = options.project.split("/");
62
+ if (!org || !slug) {
63
+ console.error(" Invalid project format. Use org/project (e.g. acme/dashboard)");
64
+ process.exit(1);
65
+ }
66
+ return { org, slug };
67
+ }
68
+ // Try to detect from i18n.config.ts
69
+ const { detectProjectContext } = await import("../context/detector.js");
70
+ const ctx = await detectProjectContext(options.dir || process.cwd(), true);
71
+ if (ctx?.workspaceId && ctx?.projectSlug) {
72
+ return { org: ctx.workspaceId, slug: ctx.projectSlug };
73
+ }
74
+ console.error(" No project specified. Use --project org/name or add i18n.config.ts");
75
+ process.exit(1);
76
+ }
77
+ export { resolveProject };
78
+ //# sourceMappingURL=projects.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projects.js","sourceRoot":"","sources":["../../src/commands/projects.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAQpE,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAAwB;IAC5D,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,KAAK,EAAE,CAAC;IAE1E,MAAM,MAAM,GAAG,MAAM,IA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GAAG,EAAE,CAAC;IAChB,CAAC;AACH,CAAC;AAED,KAAK,UAAU,cAAc,CAAC,OAA2C;IACvE,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC/C,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,OAAO,CAAC,KAAK,CAAC,iEAAiE,CAAC,CAAC;YACjF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QACD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;IACvB,CAAC;IAED,oCAAoC;IACpC,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,MAAM,CAAC,wBAAwB,CAAC,CAAC;IACxE,MAAM,GAAG,GAAG,MAAM,oBAAoB,CAAC,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;IAC3E,IAAI,GAAG,EAAE,WAAW,IAAI,GAAG,EAAE,WAAW,EAAE,CAAC;QACzC,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,WAAW,EAAE,IAAI,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC;IACzD,CAAC;IAED,OAAO,CAAC,KAAK,CAAC,sEAAsE,CAAC,CAAC;IACtF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -8,6 +8,11 @@ export interface SyncOptions extends ScanOptions {
8
8
  format: "eslint" | "json";
9
9
  summary?: boolean;
10
10
  checkType?: "missing" | "unused" | "both";
11
+ push?: boolean;
12
+ yes?: boolean;
13
+ project?: string;
14
+ apiKey?: string;
15
+ apiUrl?: string;
11
16
  }
12
17
  export declare function syncCommand(options: SyncOptions): Promise<void>;
13
18
  //# sourceMappingURL=sync.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAAsB,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAkC5E,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC9C,MAAM,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAC;CAC3C;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,WAAW,iBAoQrD"}
1
+ {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAAsB,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAkC5E,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC9C,MAAM,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC1C,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,WAAW,iBA8RrD"}
@@ -54,6 +54,8 @@ export async function syncCommand(options) {
54
54
  spinner.succeed(`Manifest loaded (source: ${bold(sourceLocale)}, ${manifest.languages.length} languages)`);
55
55
  }
56
56
  catch (error) {
57
+ // Reset so a half-assigned manifest can't leak into the comparison step
58
+ manifest = null;
57
59
  spinner.warn(`Could not fetch manifest: ${error instanceof Error ? error.message : String(error)}`);
58
60
  }
59
61
  }
@@ -200,6 +202,17 @@ export async function syncCommand(options) {
200
202
  metrics, duration, sourceLocale, options.summary, verificationResults, options.checkType // Pass checkType to filter report
201
203
  );
202
204
  }
205
+ // Step 7: Push missing keys (opt-in) or point at the next step
206
+ const includesMissing = (options.checkType ?? "both") !== "unused";
207
+ const totalMissing = countMissingKeysFromEntries(metrics.missing);
208
+ if (includesMissing && totalMissing > 0) {
209
+ if (options.push) {
210
+ await pushMissingKeys(metrics.missing, options, isJson);
211
+ }
212
+ else if (!isJson && !options.summary) {
213
+ printPushHint();
214
+ }
215
+ }
203
216
  }
204
217
  catch (error) {
205
218
  spinner.fail(`Failed to fetch remote keys: ${error instanceof Error ? error.message : String(error)}`);
@@ -220,7 +233,35 @@ export async function syncCommand(options) {
220
233
  else {
221
234
  reportLocalKeys(localKeys, allIssues.length, duration);
222
235
  }
236
+ // No manifest (never published / GitHub-only project): with --push we
237
+ // can't diff against the CDN, so push everything we found locally.
238
+ // The server skips keys that already exist (reported as duplicates).
239
+ if (options.push && allIssues.length > 0) {
240
+ if (!isJson) {
241
+ console.log(dim(" No published manifest to compare against — pushing all local keys (existing keys are skipped server-side)."));
242
+ console.log();
243
+ }
244
+ await pushMissingKeys(groupIssuesAsMissing(allIssues), options, isJson);
245
+ }
246
+ }
247
+ }
248
+ /**
249
+ * Group extracted issues into the missing-keys shape used by pushMissingKeys.
250
+ * Mirrors the namespace grouping in key-comparison: first dot segment.
251
+ */
252
+ function groupIssuesAsMissing(allIssues) {
253
+ const grouped = {};
254
+ const seen = new Set();
255
+ for (const issue of allIssues) {
256
+ if (!issue.key || issue.isDynamic || seen.has(issue.key))
257
+ continue;
258
+ seen.add(issue.key);
259
+ const ns = issue.key.split(".")[0] || "default";
260
+ if (!grouped[ns])
261
+ grouped[ns] = [];
262
+ grouped[ns].push({ key: issue.key, value: issue.text || "", namespace: issue.namespace });
223
263
  }
264
+ return grouped;
224
265
  }
225
266
  // fetchManifest, groupKeysByNamespace, fetchRemoteKeys → imported from utils/
226
267
  // getSummary → imported from utils/key-comparison.js
@@ -245,6 +286,107 @@ function reportLocalKeys(localKeys, _issueCount, duration) {
245
286
  /**
246
287
  * Report comparison (human-readable)
247
288
  */
289
+ /**
290
+ * Print the next-step hint after a comparison that found missing keys.
291
+ * Keeps users from dead-ending on "sync found them, now what?".
292
+ */
293
+ function printPushHint() {
294
+ console.log(dim(" To create the missing keys in Better i18n:"));
295
+ console.log(` ${cyan("better-i18n sync --push")}`);
296
+ console.log(dim(" Or hand it to your AI agent (better-i18n MCP) for context-aware source text:"));
297
+ console.log(dim(` "run better-i18n sync --format json and create the missing keys"`));
298
+ console.log();
299
+ }
300
+ /**
301
+ * Create the missing keys in Better i18n via mcp.createKeys.
302
+ *
303
+ * Namespace rule matches the platform convention: the first dot segment
304
+ * becomes the namespace, the rest is the key. Single-segment keys go to
305
+ * "default". Always confirm before writing unless --yes (or JSON mode).
306
+ */
307
+ async function pushMissingKeys(missing, options, isJson) {
308
+ const { requireAuth, handleError } = await import("../utils/require-auth.js");
309
+ const { resolveProject } = await import("./projects.js");
310
+ const { trpc } = requireAuth({ ...options, json: isJson });
311
+ const project = await resolveProject(options);
312
+ const keys = Object.values(missing)
313
+ .flat()
314
+ .map((entry) => {
315
+ // Natural-language keys (lingui style: t`Cancel order`) ARE the source text
316
+ if (entry.key.includes(" ")) {
317
+ const n = entry.namespace && entry.key.startsWith(`${entry.namespace}.`)
318
+ ? entry.key.slice(entry.namespace.length + 1)
319
+ : entry.key;
320
+ return { n, ns: entry.namespace ?? "default", v: n };
321
+ }
322
+ // Namespace from the code binding (useTranslation("common")) wins —
323
+ // it's a fact, not a guess. The analyzer prefixes the key with it.
324
+ if (entry.namespace) {
325
+ const n = entry.key.startsWith(`${entry.namespace}.`)
326
+ ? entry.key.slice(entry.namespace.length + 1)
327
+ : entry.key;
328
+ return { n, ns: entry.namespace, v: undefined };
329
+ }
330
+ // Unbound keys: apply the platform convention (first segment = namespace).
331
+ const parts = entry.key.split(".");
332
+ const ns = parts.length > 1 ? parts[0] : "default";
333
+ const n = parts.length > 1 ? parts.slice(1).join(".") : entry.key;
334
+ // entry.value is the raw t() argument (the key itself), never real
335
+ // source text — the CLI has no default-value extraction, so omit v
336
+ // and let the dashboard / Better AI / MCP fill the source text in.
337
+ return { n, ns, v: undefined };
338
+ });
339
+ if (!isJson && !options.yes) {
340
+ console.log(bold(` Creating ${keys.length} key${keys.length !== 1 ? "s" : ""} in ${green(project.org + "/" + project.slug)}`));
341
+ console.log();
342
+ for (const k of keys.slice(0, 10)) {
343
+ const nsLabel = k.ns !== "default" ? dim(`[${k.ns}] `) : "";
344
+ console.log(` ${nsLabel}${cyan(k.n)}${k.v ? dim(` → "${k.v}"`) : ""}`);
345
+ }
346
+ if (keys.length > 10)
347
+ console.log(dim(` ... and ${keys.length - 10} more`));
348
+ console.log();
349
+ const { confirm } = await import("@inquirer/prompts");
350
+ const proceed = await confirm({ message: "Create these keys?", default: true });
351
+ if (!proceed) {
352
+ console.log(dim(" Cancelled."));
353
+ return;
354
+ }
355
+ }
356
+ const spinner = isJson
357
+ ? null
358
+ : ora(`Creating ${keys.length} key${keys.length !== 1 ? "s" : ""}...`).start();
359
+ const result = await trpc.mutate("mcp.createKeys", {
360
+ orgSlug: project.org,
361
+ projectSlug: project.slug,
362
+ k: keys,
363
+ });
364
+ if (!result.ok || !result.data) {
365
+ spinner?.fail("Failed to create keys");
366
+ handleError(result, isJson);
367
+ return;
368
+ }
369
+ const d = result.data;
370
+ if (isJson) {
371
+ console.log(JSON.stringify({ ok: true, push: d }));
372
+ return;
373
+ }
374
+ spinner?.succeed(`${d.cnt} key${d.cnt !== 1 ? "s" : ""} created`);
375
+ if (d.dup > 0) {
376
+ console.log(yellow(` ${d.dup} duplicate${d.dup !== 1 ? "s" : ""} skipped (already exist)`));
377
+ }
378
+ for (const s of d.skip ?? []) {
379
+ console.log(yellow(` Skipped ${s.k}: ${s.reason}`));
380
+ }
381
+ for (const w of d.warn ?? []) {
382
+ console.log(yellow(` "${w.k}" created in [${w.ns}] but also exists in: ${w.other.join(", ")}`));
383
+ }
384
+ for (const b of d.blocked ?? []) {
385
+ console.log(yellow(` Blocked ${b.k} [${b.ns}]: same source text already exists (use --force via keys create)`));
386
+ }
387
+ console.log(dim(" Keys are now in the dashboard. Translate them there, with Better AI, or via MCP, then publish."));
388
+ console.log();
389
+ }
248
390
  function reportComparisonReport(localKeys, metrics, duration, sourceLocale, onlySummary, verificationResults, checkType) {
249
391
  // Default to 'both' if not specified (backward compatibility)
250
392
  const effectiveCheckType = checkType || "both";