@localess/cli 3.0.2-dev.20260426174629 → 3.0.2
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 +91 -38
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -315,11 +315,64 @@ var D = new e("login").description("Login to Localess CLI").option("-o, --origin
|
|
|
315
315
|
return e.ADD_MISSING = "add-missing", e.UPDATE_EXISTING = "update-existing", e.DELETE_MISSING = "delete-missing", e;
|
|
316
316
|
}({}), M = /* @__PURE__ */ function(e) {
|
|
317
317
|
return e.FLAT = "flat", e.NESTED = "nested", e;
|
|
318
|
-
}({})
|
|
318
|
+
}({});
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region src/commands/types/generate/generator.ts
|
|
321
|
+
function N(e) {
|
|
322
|
+
return `/**
|
|
323
|
+
* Generated by Localess CLI
|
|
324
|
+
* Do not edit manually.
|
|
325
|
+
*/
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Content Asset define reference to a Asset.
|
|
329
|
+
*/
|
|
330
|
+
export interface ${e}ContentAsset {
|
|
331
|
+
/** Define the type of Asset */
|
|
332
|
+
kind: 'ASSET';
|
|
333
|
+
/** Unique identifier for the asset. */
|
|
334
|
+
uri: string;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Content Link define reference to a Link.
|
|
339
|
+
*/
|
|
340
|
+
export interface ${e}ContentLink {
|
|
341
|
+
/** Define the type of Link */
|
|
342
|
+
kind: 'LINK';
|
|
343
|
+
/** Define the target of the link. _blank for new tab and _self for same tab. */
|
|
344
|
+
target: '_blank' | '_self';
|
|
345
|
+
/** Define the type of Link. URL for external links and Content for internal links. */
|
|
346
|
+
type: 'url' | 'content';
|
|
347
|
+
/** If type is content, then it will be Content ID. Otherwise it will be URL. */
|
|
348
|
+
uri: string;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Content Reference define reference to a Content.
|
|
353
|
+
*/
|
|
354
|
+
export interface ${e}ContentReference {
|
|
355
|
+
/** Define the type of Reference */
|
|
356
|
+
kind: 'REFERENCE';
|
|
357
|
+
/** Unique identifier for the Content Document. */
|
|
358
|
+
uri: string;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Content RichText define content as JSON Object.
|
|
363
|
+
*/
|
|
364
|
+
export interface ${e}ContentRichText {
|
|
365
|
+
/** Define the type of Content Node */
|
|
366
|
+
type?: string;
|
|
367
|
+
/** List of Content Nodes */
|
|
368
|
+
content?: ${e}ContentRichText[];
|
|
369
|
+
}
|
|
370
|
+
`;
|
|
371
|
+
}
|
|
319
372
|
function P(e) {
|
|
320
373
|
return e.replace(/[-_\s]+([a-zA-Z0-9])/g, (e, t) => t.toUpperCase()).replace(/^[a-z]/, (e) => e.toUpperCase());
|
|
321
374
|
}
|
|
322
|
-
function F(e) {
|
|
375
|
+
function F(e, t) {
|
|
323
376
|
switch (e.kind) {
|
|
324
377
|
case A.TEXT:
|
|
325
378
|
case A.TEXTAREA:
|
|
@@ -329,63 +382,63 @@ function F(e) {
|
|
|
329
382
|
case A.DATETIME: return "string";
|
|
330
383
|
case A.NUMBER: return "number";
|
|
331
384
|
case A.BOOLEAN: return "boolean";
|
|
332
|
-
case A.RICH_TEXT: return
|
|
333
|
-
case A.LINK: return
|
|
334
|
-
case A.ASSET: return
|
|
335
|
-
case A.ASSETS: return
|
|
336
|
-
case A.REFERENCE: return
|
|
337
|
-
case A.REFERENCES: return
|
|
338
|
-
case A.OPTION: return e.source ? P(e.source) : "string";
|
|
339
|
-
case A.OPTIONS: return e.source ? `${P(e.source)}[]` : "string[]";
|
|
385
|
+
case A.RICH_TEXT: return `${t}ContentRichText`;
|
|
386
|
+
case A.LINK: return `${t}ContentLink`;
|
|
387
|
+
case A.ASSET: return `${t}ContentAsset`;
|
|
388
|
+
case A.ASSETS: return `${t}ContentAsset[]`;
|
|
389
|
+
case A.REFERENCE: return `${t}ContentReference`;
|
|
390
|
+
case A.REFERENCES: return `${t}ContentReference[]`;
|
|
391
|
+
case A.OPTION: return e.source ? t + P(e.source) : "string";
|
|
392
|
+
case A.OPTIONS: return e.source ? `${t + P(e.source)}[]` : "string[]";
|
|
340
393
|
case A.SCHEMA: {
|
|
341
|
-
let
|
|
342
|
-
if (!
|
|
343
|
-
let
|
|
344
|
-
return
|
|
394
|
+
let n = e.schemas;
|
|
395
|
+
if (!n || n.length === 0) return "unknown";
|
|
396
|
+
let r = n.map((e) => t + P(e));
|
|
397
|
+
return r.length === 1 ? r[0] : r.join(" | ");
|
|
345
398
|
}
|
|
346
399
|
case A.SCHEMAS: {
|
|
347
|
-
let
|
|
348
|
-
if (!
|
|
349
|
-
let
|
|
350
|
-
return `${
|
|
400
|
+
let n = e.schemas;
|
|
401
|
+
if (!n || n.length === 0) return "unknown[]";
|
|
402
|
+
let r = n.map((e) => t + P(e));
|
|
403
|
+
return `${r.length === 1 ? r[0] : `(${r.join(" | ")})`}[]`;
|
|
351
404
|
}
|
|
352
405
|
}
|
|
353
406
|
}
|
|
354
407
|
function I(e, t = "") {
|
|
355
408
|
return `${t}/**\n${t} * ${e}\n${t} */`;
|
|
356
409
|
}
|
|
357
|
-
function L(e) {
|
|
358
|
-
let
|
|
359
|
-
for (let [
|
|
360
|
-
let e = P(
|
|
361
|
-
if (
|
|
362
|
-
let
|
|
363
|
-
if (
|
|
410
|
+
function L(e, t = "") {
|
|
411
|
+
let n = [N(t)], r = [];
|
|
412
|
+
for (let [i, a] of Object.entries(e)) {
|
|
413
|
+
let e = t + P(i), o = a.description ? `${I(a.description)}\n` : "";
|
|
414
|
+
if (a.type === k.ENUM) {
|
|
415
|
+
let t = a.values ?? [];
|
|
416
|
+
if (t.length === 0) n.push(`${o}export type ${e} = string;\n`);
|
|
364
417
|
else {
|
|
365
|
-
let r =
|
|
366
|
-
|
|
418
|
+
let r = t.map((e) => `'${e.value}'`).join(" | ");
|
|
419
|
+
n.push(`${o}export type ${e} = ${r};\n`);
|
|
367
420
|
}
|
|
368
421
|
} else {
|
|
369
|
-
let
|
|
370
|
-
|
|
371
|
-
let
|
|
422
|
+
let s = a;
|
|
423
|
+
a.type === k.ROOT && r.push(e);
|
|
424
|
+
let c = [
|
|
372
425
|
" /** Unique identifier of a component in a content. */",
|
|
373
426
|
" _id: string;",
|
|
374
427
|
" /** Unique identifier for the Schema object. */",
|
|
375
|
-
` _schema: '${
|
|
376
|
-
...(
|
|
377
|
-
let
|
|
378
|
-
return e.description &&
|
|
428
|
+
` _schema: '${i}';`,
|
|
429
|
+
...(s.fields ?? []).flatMap((e) => {
|
|
430
|
+
let n = F(e, t), r = e.required ? "" : "?", i = [];
|
|
431
|
+
return e.description && i.push(` /** ${e.description} */`), i.push(` ${e.name}${r}: ${n};`), i;
|
|
379
432
|
})
|
|
380
433
|
];
|
|
381
|
-
|
|
434
|
+
n.push(`${o}export interface ${e} {\n${c.join("\n")}\n}\n`);
|
|
382
435
|
}
|
|
383
436
|
}
|
|
384
|
-
return
|
|
437
|
+
return n.push("/**\n* ContentData defined Object to connect all possible root Schemas.\n*/"), r.length > 0 ? n.push(`export type ${t}ContentData = ${r.join(" | ")};\n`) : n.push(`export type ${t}ContentData = unknown;\n`), n.join("\n");
|
|
385
438
|
}
|
|
386
439
|
//#endregion
|
|
387
440
|
//#region src/commands/types/generate/index.ts
|
|
388
|
-
var R = s(u.cwd(), b, "localess.ts"), z = 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", R).action(async (e) => {
|
|
441
|
+
var R = s(u.cwd(), b, "localess.ts"), z = 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", R).option("--prefix <prefix>", "Prefix to prepend to all generated type names", "").action(async (e) => {
|
|
389
442
|
console.log("Types in with options:", e);
|
|
390
443
|
let t = await w();
|
|
391
444
|
if (!t.isLoggedIn) {
|
|
@@ -400,7 +453,7 @@ var R = s(u.cwd(), b, "localess.ts"), z = new e("generate").description("Generat
|
|
|
400
453
|
console.log("Fetching schemas from Localess...");
|
|
401
454
|
let r = await n.getSchemas();
|
|
402
455
|
console.log("Generating types...");
|
|
403
|
-
let i = L(r);
|
|
456
|
+
let i = L(r, e.prefix);
|
|
404
457
|
await x(e.path, i), console.log(`Types written to ${e.path}`);
|
|
405
458
|
}), B = new e("types").description("Generate types for your schemas").addCommand(z), V = d.record(d.string(), d.string()), H = d.enum(["add-missing", "update-existing"]);
|
|
406
459
|
d.object({
|