@localess/cli 3.0.5-dev.20260501212257 → 3.0.5-dev.20260502213523
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/client.d.ts +1 -1
- package/dist/index.mjs +102 -102
- package/dist/models/content-data.d.ts +1 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Content, ContentAsset, ContentData, Links, Space, Translations, TranslationUpdateResponse, TranslationUpdateType, Schemas } from './models';
|
|
2
1
|
import { OpenAPIObject } from 'openapi3-ts/oas30';
|
|
2
|
+
import { Content, ContentAsset, ContentData, Links, Schemas, Space, Translations, TranslationUpdateResponse, TranslationUpdateType } from './models';
|
|
3
3
|
export type LocalessClientOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* A fully qualified domain name with protocol (http/https) and port.
|
package/dist/index.mjs
CHANGED
|
@@ -6,39 +6,14 @@ import { join as c, parse as l } from "node:path";
|
|
|
6
6
|
import * as u from "node:process";
|
|
7
7
|
import d from "node:process";
|
|
8
8
|
import { z as f } from "zod";
|
|
9
|
-
//#region src/utils.ts
|
|
10
|
-
var p = "\x1B[0m", m = "\x1B[34m";
|
|
11
|
-
function h(e) {
|
|
12
|
-
return Object.keys(e).sort().reduce((t, n) => {
|
|
13
|
-
let r = e[n];
|
|
14
|
-
return t[n] = typeof r == "object" && r && !Array.isArray(r) ? h(r) : r, t;
|
|
15
|
-
}, {});
|
|
16
|
-
}
|
|
17
|
-
function g(e, t = "") {
|
|
18
|
-
let n = {};
|
|
19
|
-
for (let [r, i] of Object.entries(e)) {
|
|
20
|
-
let e = t ? `${t}.${r}` : r;
|
|
21
|
-
typeof i == "object" && i && !Array.isArray(i) ? Object.assign(n, g(i, e)) : n[e] = String(i);
|
|
22
|
-
}
|
|
23
|
-
return n;
|
|
24
|
-
}
|
|
25
|
-
function _(e) {
|
|
26
|
-
let t = {};
|
|
27
|
-
for (let [n, r] of Object.entries(e)) {
|
|
28
|
-
let e = n.split("."), i = t;
|
|
29
|
-
for (let t = 0; t < e.length; t++) t === e.length - 1 ? i[e[t]] = r : (e[t] in i || (i[e[t]] = {}), i = i[e[t]]);
|
|
30
|
-
}
|
|
31
|
-
return t;
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
9
|
//#region src/cache.ts
|
|
35
|
-
var
|
|
10
|
+
var p = class {
|
|
36
11
|
set(e, t) {}
|
|
37
12
|
get(e) {}
|
|
38
13
|
has(e) {
|
|
39
14
|
return !1;
|
|
40
15
|
}
|
|
41
|
-
},
|
|
16
|
+
}, m = class {
|
|
42
17
|
cache = /* @__PURE__ */ new Map();
|
|
43
18
|
constructor(e = 3e5) {
|
|
44
19
|
this.ttlMs = e;
|
|
@@ -62,7 +37,32 @@ var v = class {
|
|
|
62
37
|
has(e) {
|
|
63
38
|
return this.get(e) !== void 0;
|
|
64
39
|
}
|
|
65
|
-
},
|
|
40
|
+
}, h = "\x1B[0m", g = "\x1B[34m";
|
|
41
|
+
function _(e) {
|
|
42
|
+
return Object.keys(e).sort().reduce((t, n) => {
|
|
43
|
+
let r = e[n];
|
|
44
|
+
return t[n] = typeof r == "object" && r && !Array.isArray(r) ? _(r) : r, t;
|
|
45
|
+
}, {});
|
|
46
|
+
}
|
|
47
|
+
function v(e, t = "") {
|
|
48
|
+
let n = {};
|
|
49
|
+
for (let [r, i] of Object.entries(e)) {
|
|
50
|
+
let e = t ? `${t}.${r}` : r;
|
|
51
|
+
typeof i == "object" && i && !Array.isArray(i) ? Object.assign(n, v(i, e)) : n[e] = String(i);
|
|
52
|
+
}
|
|
53
|
+
return n;
|
|
54
|
+
}
|
|
55
|
+
function y(e) {
|
|
56
|
+
let t = {};
|
|
57
|
+
for (let [n, r] of Object.entries(e)) {
|
|
58
|
+
let e = n.split("."), i = t;
|
|
59
|
+
for (let t = 0; t < e.length; t++) t === e.length - 1 ? i[e[t]] = r : (e[t] in i || (i[e[t]] = {}), i = i[e[t]]);
|
|
60
|
+
}
|
|
61
|
+
return t;
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/client.ts
|
|
65
|
+
var b = `${g}[Localess:Client]${h}`;
|
|
66
66
|
async function x(e, t, n = 3, r = 500, i) {
|
|
67
67
|
let a = 0, o;
|
|
68
68
|
for (; a <= n;) {
|
|
@@ -87,7 +87,7 @@ function S(e) {
|
|
|
87
87
|
"X-Localess-Agent": "Localess-CLI-Client",
|
|
88
88
|
"X-Localess-Agent-Version": "0.9.0"
|
|
89
89
|
}
|
|
90
|
-
}, r = e.cacheTTL === !1 ? new
|
|
90
|
+
}, r = e.cacheTTL === !1 ? new p() : new m(e.cacheTTL);
|
|
91
91
|
return {
|
|
92
92
|
async getSpace() {
|
|
93
93
|
e.debug && console.log(b, "getSpace()");
|
|
@@ -336,10 +336,66 @@ var j = new e("login").description("Login to Localess CLI").option("-o, --origin
|
|
|
336
336
|
return e.ADD_MISSING = "add-missing", e.UPDATE_EXISTING = "update-existing", e.DELETE_MISSING = "delete-missing", e;
|
|
337
337
|
}({}), I = /* @__PURE__ */ function(e) {
|
|
338
338
|
return e.FLAT = "flat", e.NESTED = "nested", e;
|
|
339
|
-
}({})
|
|
339
|
+
}({}), L = 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(I)}`, I.FLAT).action(async (e, t) => {
|
|
340
|
+
if (console.log("Pulling translations with arguments:", e), console.log("Pulling translations with options:", t), !Object.values(I).includes(t.format)) {
|
|
341
|
+
console.error("Invalid format provided. Possible values are :", Object.values(I));
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
let n = await O();
|
|
345
|
+
if (!n.isLoggedIn) {
|
|
346
|
+
console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
let r = S({
|
|
350
|
+
origin: n.origin,
|
|
351
|
+
spaceId: n.space,
|
|
352
|
+
token: n.token
|
|
353
|
+
});
|
|
354
|
+
console.log("Pulling translations from Localess for locale:", e);
|
|
355
|
+
let i = await r.getTranslations(e);
|
|
356
|
+
if (console.log("Saving translations in file:", t.path), t.format === I.FLAT) await w(t.path, JSON.stringify(_(i), null, 2));
|
|
357
|
+
else if (t.format === I.NESTED) {
|
|
358
|
+
let e = _(y(i));
|
|
359
|
+
await w(t.path, JSON.stringify(e, null, 2));
|
|
360
|
+
}
|
|
361
|
+
console.log("Successfully saved translations from Localess");
|
|
362
|
+
}), R = f.record(f.string(), f.string()), z = f.enum(["add-missing", "update-existing"]);
|
|
363
|
+
f.object({
|
|
364
|
+
type: z,
|
|
365
|
+
values: R
|
|
366
|
+
});
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region src/commands/translations/push/index.ts
|
|
369
|
+
var B = 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(I)}`, I.FLAT).option("-t, --type <type>", `Push type. Possible values are : ${Object.values(F)}`, F.ADD_MISSING).option("--dry-run", "Preview changes without applying them to Localess").action(async (e, t) => {
|
|
370
|
+
if (console.log("Pushing translations with arguments:", e), console.log("Pushing translations with options:", t), !z.safeParse(t.type).success) {
|
|
371
|
+
console.error("Invalid type provided. Possible values are :", Object.values(F));
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
let n = await O();
|
|
375
|
+
if (!n.isLoggedIn) {
|
|
376
|
+
console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
let r = S({
|
|
380
|
+
origin: n.origin,
|
|
381
|
+
spaceId: n.space,
|
|
382
|
+
token: n.token
|
|
383
|
+
});
|
|
384
|
+
t.dryRun && console.warn("Dry run mode enabled: No changes will be made."), console.log("Reading translations file from:", t.path);
|
|
385
|
+
let i = await T(t.path), a = JSON.parse(i), o;
|
|
386
|
+
o = t.format === I.NESTED ? v(a) : a;
|
|
387
|
+
let s = R.safeParse(o);
|
|
388
|
+
if (!s.success) {
|
|
389
|
+
console.error("Invalid translations file format:", s.error);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
console.log("Pushing translations to Localess with locale:", e, "and type:", t.type);
|
|
393
|
+
let c = await r.updateTranslations(e, t.type, o, t.dryRun);
|
|
394
|
+
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");
|
|
395
|
+
}), V = new e("translations").description("Manage translations").addCommand(B).addCommand(L);
|
|
340
396
|
//#endregion
|
|
341
397
|
//#region src/commands/types/generate/generator.ts
|
|
342
|
-
function
|
|
398
|
+
function H(e) {
|
|
343
399
|
return `/**
|
|
344
400
|
* Generated by Localess CLI
|
|
345
401
|
* Do not edit manually.
|
|
@@ -390,10 +446,10 @@ export interface ${e}ContentRichText {
|
|
|
390
446
|
}
|
|
391
447
|
`;
|
|
392
448
|
}
|
|
393
|
-
function
|
|
449
|
+
function U(e) {
|
|
394
450
|
return e.replace(/[-_\s]+([a-zA-Z0-9])/g, (e, t) => t.toUpperCase()).replace(/^[a-z]/, (e) => e.toUpperCase());
|
|
395
451
|
}
|
|
396
|
-
function
|
|
452
|
+
function W(e, t) {
|
|
397
453
|
switch (e.kind) {
|
|
398
454
|
case P.TEXT:
|
|
399
455
|
case P.TEXTAREA:
|
|
@@ -409,29 +465,29 @@ function z(e, t) {
|
|
|
409
465
|
case P.ASSETS: return `${t}ContentAsset[]`;
|
|
410
466
|
case P.REFERENCE: return `${t}ContentReference`;
|
|
411
467
|
case P.REFERENCES: return `${t}ContentReference[]`;
|
|
412
|
-
case P.OPTION: return e.source ? t +
|
|
413
|
-
case P.OPTIONS: return e.source ? `${t +
|
|
468
|
+
case P.OPTION: return e.source ? t + U(e.source) : "string";
|
|
469
|
+
case P.OPTIONS: return e.source ? `${t + U(e.source)}[]` : "string[]";
|
|
414
470
|
case P.SCHEMA: {
|
|
415
471
|
let n = e.schemas;
|
|
416
472
|
if (!n || n.length === 0) return "unknown";
|
|
417
|
-
let r = n.map((e) => t +
|
|
473
|
+
let r = n.map((e) => t + U(e));
|
|
418
474
|
return r.length === 1 ? r[0] : r.join(" | ");
|
|
419
475
|
}
|
|
420
476
|
case P.SCHEMAS: {
|
|
421
477
|
let n = e.schemas;
|
|
422
478
|
if (!n || n.length === 0) return "unknown[]";
|
|
423
|
-
let r = n.map((e) => t +
|
|
479
|
+
let r = n.map((e) => t + U(e));
|
|
424
480
|
return `${r.length === 1 ? r[0] : `(${r.join(" | ")})`}[]`;
|
|
425
481
|
}
|
|
426
482
|
}
|
|
427
483
|
}
|
|
428
|
-
function
|
|
484
|
+
function G(e, t = "") {
|
|
429
485
|
return `${t}/**\n${t} * ${e}\n${t} */`;
|
|
430
486
|
}
|
|
431
|
-
function
|
|
432
|
-
let n = [
|
|
487
|
+
function K(e, t = "") {
|
|
488
|
+
let n = [H(t)], r = [];
|
|
433
489
|
for (let [i, a] of Object.entries(e)) {
|
|
434
|
-
let e = t +
|
|
490
|
+
let e = t + U(i), o = a.description ? `${G(a.description)}\n` : "";
|
|
435
491
|
if (a.type === N.ENUM) {
|
|
436
492
|
let t = a.values ?? [];
|
|
437
493
|
if (t.length === 0) n.push(`${o}export type ${e} = string;\n`);
|
|
@@ -448,7 +504,7 @@ function V(e, t = "") {
|
|
|
448
504
|
" /** Unique identifier for the Schema object. */",
|
|
449
505
|
` _schema: '${i}';`,
|
|
450
506
|
...(s.fields ?? []).slice().sort((e, t) => e.name.localeCompare(t.name)).flatMap((e) => {
|
|
451
|
-
let n =
|
|
507
|
+
let n = W(e, t), r = e.required ? "" : "?", i = [];
|
|
452
508
|
return e.description && i.push(` /** ${e.description} */`), i.push(` ${e.name}${r}: ${n};`), i;
|
|
453
509
|
})
|
|
454
510
|
];
|
|
@@ -459,7 +515,7 @@ function V(e, t = "") {
|
|
|
459
515
|
}
|
|
460
516
|
//#endregion
|
|
461
517
|
//#region src/commands/types/generate/index.ts
|
|
462
|
-
var
|
|
518
|
+
var q = c(d.cwd(), C, "localess.ts"), J = 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", q).option("--prefix <prefix>", "Prefix to prepend to all generated type names", "").action(async (e) => {
|
|
463
519
|
console.log("Types in with options:", e);
|
|
464
520
|
let t = await O();
|
|
465
521
|
if (!t.isLoggedIn) {
|
|
@@ -474,66 +530,10 @@ var H = c(d.cwd(), C, "localess.ts"), U = new e("generate").description("Generat
|
|
|
474
530
|
console.log("Fetching schemas from Localess...");
|
|
475
531
|
let r = await n.getSchemas();
|
|
476
532
|
console.log("Generating types...");
|
|
477
|
-
let i =
|
|
533
|
+
let i = K(r, e.prefix);
|
|
478
534
|
await w(e.path, i), console.log(`Types written to ${e.path}`);
|
|
479
|
-
}),
|
|
480
|
-
|
|
481
|
-
type: K,
|
|
482
|
-
values: G
|
|
483
|
-
});
|
|
484
|
-
//#endregion
|
|
485
|
-
//#region src/commands/translations/push/index.ts
|
|
486
|
-
var q = 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(I)}`, I.FLAT).option("-t, --type <type>", `Push type. Possible values are : ${Object.values(F)}`, F.ADD_MISSING).option("--dry-run", "Preview changes without applying them to Localess").action(async (e, t) => {
|
|
487
|
-
if (console.log("Pushing translations with arguments:", e), console.log("Pushing translations with options:", t), !K.safeParse(t.type).success) {
|
|
488
|
-
console.error("Invalid type provided. Possible values are :", Object.values(F));
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
let n = await O();
|
|
492
|
-
if (!n.isLoggedIn) {
|
|
493
|
-
console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
let r = S({
|
|
497
|
-
origin: n.origin,
|
|
498
|
-
spaceId: n.space,
|
|
499
|
-
token: n.token
|
|
500
|
-
});
|
|
501
|
-
t.dryRun && console.warn("Dry run mode enabled: No changes will be made."), console.log("Reading translations file from:", t.path);
|
|
502
|
-
let i = await T(t.path), a = JSON.parse(i), o;
|
|
503
|
-
o = t.format === I.NESTED ? g(a) : a;
|
|
504
|
-
let s = G.safeParse(o);
|
|
505
|
-
if (!s.success) {
|
|
506
|
-
console.error("Invalid translations file format:", s.error);
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
console.log("Pushing translations to Localess with locale:", e, "and type:", t.type);
|
|
510
|
-
let c = await r.updateTranslations(e, t.type, o, t.dryRun);
|
|
511
|
-
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");
|
|
512
|
-
}), J = 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(I)}`, I.FLAT).action(async (e, t) => {
|
|
513
|
-
if (console.log("Pulling translations with arguments:", e), console.log("Pulling translations with options:", t), !Object.values(I).includes(t.format)) {
|
|
514
|
-
console.error("Invalid format provided. Possible values are :", Object.values(I));
|
|
515
|
-
return;
|
|
516
|
-
}
|
|
517
|
-
let n = await O();
|
|
518
|
-
if (!n.isLoggedIn) {
|
|
519
|
-
console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
|
|
520
|
-
return;
|
|
521
|
-
}
|
|
522
|
-
let r = S({
|
|
523
|
-
origin: n.origin,
|
|
524
|
-
spaceId: n.space,
|
|
525
|
-
token: n.token
|
|
526
|
-
});
|
|
527
|
-
console.log("Pulling translations from Localess for locale:", e);
|
|
528
|
-
let i = await r.getTranslations(e);
|
|
529
|
-
if (console.log("Saving translations in file:", t.path), t.format === I.FLAT) await w(t.path, JSON.stringify(h(i), null, 2));
|
|
530
|
-
else if (t.format === I.NESTED) {
|
|
531
|
-
let e = h(_(i));
|
|
532
|
-
await w(t.path, JSON.stringify(e, null, 2));
|
|
533
|
-
}
|
|
534
|
-
console.log("Successfully saved translations from Localess");
|
|
535
|
-
}), Y = new e("translations").description("Manage translations").addCommand(q).addCommand(J), X = new e();
|
|
536
|
-
X.name("Localess CLI").description("CLI tool for Localess platform management").version("3.0.5"), X.addCommand(j), X.addCommand(M), X.addCommand(Y), X.addCommand(W);
|
|
535
|
+
}), Y = new e("types").description("Generate types for your schemas").addCommand(J), X = new e();
|
|
536
|
+
X.name("Localess CLI").description("CLI tool for Localess platform management").version("3.0.5"), X.addCommand(j), X.addCommand(M), X.addCommand(V), X.addCommand(Y);
|
|
537
537
|
//#endregion
|
|
538
538
|
//#region src/index.ts
|
|
539
539
|
try {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ContentAsset } from './content-asset';
|
|
2
2
|
import { ContentLink } from './content-link';
|
|
3
|
-
import { ContentRichText } from './content-rich-text';
|
|
4
3
|
import { ContentReference } from './content-reference';
|
|
4
|
+
import { ContentRichText } from './content-rich-text';
|
|
5
5
|
export type ContentDataField = any | string | string[] | number | boolean | ContentLink | ContentRichText | ContentData | ContentData[] | ContentAsset | ContentAsset[] | ContentReference | ContentReference[];
|
|
6
6
|
/**
|
|
7
7
|
* Content Data Schema related information.
|