@localess/cli 3.0.7-dev.20260512203425 → 3.0.7-dev.20260514085047

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 (38) hide show
  1. package/dist/index.mjs +190 -136
  2. package/dist/{client.d.ts → src/client.d.ts} +3 -3
  3. package/dist/src/version-check.d.ts +2 -0
  4. package/dist/src/version-check.test.d.ts +1 -0
  5. package/package.json +1 -1
  6. /package/dist/{cache.d.ts → src/cache.d.ts} +0 -0
  7. /package/dist/{commands → src/commands}/login/index.d.ts +0 -0
  8. /package/dist/{commands → src/commands}/login/login.test.d.ts +0 -0
  9. /package/dist/{commands → src/commands}/logout/index.d.ts +0 -0
  10. /package/dist/{commands → src/commands}/translations/index.d.ts +0 -0
  11. /package/dist/{commands → src/commands}/translations/pull/index.d.ts +0 -0
  12. /package/dist/{commands → src/commands}/translations/push/index.d.ts +0 -0
  13. /package/dist/{commands → src/commands}/types/generate/generator.d.ts +0 -0
  14. /package/dist/{commands → src/commands}/types/generate/generator.test.d.ts +0 -0
  15. /package/dist/{commands → src/commands}/types/generate/index.d.ts +0 -0
  16. /package/dist/{commands → src/commands}/types/index.d.ts +0 -0
  17. /package/dist/{commands → src/commands}/types/types.test.d.ts +0 -0
  18. /package/dist/{file.d.ts → src/file.d.ts} +0 -0
  19. /package/dist/{index.d.ts → src/index.d.ts} +0 -0
  20. /package/dist/{models → src/models}/content-asset.d.ts +0 -0
  21. /package/dist/{models → src/models}/content-data.d.ts +0 -0
  22. /package/dist/{models → src/models}/content-link.d.ts +0 -0
  23. /package/dist/{models → src/models}/content-metadata.d.ts +0 -0
  24. /package/dist/{models → src/models}/content-reference.d.ts +0 -0
  25. /package/dist/{models → src/models}/content-rich-text.d.ts +0 -0
  26. /package/dist/{models → src/models}/content.d.ts +0 -0
  27. /package/dist/{models → src/models}/index.d.ts +0 -0
  28. /package/dist/{models → src/models}/links.d.ts +0 -0
  29. /package/dist/{models → src/models}/locale.d.ts +0 -0
  30. /package/dist/{models → src/models}/references.d.ts +0 -0
  31. /package/dist/{models → src/models}/schema.d.ts +0 -0
  32. /package/dist/{models → src/models}/space.d.ts +0 -0
  33. /package/dist/{models → src/models}/translation.zod.d.ts +0 -0
  34. /package/dist/{models → src/models}/translations.d.ts +0 -0
  35. /package/dist/{program.d.ts → src/program.d.ts} +0 -0
  36. /package/dist/{session.d.ts → src/session.d.ts} +0 -0
  37. /package/dist/{utils.d.ts → src/utils.d.ts} +0 -0
  38. /package/dist/{utils.test.d.ts → src/utils.test.d.ts} +0 -0
package/dist/index.mjs CHANGED
@@ -6,8 +6,9 @@ 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
+ import p from "chalk";
9
10
  //#region src/cache.ts
10
- var p = class {
11
+ var ee = class {
11
12
  set(e, t) {}
12
13
  get(e) {}
13
14
  has(e) {
@@ -37,22 +38,22 @@ var p = class {
37
38
  has(e) {
38
39
  return this.get(e) !== void 0;
39
40
  }
40
- }, h = "\x1B[0m", g = "\x1B[34m";
41
- function _(e) {
41
+ }, te = "\x1B[0m", ne = "\x1B[34m";
42
+ function h(e) {
42
43
  return Object.keys(e).sort().reduce((t, n) => {
43
44
  let r = e[n];
44
- return t[n] = typeof r == "object" && r && !Array.isArray(r) ? _(r) : r, t;
45
+ return t[n] = typeof r == "object" && r && !Array.isArray(r) ? h(r) : r, t;
45
46
  }, {});
46
47
  }
47
- function v(e, t = "") {
48
+ function g(e, t = "") {
48
49
  let n = {};
49
50
  for (let [r, i] of Object.entries(e)) {
50
51
  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
+ typeof i == "object" && i && !Array.isArray(i) ? Object.assign(n, g(i, e)) : n[e] = String(i);
52
53
  }
53
54
  return n;
54
55
  }
55
- function y(e) {
56
+ function _(e) {
56
57
  let t = {};
57
58
  for (let [n, r] of Object.entries(e)) {
58
59
  let e = n.split("."), i = t;
@@ -62,23 +63,23 @@ function y(e) {
62
63
  }
63
64
  //#endregion
64
65
  //#region src/client.ts
65
- var b = `${g}[Localess:Client]${h}`;
66
- async function x(e, t, n = 3, r = 500, i) {
66
+ var v = `${ne}[Localess:Client]${te}`;
67
+ async function y(e, t, n = 3, r = 500, i) {
67
68
  let a = 0, o;
68
69
  for (; a <= n;) {
69
70
  try {
70
71
  let n = await fetch(e, t);
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
+ if (!n.ok && n.status >= 500) i && console.log(v, `fetchWithRetry: HTTP ${n.status} on attempt ${a + 1}`), o = /* @__PURE__ */ Error(`HTTP ${n.status}`);
72
73
  else return n;
73
74
  } catch (e) {
74
- i && console.log(b, `fetchWithRetry: network error on attempt ${a + 1}`, e), o = e;
75
+ i && console.log(v, `fetchWithRetry: network error on attempt ${a + 1}`, e), o = e;
75
76
  }
76
77
  a++, a <= n && await new Promise((e) => setTimeout(e, r));
77
78
  }
78
79
  throw o;
79
80
  }
80
- function S(e) {
81
- e.debug && console.log(b, "Client Options : ", e);
81
+ function b(e) {
82
+ e.debug && console.log(v, "Client Options : ", e);
82
83
  let t = e.origin.replace(/\/+$/, ""), n = {
83
84
  redirect: "follow",
84
85
  headers: {
@@ -87,23 +88,23 @@ function S(e) {
87
88
  "X-Localess-Agent": "Localess-CLI-Client",
88
89
  "X-Localess-Agent-Version": "0.9.0"
89
90
  }
90
- }, r = typeof e.cacheTTL == "number" ? e.cacheTTL * 1e3 : void 0, i = e.cacheTTL === !1 ? new p() : new m(r);
91
+ }, r = typeof e.cacheTTL == "number" ? e.cacheTTL * 1e3 : void 0, i = e.cacheTTL === !1 ? new ee() : new m(r);
91
92
  return {
92
93
  async getSpace() {
93
- e.debug && console.log(b, "getSpace()");
94
+ e.debug && console.log(v, "getSpace()");
94
95
  let r = `${t}/api/v1/spaces/${e.spaceId}?token=${e.token}`;
95
- if (e.debug && console.log(b, "getSpace fetch url : ", r), i.has(r)) return e.debug && console.log(b, "getSpace cache hit"), i.get(r);
96
+ if (e.debug && console.log(v, "getSpace fetch url : ", r), i.has(r)) return e.debug && console.log(v, "getSpace cache hit"), i.get(r);
96
97
  try {
97
- let t = await x(r, n, e.retryCount, e.retryDelay, e.debug);
98
- e.debug && console.log(b, "getSpace status : ", t.status);
98
+ let t = await y(r, n, e.retryCount, e.retryDelay, e.debug);
99
+ e.debug && console.log(v, "getSpace status : ", t.status);
99
100
  let a = await t.json();
100
101
  return i.set(r, a), a;
101
102
  } catch (e) {
102
- return console.error(b, "getSpace error : ", e), {};
103
+ return console.error(v, "getSpace error : ", e), {};
103
104
  }
104
105
  },
105
106
  async getLinks(r) {
106
- e.debug && console.log(b, "getLinks() params : ", JSON.stringify(r));
107
+ e.debug && console.log(v, "getLinks() params : ", JSON.stringify(r));
107
108
  let a = "";
108
109
  r?.kind && (a = `&kind=${r.kind}`);
109
110
  let o = "";
@@ -111,72 +112,72 @@ function S(e) {
111
112
  let s = "";
112
113
  r?.excludeChildren && (s = `&excludeChildren=${r.excludeChildren}`);
113
114
  let c = `${t}/api/v1/spaces/${e.spaceId}/links?token=${e.token}${a}${o}${s}`;
114
- if (e.debug && console.log(b, "getLinks fetch url : ", c), i.has(c)) return e.debug && console.log(b, "getLinks cache hit"), i.get(c);
115
+ if (e.debug && console.log(v, "getLinks fetch url : ", c), i.has(c)) return e.debug && console.log(v, "getLinks cache hit"), i.get(c);
115
116
  try {
116
- let t = await x(c, n, e.retryCount, e.retryDelay, e.debug);
117
- e.debug && console.log(b, "getLinks status : ", t.status);
117
+ let t = await y(c, n, e.retryCount, e.retryDelay, e.debug);
118
+ e.debug && console.log(v, "getLinks status : ", t.status);
118
119
  let r = await t.json();
119
120
  return i.set(c, r), r;
120
121
  } catch (e) {
121
- return console.error(b, "getLinks error : ", e), {};
122
+ return console.error(v, "getLinks error : ", e), {};
122
123
  }
123
124
  },
124
125
  async getContentBySlug(r, a) {
125
- e.debug && (console.log(b, "getContentBySlug() slug : ", r), console.log(b, "getContentBySlug() params : ", JSON.stringify(a)));
126
+ e.debug && (console.log(v, "getContentBySlug() slug : ", r), console.log(v, "getContentBySlug() params : ", JSON.stringify(a)));
126
127
  let o = "";
127
128
  e?.version && e.version == "draft" && (o = `&version=${e.version}`), a?.version && a.version == "draft" && (o = `&version=${a.version}`);
128
129
  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/${r}?token=${e.token}${o}${s}${c}${l}`;
129
- if (e.debug && console.log(b, "getContentBySlug fetch url : ", u), i.has(u)) return e.debug && console.log(b, "getContentBySlug cache hit"), i.get(u);
130
+ if (e.debug && console.log(v, "getContentBySlug fetch url : ", u), i.has(u)) return e.debug && console.log(v, "getContentBySlug cache hit"), i.get(u);
130
131
  try {
131
- let t = await x(u, n, e.retryCount, e.retryDelay, e.debug);
132
- e.debug && console.log(b, "getContentBySlug status : ", t.status);
132
+ let t = await y(u, n, e.retryCount, e.retryDelay, e.debug);
133
+ e.debug && console.log(v, "getContentBySlug status : ", t.status);
133
134
  let r = await t.json();
134
135
  return i.set(u, r), r;
135
136
  } catch (e) {
136
- return console.error(b, "getContentBySlug error : ", e), {};
137
+ return console.error(v, "getContentBySlug error : ", e), {};
137
138
  }
138
139
  },
139
140
  async getContentById(r, a) {
140
- e.debug && (console.log(b, "getContentById() id : ", r), console.log(b, "getContentById() params : ", JSON.stringify(a)));
141
+ e.debug && (console.log(v, "getContentById() id : ", r), console.log(v, "getContentById() params : ", JSON.stringify(a)));
141
142
  let o = "";
142
143
  e?.version && e.version == "draft" && (o = `&version=${e.version}`), a?.version && a.version == "draft" && (o = `&version=${a.version}`);
143
144
  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/${r}?token=${e.token}${o}${s}${c}${l}`;
144
- if (e.debug && console.log(b, "getContentById fetch url : ", u), i.has(u)) return e.debug && console.log(b, "getContentById cache hit"), i.get(u);
145
+ if (e.debug && console.log(v, "getContentById fetch url : ", u), i.has(u)) return e.debug && console.log(v, "getContentById cache hit"), i.get(u);
145
146
  try {
146
- let t = await x(u, n, e.retryCount, e.retryDelay, e.debug);
147
- e.debug && console.log(b, "getContentById status : ", t.status);
147
+ let t = await y(u, n, e.retryCount, e.retryDelay, e.debug);
148
+ e.debug && console.log(v, "getContentById status : ", t.status);
148
149
  let r = await t.json();
149
150
  return i.set(u, r), r;
150
151
  } catch (e) {
151
- return console.error(b, "getContentById error : ", e), {};
152
+ return console.error(v, "getContentById error : ", e), {};
152
153
  }
153
154
  },
154
155
  async getTranslations(r, a) {
155
- e.debug && (console.log(b, "getTranslations() locale : ", r), console.log(b, "getTranslations() params : ", JSON.stringify(a)));
156
+ e.debug && (console.log(v, "getTranslations() locale : ", r), console.log(v, "getTranslations() params : ", JSON.stringify(a)));
156
157
  let o = "";
157
158
  e?.version && e.version == "draft" && (o = `&version=${e.version}`), a?.version && a.version == "draft" && (o = `&version=${a.version}`);
158
159
  let s = `${t}/api/v1/spaces/${e.spaceId}/translations/${r}?token=${e.token}${o}`;
159
- if (e.debug && console.log(b, "getTranslations fetch url : ", s), i.has(s)) return e.debug && console.log(b, "getTranslations cache hit"), i.get(s);
160
+ if (e.debug && console.log(v, "getTranslations fetch url : ", s), i.has(s)) return e.debug && console.log(v, "getTranslations cache hit"), i.get(s);
160
161
  try {
161
- let t = await x(s, n, e.retryCount, e.retryDelay, e.debug);
162
- e.debug && console.log(b, "getTranslations status : ", t.status);
162
+ let t = await y(s, n, e.retryCount, e.retryDelay, e.debug);
163
+ e.debug && console.log(v, "getTranslations status : ", t.status);
163
164
  let r = await t.json();
164
165
  return i.set(s, r), r;
165
166
  } catch (e) {
166
- return console.error(b, "getTranslations error : ", e), {};
167
+ return console.error(v, "getTranslations error : ", e), {};
167
168
  }
168
169
  },
169
170
  async updateTranslations(r, i, a, o) {
170
- e.debug && (console.log(b, "updateTranslations() locale : ", r), console.log(b, "updateTranslations() type : ", i), console.log(b, "updateTranslations() values : ", JSON.stringify(a)));
171
+ e.debug && (console.log(v, "updateTranslations() locale : ", r), console.log(v, "updateTranslations() type : ", i), console.log(v, "updateTranslations() values : ", JSON.stringify(a)));
171
172
  let s = `${t}/api/v1/spaces/${e.spaceId}/translations/${r}`;
172
- e.debug && console.log(b, "updateTranslations fetch url : ", s);
173
+ e.debug && console.log(v, "updateTranslations fetch url : ", s);
173
174
  let c = {
174
175
  type: i,
175
176
  values: a,
176
177
  dryRun: o
177
178
  };
178
179
  try {
179
- let t = await x(s, {
180
+ let t = await y(s, {
180
181
  method: "POST",
181
182
  headers: {
182
183
  "X-API-KEY": e.token,
@@ -184,35 +185,35 @@ function S(e) {
184
185
  },
185
186
  body: JSON.stringify(c)
186
187
  }, e.retryCount, e.retryDelay, e.debug);
187
- return e.debug && console.log(b, "updateTranslations status : ", t.status), t.json();
188
+ return e.debug && console.log(v, "updateTranslations status : ", t.status), t.json();
188
189
  } catch (e) {
189
- console.error(b, "updateTranslations error : ", e);
190
+ console.error(v, "updateTranslations error : ", e);
190
191
  }
191
192
  },
192
193
  async getOpenApi() {
193
- e.debug && console.log(b, "getOpenApi()");
194
+ e.debug && console.log(v, "getOpenApi()");
194
195
  let r = `${t}/api/v1/spaces/${e.spaceId}/open-api?token=${e.token}`;
195
- if (e.debug && console.log(b, "getOpenApi fetch url : ", r), i.has(r)) return e.debug && console.log(b, "getOpenApi cache hit"), i.get(r);
196
+ if (e.debug && console.log(v, "getOpenApi fetch url : ", r), i.has(r)) return e.debug && console.log(v, "getOpenApi cache hit"), i.get(r);
196
197
  try {
197
- let t = await x(r, n, e.retryCount, e.retryDelay, e.debug);
198
- e.debug && console.log(b, "getOpenApi status : ", t.status);
198
+ let t = await y(r, n, e.retryCount, e.retryDelay, e.debug);
199
+ e.debug && console.log(v, "getOpenApi status : ", t.status);
199
200
  let a = await t.json();
200
201
  return i.set(r, a), a;
201
202
  } catch (e) {
202
- return console.error(b, "getOpenApi error : ", e), {};
203
+ return console.error(v, "getOpenApi error : ", e), {};
203
204
  }
204
205
  },
205
206
  async getSchemas() {
206
- e.debug && console.log(b, "getSchemas()");
207
+ e.debug && console.log(v, "getSchemas()");
207
208
  let r = `${t}/api/v1/spaces/${e.spaceId}/schemas?token=${e.token}`;
208
- if (e.debug && console.log(b, "getSchemas fetch url : ", r), i.has(r)) return e.debug && console.log(b, "getSchemas cache hit"), i.get(r);
209
+ if (e.debug && console.log(v, "getSchemas fetch url : ", r), i.has(r)) return e.debug && console.log(v, "getSchemas cache hit"), i.get(r);
209
210
  try {
210
- let t = await x(r, n, e.retryCount, e.retryDelay, e.debug);
211
- e.debug && console.log(b, "getSchemas status : ", t.status);
211
+ let t = await y(r, n, e.retryCount, e.retryDelay, e.debug);
212
+ e.debug && console.log(v, "getSchemas status : ", t.status);
212
213
  let a = await t.json();
213
214
  return i.set(r, a), a;
214
215
  } catch (e) {
215
- return console.error(b, "getSchemas error : ", e), {};
216
+ return console.error(v, "getSchemas error : ", e), {};
216
217
  }
217
218
  },
218
219
  assetLink(n) {
@@ -222,8 +223,8 @@ function S(e) {
222
223
  }
223
224
  //#endregion
224
225
  //#region src/file.ts
225
- var C = ".localess";
226
- async function w(e, t, n) {
226
+ var x = ".localess";
227
+ async function S(e, t, n) {
227
228
  let r = l(e).dir;
228
229
  try {
229
230
  await a(r, { recursive: !0 });
@@ -234,10 +235,10 @@ async function w(e, t, n) {
234
235
  await s(e, t, n);
235
236
  } catch {}
236
237
  }
237
- async function T(e) {
238
+ async function re(e) {
238
239
  return o(e, "utf-8");
239
240
  }
240
- async function E(e, t) {
241
+ async function ie(e, t) {
241
242
  let n = c(e, ".gitignore"), r = "";
242
243
  try {
243
244
  r = await o(n, "utf-8");
@@ -246,8 +247,8 @@ async function E(e, t) {
246
247
  }
247
248
  //#endregion
248
249
  //#region src/session.ts
249
- var D = c(u.cwd(), C, "credentials.json");
250
- async function O() {
250
+ var C = c(u.cwd(), x, "credentials.json");
251
+ async function w() {
251
252
  let e = { isLoggedIn: !1 }, t = u.env.LOCALESS_TOKEN, n = u.env.LOCALESS_SPACE, i = u.env.LOCALESS_ORIGIN;
252
253
  if (t && n && i) return console.debug("Login in using environment variables."), {
253
254
  isLoggedIn: !0,
@@ -257,8 +258,8 @@ async function O() {
257
258
  method: "env"
258
259
  };
259
260
  try {
260
- await r(D);
261
- let t = await o(D, "utf8"), n = JSON.parse(t);
261
+ await r(C);
262
+ let t = await o(C, "utf8"), n = JSON.parse(t);
262
263
  if (Object.keys(n).length === 0) return e;
263
264
  if (n.origin && n.token && n.space) return console.debug("Login in using credentials file."), {
264
265
  isLoggedIn: !0,
@@ -270,21 +271,21 @@ async function O() {
270
271
  } catch {}
271
272
  return e;
272
273
  }
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.`);
274
+ async function T(e) {
275
+ if (e.origin && e.token && e.space) await S(C, JSON.stringify(e, null, 2), { mode: 384 }), console.log("Session credentials saved to file system."), await ie(u.cwd(), x), console.log(`Added '${x}' to .gitignore to prevent credentials from being committed.`);
275
276
  else throw Error("Cannot persist session: missing required fields.");
276
277
  }
277
- async function A() {
278
+ async function E() {
278
279
  try {
279
- await r(D), await w(D, "{}", { mode: 384 });
280
+ await r(C), await S(C, "{}", { mode: 384 });
280
281
  } catch {
281
282
  throw Error("Failed to clear session credentials.");
282
283
  }
283
284
  }
284
285
  //#endregion
285
286
  //#region src/commands/login/index.ts
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) {
287
+ var D = 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 w()).isLoggedIn) {
288
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.");
289
290
  return;
290
291
  }
@@ -297,14 +298,14 @@ var j = new e("login").description("Login to Localess CLI").option("-o, --origin
297
298
  }), a = e.token ?? await n({
298
299
  message: "Token:",
299
300
  mask: !0
300
- }), o = S({
301
+ }), o = b({
301
302
  origin: r,
302
303
  spaceId: i,
303
304
  token: a
304
305
  });
305
306
  try {
306
307
  let e = await o.getSpace();
307
- console.log(`Successfully logged in to space: ${e.name} (${e.id})`), await k({
308
+ console.log(`Successfully logged in to space: ${e.name} (${e.id})`), await T({
308
309
  origin: r,
309
310
  space: i,
310
311
  token: a
@@ -312,9 +313,9 @@ var j = new e("login").description("Login to Localess CLI").option("-o, --origin
312
313
  } catch {
313
314
  console.error("Login failed");
314
315
  }
315
- }), M = new e("logout").description("Logout from Localess CLI").action(async () => {
316
+ }), ae = new e("logout").description("Logout from Localess CLI").action(async () => {
316
317
  console.log("Logging out...");
317
- let e = await O();
318
+ let e = await w();
318
319
  if (!e.isLoggedIn) {
319
320
  console.log("Not currently logged in.");
320
321
  return;
@@ -324,71 +325,71 @@ var j = new e("login").description("Login to Localess CLI").option("-o, --origin
324
325
  return;
325
326
  }
326
327
  try {
327
- await A(), console.log("Successfully logged out.");
328
+ await E(), console.log("Successfully logged out.");
328
329
  } catch (e) {
329
330
  console.error("Failed to log out:", e);
330
331
  }
331
- }), N = /* @__PURE__ */ function(e) {
332
+ }), O = /* @__PURE__ */ function(e) {
332
333
  return e.ROOT = "ROOT", e.NODE = "NODE", e.ENUM = "ENUM", e;
333
- }({}), P = /* @__PURE__ */ function(e) {
334
+ }({}), k = /* @__PURE__ */ function(e) {
334
335
  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;
335
- }({}), F = /* @__PURE__ */ function(e) {
336
+ }({}), A = /* @__PURE__ */ function(e) {
336
337
  return e.ADD_MISSING = "add-missing", e.UPDATE_EXISTING = "update-existing", e.DELETE_MISSING = "delete-missing", e;
337
- }({}), I = /* @__PURE__ */ function(e) {
338
+ }({}), j = /* @__PURE__ */ function(e) {
338
339
  return e.FLAT = "flat", e.NESTED = "nested", e;
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));
340
+ }({}), oe = 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
+ if (console.log("Pulling translations with arguments:", e), console.log("Pulling translations with options:", t), !Object.values(j).includes(t.format)) {
342
+ console.error("Invalid format provided. Possible values are :", Object.values(j));
342
343
  return;
343
344
  }
344
- let n = await O();
345
+ let n = await w();
345
346
  if (!n.isLoggedIn) {
346
347
  console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
347
348
  return;
348
349
  }
349
- let r = S({
350
+ let r = b({
350
351
  origin: n.origin,
351
352
  spaceId: n.space,
352
353
  token: n.token
353
354
  });
354
355
  console.log("Pulling translations from Localess for locale:", e);
355
356
  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));
357
+ if (console.log("Saving translations in file:", t.path), t.format === j.FLAT) await S(t.path, JSON.stringify(h(i), null, 2));
358
+ else if (t.format === j.NESTED) {
359
+ let e = h(_(i));
360
+ await S(t.path, JSON.stringify(e, null, 2));
360
361
  }
361
362
  console.log("Successfully saved translations from Localess");
362
- }), R = f.record(f.string(), f.string()), z = f.enum([
363
+ }), M = f.record(f.string(), f.string()), N = f.enum([
363
364
  "add-missing",
364
365
  "update-existing",
365
366
  "delete-missing"
366
367
  ]);
367
368
  f.object({
368
- type: z,
369
- values: R
369
+ type: N,
370
+ values: M
370
371
  });
371
372
  //#endregion
372
373
  //#region src/commands/translations/push/index.ts
373
- 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) => {
374
- if (console.log("Pushing translations with arguments:", e), console.log("Pushing translations with options:", t), !z.safeParse(t.type).success) {
375
- console.error("Invalid type provided. Possible values are :", Object.values(F));
374
+ var P = 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), !N.safeParse(t.type).success) {
376
+ console.error("Invalid type provided. Possible values are :", Object.values(A));
376
377
  return;
377
378
  }
378
- let n = await O();
379
+ let n = await w();
379
380
  if (!n.isLoggedIn) {
380
381
  console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
381
382
  return;
382
383
  }
383
- let r = S({
384
+ let r = b({
384
385
  origin: n.origin,
385
386
  spaceId: n.space,
386
387
  token: n.token
387
388
  });
388
389
  t.dryRun && console.warn("Dry run mode enabled: No changes will be made."), console.log("Reading translations file from:", t.path);
389
- let i = await T(t.path), a = JSON.parse(i), o;
390
- o = t.format === I.NESTED ? v(a) : a;
391
- let s = R.safeParse(o);
390
+ let i = await re(t.path), a = JSON.parse(i), o;
391
+ o = t.format === j.NESTED ? g(a) : a;
392
+ let s = M.safeParse(o);
392
393
  if (!s.success) {
393
394
  console.error("Invalid translations file format:", s.error);
394
395
  return;
@@ -396,10 +397,10 @@ var B = new e("push").argument("<locale>", "Locale to push").description("Push l
396
397
  console.log("Pushing translations to Localess with locale:", e, "and type:", t.type);
397
398
  let c = await r.updateTranslations(e, t.type, o, t.dryRun);
398
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");
399
- }), V = new e("translations").description("Manage translations").addCommand(B).addCommand(L);
400
+ }), F = new e("translations").description("Manage translations").addCommand(P).addCommand(oe);
400
401
  //#endregion
401
402
  //#region src/commands/types/generate/generator.ts
402
- function H(e) {
403
+ function I(e) {
403
404
  return `/**
404
405
  * Generated by Localess CLI
405
406
  * Do not edit manually.
@@ -450,49 +451,49 @@ export interface ${e}ContentRichText {
450
451
  }
451
452
  `;
452
453
  }
453
- function U(e) {
454
+ function L(e) {
454
455
  return e.replace(/[-_\s]+([a-zA-Z0-9])/g, (e, t) => t.toUpperCase()).replace(/^[a-z]/, (e) => e.toUpperCase());
455
456
  }
456
- function W(e, t) {
457
+ function R(e, t) {
457
458
  switch (e.kind) {
458
- case P.TEXT:
459
- case P.TEXTAREA:
460
- case P.MARKDOWN:
461
- case P.COLOR:
462
- case P.DATE:
463
- case P.DATETIME: return "string";
464
- case P.NUMBER: return "number";
465
- case P.BOOLEAN: return "boolean";
466
- case P.RICH_TEXT: return `${t}ContentRichText`;
467
- case P.LINK: return `${t}ContentLink`;
468
- case P.ASSET: return `${t}ContentAsset`;
469
- case P.ASSETS: return `${t}ContentAsset[]`;
470
- case P.REFERENCE: return `${t}ContentReference`;
471
- case P.REFERENCES: return `${t}ContentReference[]`;
472
- case P.OPTION: return e.source ? t + U(e.source) : "string";
473
- case P.OPTIONS: return e.source ? `${t + U(e.source)}[]` : "string[]";
474
- case P.SCHEMA: {
459
+ case k.TEXT:
460
+ case k.TEXTAREA:
461
+ case k.MARKDOWN:
462
+ case k.COLOR:
463
+ case k.DATE:
464
+ case k.DATETIME: return "string";
465
+ case k.NUMBER: return "number";
466
+ case k.BOOLEAN: return "boolean";
467
+ case k.RICH_TEXT: return `${t}ContentRichText`;
468
+ case k.LINK: return `${t}ContentLink`;
469
+ case k.ASSET: return `${t}ContentAsset`;
470
+ case k.ASSETS: return `${t}ContentAsset[]`;
471
+ case k.REFERENCE: return `${t}ContentReference`;
472
+ case k.REFERENCES: return `${t}ContentReference[]`;
473
+ case k.OPTION: return e.source ? t + L(e.source) : "string";
474
+ case k.OPTIONS: return e.source ? `${t + L(e.source)}[]` : "string[]";
475
+ case k.SCHEMA: {
475
476
  let n = e.schemas;
476
477
  if (!n || n.length === 0) return "unknown";
477
- let r = n.map((e) => t + U(e));
478
+ let r = n.map((e) => t + L(e));
478
479
  return r.length === 1 ? r[0] : r.join(" | ");
479
480
  }
480
- case P.SCHEMAS: {
481
+ case k.SCHEMAS: {
481
482
  let n = e.schemas;
482
483
  if (!n || n.length === 0) return "unknown[]";
483
- let r = n.map((e) => t + U(e));
484
+ let r = n.map((e) => t + L(e));
484
485
  return `${r.length === 1 ? r[0] : `(${r.join(" | ")})`}[]`;
485
486
  }
486
487
  }
487
488
  }
488
- function G(e, t = "") {
489
+ function z(e, t = "") {
489
490
  return `${t}/**\n${t} * ${e}\n${t} */`;
490
491
  }
491
- function K(e, t = "") {
492
- let n = [H(t)], r = [];
492
+ function B(e, t = "") {
493
+ let n = [I(t)], r = [];
493
494
  for (let [i, a] of Object.entries(e)) {
494
- let e = t + U(i), o = a.description ? `${G(a.description)}\n` : "";
495
- if (a.type === N.ENUM) {
495
+ let e = t + L(i), o = a.description ? `${z(a.description)}\n` : "";
496
+ if (a.type === O.ENUM) {
496
497
  let t = a.values ?? [];
497
498
  if (t.length === 0) n.push(`${o}export type ${e} = string;\n`);
498
499
  else {
@@ -501,14 +502,14 @@ function K(e, t = "") {
501
502
  }
502
503
  } else {
503
504
  let s = a;
504
- a.type === N.ROOT && r.push(e);
505
+ a.type === O.ROOT && r.push(e);
505
506
  let c = [
506
507
  " /** Unique identifier of a component in a content. */",
507
508
  " _id: string;",
508
509
  " /** Unique identifier for the Schema object. */",
509
510
  ` _schema: '${i}';`,
510
511
  ...(s.fields ?? []).slice().sort((e, t) => e.name.localeCompare(t.name)).flatMap((e) => {
511
- let n = W(e, t), r = e.required ? "" : "?", i = [];
512
+ let n = R(e, t), r = e.required ? "" : "?", i = [];
512
513
  return e.description && i.push(` /** ${e.description} */`), i.push(` ${e.name}${r}: ${n};`), i;
513
514
  })
514
515
  ];
@@ -519,14 +520,14 @@ function K(e, t = "") {
519
520
  }
520
521
  //#endregion
521
522
  //#region src/commands/types/generate/index.ts
522
- 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) => {
523
+ var V = c(d.cwd(), x, "localess.ts"), H = 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", V).option("--prefix <prefix>", "Prefix to prepend to all generated type names", "").action(async (e) => {
523
524
  console.log("Types in with options:", e);
524
- let t = await O();
525
+ let t = await w();
525
526
  if (!t.isLoggedIn) {
526
527
  console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
527
528
  return;
528
529
  }
529
- let n = S({
530
+ let n = b({
530
531
  origin: t.origin,
531
532
  spaceId: t.space,
532
533
  token: t.token
@@ -534,14 +535,67 @@ var q = c(d.cwd(), C, "localess.ts"), J = new e("generate").description("Generat
534
535
  console.log("Fetching schemas from Localess...");
535
536
  let r = await n.getSchemas();
536
537
  console.log("Generating types...");
537
- let i = K(r, e.prefix);
538
- await w(e.path, i), console.log(`Types written to ${e.path}`);
539
- }), Y = new e("types").description("Generate types for your schemas").addCommand(J), X = new e();
540
- 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);
538
+ let i = B(r, e.prefix);
539
+ await S(e.path, i), console.log(`Types written to ${e.path}`);
540
+ }), U = new e("types").description("Generate types for your schemas").addCommand(H), W = "@localess/cli", G = `https://registry.npmjs.org/${W}`;
541
+ function K(e) {
542
+ let [t, n = null] = e.split("-"), r = t.split(".").map(Number);
543
+ return {
544
+ major: r[0] ?? 0,
545
+ minor: r[1] ?? 0,
546
+ patch: r[2] ?? 0,
547
+ preRelease: n ?? null
548
+ };
549
+ }
550
+ function q(e, t) {
551
+ let n = K(e), r = K(t);
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
+ }
554
+ async function J(e, t) {
555
+ try {
556
+ let n = await fetch(`${G}/${e}`, { signal: t });
557
+ return n.ok ? (await n.json()).version : null;
558
+ } catch {
559
+ return null;
560
+ }
561
+ }
562
+ function Y(e) {
563
+ return e.replace(/\u001B\[[0-9;]*m/g, "").length;
564
+ }
565
+ function X(e, t, n) {
566
+ let r = ` Update available: ${p.dim(e)} → ${p.green.bold(t)} `, i = ` Run ${p.cyan(`npm install --save-dev ${W}@${n}`)} to update `, a = Math.max(Y(r), Y(i)), o = (e) => e + " ".repeat(a - Y(e)), s = p.yellow("─".repeat(a + 1));
567
+ return [
568
+ "",
569
+ p.yellow("┌") + s + p.yellow("┐"),
570
+ p.yellow("│") + " " + o(r) + p.yellow("│"),
571
+ p.yellow("│") + " " + o(i) + p.yellow("│"),
572
+ p.yellow("└") + s + p.yellow("┘"),
573
+ ""
574
+ ].join("\n");
575
+ }
576
+ async function se(e) {
577
+ try {
578
+ let t = new AbortController(), n = setTimeout(() => t.abort(), 3e3), r = K(e).preRelease !== null, [i, a] = await Promise.all([J("latest", t.signal), r ? J("dev", t.signal) : Promise.resolve(null)]);
579
+ if (clearTimeout(n), i && q(i, e)) return X(e, i, "latest");
580
+ if (a && q(a, e)) return X(e, a, "dev");
581
+ } catch {}
582
+ return null;
583
+ }
584
+ //#endregion
585
+ //#region package.json
586
+ var Z = "3.0.7-dev.20260514085047", Q = new e();
587
+ Q.name("Localess CLI").description("CLI tool for Localess platform management").version(Z);
588
+ var $;
589
+ Q.hook("preAction", () => {
590
+ $ = se(Z);
591
+ }), Q.hook("postAction", async () => {
592
+ let e = await $;
593
+ e && console.log(e);
594
+ }), Q.addCommand(D), Q.addCommand(ae), Q.addCommand(F), Q.addCommand(U);
541
595
  //#endregion
542
596
  //#region src/index.ts
543
597
  try {
544
- X.parse(process.argv);
598
+ Q.parse(process.argv);
545
599
  } catch (e) {
546
600
  console.error("Error executing command:", e instanceof Error ? e.message : e), process.exit(1);
547
601
  }
@@ -18,7 +18,7 @@ export type LocalessClientOptions = {
18
18
  /**
19
19
  * Content version to fetch, leave empty for 'published' or 'draft' for the latest draft
20
20
  */
21
- version?: 'draft' | string;
21
+ version?: 'draft';
22
22
  /**
23
23
  * Enable debug mode
24
24
  */
@@ -64,7 +64,7 @@ export type ContentFetchParams = {
64
64
  * Content version to fetch, leave empty for 'published' or 'draft' for the latest draft.
65
65
  * Overrides the version set in the client options.
66
66
  */
67
- version?: 'draft' | string;
67
+ version?: 'draft';
68
68
  /**
69
69
  * Locale identifier (ISO 639-1) to fetch content in, leave empty for default locale.
70
70
  *
@@ -85,7 +85,7 @@ export type TranslationFetchParams = {
85
85
  * Translation version to fetch, leave empty for 'published' or 'draft' for the latest draft.
86
86
  * Overrides the version set in the client options.
87
87
  */
88
- version?: 'draft' | string;
88
+ version?: 'draft';
89
89
  };
90
90
  export interface LocalessClient {
91
91
  /**
@@ -0,0 +1,2 @@
1
+ export declare function isNewer(candidate: string, current: string): boolean;
2
+ export declare function checkForUpdate(currentVersion: string): Promise<string | null>;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@localess/cli",
3
- "version": "3.0.7-dev.20260512203425",
3
+ "version": "3.0.7-dev.20260514085047",
4
4
  "description": "Localess Command Line.",
5
5
  "keywords": [
6
6
  "localess",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes