@localess/cli 3.0.7-dev.20260514090404 → 3.0.7
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/dist/index.mjs +72 -72
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4,11 +4,11 @@ import { input as t, password as n } from "@inquirer/prompts";
|
|
|
4
4
|
import { access as r, appendFile as i, mkdir as a, readFile as o, writeFile as s } from "node:fs/promises";
|
|
5
5
|
import { join as c, parse as l } from "node:path";
|
|
6
6
|
import * as u from "node:process";
|
|
7
|
-
import
|
|
8
|
-
import { z as
|
|
9
|
-
import
|
|
10
|
-
//#region
|
|
11
|
-
var
|
|
7
|
+
import ee from "node:process";
|
|
8
|
+
import { z as d } from "zod";
|
|
9
|
+
import f from "chalk";
|
|
10
|
+
//#region package.json
|
|
11
|
+
var p = "3.0.7", te = class {
|
|
12
12
|
set(e, t) {}
|
|
13
13
|
get(e) {}
|
|
14
14
|
has(e) {
|
|
@@ -38,7 +38,7 @@ var ee = class {
|
|
|
38
38
|
has(e) {
|
|
39
39
|
return this.get(e) !== void 0;
|
|
40
40
|
}
|
|
41
|
-
},
|
|
41
|
+
}, ne = "\x1B[0m", re = "\x1B[34m";
|
|
42
42
|
function h(e) {
|
|
43
43
|
return Object.keys(e).sort().reduce((t, n) => {
|
|
44
44
|
let r = e[n];
|
|
@@ -63,7 +63,7 @@ function _(e) {
|
|
|
63
63
|
}
|
|
64
64
|
//#endregion
|
|
65
65
|
//#region src/client.ts
|
|
66
|
-
var v = `${
|
|
66
|
+
var v = `${re}[Localess:Client]${ne}`;
|
|
67
67
|
async function y(e, t, n = 3, r = 500, i) {
|
|
68
68
|
let a = 0, o;
|
|
69
69
|
for (; a <= n;) {
|
|
@@ -88,7 +88,7 @@ function b(e) {
|
|
|
88
88
|
"X-Localess-Agent": "Localess-CLI-Client",
|
|
89
89
|
"X-Localess-Agent-Version": "0.9.0"
|
|
90
90
|
}
|
|
91
|
-
}, r = typeof e.cacheTTL == "number" ? e.cacheTTL * 1e3 : void 0, i = e.cacheTTL === !1 ? new
|
|
91
|
+
}, r = typeof e.cacheTTL == "number" ? e.cacheTTL * 1e3 : void 0, i = e.cacheTTL === !1 ? new te() : new m(r);
|
|
92
92
|
return {
|
|
93
93
|
async getSpace() {
|
|
94
94
|
e.debug && console.log(v, "getSpace()");
|
|
@@ -235,10 +235,10 @@ async function S(e, t, n) {
|
|
|
235
235
|
await s(e, t, n);
|
|
236
236
|
} catch {}
|
|
237
237
|
}
|
|
238
|
-
async function
|
|
238
|
+
async function C(e) {
|
|
239
239
|
return o(e, "utf-8");
|
|
240
240
|
}
|
|
241
|
-
async function
|
|
241
|
+
async function w(e, t) {
|
|
242
242
|
let n = c(e, ".gitignore"), r = "";
|
|
243
243
|
try {
|
|
244
244
|
r = await o(n, "utf-8");
|
|
@@ -247,8 +247,8 @@ async function ie(e, t) {
|
|
|
247
247
|
}
|
|
248
248
|
//#endregion
|
|
249
249
|
//#region src/session.ts
|
|
250
|
-
var
|
|
251
|
-
async function
|
|
250
|
+
var T = c(u.cwd(), x, "credentials.json");
|
|
251
|
+
async function E() {
|
|
252
252
|
let e = { isLoggedIn: !1 }, t = u.env.LOCALESS_TOKEN, n = u.env.LOCALESS_SPACE, i = u.env.LOCALESS_ORIGIN;
|
|
253
253
|
if (t && n && i) return console.debug("Login in using environment variables."), {
|
|
254
254
|
isLoggedIn: !0,
|
|
@@ -258,8 +258,8 @@ async function w() {
|
|
|
258
258
|
method: "env"
|
|
259
259
|
};
|
|
260
260
|
try {
|
|
261
|
-
await r(
|
|
262
|
-
let t = await o(
|
|
261
|
+
await r(T);
|
|
262
|
+
let t = await o(T, "utf8"), n = JSON.parse(t);
|
|
263
263
|
if (Object.keys(n).length === 0) return e;
|
|
264
264
|
if (n.origin && n.token && n.space) return console.debug("Login in using credentials file."), {
|
|
265
265
|
isLoggedIn: !0,
|
|
@@ -271,21 +271,21 @@ async function w() {
|
|
|
271
271
|
} catch {}
|
|
272
272
|
return e;
|
|
273
273
|
}
|
|
274
|
-
async function
|
|
275
|
-
if (e.origin && e.token && e.space) await S(
|
|
274
|
+
async function D(e) {
|
|
275
|
+
if (e.origin && e.token && e.space) await S(T, JSON.stringify(e, null, 2), { mode: 384 }), console.log("Session credentials saved to file system."), await w(u.cwd(), x), console.log(`Added '${x}' to .gitignore to prevent credentials from being committed.`);
|
|
276
276
|
else throw Error("Cannot persist session: missing required fields.");
|
|
277
277
|
}
|
|
278
|
-
async function
|
|
278
|
+
async function ie() {
|
|
279
279
|
try {
|
|
280
|
-
await r(
|
|
280
|
+
await r(T), await S(T, "{}", { mode: 384 });
|
|
281
281
|
} catch {
|
|
282
282
|
throw Error("Failed to clear session credentials.");
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
285
|
//#endregion
|
|
286
286
|
//#region src/commands/login/index.ts
|
|
287
|
-
var
|
|
288
|
-
if ((await
|
|
287
|
+
var ae = new e("login").description("Login to Localess CLI").option("-o, --origin <origin>", "Origin of the Localess instance").option("-s, --space <space>", "Space ID to login to").option("-t, --token <token>", "Token to login to Localess CLI").action(async (e) => {
|
|
288
|
+
if ((await E()).isLoggedIn) {
|
|
289
289
|
console.log("Already logged in."), console.log("If you want to log in with different credentials, please log out first using \"localess logout\" command.");
|
|
290
290
|
return;
|
|
291
291
|
}
|
|
@@ -305,7 +305,7 @@ var D = new e("login").description("Login to Localess CLI").option("-o, --origin
|
|
|
305
305
|
});
|
|
306
306
|
try {
|
|
307
307
|
let e = await o.getSpace();
|
|
308
|
-
console.log(`Successfully logged in to space: ${e.name} (${e.id})`), await
|
|
308
|
+
console.log(`Successfully logged in to space: ${e.name} (${e.id})`), await D({
|
|
309
309
|
origin: r,
|
|
310
310
|
space: i,
|
|
311
311
|
token: a
|
|
@@ -313,9 +313,9 @@ var D = new e("login").description("Login to Localess CLI").option("-o, --origin
|
|
|
313
313
|
} catch {
|
|
314
314
|
console.error("Login failed");
|
|
315
315
|
}
|
|
316
|
-
}),
|
|
316
|
+
}), oe = new e("logout").description("Logout from Localess CLI").action(async () => {
|
|
317
317
|
console.log("Logging out...");
|
|
318
|
-
let e = await
|
|
318
|
+
let e = await E();
|
|
319
319
|
if (!e.isLoggedIn) {
|
|
320
320
|
console.log("Not currently logged in.");
|
|
321
321
|
return;
|
|
@@ -325,7 +325,7 @@ var D = new e("login").description("Login to Localess CLI").option("-o, --origin
|
|
|
325
325
|
return;
|
|
326
326
|
}
|
|
327
327
|
try {
|
|
328
|
-
await
|
|
328
|
+
await ie(), console.log("Successfully logged out.");
|
|
329
329
|
} catch (e) {
|
|
330
330
|
console.error("Failed to log out:", e);
|
|
331
331
|
}
|
|
@@ -337,12 +337,12 @@ var D = new e("login").description("Login to Localess CLI").option("-o, --origin
|
|
|
337
337
|
return e.ADD_MISSING = "add-missing", e.UPDATE_EXISTING = "update-existing", e.DELETE_MISSING = "delete-missing", e;
|
|
338
338
|
}({}), j = /* @__PURE__ */ function(e) {
|
|
339
339
|
return e.FLAT = "flat", e.NESTED = "nested", e;
|
|
340
|
-
}({}),
|
|
340
|
+
}({}), M = new e("pull").argument("<locale>", "Locale to pull").description("Pull locale translations from Localess").requiredOption("-p, --path <path>", "Path where the translations file will be saved").option("-f, --format <format>", `File format. Possible values are : ${Object.values(j)}`, j.FLAT).action(async (e, t) => {
|
|
341
341
|
if (console.log("Pulling translations with arguments:", e), console.log("Pulling translations with options:", t), !Object.values(j).includes(t.format)) {
|
|
342
342
|
console.error("Invalid format provided. Possible values are :", Object.values(j));
|
|
343
343
|
return;
|
|
344
344
|
}
|
|
345
|
-
let n = await
|
|
345
|
+
let n = await E();
|
|
346
346
|
if (!n.isLoggedIn) {
|
|
347
347
|
console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
|
|
348
348
|
return;
|
|
@@ -360,23 +360,23 @@ var D = new e("login").description("Login to Localess CLI").option("-o, --origin
|
|
|
360
360
|
await S(t.path, JSON.stringify(e, null, 2));
|
|
361
361
|
}
|
|
362
362
|
console.log("Successfully saved translations from Localess");
|
|
363
|
-
}),
|
|
363
|
+
}), N = d.record(d.string(), d.string()), P = d.enum([
|
|
364
364
|
"add-missing",
|
|
365
365
|
"update-existing",
|
|
366
366
|
"delete-missing"
|
|
367
367
|
]);
|
|
368
|
-
|
|
369
|
-
type:
|
|
370
|
-
values:
|
|
368
|
+
d.object({
|
|
369
|
+
type: P,
|
|
370
|
+
values: N
|
|
371
371
|
});
|
|
372
372
|
//#endregion
|
|
373
373
|
//#region src/commands/translations/push/index.ts
|
|
374
|
-
var
|
|
375
|
-
if (console.log("Pushing translations with arguments:", e), console.log("Pushing translations with options:", t), !
|
|
374
|
+
var F = new e("push").argument("<locale>", "Locale to push").description("Push locale translations to Localess").requiredOption("-p, --path <path>", "Path to the translations file to push").option("-f, --format <format>", `File format. Possible values are : ${Object.values(j)}`, j.FLAT).option("-t, --type <type>", `Push type. Possible values are : ${Object.values(A)}`, A.ADD_MISSING).option("--dry-run", "Preview changes without applying them to Localess").action(async (e, t) => {
|
|
375
|
+
if (console.log("Pushing translations with arguments:", e), console.log("Pushing translations with options:", t), !P.safeParse(t.type).success) {
|
|
376
376
|
console.error("Invalid type provided. Possible values are :", Object.values(A));
|
|
377
377
|
return;
|
|
378
378
|
}
|
|
379
|
-
let n = await
|
|
379
|
+
let n = await E();
|
|
380
380
|
if (!n.isLoggedIn) {
|
|
381
381
|
console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
|
|
382
382
|
return;
|
|
@@ -387,9 +387,9 @@ var P = new e("push").argument("<locale>", "Locale to push").description("Push l
|
|
|
387
387
|
token: n.token
|
|
388
388
|
});
|
|
389
389
|
t.dryRun && console.warn("Dry run mode enabled: No changes will be made."), console.log("Reading translations file from:", t.path);
|
|
390
|
-
let i = await
|
|
390
|
+
let i = await C(t.path), a = JSON.parse(i), o;
|
|
391
391
|
o = t.format === j.NESTED ? g(a) : a;
|
|
392
|
-
let s =
|
|
392
|
+
let s = N.safeParse(o);
|
|
393
393
|
if (!s.success) {
|
|
394
394
|
console.error("Invalid translations file format:", s.error);
|
|
395
395
|
return;
|
|
@@ -397,10 +397,10 @@ var P = new e("push").argument("<locale>", "Locale to push").description("Push l
|
|
|
397
397
|
console.log("Pushing translations to Localess with locale:", e, "and type:", t.type);
|
|
398
398
|
let c = await r.updateTranslations(e, t.type, o, t.dryRun);
|
|
399
399
|
c ? (c.dryRun && console.log("Dry run results:"), console.log("Successfully pushed translations to Localess"), console.log("Summary:", c.message), c.ids && console.log("Updated translation IDs:", c.ids)) : console.log("Something went wrong while pushing translations to Localess");
|
|
400
|
-
}),
|
|
400
|
+
}), I = new e("translations").description("Manage translations").addCommand(F).addCommand(M);
|
|
401
401
|
//#endregion
|
|
402
402
|
//#region src/commands/types/generate/generator.ts
|
|
403
|
-
function
|
|
403
|
+
function L(e) {
|
|
404
404
|
return `/**
|
|
405
405
|
* Generated by Localess CLI
|
|
406
406
|
* Do not edit manually.
|
|
@@ -451,10 +451,10 @@ export interface ${e}ContentRichText {
|
|
|
451
451
|
}
|
|
452
452
|
`;
|
|
453
453
|
}
|
|
454
|
-
function
|
|
454
|
+
function R(e) {
|
|
455
455
|
return e.replace(/[-_\s]+([a-zA-Z0-9])/g, (e, t) => t.toUpperCase()).replace(/^[a-z]/, (e) => e.toUpperCase());
|
|
456
456
|
}
|
|
457
|
-
function
|
|
457
|
+
function z(e, t) {
|
|
458
458
|
switch (e.kind) {
|
|
459
459
|
case k.TEXT:
|
|
460
460
|
case k.TEXTAREA:
|
|
@@ -470,29 +470,29 @@ function R(e, t) {
|
|
|
470
470
|
case k.ASSETS: return `${t}ContentAsset[]`;
|
|
471
471
|
case k.REFERENCE: return `${t}ContentReference`;
|
|
472
472
|
case k.REFERENCES: return `${t}ContentReference[]`;
|
|
473
|
-
case k.OPTION: return e.source ? t +
|
|
474
|
-
case k.OPTIONS: return e.source ? `${t +
|
|
473
|
+
case k.OPTION: return e.source ? t + R(e.source) : "string";
|
|
474
|
+
case k.OPTIONS: return e.source ? `${t + R(e.source)}[]` : "string[]";
|
|
475
475
|
case k.SCHEMA: {
|
|
476
476
|
let n = e.schemas;
|
|
477
477
|
if (!n || n.length === 0) return "unknown";
|
|
478
|
-
let r = n.map((e) => t +
|
|
478
|
+
let r = n.map((e) => t + R(e));
|
|
479
479
|
return r.length === 1 ? r[0] : r.join(" | ");
|
|
480
480
|
}
|
|
481
481
|
case k.SCHEMAS: {
|
|
482
482
|
let n = e.schemas;
|
|
483
483
|
if (!n || n.length === 0) return "unknown[]";
|
|
484
|
-
let r = n.map((e) => t +
|
|
484
|
+
let r = n.map((e) => t + R(e));
|
|
485
485
|
return `${r.length === 1 ? r[0] : `(${r.join(" | ")})`}[]`;
|
|
486
486
|
}
|
|
487
487
|
}
|
|
488
488
|
}
|
|
489
|
-
function
|
|
489
|
+
function B(e, t = "") {
|
|
490
490
|
return `${t}/**\n${t} * ${e}\n${t} */`;
|
|
491
491
|
}
|
|
492
|
-
function
|
|
493
|
-
let n = [
|
|
492
|
+
function V(e, t = "") {
|
|
493
|
+
let n = [L(t)], r = [];
|
|
494
494
|
for (let [i, a] of Object.entries(e)) {
|
|
495
|
-
let e = t +
|
|
495
|
+
let e = t + R(i), o = a.description ? `${B(a.description)}\n` : "";
|
|
496
496
|
if (a.type === O.ENUM) {
|
|
497
497
|
let t = a.values ?? [];
|
|
498
498
|
if (t.length === 0) n.push(`${o}export type ${e} = string;\n`);
|
|
@@ -509,7 +509,7 @@ function B(e, t = "") {
|
|
|
509
509
|
" /** Unique identifier for the Schema object. */",
|
|
510
510
|
` _schema: '${i}';`,
|
|
511
511
|
...(s.fields ?? []).slice().sort((e, t) => e.name.localeCompare(t.name)).flatMap((e) => {
|
|
512
|
-
let n =
|
|
512
|
+
let n = z(e, t), r = e.required ? "" : "?", i = [];
|
|
513
513
|
return e.description && i.push(` /** ${e.description} */`), i.push(` ${e.name}${r}: ${n};`), i;
|
|
514
514
|
})
|
|
515
515
|
];
|
|
@@ -520,9 +520,9 @@ function B(e, t = "") {
|
|
|
520
520
|
}
|
|
521
521
|
//#endregion
|
|
522
522
|
//#region src/commands/types/generate/index.ts
|
|
523
|
-
var
|
|
523
|
+
var H = c(ee.cwd(), x, "localess.ts"), U = new e("generate").description("Generate types for your schemas").option("-p, --path <path>", "Path to the file where to save the generated types. Default is .localess/localess.ts", H).option("--prefix <prefix>", "Prefix to prepend to all generated type names", "").action(async (e) => {
|
|
524
524
|
console.log("Types in with options:", e);
|
|
525
|
-
let t = await
|
|
525
|
+
let t = await E();
|
|
526
526
|
if (!t.isLoggedIn) {
|
|
527
527
|
console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
|
|
528
528
|
return;
|
|
@@ -535,10 +535,10 @@ var V = c(d.cwd(), x, "localess.ts"), H = new e("generate").description("Generat
|
|
|
535
535
|
console.log("Fetching schemas from Localess...");
|
|
536
536
|
let r = await n.getSchemas();
|
|
537
537
|
console.log("Generating types...");
|
|
538
|
-
let i =
|
|
538
|
+
let i = V(r, e.prefix);
|
|
539
539
|
await S(e.path, i), console.log(`Types written to ${e.path}`);
|
|
540
|
-
}),
|
|
541
|
-
function
|
|
540
|
+
}), W = new e("types").description("Generate types for your schemas").addCommand(U), G = "@localess/cli", K = `https://registry.npmjs.org/${G}`;
|
|
541
|
+
function q(e) {
|
|
542
542
|
let [t, n = null] = e.split("-"), r = t.split(".").map(Number);
|
|
543
543
|
return {
|
|
544
544
|
major: r[0] ?? 0,
|
|
@@ -547,51 +547,51 @@ function K(e) {
|
|
|
547
547
|
preRelease: n ?? null
|
|
548
548
|
};
|
|
549
549
|
}
|
|
550
|
-
function
|
|
551
|
-
let n =
|
|
550
|
+
function J(e, t) {
|
|
551
|
+
let n = q(e), r = q(t);
|
|
552
552
|
return n.major === r.major ? n.minor === r.minor ? n.patch === r.patch ? n.preRelease === null && r.preRelease !== null ? !0 : n.preRelease !== null && r.preRelease === null ? !1 : n.preRelease !== null && r.preRelease !== null ? n.preRelease > r.preRelease : !1 : n.patch > r.patch : n.minor > r.minor : n.major > r.major;
|
|
553
553
|
}
|
|
554
|
-
async function
|
|
554
|
+
async function Y(e, t) {
|
|
555
555
|
try {
|
|
556
|
-
let n = await fetch(`${
|
|
556
|
+
let n = await fetch(`${K}/${e}`, { signal: t });
|
|
557
557
|
return n.ok ? (await n.json()).version : null;
|
|
558
558
|
} catch {
|
|
559
559
|
return null;
|
|
560
560
|
}
|
|
561
561
|
}
|
|
562
|
-
function
|
|
562
|
+
function X(e) {
|
|
563
563
|
return e.replace(/\u001B\[[0-9;]*m/g, "").length;
|
|
564
564
|
}
|
|
565
|
-
function
|
|
566
|
-
let r = ` Update available: ${
|
|
565
|
+
function Z(e, t, n) {
|
|
566
|
+
let r = ` Update available: ${f.dim(e)} → ${f.green.bold(t)} `, i = ` Run ${f.cyan(`npm install --save-dev ${G}@${n}`)} to update `, a = Math.max(X(r), X(i)), o = (e) => e + " ".repeat(a - X(e)), s = f.yellow("─".repeat(a + 1));
|
|
567
567
|
return [
|
|
568
568
|
"",
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
569
|
+
f.yellow("┌") + s + f.yellow("┐"),
|
|
570
|
+
f.yellow("│") + " " + o(r) + f.yellow("│"),
|
|
571
|
+
f.yellow("│") + " " + o(i) + f.yellow("│"),
|
|
572
|
+
f.yellow("└") + s + f.yellow("┘"),
|
|
573
573
|
""
|
|
574
574
|
].join("\n");
|
|
575
575
|
}
|
|
576
576
|
async function se(e) {
|
|
577
577
|
try {
|
|
578
|
-
let t = new AbortController(), n = setTimeout(() => t.abort(), 3e3), r =
|
|
579
|
-
if (clearTimeout(n), i &&
|
|
580
|
-
if (a &&
|
|
578
|
+
let t = new AbortController(), n = setTimeout(() => t.abort(), 3e3), r = q(e).preRelease !== null, [i, a] = await Promise.all([Y("latest", t.signal), r ? Y("dev", t.signal) : Promise.resolve(null)]);
|
|
579
|
+
if (clearTimeout(n), i && J(i, e)) return Z(e, i, "latest");
|
|
580
|
+
if (a && J(a, e)) return Z(e, a, "dev");
|
|
581
581
|
} catch {}
|
|
582
582
|
return null;
|
|
583
583
|
}
|
|
584
584
|
//#endregion
|
|
585
|
-
//#region
|
|
586
|
-
var
|
|
587
|
-
Q.name("Localess CLI").description("CLI tool for Localess platform management").version(
|
|
585
|
+
//#region src/program.ts
|
|
586
|
+
var Q = new e();
|
|
587
|
+
Q.name("Localess CLI").description("CLI tool for Localess platform management").version(p);
|
|
588
588
|
var $;
|
|
589
589
|
Q.hook("preAction", () => {
|
|
590
|
-
$ = se(
|
|
590
|
+
$ = se(p);
|
|
591
591
|
}), Q.hook("postAction", async () => {
|
|
592
592
|
let e = await $;
|
|
593
593
|
e && console.log(e);
|
|
594
|
-
}), Q.addCommand(
|
|
594
|
+
}), Q.addCommand(ae), Q.addCommand(oe), Q.addCommand(I), Q.addCommand(W);
|
|
595
595
|
//#endregion
|
|
596
596
|
//#region src/index.ts
|
|
597
597
|
try {
|