@localess/cli 3.0.5-dev.20260428203008 → 3.0.5-dev.20260501214755

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 (37) hide show
  1. package/SKILL.md +11 -6
  2. package/dist/cache.d.ts +29 -0
  3. package/dist/client.d.ts +142 -0
  4. package/dist/commands/login/index.d.ts +2 -0
  5. package/dist/commands/login/login.test.d.ts +1 -0
  6. package/dist/commands/logout/index.d.ts +2 -0
  7. package/dist/commands/translations/index.d.ts +2 -0
  8. package/dist/commands/translations/pull/index.d.ts +7 -0
  9. package/dist/commands/translations/push/index.d.ts +9 -0
  10. package/dist/commands/types/generate/generator.d.ts +3 -0
  11. package/dist/commands/types/generate/generator.test.d.ts +1 -0
  12. package/dist/commands/types/generate/index.d.ts +2 -0
  13. package/dist/commands/types/index.d.ts +2 -0
  14. package/dist/commands/types/types.test.d.ts +1 -0
  15. package/dist/file.d.ts +7 -0
  16. package/dist/index.d.ts +2 -1
  17. package/dist/index.mjs +208 -201
  18. package/dist/models/content-asset.d.ts +13 -0
  19. package/dist/models/content-data.d.ts +27 -0
  20. package/dist/models/content-link.d.ts +21 -0
  21. package/dist/models/content-metadata.d.ts +41 -0
  22. package/dist/models/content-reference.d.ts +13 -0
  23. package/dist/models/content-rich-text.d.ts +13 -0
  24. package/dist/models/content.d.ts +21 -0
  25. package/dist/models/index.d.ts +13 -0
  26. package/dist/models/links.d.ts +7 -0
  27. package/dist/models/locale.d.ts +10 -0
  28. package/dist/models/references.d.ts +7 -0
  29. package/dist/models/schema.d.ts +142 -0
  30. package/dist/models/space.d.ts +21 -0
  31. package/dist/models/translation.zod.d.ts +13 -0
  32. package/dist/models/translations.d.ts +25 -0
  33. package/dist/program.d.ts +2 -0
  34. package/dist/session.d.ts +22 -0
  35. package/dist/utils.d.ts +45 -0
  36. package/dist/utils.test.d.ts +1 -0
  37. package/package.json +2 -3
package/dist/index.mjs CHANGED
@@ -1,44 +1,19 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command as e } from "commander";
3
3
  import { input as t, password as n } from "@inquirer/prompts";
4
- import { access as r, mkdir as i, readFile as a, writeFile as o } from "node:fs/promises";
5
- import { join as s, parse as c } from "node:path";
6
- import * as l from "node:process";
7
- import u from "node:process";
8
- import { z as d } from "zod";
9
- //#region src/utils.ts
10
- var f = "\x1B[0m", p = "\x1B[34m";
11
- function m(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) ? m(r) : r, t;
15
- }, {});
16
- }
17
- function h(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, h(i, e)) : n[e] = String(i);
22
- }
23
- return n;
24
- }
25
- function g(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
4
+ import { access as r, appendFile as i, mkdir as a, readFile as o, writeFile as s } from "node:fs/promises";
5
+ import { join as c, parse as l } from "node:path";
6
+ import * as u from "node:process";
7
+ import d from "node:process";
8
+ import { z as f } from "zod";
34
9
  //#region src/cache.ts
35
- var _ = class {
10
+ var p = class {
36
11
  set(e, t) {}
37
12
  get(e) {}
38
13
  has(e) {
39
14
  return !1;
40
15
  }
41
- }, v = class {
16
+ }, m = class {
42
17
  cache = /* @__PURE__ */ new Map();
43
18
  constructor(e = 3e5) {
44
19
  this.ttlMs = e;
@@ -62,23 +37,48 @@ var _ = class {
62
37
  has(e) {
63
38
  return this.get(e) !== void 0;
64
39
  }
65
- }, y = `${p}[Localess:Client]${f}`;
66
- async function b(e, t, n = 3, r = 500, i) {
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
+ async function x(e, t, n = 3, r = 500, i) {
67
67
  let a = 0, o;
68
68
  for (; a <= n;) {
69
69
  try {
70
70
  let n = await fetch(e, t);
71
- if (!n.ok && n.status >= 500) i && console.log(y, `fetchWithRetry: HTTP ${n.status} on attempt ${a + 1}`), o = /* @__PURE__ */ Error(`HTTP ${n.status}`);
71
+ if (!n.ok && n.status >= 500) i && console.log(b, `fetchWithRetry: HTTP ${n.status} on attempt ${a + 1}`), o = /* @__PURE__ */ Error(`HTTP ${n.status}`);
72
72
  else return n;
73
73
  } catch (e) {
74
- i && console.log(y, `fetchWithRetry: network error on attempt ${a + 1}`, e), o = e;
74
+ i && console.log(b, `fetchWithRetry: network error on attempt ${a + 1}`, e), o = e;
75
75
  }
76
76
  a++, a <= n && await new Promise((e) => setTimeout(e, r));
77
77
  }
78
78
  throw o;
79
79
  }
80
- function x(e) {
81
- e.debug && console.log(y, "Client Options : ", e);
80
+ function S(e) {
81
+ e.debug && console.log(b, "Client Options : ", e);
82
82
  let t = e.origin.replace(/\/+$/, ""), n = {
83
83
  redirect: "follow",
84
84
  headers: {
@@ -87,23 +87,23 @@ function x(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 _() : new v(e.cacheTTL);
90
+ }, r = e.cacheTTL === !1 ? new p() : new m(e.cacheTTL);
91
91
  return {
92
92
  async getSpace() {
93
- e.debug && console.log(y, "getSpace()");
93
+ e.debug && console.log(b, "getSpace()");
94
94
  let i = `${t}/api/v1/spaces/${e.spaceId}?token=${e.token}`;
95
- if (e.debug && console.log(y, "getSpace fetch url : ", i), r.has(i)) return e.debug && console.log(y, "getSpace cache hit"), r.get(i);
95
+ if (e.debug && console.log(b, "getSpace fetch url : ", i), r.has(i)) return e.debug && console.log(b, "getSpace cache hit"), r.get(i);
96
96
  try {
97
- let t = await b(i, n, e.retryCount, e.retryDelay, e.debug);
98
- e.debug && console.log(y, "getSpace status : ", t.status);
97
+ let t = await x(i, n, e.retryCount, e.retryDelay, e.debug);
98
+ e.debug && console.log(b, "getSpace status : ", t.status);
99
99
  let a = await t.json();
100
100
  return r.set(i, a), a;
101
101
  } catch (e) {
102
- return console.error(y, "getSpace error : ", e), {};
102
+ return console.error(b, "getSpace error : ", e), {};
103
103
  }
104
104
  },
105
105
  async getLinks(i) {
106
- e.debug && console.log(y, "getLinks() params : ", JSON.stringify(i));
106
+ e.debug && console.log(b, "getLinks() params : ", JSON.stringify(i));
107
107
  let a = "";
108
108
  i?.kind && (a = `&kind=${i.kind}`);
109
109
  let o = "";
@@ -111,72 +111,72 @@ function x(e) {
111
111
  let s = "";
112
112
  i?.excludeChildren && (s = `&excludeChildren=${i.excludeChildren}`);
113
113
  let c = `${t}/api/v1/spaces/${e.spaceId}/links?token=${e.token}${a}${o}${s}`;
114
- if (e.debug && console.log(y, "getLinks fetch url : ", c), r.has(c)) return e.debug && console.log(y, "getLinks cache hit"), r.get(c);
114
+ if (e.debug && console.log(b, "getLinks fetch url : ", c), r.has(c)) return e.debug && console.log(b, "getLinks cache hit"), r.get(c);
115
115
  try {
116
- let t = await b(c, n, e.retryCount, e.retryDelay, e.debug);
117
- e.debug && console.log(y, "getLinks status : ", t.status);
116
+ let t = await x(c, n, e.retryCount, e.retryDelay, e.debug);
117
+ e.debug && console.log(b, "getLinks status : ", t.status);
118
118
  let i = await t.json();
119
119
  return r.set(c, i), i;
120
120
  } catch (e) {
121
- return console.error(y, "getLinks error : ", e), {};
121
+ return console.error(b, "getLinks error : ", e), {};
122
122
  }
123
123
  },
124
124
  async getContentBySlug(i, a) {
125
- e.debug && (console.log(y, "getContentBySlug() slug : ", i), console.log(y, "getContentBySlug() params : ", JSON.stringify(a)));
125
+ e.debug && (console.log(b, "getContentBySlug() slug : ", i), console.log(b, "getContentBySlug() params : ", JSON.stringify(a)));
126
126
  let o = "";
127
127
  e?.version && e.version == "draft" && (o = `&version=${e.version}`), a?.version && a.version == "draft" && (o = `&version=${a.version}`);
128
128
  let s = a?.locale ? `&locale=${a.locale}` : "", c = a?.resolveReference ? `&resolveReference=${a.resolveReference}` : "", l = a?.resolveLink ? `&resolveLink=${a.resolveLink}` : "", u = `${t}/api/v1/spaces/${e.spaceId}/contents/slugs/${i}?token=${e.token}${o}${s}${c}${l}`;
129
- if (e.debug && console.log(y, "getContentBySlug fetch url : ", u), r.has(u)) return e.debug && console.log(y, "getContentBySlug cache hit"), r.get(u);
129
+ if (e.debug && console.log(b, "getContentBySlug fetch url : ", u), r.has(u)) return e.debug && console.log(b, "getContentBySlug cache hit"), r.get(u);
130
130
  try {
131
- let t = await b(u, n, e.retryCount, e.retryDelay, e.debug);
132
- e.debug && console.log(y, "getContentBySlug status : ", t.status);
131
+ let t = await x(u, n, e.retryCount, e.retryDelay, e.debug);
132
+ e.debug && console.log(b, "getContentBySlug status : ", t.status);
133
133
  let i = await t.json();
134
134
  return r.set(u, i), i;
135
135
  } catch (e) {
136
- return console.error(y, "getContentBySlug error : ", e), {};
136
+ return console.error(b, "getContentBySlug error : ", e), {};
137
137
  }
138
138
  },
139
139
  async getContentById(i, a) {
140
- e.debug && (console.log(y, "getContentById() id : ", i), console.log(y, "getContentById() params : ", JSON.stringify(a)));
140
+ e.debug && (console.log(b, "getContentById() id : ", i), console.log(b, "getContentById() params : ", JSON.stringify(a)));
141
141
  let o = "";
142
142
  e?.version && e.version == "draft" && (o = `&version=${e.version}`), a?.version && a.version == "draft" && (o = `&version=${a.version}`);
143
143
  let s = a?.locale ? `&locale=${a.locale}` : "", c = a?.resolveReference ? `&resolveReference=${a.resolveReference}` : "", l = a?.resolveLink ? `&resolveLink=${a.resolveLink}` : "", u = `${t}/api/v1/spaces/${e.spaceId}/contents/${i}?token=${e.token}${o}${s}${c}${l}`;
144
- if (e.debug && console.log(y, "getContentById fetch url : ", u), r.has(u)) return e.debug && console.log(y, "getContentById cache hit"), r.get(u);
144
+ if (e.debug && console.log(b, "getContentById fetch url : ", u), r.has(u)) return e.debug && console.log(b, "getContentById cache hit"), r.get(u);
145
145
  try {
146
- let t = await b(u, n, e.retryCount, e.retryDelay, e.debug);
147
- e.debug && console.log(y, "getContentById status : ", t.status);
146
+ let t = await x(u, n, e.retryCount, e.retryDelay, e.debug);
147
+ e.debug && console.log(b, "getContentById status : ", t.status);
148
148
  let i = await t.json();
149
149
  return r.set(u, i), i;
150
150
  } catch (e) {
151
- return console.error(y, "getContentById error : ", e), {};
151
+ return console.error(b, "getContentById error : ", e), {};
152
152
  }
153
153
  },
154
154
  async getTranslations(i, a) {
155
- e.debug && (console.log(y, "getTranslations() locale : ", i), console.log(y, "getTranslations() params : ", JSON.stringify(a)));
155
+ e.debug && (console.log(b, "getTranslations() locale : ", i), console.log(b, "getTranslations() params : ", JSON.stringify(a)));
156
156
  let o = "";
157
157
  e?.version && e.version == "draft" && (o = `&version=${e.version}`), a?.version && a.version == "draft" && (o = `&version=${a.version}`);
158
158
  let s = `${t}/api/v1/spaces/${e.spaceId}/translations/${i}?token=${e.token}${o}`;
159
- if (e.debug && console.log(y, "getTranslations fetch url : ", s), r.has(s)) return e.debug && console.log(y, "getTranslations cache hit"), r.get(s);
159
+ if (e.debug && console.log(b, "getTranslations fetch url : ", s), r.has(s)) return e.debug && console.log(b, "getTranslations cache hit"), r.get(s);
160
160
  try {
161
- let t = await b(s, n, e.retryCount, e.retryDelay, e.debug);
162
- e.debug && console.log(y, "getTranslations status : ", t.status);
161
+ let t = await x(s, n, e.retryCount, e.retryDelay, e.debug);
162
+ e.debug && console.log(b, "getTranslations status : ", t.status);
163
163
  let i = await t.json();
164
164
  return r.set(s, i), i;
165
165
  } catch (e) {
166
- return console.error(y, "getTranslations error : ", e), {};
166
+ return console.error(b, "getTranslations error : ", e), {};
167
167
  }
168
168
  },
169
169
  async updateTranslations(r, i, a, o) {
170
- e.debug && (console.log(y, "updateTranslations() locale : ", r), console.log(y, "updateTranslations() type : ", i), console.log(y, "updateTranslations() values : ", JSON.stringify(a)));
170
+ e.debug && (console.log(b, "updateTranslations() locale : ", r), console.log(b, "updateTranslations() type : ", i), console.log(b, "updateTranslations() values : ", JSON.stringify(a)));
171
171
  let s = `${t}/api/v1/spaces/${e.spaceId}/translations/${r}`;
172
- e.debug && console.log(y, "updateTranslations fetch url : ", s);
172
+ e.debug && console.log(b, "updateTranslations fetch url : ", s);
173
173
  let c = {
174
174
  type: i,
175
175
  values: a,
176
176
  dryRun: o
177
177
  };
178
178
  try {
179
- let t = await b(s, {
179
+ let t = await x(s, {
180
180
  method: "POST",
181
181
  headers: {
182
182
  "X-API-KEY": e.token,
@@ -184,35 +184,35 @@ function x(e) {
184
184
  },
185
185
  body: JSON.stringify(c)
186
186
  }, e.retryCount, e.retryDelay, e.debug);
187
- return e.debug && console.log(y, "updateTranslations status : ", t.status), t.json();
187
+ return e.debug && console.log(b, "updateTranslations status : ", t.status), t.json();
188
188
  } catch (e) {
189
- console.error(y, "updateTranslations error : ", e);
189
+ console.error(b, "updateTranslations error : ", e);
190
190
  }
191
191
  },
192
192
  async getOpenApi() {
193
- e.debug && console.log(y, "getOpenApi()");
193
+ e.debug && console.log(b, "getOpenApi()");
194
194
  let i = `${t}/api/v1/spaces/${e.spaceId}/open-api?token=${e.token}`;
195
- if (e.debug && console.log(y, "getOpenApi fetch url : ", i), r.has(i)) return e.debug && console.log(y, "getOpenApi cache hit"), r.get(i);
195
+ if (e.debug && console.log(b, "getOpenApi fetch url : ", i), r.has(i)) return e.debug && console.log(b, "getOpenApi cache hit"), r.get(i);
196
196
  try {
197
- let t = await b(i, n, e.retryCount, e.retryDelay, e.debug);
198
- e.debug && console.log(y, "getOpenApi status : ", t.status);
197
+ let t = await x(i, n, e.retryCount, e.retryDelay, e.debug);
198
+ e.debug && console.log(b, "getOpenApi status : ", t.status);
199
199
  let a = await t.json();
200
200
  return r.set(i, a), a;
201
201
  } catch (e) {
202
- return console.error(y, "getOpenApi error : ", e), {};
202
+ return console.error(b, "getOpenApi error : ", e), {};
203
203
  }
204
204
  },
205
205
  async getSchemas() {
206
- e.debug && console.log(y, "getSchemas()");
206
+ e.debug && console.log(b, "getSchemas()");
207
207
  let i = `${t}/api/v1/spaces/${e.spaceId}/schemas?token=${e.token}`;
208
- if (e.debug && console.log(y, "getSchemas fetch url : ", i), r.has(i)) return e.debug && console.log(y, "getSchemas cache hit"), r.get(i);
208
+ if (e.debug && console.log(b, "getSchemas fetch url : ", i), r.has(i)) return e.debug && console.log(b, "getSchemas cache hit"), r.get(i);
209
209
  try {
210
- let t = await b(i, n, e.retryCount, e.retryDelay, e.debug);
211
- e.debug && console.log(y, "getSchemas status : ", t.status);
210
+ let t = await x(i, n, e.retryCount, e.retryDelay, e.debug);
211
+ e.debug && console.log(b, "getSchemas status : ", t.status);
212
212
  let a = await t.json();
213
213
  return r.set(i, a), a;
214
214
  } catch (e) {
215
- return console.error(y, "getSchemas error : ", e), {};
215
+ return console.error(b, "getSchemas error : ", e), {};
216
216
  }
217
217
  },
218
218
  assetLink(n) {
@@ -222,26 +222,33 @@ function x(e) {
222
222
  }
223
223
  //#endregion
224
224
  //#region src/file.ts
225
- var S = ".localess";
226
- async function C(e, t, n) {
227
- let r = c(e).dir;
225
+ var C = ".localess";
226
+ async function w(e, t, n) {
227
+ let r = l(e).dir;
228
228
  try {
229
- await i(r, { recursive: !0 });
229
+ await a(r, { recursive: !0 });
230
230
  } catch {
231
231
  return;
232
232
  }
233
233
  try {
234
- await o(e, t, n);
234
+ await s(e, t, n);
235
235
  } catch {}
236
236
  }
237
- async function w(e) {
238
- return a(e, "utf-8");
237
+ async function T(e) {
238
+ return o(e, "utf-8");
239
+ }
240
+ async function E(e, t) {
241
+ let n = c(e, ".gitignore"), r = "";
242
+ try {
243
+ r = await o(n, "utf-8");
244
+ } catch {}
245
+ r.split("\n").map((e) => e.trim()).includes(t) || await i(n, `${r.length > 0 && !r.endsWith("\n") ? "\n" : ""}${t}\n`, "utf-8");
239
246
  }
240
247
  //#endregion
241
248
  //#region src/session.ts
242
- var T = s(l.cwd(), S, "credentials.json");
243
- async function E() {
244
- let e = { isLoggedIn: !1 }, t = l.env.LOCALESS_TOKEN, n = l.env.LOCALESS_SPACE, i = l.env.LOCALESS_ORIGIN;
249
+ var D = c(u.cwd(), C, "credentials.json");
250
+ async function O() {
251
+ let e = { isLoggedIn: !1 }, t = u.env.LOCALESS_TOKEN, n = u.env.LOCALESS_SPACE, i = u.env.LOCALESS_ORIGIN;
245
252
  if (t && n && i) return console.debug("Login in using environment variables."), {
246
253
  isLoggedIn: !0,
247
254
  space: n,
@@ -250,8 +257,8 @@ async function E() {
250
257
  method: "env"
251
258
  };
252
259
  try {
253
- await r(T);
254
- let t = await a(T, "utf8"), n = JSON.parse(t);
260
+ await r(D);
261
+ let t = await o(D, "utf8"), n = JSON.parse(t);
255
262
  if (Object.keys(n).length === 0) return e;
256
263
  if (n.origin && n.token && n.space) return console.debug("Login in using credentials file."), {
257
264
  isLoggedIn: !0,
@@ -263,21 +270,21 @@ async function E() {
263
270
  } catch {}
264
271
  return e;
265
272
  }
266
- async function D(e) {
267
- if (e.origin && e.token && e.space) await C(T, JSON.stringify(e, null, 2), { mode: 384 }), console.log("Add session credentials to file system."), console.log("Add .localess to .gitignore to avoid committing them to your repository.");
273
+ async function k(e) {
274
+ if (e.origin && e.token && e.space) await w(D, JSON.stringify(e, null, 2), { mode: 384 }), console.log("Session credentials saved to file system."), await E(u.cwd(), C), console.log(`Added '${C}' to .gitignore to prevent credentials from being committed.`);
268
275
  else throw Error("Cannot persist session: missing required fields.");
269
276
  }
270
- async function O() {
277
+ async function A() {
271
278
  try {
272
- await r(T), await C(T, "{}", { mode: 384 });
279
+ await r(D), await w(D, "{}", { mode: 384 });
273
280
  } catch {
274
281
  throw Error("Failed to clear session credentials.");
275
282
  }
276
283
  }
277
284
  //#endregion
278
285
  //#region src/commands/login/index.ts
279
- var k = 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) => {
280
- if ((await E()).isLoggedIn) {
286
+ var j = 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) => {
287
+ if ((await O()).isLoggedIn) {
281
288
  console.log("Already logged in."), console.log("If you want to log in with different credentials, please log out first using \"localess logout\" command.");
282
289
  return;
283
290
  }
@@ -290,14 +297,14 @@ var k = new e("login").description("Login to Localess CLI").option("-o, --origin
290
297
  }), a = e.token ?? await n({
291
298
  message: "Token:",
292
299
  mask: !0
293
- }), o = x({
300
+ }), o = S({
294
301
  origin: r,
295
302
  spaceId: i,
296
303
  token: a
297
304
  });
298
305
  try {
299
306
  let e = await o.getSpace();
300
- console.log(`Successfully logged in to space: ${e.name} (${e.id})`), await D({
307
+ console.log(`Successfully logged in to space: ${e.name} (${e.id})`), await k({
301
308
  origin: r,
302
309
  space: i,
303
310
  token: a
@@ -305,9 +312,9 @@ var k = new e("login").description("Login to Localess CLI").option("-o, --origin
305
312
  } catch {
306
313
  console.error("Login failed");
307
314
  }
308
- }), A = new e("logout").description("Logout from Localess CLI").action(async () => {
315
+ }), M = new e("logout").description("Logout from Localess CLI").action(async () => {
309
316
  console.log("Logging out...");
310
- let e = await E();
317
+ let e = await O();
311
318
  if (!e.isLoggedIn) {
312
319
  console.log("Not currently logged in.");
313
320
  return;
@@ -317,22 +324,78 @@ var k = new e("login").description("Login to Localess CLI").option("-o, --origin
317
324
  return;
318
325
  }
319
326
  try {
320
- await O(), console.log("Successfully logged out.");
327
+ await A(), console.log("Successfully logged out.");
321
328
  } catch (e) {
322
329
  console.error("Failed to log out:", e);
323
330
  }
324
- }), j = /* @__PURE__ */ function(e) {
331
+ }), N = /* @__PURE__ */ function(e) {
325
332
  return e.ROOT = "ROOT", e.NODE = "NODE", e.ENUM = "ENUM", e;
326
- }({}), M = /* @__PURE__ */ function(e) {
333
+ }({}), P = /* @__PURE__ */ function(e) {
327
334
  return e.TEXT = "TEXT", e.TEXTAREA = "TEXTAREA", e.RICH_TEXT = "RICH_TEXT", e.MARKDOWN = "MARKDOWN", e.NUMBER = "NUMBER", e.COLOR = "COLOR", e.DATE = "DATE", e.DATETIME = "DATETIME", e.BOOLEAN = "BOOLEAN", e.OPTION = "OPTION", e.OPTIONS = "OPTIONS", e.LINK = "LINK", e.REFERENCE = "REFERENCE", e.REFERENCES = "REFERENCES", e.ASSET = "ASSET", e.ASSETS = "ASSETS", e.SCHEMA = "SCHEMA", e.SCHEMAS = "SCHEMAS", e;
328
- }({}), N = /* @__PURE__ */ function(e) {
335
+ }({}), F = /* @__PURE__ */ function(e) {
329
336
  return e.ADD_MISSING = "add-missing", e.UPDATE_EXISTING = "update-existing", e.DELETE_MISSING = "delete-missing", e;
330
- }({}), P = /* @__PURE__ */ function(e) {
337
+ }({}), I = /* @__PURE__ */ function(e) {
331
338
  return e.FLAT = "flat", e.NESTED = "nested", e;
332
- }({});
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);
333
396
  //#endregion
334
397
  //#region src/commands/types/generate/generator.ts
335
- function F(e) {
398
+ function H(e) {
336
399
  return `/**
337
400
  * Generated by Localess CLI
338
401
  * Do not edit manually.
@@ -383,49 +446,49 @@ export interface ${e}ContentRichText {
383
446
  }
384
447
  `;
385
448
  }
386
- function I(e) {
449
+ function U(e) {
387
450
  return e.replace(/[-_\s]+([a-zA-Z0-9])/g, (e, t) => t.toUpperCase()).replace(/^[a-z]/, (e) => e.toUpperCase());
388
451
  }
389
- function L(e, t) {
452
+ function W(e, t) {
390
453
  switch (e.kind) {
391
- case M.TEXT:
392
- case M.TEXTAREA:
393
- case M.MARKDOWN:
394
- case M.COLOR:
395
- case M.DATE:
396
- case M.DATETIME: return "string";
397
- case M.NUMBER: return "number";
398
- case M.BOOLEAN: return "boolean";
399
- case M.RICH_TEXT: return `${t}ContentRichText`;
400
- case M.LINK: return `${t}ContentLink`;
401
- case M.ASSET: return `${t}ContentAsset`;
402
- case M.ASSETS: return `${t}ContentAsset[]`;
403
- case M.REFERENCE: return `${t}ContentReference`;
404
- case M.REFERENCES: return `${t}ContentReference[]`;
405
- case M.OPTION: return e.source ? t + I(e.source) : "string";
406
- case M.OPTIONS: return e.source ? `${t + I(e.source)}[]` : "string[]";
407
- case M.SCHEMA: {
454
+ case P.TEXT:
455
+ case P.TEXTAREA:
456
+ case P.MARKDOWN:
457
+ case P.COLOR:
458
+ case P.DATE:
459
+ case P.DATETIME: return "string";
460
+ case P.NUMBER: return "number";
461
+ case P.BOOLEAN: return "boolean";
462
+ case P.RICH_TEXT: return `${t}ContentRichText`;
463
+ case P.LINK: return `${t}ContentLink`;
464
+ case P.ASSET: return `${t}ContentAsset`;
465
+ case P.ASSETS: return `${t}ContentAsset[]`;
466
+ case P.REFERENCE: return `${t}ContentReference`;
467
+ case P.REFERENCES: return `${t}ContentReference[]`;
468
+ case P.OPTION: return e.source ? t + U(e.source) : "string";
469
+ case P.OPTIONS: return e.source ? `${t + U(e.source)}[]` : "string[]";
470
+ case P.SCHEMA: {
408
471
  let n = e.schemas;
409
472
  if (!n || n.length === 0) return "unknown";
410
- let r = n.map((e) => t + I(e));
473
+ let r = n.map((e) => t + U(e));
411
474
  return r.length === 1 ? r[0] : r.join(" | ");
412
475
  }
413
- case M.SCHEMAS: {
476
+ case P.SCHEMAS: {
414
477
  let n = e.schemas;
415
478
  if (!n || n.length === 0) return "unknown[]";
416
- let r = n.map((e) => t + I(e));
479
+ let r = n.map((e) => t + U(e));
417
480
  return `${r.length === 1 ? r[0] : `(${r.join(" | ")})`}[]`;
418
481
  }
419
482
  }
420
483
  }
421
- function R(e, t = "") {
484
+ function G(e, t = "") {
422
485
  return `${t}/**\n${t} * ${e}\n${t} */`;
423
486
  }
424
- function z(e, t = "") {
425
- let n = [F(t)], r = [];
487
+ function K(e, t = "") {
488
+ let n = [H(t)], r = [];
426
489
  for (let [i, a] of Object.entries(e)) {
427
- let e = t + I(i), o = a.description ? `${R(a.description)}\n` : "";
428
- if (a.type === j.ENUM) {
490
+ let e = t + U(i), o = a.description ? `${G(a.description)}\n` : "";
491
+ if (a.type === N.ENUM) {
429
492
  let t = a.values ?? [];
430
493
  if (t.length === 0) n.push(`${o}export type ${e} = string;\n`);
431
494
  else {
@@ -434,14 +497,14 @@ function z(e, t = "") {
434
497
  }
435
498
  } else {
436
499
  let s = a;
437
- a.type === j.ROOT && r.push(e);
500
+ a.type === N.ROOT && r.push(e);
438
501
  let c = [
439
502
  " /** Unique identifier of a component in a content. */",
440
503
  " _id: string;",
441
504
  " /** Unique identifier for the Schema object. */",
442
505
  ` _schema: '${i}';`,
443
506
  ...(s.fields ?? []).slice().sort((e, t) => e.name.localeCompare(t.name)).flatMap((e) => {
444
- let n = L(e, t), r = e.required ? "" : "?", i = [];
507
+ let n = W(e, t), r = e.required ? "" : "?", i = [];
445
508
  return e.description && i.push(` /** ${e.description} */`), i.push(` ${e.name}${r}: ${n};`), i;
446
509
  })
447
510
  ];
@@ -452,14 +515,14 @@ function z(e, t = "") {
452
515
  }
453
516
  //#endregion
454
517
  //#region src/commands/types/generate/index.ts
455
- var B = s(u.cwd(), S, "localess.ts"), V = 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", B).option("--prefix <prefix>", "Prefix to prepend to all generated type names", "").action(async (e) => {
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) => {
456
519
  console.log("Types in with options:", e);
457
- let t = await E();
520
+ let t = await O();
458
521
  if (!t.isLoggedIn) {
459
522
  console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
460
523
  return;
461
524
  }
462
- let n = x({
525
+ let n = S({
463
526
  origin: t.origin,
464
527
  spaceId: t.space,
465
528
  token: t.token
@@ -467,70 +530,14 @@ var B = s(u.cwd(), S, "localess.ts"), V = new e("generate").description("Generat
467
530
  console.log("Fetching schemas from Localess...");
468
531
  let r = await n.getSchemas();
469
532
  console.log("Generating types...");
470
- let i = z(r, e.prefix);
471
- await C(e.path, i), console.log(`Types written to ${e.path}`);
472
- }), H = new e("types").description("Generate types for your schemas").addCommand(V), U = d.record(d.string(), d.string()), W = d.enum(["add-missing", "update-existing"]);
473
- d.object({
474
- type: W,
475
- values: U
476
- });
477
- //#endregion
478
- //#region src/commands/translations/push/index.ts
479
- var G = 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(P)}`, P.FLAT).option("-t, --type <type>", `Push type. Possible values are : ${Object.values(N)}`, N.ADD_MISSING).option("--dry-run", "Preview changes without applying them to Localess").action(async (e, t) => {
480
- if (console.log("Pushing translations with arguments:", e), console.log("Pushing translations with options:", t), !W.safeParse(t.type).success) {
481
- console.error("Invalid type provided. Possible values are :", Object.values(N));
482
- return;
483
- }
484
- let n = await E();
485
- if (!n.isLoggedIn) {
486
- console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
487
- return;
488
- }
489
- let r = x({
490
- origin: n.origin,
491
- spaceId: n.space,
492
- token: n.token
493
- });
494
- t.dryRun && console.warn("Dry run mode enabled: No changes will be made."), console.log("Reading translations file from:", t.path);
495
- let i = await w(t.path), a = JSON.parse(i), o;
496
- o = t.format === P.NESTED ? h(a) : a;
497
- let s = U.safeParse(o);
498
- if (!s.success) {
499
- console.error("Invalid translations file format:", s.error);
500
- return;
501
- }
502
- console.log("Pushing translations to Localess with locale:", e, "and type:", t.type);
503
- let c = await r.updateTranslations(e, t.type, o, t.dryRun);
504
- 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");
505
- }), K = 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(P)}`, P.FLAT).action(async (e, t) => {
506
- if (console.log("Pulling translations with arguments:", e), console.log("Pulling translations with options:", t), !Object.values(P).includes(t.format)) {
507
- console.error("Invalid format provided. Possible values are :", Object.values(P));
508
- return;
509
- }
510
- let n = await E();
511
- if (!n.isLoggedIn) {
512
- console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
513
- return;
514
- }
515
- let r = x({
516
- origin: n.origin,
517
- spaceId: n.space,
518
- token: n.token
519
- });
520
- console.log("Pulling translations from Localess for locale:", e);
521
- let i = await r.getTranslations(e);
522
- if (console.log("Saving translations in file:", t.path), t.format === P.FLAT) await C(t.path, JSON.stringify(m(i), null, 2));
523
- else if (t.format === P.NESTED) {
524
- let e = m(g(i));
525
- await C(t.path, JSON.stringify(e, null, 2));
526
- }
527
- console.log("Successfully saved translations from Localess");
528
- }), q = new e("translations").description("Manage translations").addCommand(G).addCommand(K), J = new e();
529
- J.name("Localess CLI").description("CLI tool for Localess platform management").version("3.0.5"), J.addCommand(k), J.addCommand(A), J.addCommand(q), J.addCommand(H);
533
+ let i = K(r, e.prefix);
534
+ await w(e.path, i), console.log(`Types written to ${e.path}`);
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);
530
537
  //#endregion
531
538
  //#region src/index.ts
532
539
  try {
533
- J.parse(process.argv);
540
+ X.parse(process.argv);
534
541
  } catch (e) {
535
542
  console.error("Error executing command:", e instanceof Error ? e.message : e), process.exit(1);
536
543
  }