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