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