@localess/cli 3.0.1-dev.20260410071322 → 3.0.1-dev.20260412201733
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.d.ts +1 -1
- package/dist/index.mjs +382 -661
- package/package.json +6 -5
- package/dist/index.d.mts +0 -1
- package/dist/index.js +0 -697
package/dist/index.mjs
CHANGED
|
@@ -1,674 +1,395 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (i === parts.length - 1) {
|
|
20
|
-
current[parts[i]] = value;
|
|
21
|
-
} else {
|
|
22
|
-
if (!(parts[i] in current)) {
|
|
23
|
-
current[parts[i]] = {};
|
|
24
|
-
}
|
|
25
|
-
current = current[parts[i]];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
2
|
+
import { Command as e } from "commander";
|
|
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 { generate as d } from "orval";
|
|
9
|
+
import { z as f } from "zod";
|
|
10
|
+
//#region src/utils.ts
|
|
11
|
+
var p = "\x1B[0m", m = "\x1B[34m";
|
|
12
|
+
function h(e) {
|
|
13
|
+
let t = {};
|
|
14
|
+
for (let [n, r] of Object.entries(e)) {
|
|
15
|
+
let e = n.split("."), i = t;
|
|
16
|
+
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]]);
|
|
17
|
+
}
|
|
18
|
+
return t;
|
|
30
19
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
const response = await fetch(url, options);
|
|
79
|
-
if (!response.ok && response.status >= 500) {
|
|
80
|
-
if (debug) {
|
|
81
|
-
console.log(LOG_GROUP, `fetchWithRetry: HTTP ${response.status} on attempt ${attempt + 1}`);
|
|
82
|
-
}
|
|
83
|
-
lastError = new Error(`HTTP ${response.status}`);
|
|
84
|
-
} else {
|
|
85
|
-
return response;
|
|
86
|
-
}
|
|
87
|
-
} catch (err) {
|
|
88
|
-
if (debug) {
|
|
89
|
-
console.log(LOG_GROUP, `fetchWithRetry: network error on attempt ${attempt + 1}`, err);
|
|
90
|
-
}
|
|
91
|
-
lastError = err;
|
|
92
|
-
}
|
|
93
|
-
attempt++;
|
|
94
|
-
if (attempt <= retryCount) {
|
|
95
|
-
await new Promise((res) => setTimeout(res, retryDelay));
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
throw lastError;
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/cache.ts
|
|
22
|
+
var g = class {
|
|
23
|
+
set(e, t) {}
|
|
24
|
+
get(e) {}
|
|
25
|
+
has(e) {
|
|
26
|
+
return !1;
|
|
27
|
+
}
|
|
28
|
+
}, _ = class {
|
|
29
|
+
cache = /* @__PURE__ */ new Map();
|
|
30
|
+
constructor(e = 3e5) {
|
|
31
|
+
this.ttlMs = e;
|
|
32
|
+
}
|
|
33
|
+
set(e, t) {
|
|
34
|
+
this.cache.set(e, {
|
|
35
|
+
value: t,
|
|
36
|
+
expiresAt: Date.now() + this.ttlMs
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
get(e) {
|
|
40
|
+
let t = this.cache.get(e);
|
|
41
|
+
if (t) {
|
|
42
|
+
if (Date.now() > t.expiresAt) {
|
|
43
|
+
this.cache.delete(e);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
return t.value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
has(e) {
|
|
50
|
+
return this.get(e) !== void 0;
|
|
51
|
+
}
|
|
52
|
+
}, v = `${m}[Localess:Client]${p}`;
|
|
53
|
+
async function y(e, t, n = 3, r = 500, i) {
|
|
54
|
+
let a = 0, o;
|
|
55
|
+
for (; a <= n;) {
|
|
56
|
+
try {
|
|
57
|
+
let n = await fetch(e, t);
|
|
58
|
+
if (!n.ok && n.status >= 500) i && console.log(v, `fetchWithRetry: HTTP ${n.status} on attempt ${a + 1}`), o = /* @__PURE__ */ Error(`HTTP ${n.status}`);
|
|
59
|
+
else return n;
|
|
60
|
+
} catch (e) {
|
|
61
|
+
i && console.log(v, `fetchWithRetry: network error on attempt ${a + 1}`, e), o = e;
|
|
62
|
+
}
|
|
63
|
+
a++, a <= n && await new Promise((e) => setTimeout(e, r));
|
|
64
|
+
}
|
|
65
|
+
throw o;
|
|
99
66
|
}
|
|
100
|
-
function
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const locale = params?.locale ? `&locale=${params.locale}` : "";
|
|
233
|
-
const resolveReference = params?.resolveReference ? `&resolveReference=${params.resolveReference}` : "";
|
|
234
|
-
const resolveLink = params?.resolveLink ? `&resolveLink=${params.resolveLink}` : "";
|
|
235
|
-
let url = `${normalizedOrigin}/api/v1/spaces/${options.spaceId}/contents/${id}?token=${options.token}${version}${locale}${resolveReference}${resolveLink}`;
|
|
236
|
-
if (options.debug) {
|
|
237
|
-
console.log(LOG_GROUP, "getContentById fetch url : ", url);
|
|
238
|
-
}
|
|
239
|
-
if (cache.has(url)) {
|
|
240
|
-
if (options.debug) {
|
|
241
|
-
console.log(LOG_GROUP, "getContentById cache hit");
|
|
242
|
-
}
|
|
243
|
-
return cache.get(url);
|
|
244
|
-
}
|
|
245
|
-
try {
|
|
246
|
-
const response = await fetchWithRetry(url, fetchOptions, options.retryCount, options.retryDelay, options.debug);
|
|
247
|
-
if (options.debug) {
|
|
248
|
-
console.log(LOG_GROUP, "getContentById status : ", response.status);
|
|
249
|
-
}
|
|
250
|
-
const data = await response.json();
|
|
251
|
-
cache.set(url, data);
|
|
252
|
-
return data;
|
|
253
|
-
} catch (error) {
|
|
254
|
-
console.error(LOG_GROUP, "getContentById error : ", error);
|
|
255
|
-
return {};
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
async getTranslations(locale, params) {
|
|
259
|
-
if (options.debug) {
|
|
260
|
-
console.log(LOG_GROUP, "getTranslations() locale : ", locale);
|
|
261
|
-
console.log(LOG_GROUP, "getTranslations() params : ", JSON.stringify(params));
|
|
262
|
-
}
|
|
263
|
-
let version = "";
|
|
264
|
-
if (options?.version && options.version == "draft") {
|
|
265
|
-
version = `&version=${options.version}`;
|
|
266
|
-
}
|
|
267
|
-
if (params?.version && params.version == "draft") {
|
|
268
|
-
version = `&version=${params.version}`;
|
|
269
|
-
}
|
|
270
|
-
let url = `${normalizedOrigin}/api/v1/spaces/${options.spaceId}/translations/${locale}?token=${options.token}${version}`;
|
|
271
|
-
if (options.debug) {
|
|
272
|
-
console.log(LOG_GROUP, "getTranslations fetch url : ", url);
|
|
273
|
-
}
|
|
274
|
-
if (cache.has(url)) {
|
|
275
|
-
if (options.debug) {
|
|
276
|
-
console.log(LOG_GROUP, "getTranslations cache hit");
|
|
277
|
-
}
|
|
278
|
-
return cache.get(url);
|
|
279
|
-
}
|
|
280
|
-
try {
|
|
281
|
-
const response = await fetchWithRetry(url, fetchOptions, options.retryCount, options.retryDelay, options.debug);
|
|
282
|
-
if (options.debug) {
|
|
283
|
-
console.log(LOG_GROUP, "getTranslations status : ", response.status);
|
|
284
|
-
}
|
|
285
|
-
const data = await response.json();
|
|
286
|
-
cache.set(url, data);
|
|
287
|
-
return data;
|
|
288
|
-
} catch (error) {
|
|
289
|
-
console.error(LOG_GROUP, "getTranslations error : ", error);
|
|
290
|
-
return {};
|
|
291
|
-
}
|
|
292
|
-
},
|
|
293
|
-
async updateTranslations(locale, type, values, dryRun) {
|
|
294
|
-
if (options.debug) {
|
|
295
|
-
console.log(LOG_GROUP, "updateTranslations() locale : ", locale);
|
|
296
|
-
console.log(LOG_GROUP, "updateTranslations() type : ", type);
|
|
297
|
-
console.log(LOG_GROUP, "updateTranslations() values : ", JSON.stringify(values));
|
|
298
|
-
}
|
|
299
|
-
let url = `${normalizedOrigin}/api/v1/spaces/${options.spaceId}/translations/${locale}`;
|
|
300
|
-
if (options.debug) {
|
|
301
|
-
console.log(LOG_GROUP, "updateTranslations fetch url : ", url);
|
|
302
|
-
}
|
|
303
|
-
const body = {
|
|
304
|
-
type,
|
|
305
|
-
values,
|
|
306
|
-
dryRun
|
|
307
|
-
};
|
|
308
|
-
try {
|
|
309
|
-
const response = await fetchWithRetry(url, {
|
|
310
|
-
method: "POST",
|
|
311
|
-
headers: {
|
|
312
|
-
"X-API-KEY": options.token,
|
|
313
|
-
...fetchOptions.headers
|
|
314
|
-
},
|
|
315
|
-
body: JSON.stringify(body)
|
|
316
|
-
}, options.retryCount, options.retryDelay, options.debug);
|
|
317
|
-
if (options.debug) {
|
|
318
|
-
console.log(LOG_GROUP, "updateTranslations status : ", response.status);
|
|
319
|
-
}
|
|
320
|
-
return response.json();
|
|
321
|
-
} catch (error) {
|
|
322
|
-
console.error(LOG_GROUP, "updateTranslations error : ", error);
|
|
323
|
-
}
|
|
324
|
-
},
|
|
325
|
-
async getOpenApi() {
|
|
326
|
-
if (options.debug) {
|
|
327
|
-
console.log(LOG_GROUP, "getOpenApi()");
|
|
328
|
-
}
|
|
329
|
-
let url = `${normalizedOrigin}/api/v1/spaces/${options.spaceId}/open-api?token=${options.token}`;
|
|
330
|
-
if (options.debug) {
|
|
331
|
-
console.log(LOG_GROUP, "getOpenApi fetch url : ", url);
|
|
332
|
-
}
|
|
333
|
-
if (cache.has(url)) {
|
|
334
|
-
if (options.debug) {
|
|
335
|
-
console.log(LOG_GROUP, "getTranslations cache hit");
|
|
336
|
-
}
|
|
337
|
-
return cache.get(url);
|
|
338
|
-
}
|
|
339
|
-
try {
|
|
340
|
-
const response = await fetchWithRetry(url, fetchOptions, options.retryCount, options.retryDelay, options.debug);
|
|
341
|
-
if (options.debug) {
|
|
342
|
-
console.log(LOG_GROUP, "getOpenApi status : ", response.status);
|
|
343
|
-
}
|
|
344
|
-
const data = await response.json();
|
|
345
|
-
cache.set(url, data);
|
|
346
|
-
return data;
|
|
347
|
-
} catch (error) {
|
|
348
|
-
console.error(LOG_GROUP, "getOpenApi error : ", error);
|
|
349
|
-
return {};
|
|
350
|
-
}
|
|
351
|
-
},
|
|
352
|
-
syncScriptUrl() {
|
|
353
|
-
return `${normalizedOrigin}/scripts/sync-v1.js`;
|
|
354
|
-
},
|
|
355
|
-
assetLink(asset) {
|
|
356
|
-
if (typeof asset === "string") {
|
|
357
|
-
return `${normalizedOrigin}/api/v1/spaces/${options.spaceId}/assets/${asset}`;
|
|
358
|
-
} else {
|
|
359
|
-
return `${normalizedOrigin}/api/v1/spaces/${options.spaceId}/assets/${asset.uri}`;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
};
|
|
67
|
+
function b(e) {
|
|
68
|
+
e.debug && console.log(v, "Client Options : ", e);
|
|
69
|
+
let t = e.origin.replace(/\/+$/, ""), n = {
|
|
70
|
+
redirect: "follow",
|
|
71
|
+
headers: {
|
|
72
|
+
"Content-Type": "application/json",
|
|
73
|
+
Accept: "application/json",
|
|
74
|
+
"X-Localess-Agent": "Localess-CLI-Client",
|
|
75
|
+
"X-Localess-Agent-Version": "0.9.0"
|
|
76
|
+
}
|
|
77
|
+
}, r = e.cacheTTL === !1 ? new g() : new _(e.cacheTTL);
|
|
78
|
+
return {
|
|
79
|
+
async getSpace() {
|
|
80
|
+
e.debug && console.log(v, "getSpace()");
|
|
81
|
+
let i = `${t}/api/v1/spaces/${e.spaceId}?token=${e.token}`;
|
|
82
|
+
if (e.debug && console.log(v, "getSpace fetch url : ", i), r.has(i)) return e.debug && console.log(v, "getSpace cache hit"), r.get(i);
|
|
83
|
+
try {
|
|
84
|
+
let t = await y(i, n, e.retryCount, e.retryDelay, e.debug);
|
|
85
|
+
e.debug && console.log(v, "getSpace status : ", t.status);
|
|
86
|
+
let a = await t.json();
|
|
87
|
+
return r.set(i, a), a;
|
|
88
|
+
} catch (e) {
|
|
89
|
+
return console.error(v, "getSpace error : ", e), {};
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
async getLinks(i) {
|
|
93
|
+
e.debug && console.log(v, "getLinks() params : ", JSON.stringify(i));
|
|
94
|
+
let a = "";
|
|
95
|
+
i?.kind && (a = `&kind=${i.kind}`);
|
|
96
|
+
let o = "";
|
|
97
|
+
i?.parentSlug && (o = `&parentSlug=${i.parentSlug}`);
|
|
98
|
+
let s = "";
|
|
99
|
+
i?.excludeChildren && (s = `&excludeChildren=${i.excludeChildren}`);
|
|
100
|
+
let c = `${t}/api/v1/spaces/${e.spaceId}/links?token=${e.token}${a}${o}${s}`;
|
|
101
|
+
if (e.debug && console.log(v, "getLinks fetch url : ", c), r.has(c)) return e.debug && console.log(v, "getLinks cache hit"), r.get(c);
|
|
102
|
+
try {
|
|
103
|
+
let t = await y(c, n, e.retryCount, e.retryDelay, e.debug);
|
|
104
|
+
e.debug && console.log(v, "getLinks status : ", t.status);
|
|
105
|
+
let i = await t.json();
|
|
106
|
+
return r.set(c, i), i;
|
|
107
|
+
} catch (e) {
|
|
108
|
+
return console.error(v, "getLinks error : ", e), {};
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
async getContentBySlug(i, a) {
|
|
112
|
+
e.debug && (console.log(v, "getContentBySlug() slug : ", i), console.log(v, "getContentBySlug() params : ", JSON.stringify(a)));
|
|
113
|
+
let o = "";
|
|
114
|
+
e?.version && e.version == "draft" && (o = `&version=${e.version}`), a?.version && a.version == "draft" && (o = `&version=${a.version}`);
|
|
115
|
+
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}`;
|
|
116
|
+
if (e.debug && console.log(v, "getContentBySlug fetch url : ", u), r.has(u)) return e.debug && console.log(v, "getContentBySlug cache hit"), r.get(u);
|
|
117
|
+
try {
|
|
118
|
+
let t = await y(u, n, e.retryCount, e.retryDelay, e.debug);
|
|
119
|
+
e.debug && console.log(v, "getContentBySlug status : ", t.status);
|
|
120
|
+
let i = await t.json();
|
|
121
|
+
return r.set(u, i), i;
|
|
122
|
+
} catch (e) {
|
|
123
|
+
return console.error(v, "getContentBySlug error : ", e), {};
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
async getContentById(i, a) {
|
|
127
|
+
e.debug && (console.log(v, "getContentById() id : ", i), console.log(v, "getContentById() params : ", JSON.stringify(a)));
|
|
128
|
+
let o = "";
|
|
129
|
+
e?.version && e.version == "draft" && (o = `&version=${e.version}`), a?.version && a.version == "draft" && (o = `&version=${a.version}`);
|
|
130
|
+
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}`;
|
|
131
|
+
if (e.debug && console.log(v, "getContentById fetch url : ", u), r.has(u)) return e.debug && console.log(v, "getContentById cache hit"), r.get(u);
|
|
132
|
+
try {
|
|
133
|
+
let t = await y(u, n, e.retryCount, e.retryDelay, e.debug);
|
|
134
|
+
e.debug && console.log(v, "getContentById status : ", t.status);
|
|
135
|
+
let i = await t.json();
|
|
136
|
+
return r.set(u, i), i;
|
|
137
|
+
} catch (e) {
|
|
138
|
+
return console.error(v, "getContentById error : ", e), {};
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
async getTranslations(i, a) {
|
|
142
|
+
e.debug && (console.log(v, "getTranslations() locale : ", i), console.log(v, "getTranslations() params : ", JSON.stringify(a)));
|
|
143
|
+
let o = "";
|
|
144
|
+
e?.version && e.version == "draft" && (o = `&version=${e.version}`), a?.version && a.version == "draft" && (o = `&version=${a.version}`);
|
|
145
|
+
let s = `${t}/api/v1/spaces/${e.spaceId}/translations/${i}?token=${e.token}${o}`;
|
|
146
|
+
if (e.debug && console.log(v, "getTranslations fetch url : ", s), r.has(s)) return e.debug && console.log(v, "getTranslations cache hit"), r.get(s);
|
|
147
|
+
try {
|
|
148
|
+
let t = await y(s, n, e.retryCount, e.retryDelay, e.debug);
|
|
149
|
+
e.debug && console.log(v, "getTranslations status : ", t.status);
|
|
150
|
+
let i = await t.json();
|
|
151
|
+
return r.set(s, i), i;
|
|
152
|
+
} catch (e) {
|
|
153
|
+
return console.error(v, "getTranslations error : ", e), {};
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
async updateTranslations(r, i, a, o) {
|
|
157
|
+
e.debug && (console.log(v, "updateTranslations() locale : ", r), console.log(v, "updateTranslations() type : ", i), console.log(v, "updateTranslations() values : ", JSON.stringify(a)));
|
|
158
|
+
let s = `${t}/api/v1/spaces/${e.spaceId}/translations/${r}`;
|
|
159
|
+
e.debug && console.log(v, "updateTranslations fetch url : ", s);
|
|
160
|
+
let c = {
|
|
161
|
+
type: i,
|
|
162
|
+
values: a,
|
|
163
|
+
dryRun: o
|
|
164
|
+
};
|
|
165
|
+
try {
|
|
166
|
+
let t = await y(s, {
|
|
167
|
+
method: "POST",
|
|
168
|
+
headers: {
|
|
169
|
+
"X-API-KEY": e.token,
|
|
170
|
+
...n.headers
|
|
171
|
+
},
|
|
172
|
+
body: JSON.stringify(c)
|
|
173
|
+
}, e.retryCount, e.retryDelay, e.debug);
|
|
174
|
+
return e.debug && console.log(v, "updateTranslations status : ", t.status), t.json();
|
|
175
|
+
} catch (e) {
|
|
176
|
+
console.error(v, "updateTranslations error : ", e);
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
async getOpenApi() {
|
|
180
|
+
e.debug && console.log(v, "getOpenApi()");
|
|
181
|
+
let i = `${t}/api/v1/spaces/${e.spaceId}/open-api?token=${e.token}`;
|
|
182
|
+
if (e.debug && console.log(v, "getOpenApi fetch url : ", i), r.has(i)) return e.debug && console.log(v, "getTranslations cache hit"), r.get(i);
|
|
183
|
+
try {
|
|
184
|
+
let t = await y(i, n, e.retryCount, e.retryDelay, e.debug);
|
|
185
|
+
e.debug && console.log(v, "getOpenApi status : ", t.status);
|
|
186
|
+
let a = await t.json();
|
|
187
|
+
return r.set(i, a), a;
|
|
188
|
+
} catch (e) {
|
|
189
|
+
return console.error(v, "getOpenApi error : ", e), {};
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
syncScriptUrl() {
|
|
193
|
+
return `${t}/scripts/sync-v1.js`;
|
|
194
|
+
},
|
|
195
|
+
assetLink(n) {
|
|
196
|
+
return typeof n == "string" ? `${t}/api/v1/spaces/${e.spaceId}/assets/${n}` : `${t}/api/v1/spaces/${e.spaceId}/assets/${n.uri}`;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
363
199
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
await mkdir(resolvedPath, { recursive: true });
|
|
378
|
-
} catch (mkdirError) {
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
try {
|
|
382
|
-
await nodeWriteFile(filePath, data, option);
|
|
383
|
-
} catch (writeError) {
|
|
384
|
-
}
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/file.ts
|
|
202
|
+
var x = ".localess";
|
|
203
|
+
async function S(e, t, n) {
|
|
204
|
+
let r = c(e).dir;
|
|
205
|
+
try {
|
|
206
|
+
await i(r, { recursive: !0 });
|
|
207
|
+
} catch {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
await o(e, t, n);
|
|
212
|
+
} catch {}
|
|
385
213
|
}
|
|
386
|
-
async function
|
|
387
|
-
|
|
214
|
+
async function C(e) {
|
|
215
|
+
return a(e, "utf-8");
|
|
388
216
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
var
|
|
392
|
-
async function
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
return session;
|
|
415
|
-
}
|
|
416
|
-
if (parsedContent.origin && parsedContent.token && parsedContent.space) {
|
|
417
|
-
console.debug(`Login in using credentials file.`);
|
|
418
|
-
return {
|
|
419
|
-
isLoggedIn: true,
|
|
420
|
-
space: parsedContent.space,
|
|
421
|
-
origin: parsedContent.origin,
|
|
422
|
-
token: parsedContent.token,
|
|
423
|
-
method: "file"
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
} catch (e) {
|
|
427
|
-
}
|
|
428
|
-
return session;
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region src/session.ts
|
|
219
|
+
var w = s(l.cwd(), x, "credentials.json");
|
|
220
|
+
async function T() {
|
|
221
|
+
let e = { isLoggedIn: !1 }, t = l.env.LOCALESS_TOKEN, n = l.env.LOCALESS_SPACE, i = l.env.LOCALESS_ORIGIN;
|
|
222
|
+
if (t && n && i) return console.debug("Login in using environment variables."), {
|
|
223
|
+
isLoggedIn: !0,
|
|
224
|
+
space: n,
|
|
225
|
+
origin: i,
|
|
226
|
+
token: t,
|
|
227
|
+
method: "env"
|
|
228
|
+
};
|
|
229
|
+
try {
|
|
230
|
+
await r(w);
|
|
231
|
+
let t = await a(w, "utf8"), n = JSON.parse(t);
|
|
232
|
+
if (Object.keys(n).length === 0) return e;
|
|
233
|
+
if (n.origin && n.token && n.space) return console.debug("Login in using credentials file."), {
|
|
234
|
+
isLoggedIn: !0,
|
|
235
|
+
space: n.space,
|
|
236
|
+
origin: n.origin,
|
|
237
|
+
token: n.token,
|
|
238
|
+
method: "file"
|
|
239
|
+
};
|
|
240
|
+
} catch {}
|
|
241
|
+
return e;
|
|
429
242
|
}
|
|
430
|
-
async function
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
console.log("Add session credentials to file system.");
|
|
434
|
-
console.log("Add .localess to .gitignore to avoid committing them to your repository.");
|
|
435
|
-
} else {
|
|
436
|
-
throw new Error("Cannot persist session: missing required fields.");
|
|
437
|
-
}
|
|
243
|
+
async function E(e) {
|
|
244
|
+
if (e.origin && e.token && e.space) await S(w, 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.");
|
|
245
|
+
else throw Error("Cannot persist session: missing required fields.");
|
|
438
246
|
}
|
|
439
|
-
async function
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
}
|
|
247
|
+
async function D() {
|
|
248
|
+
try {
|
|
249
|
+
await r(w), await S(w, "{}", { mode: 384 });
|
|
250
|
+
} catch {
|
|
251
|
+
throw Error("Failed to clear session credentials.");
|
|
252
|
+
}
|
|
446
253
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
var
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/commands/login/index.ts
|
|
256
|
+
var O = 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) => {
|
|
257
|
+
if ((await T()).isLoggedIn) {
|
|
258
|
+
console.log("Already logged in."), console.log("If you want to log in with different credentials, please log out first using \"localess logout\" command.");
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
let r = e.origin ?? await t({
|
|
262
|
+
message: "Origin of the Localess instance:",
|
|
263
|
+
required: !0
|
|
264
|
+
}), i = e.space ?? await t({
|
|
265
|
+
message: "Space ID:",
|
|
266
|
+
required: !0
|
|
267
|
+
}), a = e.token ?? await n({
|
|
268
|
+
message: "Token:",
|
|
269
|
+
mask: !0
|
|
270
|
+
}), o = b({
|
|
271
|
+
origin: r,
|
|
272
|
+
spaceId: i,
|
|
273
|
+
token: a
|
|
274
|
+
});
|
|
275
|
+
try {
|
|
276
|
+
let e = await o.getSpace();
|
|
277
|
+
console.log(`Successfully logged in to space: ${e.name} (${e.id})`), await E({
|
|
278
|
+
origin: r,
|
|
279
|
+
space: i,
|
|
280
|
+
token: a
|
|
281
|
+
});
|
|
282
|
+
} catch {
|
|
283
|
+
console.error("Login failed");
|
|
284
|
+
}
|
|
285
|
+
}), k = new e("logout").description("Logout from Localess CLI").action(async () => {
|
|
286
|
+
console.log("Logging out...");
|
|
287
|
+
let e = await T();
|
|
288
|
+
if (!e.isLoggedIn) {
|
|
289
|
+
console.log("Not currently logged in.");
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (e.method === "env") {
|
|
293
|
+
console.log("You are logged in using environment variables. To log out, unset LOCALESS_TOKEN, LOCALESS_SPACE, and LOCALESS_ORIGIN.");
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
try {
|
|
297
|
+
await D(), console.log("Successfully logged out.");
|
|
298
|
+
} catch (e) {
|
|
299
|
+
console.error("Failed to log out:", e);
|
|
300
|
+
}
|
|
301
|
+
}), A = s(u.cwd(), x, "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", A).action(async (e) => {
|
|
302
|
+
console.log("Types in with options:", e);
|
|
303
|
+
let t = await T();
|
|
304
|
+
if (!t.isLoggedIn) {
|
|
305
|
+
console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
let n = b({
|
|
309
|
+
origin: t.origin,
|
|
310
|
+
spaceId: t.space,
|
|
311
|
+
token: t.token
|
|
312
|
+
});
|
|
313
|
+
console.log("Fetching OpenAPI specification from Localess...");
|
|
314
|
+
let r = await n.getOpenApi();
|
|
315
|
+
console.log("Generating types from OpenAPI specification...");
|
|
316
|
+
try {
|
|
317
|
+
await d({
|
|
318
|
+
input: { target: r },
|
|
319
|
+
output: {
|
|
320
|
+
target: e.path,
|
|
321
|
+
client: "fetch",
|
|
322
|
+
mode: "single"
|
|
323
|
+
}
|
|
324
|
+
}), console.log(`Types generated successfully at ${e.path}`);
|
|
325
|
+
} catch (e) {
|
|
326
|
+
console.error(e);
|
|
327
|
+
}
|
|
328
|
+
}), M = new e("types").description("Generate types for your schemas").addCommand(j), N = /* @__PURE__ */ function(e) {
|
|
329
|
+
return e.ADD_MISSING = "add-missing", e.UPDATE_EXISTING = "update-existing", e.DELETE_MISSING = "delete-missing", e;
|
|
330
|
+
}({}), P = /* @__PURE__ */ function(e) {
|
|
331
|
+
return e.FLAT = "flat", e.NESTED = "nested", e;
|
|
332
|
+
}({}), F = f.record(f.string(), f.string()), I = f.enum(["add-missing", "update-existing"]);
|
|
333
|
+
f.object({
|
|
334
|
+
type: I,
|
|
335
|
+
values: F
|
|
480
336
|
});
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
target: options.path,
|
|
535
|
-
client: "fetch",
|
|
536
|
-
mode: "single"
|
|
537
|
-
}
|
|
538
|
-
});
|
|
539
|
-
console.log(`Types generated successfully at ${options.path}`);
|
|
540
|
-
} catch (e) {
|
|
541
|
-
console.error(e);
|
|
542
|
-
}
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
// src/commands/types/index.ts
|
|
546
|
-
var typesCommand = new Command4("types").description("Generate types for your schemas").addCommand(typesGenerateCommand);
|
|
547
|
-
|
|
548
|
-
// src/commands/translations/index.ts
|
|
549
|
-
import { Command as Command7 } from "commander";
|
|
550
|
-
|
|
551
|
-
// src/commands/translations/push/index.ts
|
|
552
|
-
import { Command as Command5 } from "commander";
|
|
553
|
-
|
|
554
|
-
// src/models/translations.ts
|
|
555
|
-
var TranslationUpdateType = /* @__PURE__ */ ((TranslationUpdateType2) => {
|
|
556
|
-
TranslationUpdateType2["ADD_MISSING"] = "add-missing";
|
|
557
|
-
TranslationUpdateType2["UPDATE_EXISTING"] = "update-existing";
|
|
558
|
-
TranslationUpdateType2["DELETE_MISSING"] = "delete-missing";
|
|
559
|
-
return TranslationUpdateType2;
|
|
560
|
-
})(TranslationUpdateType || {});
|
|
561
|
-
var TranslationFileFormat = /* @__PURE__ */ ((TranslationFileFormat2) => {
|
|
562
|
-
TranslationFileFormat2["FLAT"] = "flat";
|
|
563
|
-
TranslationFileFormat2["NESTED"] = "nested";
|
|
564
|
-
return TranslationFileFormat2;
|
|
565
|
-
})(TranslationFileFormat || {});
|
|
566
|
-
|
|
567
|
-
// src/models/translation.zod.ts
|
|
568
|
-
import { z } from "zod";
|
|
569
|
-
var zLocaleTranslationsSchema = z.record(z.string(), z.string());
|
|
570
|
-
var zTranslationUpdateTypeSchema = z.enum(["add-missing", "update-existing"]);
|
|
571
|
-
var zTranslationUpdateSchema = z.object({
|
|
572
|
-
type: zTranslationUpdateTypeSchema,
|
|
573
|
-
values: zLocaleTranslationsSchema
|
|
574
|
-
});
|
|
575
|
-
|
|
576
|
-
// src/commands/translations/push/index.ts
|
|
577
|
-
var translationsPushCommand = new Command5("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(TranslationFileFormat)}`, "flat" /* FLAT */).option("-t, --type <type>", `Push type. Possible values are : ${Object.values(TranslationUpdateType)}`, "add-missing" /* ADD_MISSING */).option("--dry-run", "Preview changes without applying them to Localess").action(async (locale, options) => {
|
|
578
|
-
console.log("Pushing translations with arguments:", locale);
|
|
579
|
-
console.log("Pushing translations with options:", options);
|
|
580
|
-
if (!zTranslationUpdateTypeSchema.safeParse(options.type).success) {
|
|
581
|
-
console.error("Invalid type provided. Possible values are :", Object.values(TranslationUpdateType));
|
|
582
|
-
return;
|
|
583
|
-
}
|
|
584
|
-
const session = await getSession();
|
|
585
|
-
if (!session.isLoggedIn) {
|
|
586
|
-
console.error("Not logged in");
|
|
587
|
-
console.error('Please log in first using "localess login" command');
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
590
|
-
const client = localessClient({
|
|
591
|
-
origin: session.origin,
|
|
592
|
-
spaceId: session.space,
|
|
593
|
-
token: session.token
|
|
594
|
-
});
|
|
595
|
-
if (options.dryRun) {
|
|
596
|
-
console.warn("Dry run mode enabled: No changes will be made.");
|
|
597
|
-
}
|
|
598
|
-
if (options.format === "nested" /* NESTED */) {
|
|
599
|
-
console.error("Nested format is not implemented yet. Please use flat format for now.");
|
|
600
|
-
}
|
|
601
|
-
console.log("Reading translations file from:", options.path);
|
|
602
|
-
const fileContent = await readFile(options.path);
|
|
603
|
-
const translationValues = JSON.parse(fileContent);
|
|
604
|
-
const pResult = zLocaleTranslationsSchema.safeParse(translationValues);
|
|
605
|
-
if (!pResult.success) {
|
|
606
|
-
console.error("Invalid translations file format:", pResult.error);
|
|
607
|
-
return;
|
|
608
|
-
}
|
|
609
|
-
console.log("Pushing translations to Localess with locale:", locale, "and type:", options.type);
|
|
610
|
-
const response = await client.updateTranslations(locale, options.type, translationValues, options.dryRun);
|
|
611
|
-
if (response) {
|
|
612
|
-
if (response.dryRun) {
|
|
613
|
-
console.log("Dry run results:");
|
|
614
|
-
}
|
|
615
|
-
console.log("Successfully pushed translations to Localess");
|
|
616
|
-
console.log("Summary:", response.message);
|
|
617
|
-
if (response.ids) {
|
|
618
|
-
console.log("Updated translation IDs:", response.ids);
|
|
619
|
-
}
|
|
620
|
-
} else {
|
|
621
|
-
console.log("Something went wrong while pushing translations to Localess");
|
|
622
|
-
}
|
|
623
|
-
});
|
|
624
|
-
|
|
625
|
-
// src/commands/translations/pull/index.ts
|
|
626
|
-
import { Command as Command6 } from "commander";
|
|
627
|
-
var translationsPullCommand = new Command6("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(TranslationFileFormat)}`, "flat" /* FLAT */).action(async (locale, options) => {
|
|
628
|
-
console.log("Pulling translations with arguments:", locale);
|
|
629
|
-
console.log("Pulling translations with options:", options);
|
|
630
|
-
if (!Object.values(TranslationFileFormat).includes(options.format)) {
|
|
631
|
-
console.error("Invalid format provided. Possible values are :", Object.values(TranslationFileFormat));
|
|
632
|
-
return;
|
|
633
|
-
}
|
|
634
|
-
const session = await getSession();
|
|
635
|
-
if (!session.isLoggedIn) {
|
|
636
|
-
console.error("Not logged in");
|
|
637
|
-
console.error('Please log in first using "localess login" command');
|
|
638
|
-
return;
|
|
639
|
-
}
|
|
640
|
-
const client = localessClient({
|
|
641
|
-
origin: session.origin,
|
|
642
|
-
spaceId: session.space,
|
|
643
|
-
token: session.token
|
|
644
|
-
});
|
|
645
|
-
console.log("Pulling translations from Localess for locale:", locale);
|
|
646
|
-
const translations = await client.getTranslations(locale);
|
|
647
|
-
console.log("Saving translations in file:", options.path);
|
|
648
|
-
if (options.format === "flat" /* FLAT */) {
|
|
649
|
-
await writeFile(options.path, JSON.stringify(translations, null, 2));
|
|
650
|
-
} else if (options.format === "nested" /* NESTED */) {
|
|
651
|
-
const nestedTranslations = dotToNestedObject(translations);
|
|
652
|
-
await writeFile(options.path, JSON.stringify(nestedTranslations, null, 2));
|
|
653
|
-
}
|
|
654
|
-
console.log("Successfully saved translations from Localess");
|
|
655
|
-
});
|
|
656
|
-
|
|
657
|
-
// src/commands/translations/index.ts
|
|
658
|
-
var translationsCommand = new Command7("translations").description("Manage translations").addCommand(translationsPushCommand).addCommand(translationsPullCommand);
|
|
659
|
-
|
|
660
|
-
// src/program.ts
|
|
661
|
-
var program = new Command8();
|
|
662
|
-
program.name("Localess CLI").description("CLI tool for Localess platform management").version("0.0.6");
|
|
663
|
-
program.addCommand(loginCommand);
|
|
664
|
-
program.addCommand(logoutCommand);
|
|
665
|
-
program.addCommand(translationsCommand);
|
|
666
|
-
program.addCommand(typesCommand);
|
|
667
|
-
|
|
668
|
-
// src/index.ts
|
|
337
|
+
//#endregion
|
|
338
|
+
//#region src/commands/translations/push/index.ts
|
|
339
|
+
var L = 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) => {
|
|
340
|
+
if (console.log("Pushing translations with arguments:", e), console.log("Pushing translations with options:", t), !I.safeParse(t.type).success) {
|
|
341
|
+
console.error("Invalid type provided. Possible values are :", Object.values(N));
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
let n = await T();
|
|
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 = b({
|
|
350
|
+
origin: n.origin,
|
|
351
|
+
spaceId: n.space,
|
|
352
|
+
token: n.token
|
|
353
|
+
});
|
|
354
|
+
t.dryRun && console.warn("Dry run mode enabled: No changes will be made."), t.format === P.NESTED && console.error("Nested format is not implemented yet. Please use flat format for now."), console.log("Reading translations file from:", t.path);
|
|
355
|
+
let i = await C(t.path), a = JSON.parse(i), o = F.safeParse(a);
|
|
356
|
+
if (!o.success) {
|
|
357
|
+
console.error("Invalid translations file format:", o.error);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
console.log("Pushing translations to Localess with locale:", e, "and type:", t.type);
|
|
361
|
+
let s = await r.updateTranslations(e, t.type, a, t.dryRun);
|
|
362
|
+
s ? (s.dryRun && console.log("Dry run results:"), console.log("Successfully pushed translations to Localess"), console.log("Summary:", s.message), s.ids && console.log("Updated translation IDs:", s.ids)) : console.log("Something went wrong while pushing translations to Localess");
|
|
363
|
+
}), R = 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) => {
|
|
364
|
+
if (console.log("Pulling translations with arguments:", e), console.log("Pulling translations with options:", t), !Object.values(P).includes(t.format)) {
|
|
365
|
+
console.error("Invalid format provided. Possible values are :", Object.values(P));
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
let n = await T();
|
|
369
|
+
if (!n.isLoggedIn) {
|
|
370
|
+
console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
let r = b({
|
|
374
|
+
origin: n.origin,
|
|
375
|
+
spaceId: n.space,
|
|
376
|
+
token: n.token
|
|
377
|
+
});
|
|
378
|
+
console.log("Pulling translations from Localess for locale:", e);
|
|
379
|
+
let i = await r.getTranslations(e);
|
|
380
|
+
if (console.log("Saving translations in file:", t.path), t.format === P.FLAT) await S(t.path, JSON.stringify(i, null, 2));
|
|
381
|
+
else if (t.format === P.NESTED) {
|
|
382
|
+
let e = h(i);
|
|
383
|
+
await S(t.path, JSON.stringify(e, null, 2));
|
|
384
|
+
}
|
|
385
|
+
console.log("Successfully saved translations from Localess");
|
|
386
|
+
}), z = new e("translations").description("Manage translations").addCommand(L).addCommand(R), B = new e();
|
|
387
|
+
B.name("Localess CLI").description("CLI tool for Localess platform management").version("0.0.6"), B.addCommand(O), B.addCommand(k), B.addCommand(z), B.addCommand(M);
|
|
388
|
+
//#endregion
|
|
389
|
+
//#region src/index.ts
|
|
669
390
|
try {
|
|
670
|
-
|
|
391
|
+
B.parse(process.argv);
|
|
671
392
|
} catch (e) {
|
|
672
|
-
|
|
673
|
-
process.exit(1);
|
|
393
|
+
console.error("Error executing command:", e instanceof Error ? e.message : e), process.exit(1);
|
|
674
394
|
}
|
|
395
|
+
//#endregion
|