@localess/cli 3.0.1-dev.20260413071348 → 3.0.1-dev.20260425192604
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 +177 -113
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -5,11 +5,10 @@ import { access as r, mkdir as i, readFile as a, writeFile as o } from "node:fs/
|
|
|
5
5
|
import { join as s, parse as c } from "node:path";
|
|
6
6
|
import * as l from "node:process";
|
|
7
7
|
import u from "node:process";
|
|
8
|
-
import {
|
|
9
|
-
import { z as f } from "zod";
|
|
8
|
+
import { z as d } from "zod";
|
|
10
9
|
//#region src/utils.ts
|
|
11
|
-
var
|
|
12
|
-
function
|
|
10
|
+
var f = "\x1B[0m", p = "\x1B[34m";
|
|
11
|
+
function m(e) {
|
|
13
12
|
let t = {};
|
|
14
13
|
for (let [n, r] of Object.entries(e)) {
|
|
15
14
|
let e = n.split("."), i = t;
|
|
@@ -19,13 +18,13 @@ function h(e) {
|
|
|
19
18
|
}
|
|
20
19
|
//#endregion
|
|
21
20
|
//#region src/cache.ts
|
|
22
|
-
var
|
|
21
|
+
var h = class {
|
|
23
22
|
set(e, t) {}
|
|
24
23
|
get(e) {}
|
|
25
24
|
has(e) {
|
|
26
25
|
return !1;
|
|
27
26
|
}
|
|
28
|
-
},
|
|
27
|
+
}, g = class {
|
|
29
28
|
cache = /* @__PURE__ */ new Map();
|
|
30
29
|
constructor(e = 3e5) {
|
|
31
30
|
this.ttlMs = e;
|
|
@@ -49,23 +48,23 @@ var g = class {
|
|
|
49
48
|
has(e) {
|
|
50
49
|
return this.get(e) !== void 0;
|
|
51
50
|
}
|
|
52
|
-
},
|
|
53
|
-
async function
|
|
51
|
+
}, _ = `${p}[Localess:Client]${f}`;
|
|
52
|
+
async function v(e, t, n = 3, r = 500, i) {
|
|
54
53
|
let a = 0, o;
|
|
55
54
|
for (; a <= n;) {
|
|
56
55
|
try {
|
|
57
56
|
let n = await fetch(e, t);
|
|
58
|
-
if (!n.ok && n.status >= 500) i && console.log(
|
|
57
|
+
if (!n.ok && n.status >= 500) i && console.log(_, `fetchWithRetry: HTTP ${n.status} on attempt ${a + 1}`), o = /* @__PURE__ */ Error(`HTTP ${n.status}`);
|
|
59
58
|
else return n;
|
|
60
59
|
} catch (e) {
|
|
61
|
-
i && console.log(
|
|
60
|
+
i && console.log(_, `fetchWithRetry: network error on attempt ${a + 1}`, e), o = e;
|
|
62
61
|
}
|
|
63
62
|
a++, a <= n && await new Promise((e) => setTimeout(e, r));
|
|
64
63
|
}
|
|
65
64
|
throw o;
|
|
66
65
|
}
|
|
67
|
-
function
|
|
68
|
-
e.debug && console.log(
|
|
66
|
+
function y(e) {
|
|
67
|
+
e.debug && console.log(_, "Client Options : ", e);
|
|
69
68
|
let t = e.origin.replace(/\/+$/, ""), n = {
|
|
70
69
|
redirect: "follow",
|
|
71
70
|
headers: {
|
|
@@ -74,23 +73,23 @@ function b(e) {
|
|
|
74
73
|
"X-Localess-Agent": "Localess-CLI-Client",
|
|
75
74
|
"X-Localess-Agent-Version": "0.9.0"
|
|
76
75
|
}
|
|
77
|
-
}, r = e.cacheTTL === !1 ? new
|
|
76
|
+
}, r = e.cacheTTL === !1 ? new h() : new g(e.cacheTTL);
|
|
78
77
|
return {
|
|
79
78
|
async getSpace() {
|
|
80
|
-
e.debug && console.log(
|
|
79
|
+
e.debug && console.log(_, "getSpace()");
|
|
81
80
|
let i = `${t}/api/v1/spaces/${e.spaceId}?token=${e.token}`;
|
|
82
|
-
if (e.debug && console.log(
|
|
81
|
+
if (e.debug && console.log(_, "getSpace fetch url : ", i), r.has(i)) return e.debug && console.log(_, "getSpace cache hit"), r.get(i);
|
|
83
82
|
try {
|
|
84
|
-
let t = await
|
|
85
|
-
e.debug && console.log(
|
|
83
|
+
let t = await v(i, n, e.retryCount, e.retryDelay, e.debug);
|
|
84
|
+
e.debug && console.log(_, "getSpace status : ", t.status);
|
|
86
85
|
let a = await t.json();
|
|
87
86
|
return r.set(i, a), a;
|
|
88
87
|
} catch (e) {
|
|
89
|
-
return console.error(
|
|
88
|
+
return console.error(_, "getSpace error : ", e), {};
|
|
90
89
|
}
|
|
91
90
|
},
|
|
92
91
|
async getLinks(i) {
|
|
93
|
-
e.debug && console.log(
|
|
92
|
+
e.debug && console.log(_, "getLinks() params : ", JSON.stringify(i));
|
|
94
93
|
let a = "";
|
|
95
94
|
i?.kind && (a = `&kind=${i.kind}`);
|
|
96
95
|
let o = "";
|
|
@@ -98,72 +97,72 @@ function b(e) {
|
|
|
98
97
|
let s = "";
|
|
99
98
|
i?.excludeChildren && (s = `&excludeChildren=${i.excludeChildren}`);
|
|
100
99
|
let c = `${t}/api/v1/spaces/${e.spaceId}/links?token=${e.token}${a}${o}${s}`;
|
|
101
|
-
if (e.debug && console.log(
|
|
100
|
+
if (e.debug && console.log(_, "getLinks fetch url : ", c), r.has(c)) return e.debug && console.log(_, "getLinks cache hit"), r.get(c);
|
|
102
101
|
try {
|
|
103
|
-
let t = await
|
|
104
|
-
e.debug && console.log(
|
|
102
|
+
let t = await v(c, n, e.retryCount, e.retryDelay, e.debug);
|
|
103
|
+
e.debug && console.log(_, "getLinks status : ", t.status);
|
|
105
104
|
let i = await t.json();
|
|
106
105
|
return r.set(c, i), i;
|
|
107
106
|
} catch (e) {
|
|
108
|
-
return console.error(
|
|
107
|
+
return console.error(_, "getLinks error : ", e), {};
|
|
109
108
|
}
|
|
110
109
|
},
|
|
111
110
|
async getContentBySlug(i, a) {
|
|
112
|
-
e.debug && (console.log(
|
|
111
|
+
e.debug && (console.log(_, "getContentBySlug() slug : ", i), console.log(_, "getContentBySlug() params : ", JSON.stringify(a)));
|
|
113
112
|
let o = "";
|
|
114
113
|
e?.version && e.version == "draft" && (o = `&version=${e.version}`), a?.version && a.version == "draft" && (o = `&version=${a.version}`);
|
|
115
114
|
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(
|
|
115
|
+
if (e.debug && console.log(_, "getContentBySlug fetch url : ", u), r.has(u)) return e.debug && console.log(_, "getContentBySlug cache hit"), r.get(u);
|
|
117
116
|
try {
|
|
118
|
-
let t = await
|
|
119
|
-
e.debug && console.log(
|
|
117
|
+
let t = await v(u, n, e.retryCount, e.retryDelay, e.debug);
|
|
118
|
+
e.debug && console.log(_, "getContentBySlug status : ", t.status);
|
|
120
119
|
let i = await t.json();
|
|
121
120
|
return r.set(u, i), i;
|
|
122
121
|
} catch (e) {
|
|
123
|
-
return console.error(
|
|
122
|
+
return console.error(_, "getContentBySlug error : ", e), {};
|
|
124
123
|
}
|
|
125
124
|
},
|
|
126
125
|
async getContentById(i, a) {
|
|
127
|
-
e.debug && (console.log(
|
|
126
|
+
e.debug && (console.log(_, "getContentById() id : ", i), console.log(_, "getContentById() params : ", JSON.stringify(a)));
|
|
128
127
|
let o = "";
|
|
129
128
|
e?.version && e.version == "draft" && (o = `&version=${e.version}`), a?.version && a.version == "draft" && (o = `&version=${a.version}`);
|
|
130
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/${i}?token=${e.token}${o}${s}${c}${l}`;
|
|
131
|
-
if (e.debug && console.log(
|
|
130
|
+
if (e.debug && console.log(_, "getContentById fetch url : ", u), r.has(u)) return e.debug && console.log(_, "getContentById cache hit"), r.get(u);
|
|
132
131
|
try {
|
|
133
|
-
let t = await
|
|
134
|
-
e.debug && console.log(
|
|
132
|
+
let t = await v(u, n, e.retryCount, e.retryDelay, e.debug);
|
|
133
|
+
e.debug && console.log(_, "getContentById status : ", t.status);
|
|
135
134
|
let i = await t.json();
|
|
136
135
|
return r.set(u, i), i;
|
|
137
136
|
} catch (e) {
|
|
138
|
-
return console.error(
|
|
137
|
+
return console.error(_, "getContentById error : ", e), {};
|
|
139
138
|
}
|
|
140
139
|
},
|
|
141
140
|
async getTranslations(i, a) {
|
|
142
|
-
e.debug && (console.log(
|
|
141
|
+
e.debug && (console.log(_, "getTranslations() locale : ", i), console.log(_, "getTranslations() params : ", JSON.stringify(a)));
|
|
143
142
|
let o = "";
|
|
144
143
|
e?.version && e.version == "draft" && (o = `&version=${e.version}`), a?.version && a.version == "draft" && (o = `&version=${a.version}`);
|
|
145
144
|
let s = `${t}/api/v1/spaces/${e.spaceId}/translations/${i}?token=${e.token}${o}`;
|
|
146
|
-
if (e.debug && console.log(
|
|
145
|
+
if (e.debug && console.log(_, "getTranslations fetch url : ", s), r.has(s)) return e.debug && console.log(_, "getTranslations cache hit"), r.get(s);
|
|
147
146
|
try {
|
|
148
|
-
let t = await
|
|
149
|
-
e.debug && console.log(
|
|
147
|
+
let t = await v(s, n, e.retryCount, e.retryDelay, e.debug);
|
|
148
|
+
e.debug && console.log(_, "getTranslations status : ", t.status);
|
|
150
149
|
let i = await t.json();
|
|
151
150
|
return r.set(s, i), i;
|
|
152
151
|
} catch (e) {
|
|
153
|
-
return console.error(
|
|
152
|
+
return console.error(_, "getTranslations error : ", e), {};
|
|
154
153
|
}
|
|
155
154
|
},
|
|
156
155
|
async updateTranslations(r, i, a, o) {
|
|
157
|
-
e.debug && (console.log(
|
|
156
|
+
e.debug && (console.log(_, "updateTranslations() locale : ", r), console.log(_, "updateTranslations() type : ", i), console.log(_, "updateTranslations() values : ", JSON.stringify(a)));
|
|
158
157
|
let s = `${t}/api/v1/spaces/${e.spaceId}/translations/${r}`;
|
|
159
|
-
e.debug && console.log(
|
|
158
|
+
e.debug && console.log(_, "updateTranslations fetch url : ", s);
|
|
160
159
|
let c = {
|
|
161
160
|
type: i,
|
|
162
161
|
values: a,
|
|
163
162
|
dryRun: o
|
|
164
163
|
};
|
|
165
164
|
try {
|
|
166
|
-
let t = await
|
|
165
|
+
let t = await v(s, {
|
|
167
166
|
method: "POST",
|
|
168
167
|
headers: {
|
|
169
168
|
"X-API-KEY": e.token,
|
|
@@ -171,26 +170,36 @@ function b(e) {
|
|
|
171
170
|
},
|
|
172
171
|
body: JSON.stringify(c)
|
|
173
172
|
}, e.retryCount, e.retryDelay, e.debug);
|
|
174
|
-
return e.debug && console.log(
|
|
173
|
+
return e.debug && console.log(_, "updateTranslations status : ", t.status), t.json();
|
|
175
174
|
} catch (e) {
|
|
176
|
-
console.error(
|
|
175
|
+
console.error(_, "updateTranslations error : ", e);
|
|
177
176
|
}
|
|
178
177
|
},
|
|
179
178
|
async getOpenApi() {
|
|
180
|
-
e.debug && console.log(
|
|
179
|
+
e.debug && console.log(_, "getOpenApi()");
|
|
181
180
|
let i = `${t}/api/v1/spaces/${e.spaceId}/open-api?token=${e.token}`;
|
|
182
|
-
if (e.debug && console.log(
|
|
181
|
+
if (e.debug && console.log(_, "getOpenApi fetch url : ", i), r.has(i)) return e.debug && console.log(_, "getOpenApi cache hit"), r.get(i);
|
|
183
182
|
try {
|
|
184
|
-
let t = await
|
|
185
|
-
e.debug && console.log(
|
|
183
|
+
let t = await v(i, n, e.retryCount, e.retryDelay, e.debug);
|
|
184
|
+
e.debug && console.log(_, "getOpenApi status : ", t.status);
|
|
186
185
|
let a = await t.json();
|
|
187
186
|
return r.set(i, a), a;
|
|
188
187
|
} catch (e) {
|
|
189
|
-
return console.error(
|
|
188
|
+
return console.error(_, "getOpenApi error : ", e), {};
|
|
190
189
|
}
|
|
191
190
|
},
|
|
192
|
-
|
|
193
|
-
|
|
191
|
+
async getSchemas() {
|
|
192
|
+
e.debug && console.log(_, "getSchemas()");
|
|
193
|
+
let i = `${t}/api/v1/spaces/${e.spaceId}/schemas?token=${e.token}`;
|
|
194
|
+
if (e.debug && console.log(_, "getSchemas fetch url : ", i), r.has(i)) return e.debug && console.log(_, "getSchemas cache hit"), r.get(i);
|
|
195
|
+
try {
|
|
196
|
+
let t = await v(i, n, e.retryCount, e.retryDelay, e.debug);
|
|
197
|
+
e.debug && console.log(_, "getSchemas status : ", t.status);
|
|
198
|
+
let a = await t.json();
|
|
199
|
+
return r.set(i, a), a;
|
|
200
|
+
} catch (e) {
|
|
201
|
+
return console.error(_, "getSchemas error : ", e), {};
|
|
202
|
+
}
|
|
194
203
|
},
|
|
195
204
|
assetLink(n) {
|
|
196
205
|
return typeof n == "string" ? `${t}/api/v1/spaces/${e.spaceId}/assets/${n}` : `${t}/api/v1/spaces/${e.spaceId}/assets/${n.uri}`;
|
|
@@ -199,8 +208,8 @@ function b(e) {
|
|
|
199
208
|
}
|
|
200
209
|
//#endregion
|
|
201
210
|
//#region src/file.ts
|
|
202
|
-
var
|
|
203
|
-
async function
|
|
211
|
+
var b = ".localess";
|
|
212
|
+
async function x(e, t, n) {
|
|
204
213
|
let r = c(e).dir;
|
|
205
214
|
try {
|
|
206
215
|
await i(r, { recursive: !0 });
|
|
@@ -211,13 +220,13 @@ async function S(e, t, n) {
|
|
|
211
220
|
await o(e, t, n);
|
|
212
221
|
} catch {}
|
|
213
222
|
}
|
|
214
|
-
async function
|
|
223
|
+
async function S(e) {
|
|
215
224
|
return a(e, "utf-8");
|
|
216
225
|
}
|
|
217
226
|
//#endregion
|
|
218
227
|
//#region src/session.ts
|
|
219
|
-
var
|
|
220
|
-
async function
|
|
228
|
+
var C = s(l.cwd(), b, "credentials.json");
|
|
229
|
+
async function w() {
|
|
221
230
|
let e = { isLoggedIn: !1 }, t = l.env.LOCALESS_TOKEN, n = l.env.LOCALESS_SPACE, i = l.env.LOCALESS_ORIGIN;
|
|
222
231
|
if (t && n && i) return console.debug("Login in using environment variables."), {
|
|
223
232
|
isLoggedIn: !0,
|
|
@@ -227,8 +236,8 @@ async function T() {
|
|
|
227
236
|
method: "env"
|
|
228
237
|
};
|
|
229
238
|
try {
|
|
230
|
-
await r(
|
|
231
|
-
let t = await a(
|
|
239
|
+
await r(C);
|
|
240
|
+
let t = await a(C, "utf8"), n = JSON.parse(t);
|
|
232
241
|
if (Object.keys(n).length === 0) return e;
|
|
233
242
|
if (n.origin && n.token && n.space) return console.debug("Login in using credentials file."), {
|
|
234
243
|
isLoggedIn: !0,
|
|
@@ -240,21 +249,21 @@ async function T() {
|
|
|
240
249
|
} catch {}
|
|
241
250
|
return e;
|
|
242
251
|
}
|
|
243
|
-
async function
|
|
244
|
-
if (e.origin && e.token && e.space) await
|
|
252
|
+
async function T(e) {
|
|
253
|
+
if (e.origin && e.token && e.space) await x(C, 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
254
|
else throw Error("Cannot persist session: missing required fields.");
|
|
246
255
|
}
|
|
247
|
-
async function
|
|
256
|
+
async function E() {
|
|
248
257
|
try {
|
|
249
|
-
await r(
|
|
258
|
+
await r(C), await x(C, "{}", { mode: 384 });
|
|
250
259
|
} catch {
|
|
251
260
|
throw Error("Failed to clear session credentials.");
|
|
252
261
|
}
|
|
253
262
|
}
|
|
254
263
|
//#endregion
|
|
255
264
|
//#region src/commands/login/index.ts
|
|
256
|
-
var
|
|
257
|
-
if ((await
|
|
265
|
+
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) => {
|
|
266
|
+
if ((await w()).isLoggedIn) {
|
|
258
267
|
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
268
|
return;
|
|
260
269
|
}
|
|
@@ -267,14 +276,14 @@ var O = new e("login").description("Login to Localess CLI").option("-o, --origin
|
|
|
267
276
|
}), a = e.token ?? await n({
|
|
268
277
|
message: "Token:",
|
|
269
278
|
mask: !0
|
|
270
|
-
}), o =
|
|
279
|
+
}), o = y({
|
|
271
280
|
origin: r,
|
|
272
281
|
spaceId: i,
|
|
273
282
|
token: a
|
|
274
283
|
});
|
|
275
284
|
try {
|
|
276
285
|
let e = await o.getSpace();
|
|
277
|
-
console.log(`Successfully logged in to space: ${e.name} (${e.id})`), await
|
|
286
|
+
console.log(`Successfully logged in to space: ${e.name} (${e.id})`), await T({
|
|
278
287
|
origin: r,
|
|
279
288
|
space: i,
|
|
280
289
|
token: a
|
|
@@ -282,9 +291,9 @@ var O = new e("login").description("Login to Localess CLI").option("-o, --origin
|
|
|
282
291
|
} catch {
|
|
283
292
|
console.error("Login failed");
|
|
284
293
|
}
|
|
285
|
-
}),
|
|
294
|
+
}), O = new e("logout").description("Logout from Localess CLI").action(async () => {
|
|
286
295
|
console.log("Logging out...");
|
|
287
|
-
let e = await
|
|
296
|
+
let e = await w();
|
|
288
297
|
if (!e.isLoggedIn) {
|
|
289
298
|
console.log("Not currently logged in.");
|
|
290
299
|
return;
|
|
@@ -294,65 +303,120 @@ var O = new e("login").description("Login to Localess CLI").option("-o, --origin
|
|
|
294
303
|
return;
|
|
295
304
|
}
|
|
296
305
|
try {
|
|
297
|
-
await
|
|
306
|
+
await E(), console.log("Successfully logged out.");
|
|
298
307
|
} catch (e) {
|
|
299
308
|
console.error("Failed to log out:", e);
|
|
300
309
|
}
|
|
301
|
-
}),
|
|
310
|
+
}), k = /* @__PURE__ */ function(e) {
|
|
311
|
+
return e.ROOT = "ROOT", e.NODE = "NODE", e.ENUM = "ENUM", e;
|
|
312
|
+
}({}), A = /* @__PURE__ */ function(e) {
|
|
313
|
+
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
|
+
}({}), j = /* @__PURE__ */ function(e) {
|
|
315
|
+
return e.ADD_MISSING = "add-missing", e.UPDATE_EXISTING = "update-existing", e.DELETE_MISSING = "delete-missing", e;
|
|
316
|
+
}({}), M = /* @__PURE__ */ function(e) {
|
|
317
|
+
return e.FLAT = "flat", e.NESTED = "nested", e;
|
|
318
|
+
}({}), N = "// Generated by Localess CLI - do not edit manually\n\nexport interface ContentAsset {\n kind: 'ASSET';\n uri: string;\n}\n\nexport interface ContentLink {\n kind: 'LINK';\n target: '_blank' | '_self';\n type: 'url' | 'content';\n uri: string;\n}\n\nexport interface ContentReference {\n kind: 'REFERENCE';\n uri: string;\n}\n\nexport interface ContentRichText {\n type?: string;\n content?: ContentRichText[];\n}\n";
|
|
319
|
+
function P(e) {
|
|
320
|
+
return e.replace(/[-_\s]+([a-zA-Z0-9])/g, (e, t) => t.toUpperCase()).replace(/^[a-z]/, (e) => e.toUpperCase());
|
|
321
|
+
}
|
|
322
|
+
function F(e) {
|
|
323
|
+
switch (e.kind) {
|
|
324
|
+
case A.TEXT:
|
|
325
|
+
case A.TEXTAREA:
|
|
326
|
+
case A.MARKDOWN:
|
|
327
|
+
case A.COLOR:
|
|
328
|
+
case A.DATE:
|
|
329
|
+
case A.DATETIME: return "string";
|
|
330
|
+
case A.NUMBER: return "number";
|
|
331
|
+
case A.BOOLEAN: return "boolean";
|
|
332
|
+
case A.RICH_TEXT: return "ContentRichText";
|
|
333
|
+
case A.LINK: return "ContentLink";
|
|
334
|
+
case A.ASSET: return "ContentAsset";
|
|
335
|
+
case A.ASSETS: return "ContentAsset[]";
|
|
336
|
+
case A.REFERENCE: return "ContentReference";
|
|
337
|
+
case A.REFERENCES: return "ContentReference[]";
|
|
338
|
+
case A.OPTION: return e.source ? P(e.source) : "string";
|
|
339
|
+
case A.OPTIONS: return e.source ? `${P(e.source)}[]` : "string[]";
|
|
340
|
+
case A.SCHEMA: {
|
|
341
|
+
let t = e.schemas;
|
|
342
|
+
if (!t || t.length === 0) return "unknown";
|
|
343
|
+
let n = t.map((e) => P(e));
|
|
344
|
+
return n.length === 1 ? n[0] : n.join(" | ");
|
|
345
|
+
}
|
|
346
|
+
case A.SCHEMAS: {
|
|
347
|
+
let t = e.schemas;
|
|
348
|
+
if (!t || t.length === 0) return "unknown[]";
|
|
349
|
+
let n = t.map((e) => P(e));
|
|
350
|
+
return `${n.length === 1 ? n[0] : `(${n.join(" | ")})`}[]`;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
function I(e) {
|
|
355
|
+
let t = [N], n = [];
|
|
356
|
+
for (let [r, i] of Object.entries(e)) {
|
|
357
|
+
let e = P(r);
|
|
358
|
+
if (i.type === k.ENUM) {
|
|
359
|
+
let n = i.values ?? [];
|
|
360
|
+
if (n.length === 0) t.push(`export type ${e} = string;\n`);
|
|
361
|
+
else {
|
|
362
|
+
let r = n.map((e) => `'${e.value}'`).join(" | ");
|
|
363
|
+
t.push(`export type ${e} = ${r};\n`);
|
|
364
|
+
}
|
|
365
|
+
} else {
|
|
366
|
+
let r = i;
|
|
367
|
+
i.type === k.ROOT && n.push(e);
|
|
368
|
+
let a = (r.fields ?? []).map((e) => {
|
|
369
|
+
let t = F(e), n = e.required ? "" : "?";
|
|
370
|
+
return ` ${e.name}${n}: ${t};`;
|
|
371
|
+
});
|
|
372
|
+
t.push(`export interface ${e} {\n${a.join("\n")}\n}\n`);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return n.length > 0 ? t.push(`export type ContentData = ${n.join(" | ")};\n`) : t.push("export type ContentData = unknown;\n"), t.join("\n");
|
|
376
|
+
}
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region src/commands/types/generate/index.ts
|
|
379
|
+
var L = s(u.cwd(), b, "localess.ts"), R = 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", L).action(async (e) => {
|
|
302
380
|
console.log("Types in with options:", e);
|
|
303
|
-
let t = await
|
|
381
|
+
let t = await w();
|
|
304
382
|
if (!t.isLoggedIn) {
|
|
305
383
|
console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
|
|
306
384
|
return;
|
|
307
385
|
}
|
|
308
|
-
let n =
|
|
386
|
+
let n = y({
|
|
309
387
|
origin: t.origin,
|
|
310
388
|
spaceId: t.space,
|
|
311
389
|
token: t.token
|
|
312
390
|
});
|
|
313
|
-
console.log("Fetching
|
|
314
|
-
let r = await n.
|
|
315
|
-
console.log("Generating types
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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
|
|
391
|
+
console.log("Fetching schemas from Localess...");
|
|
392
|
+
let r = await n.getSchemas();
|
|
393
|
+
console.log("Generating types...");
|
|
394
|
+
let i = I(r);
|
|
395
|
+
await x(e.path, i), console.log(`Types written to ${e.path}`);
|
|
396
|
+
}), z = new e("types").description("Generate types for your schemas").addCommand(R), B = d.record(d.string(), d.string()), V = d.enum(["add-missing", "update-existing"]);
|
|
397
|
+
d.object({
|
|
398
|
+
type: V,
|
|
399
|
+
values: B
|
|
336
400
|
});
|
|
337
401
|
//#endregion
|
|
338
402
|
//#region src/commands/translations/push/index.ts
|
|
339
|
-
var
|
|
340
|
-
if (console.log("Pushing translations with arguments:", e), console.log("Pushing translations with options:", t), !
|
|
341
|
-
console.error("Invalid type provided. Possible values are :", Object.values(
|
|
403
|
+
var H = 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(M)}`, M.FLAT).option("-t, --type <type>", `Push type. Possible values are : ${Object.values(j)}`, j.ADD_MISSING).option("--dry-run", "Preview changes without applying them to Localess").action(async (e, t) => {
|
|
404
|
+
if (console.log("Pushing translations with arguments:", e), console.log("Pushing translations with options:", t), !V.safeParse(t.type).success) {
|
|
405
|
+
console.error("Invalid type provided. Possible values are :", Object.values(j));
|
|
342
406
|
return;
|
|
343
407
|
}
|
|
344
|
-
let n = await
|
|
408
|
+
let n = await w();
|
|
345
409
|
if (!n.isLoggedIn) {
|
|
346
410
|
console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
|
|
347
411
|
return;
|
|
348
412
|
}
|
|
349
|
-
let r =
|
|
413
|
+
let r = y({
|
|
350
414
|
origin: n.origin,
|
|
351
415
|
spaceId: n.space,
|
|
352
416
|
token: n.token
|
|
353
417
|
});
|
|
354
|
-
t.dryRun && console.warn("Dry run mode enabled: No changes will be made."), t.format ===
|
|
355
|
-
let i = await
|
|
418
|
+
t.dryRun && console.warn("Dry run mode enabled: No changes will be made."), t.format === M.NESTED && console.error("Nested format is not implemented yet. Please use flat format for now."), console.log("Reading translations file from:", t.path);
|
|
419
|
+
let i = await S(t.path), a = JSON.parse(i), o = B.safeParse(a);
|
|
356
420
|
if (!o.success) {
|
|
357
421
|
console.error("Invalid translations file format:", o.error);
|
|
358
422
|
return;
|
|
@@ -360,35 +424,35 @@ var L = new e("push").argument("<locale>", "Locale to push").description("Push l
|
|
|
360
424
|
console.log("Pushing translations to Localess with locale:", e, "and type:", t.type);
|
|
361
425
|
let s = await r.updateTranslations(e, t.type, a, t.dryRun);
|
|
362
426
|
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
|
-
}),
|
|
364
|
-
if (console.log("Pulling translations with arguments:", e), console.log("Pulling translations with options:", t), !Object.values(
|
|
365
|
-
console.error("Invalid format provided. Possible values are :", Object.values(
|
|
427
|
+
}), U = 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(M)}`, M.FLAT).action(async (e, t) => {
|
|
428
|
+
if (console.log("Pulling translations with arguments:", e), console.log("Pulling translations with options:", t), !Object.values(M).includes(t.format)) {
|
|
429
|
+
console.error("Invalid format provided. Possible values are :", Object.values(M));
|
|
366
430
|
return;
|
|
367
431
|
}
|
|
368
|
-
let n = await
|
|
432
|
+
let n = await w();
|
|
369
433
|
if (!n.isLoggedIn) {
|
|
370
434
|
console.error("Not logged in"), console.error("Please log in first using \"localess login\" command");
|
|
371
435
|
return;
|
|
372
436
|
}
|
|
373
|
-
let r =
|
|
437
|
+
let r = y({
|
|
374
438
|
origin: n.origin,
|
|
375
439
|
spaceId: n.space,
|
|
376
440
|
token: n.token
|
|
377
441
|
});
|
|
378
442
|
console.log("Pulling translations from Localess for locale:", e);
|
|
379
443
|
let i = await r.getTranslations(e);
|
|
380
|
-
if (console.log("Saving translations in file:", t.path), t.format ===
|
|
381
|
-
else if (t.format ===
|
|
382
|
-
let e =
|
|
383
|
-
await
|
|
444
|
+
if (console.log("Saving translations in file:", t.path), t.format === M.FLAT) await x(t.path, JSON.stringify(i, null, 2));
|
|
445
|
+
else if (t.format === M.NESTED) {
|
|
446
|
+
let e = m(i);
|
|
447
|
+
await x(t.path, JSON.stringify(e, null, 2));
|
|
384
448
|
}
|
|
385
449
|
console.log("Successfully saved translations from Localess");
|
|
386
|
-
}),
|
|
387
|
-
|
|
450
|
+
}), W = new e("translations").description("Manage translations").addCommand(H).addCommand(U), G = new e();
|
|
451
|
+
G.name("Localess CLI").description("CLI tool for Localess platform management").version("0.0.6"), G.addCommand(D), G.addCommand(O), G.addCommand(W), G.addCommand(z);
|
|
388
452
|
//#endregion
|
|
389
453
|
//#region src/index.ts
|
|
390
454
|
try {
|
|
391
|
-
|
|
455
|
+
G.parse(process.argv);
|
|
392
456
|
} catch (e) {
|
|
393
457
|
console.error("Error executing command:", e instanceof Error ? e.message : e), process.exit(1);
|
|
394
458
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@localess/cli",
|
|
3
|
-
"version": "3.0.1-dev.
|
|
3
|
+
"version": "3.0.1-dev.20260425192604",
|
|
4
4
|
"description": "Localess Command Line.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"localess",
|
|
@@ -42,17 +42,17 @@
|
|
|
42
42
|
},
|
|
43
43
|
"license": "MIT",
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@inquirer/prompts": "^8.
|
|
45
|
+
"@inquirer/prompts": "^8.4.2",
|
|
46
46
|
"chalk": "^5.6.2",
|
|
47
47
|
"commander": "^14.0.3",
|
|
48
|
-
"orval": "^8.
|
|
48
|
+
"orval": "^8.8.1",
|
|
49
49
|
"zod": "^4.3.6"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/node": "^20",
|
|
53
53
|
"openapi3-ts": "^4.5.0",
|
|
54
54
|
"typescript": "^5.0.0",
|
|
55
|
-
"vite": "^8.0.
|
|
55
|
+
"vite": "^8.0.10",
|
|
56
56
|
"vite-plugin-dts": "^4.5.4"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|