@localess/cli 0.0.1-dev.20260220080241 → 0.0.1-dev.20260221221032
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.js +75 -11
- package/dist/index.mjs +75 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -24,7 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
));
|
|
25
25
|
|
|
26
26
|
// src/program.ts
|
|
27
|
-
var
|
|
27
|
+
var import_commander8 = require("commander");
|
|
28
28
|
|
|
29
29
|
// src/commands/login/index.ts
|
|
30
30
|
var import_commander = require("commander");
|
|
@@ -32,6 +32,24 @@ var import_commander = require("commander");
|
|
|
32
32
|
// src/utils.ts
|
|
33
33
|
var RESET = "\x1B[0m";
|
|
34
34
|
var FG_BLUE = "\x1B[34m";
|
|
35
|
+
function dotToNestedObject(input) {
|
|
36
|
+
const result = {};
|
|
37
|
+
for (const [key, value] of Object.entries(input)) {
|
|
38
|
+
const parts = key.split(".");
|
|
39
|
+
let current = result;
|
|
40
|
+
for (let i = 0; i < parts.length; i++) {
|
|
41
|
+
if (i === parts.length - 1) {
|
|
42
|
+
current[parts[i]] = value;
|
|
43
|
+
} else {
|
|
44
|
+
if (!(parts[i] in current)) {
|
|
45
|
+
current[parts[i]] = {};
|
|
46
|
+
}
|
|
47
|
+
current = current[parts[i]];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
35
53
|
|
|
36
54
|
// src/cache.ts
|
|
37
55
|
var NoCache = class {
|
|
@@ -501,12 +519,15 @@ var logoutCommand = new import_commander2.Command("logout").description("Logout
|
|
|
501
519
|
});
|
|
502
520
|
|
|
503
521
|
// src/commands/types/index.ts
|
|
522
|
+
var import_commander4 = require("commander");
|
|
523
|
+
|
|
524
|
+
// src/commands/types/generate/index.ts
|
|
504
525
|
var import_commander3 = require("commander");
|
|
505
526
|
var import_openapi_typescript = __toESM(require("openapi-typescript"));
|
|
506
527
|
var import_node_path3 = require("path");
|
|
507
528
|
var import_node_process = __toESM(require("process"));
|
|
508
529
|
var TYPES_PATH = (0, import_node_path3.join)(import_node_process.default.cwd(), DEFAULT_CONFIG_DIR, "localess.d.ts");
|
|
509
|
-
var
|
|
530
|
+
var typesGenerateCommand = new import_commander3.Command("generate").description("Generate types for your schemas").option("-f, --file <path>", "Path to the file where to save the generated types. Default is .localess/localess.d.ts", TYPES_PATH).action(async (options) => {
|
|
510
531
|
console.log("Types in with options:", options);
|
|
511
532
|
const session = await getSession();
|
|
512
533
|
if (!session.isLoggedIn) {
|
|
@@ -530,18 +551,21 @@ var typesCommand = new import_commander3.Command("types").description("Generate
|
|
|
530
551
|
};
|
|
531
552
|
const ast = await (0, import_openapi_typescript.default)(minimalSpec, { exportType: true, rootTypes: true, rootTypesNoSchemaPrefix: true });
|
|
532
553
|
const contents = (0, import_openapi_typescript.astToString)(ast);
|
|
533
|
-
await writeFile(
|
|
534
|
-
console.log(`Types generated successfully at ${
|
|
554
|
+
await writeFile(options.file, contents);
|
|
555
|
+
console.log(`Types generated successfully at ${options.file}`);
|
|
535
556
|
} catch (e) {
|
|
536
557
|
console.error(e);
|
|
537
558
|
}
|
|
538
559
|
});
|
|
539
560
|
|
|
561
|
+
// src/commands/types/index.ts
|
|
562
|
+
var typesCommand = new import_commander4.Command("types").description("Generate types for your schemas").addCommand(typesGenerateCommand);
|
|
563
|
+
|
|
540
564
|
// src/commands/translations/index.ts
|
|
541
|
-
var
|
|
565
|
+
var import_commander7 = require("commander");
|
|
542
566
|
|
|
543
567
|
// src/commands/translations/push/index.ts
|
|
544
|
-
var
|
|
568
|
+
var import_commander5 = require("commander");
|
|
545
569
|
|
|
546
570
|
// src/models/translations.ts
|
|
547
571
|
var TranslationUpdateType = /* @__PURE__ */ ((TranslationUpdateType2) => {
|
|
@@ -549,6 +573,11 @@ var TranslationUpdateType = /* @__PURE__ */ ((TranslationUpdateType2) => {
|
|
|
549
573
|
TranslationUpdateType2["UPDATE_EXISTING"] = "update-existing";
|
|
550
574
|
return TranslationUpdateType2;
|
|
551
575
|
})(TranslationUpdateType || {});
|
|
576
|
+
var TranslationFileFormat = /* @__PURE__ */ ((TranslationFileFormat2) => {
|
|
577
|
+
TranslationFileFormat2["FLAT"] = "flat";
|
|
578
|
+
TranslationFileFormat2["NESTED"] = "nested";
|
|
579
|
+
return TranslationFileFormat2;
|
|
580
|
+
})(TranslationFileFormat || {});
|
|
552
581
|
|
|
553
582
|
// src/models/translation.zod.ts
|
|
554
583
|
var import_zod = require("zod");
|
|
@@ -560,7 +589,7 @@ var zTranslationUpdateSchema = import_zod.z.object({
|
|
|
560
589
|
});
|
|
561
590
|
|
|
562
591
|
// src/commands/translations/push/index.ts
|
|
563
|
-
var translationsPushCommand = new
|
|
592
|
+
var translationsPushCommand = new import_commander5.Command("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 */).action(async (locale, options) => {
|
|
564
593
|
console.log("Pushing translations with arguments:", locale);
|
|
565
594
|
console.log("Pushing translations with options:", options);
|
|
566
595
|
if (!zTranslationUpdateTypeSchema.safeParse(options.type).success) {
|
|
@@ -578,8 +607,11 @@ var translationsPushCommand = new import_commander4.Command("push").argument("<l
|
|
|
578
607
|
spaceId: session.space,
|
|
579
608
|
token: session.token
|
|
580
609
|
});
|
|
581
|
-
|
|
582
|
-
|
|
610
|
+
if (options.format === "nested" /* NESTED */) {
|
|
611
|
+
console.error("Nested format is not implemented yet. Please use flat format for now.");
|
|
612
|
+
}
|
|
613
|
+
console.log("Reading translations file from:", options.path);
|
|
614
|
+
const fileContent = await readFile(options.path);
|
|
583
615
|
const translationValues = JSON.parse(fileContent);
|
|
584
616
|
const pResult = zLocaleTranslationsSchema.safeParse(translationValues);
|
|
585
617
|
if (!pResult.success) {
|
|
@@ -599,11 +631,43 @@ var translationsPushCommand = new import_commander4.Command("push").argument("<l
|
|
|
599
631
|
}
|
|
600
632
|
});
|
|
601
633
|
|
|
634
|
+
// src/commands/translations/pull/index.ts
|
|
635
|
+
var import_commander6 = require("commander");
|
|
636
|
+
var translationsPullCommand = new import_commander6.Command("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) => {
|
|
637
|
+
console.log("Pulling translations with arguments:", locale);
|
|
638
|
+
console.log("Pulling translations with options:", options);
|
|
639
|
+
if (!Object.values(TranslationFileFormat).includes(options.format)) {
|
|
640
|
+
console.error("Invalid format provided. Possible values are :", Object.values(TranslationFileFormat));
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
const session = await getSession();
|
|
644
|
+
if (!session.isLoggedIn) {
|
|
645
|
+
console.error("Not logged in");
|
|
646
|
+
console.error('Please log in first using "localess login" command');
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
const client = localessClient({
|
|
650
|
+
origin: session.origin,
|
|
651
|
+
spaceId: session.space,
|
|
652
|
+
token: session.token
|
|
653
|
+
});
|
|
654
|
+
console.log("Pulling translations from Localess for locale:", locale);
|
|
655
|
+
const translations = await client.getTranslations(locale);
|
|
656
|
+
console.log("Saving translations in file:", options.path);
|
|
657
|
+
if (options.format === "flat" /* FLAT */) {
|
|
658
|
+
await writeFile(options.path, JSON.stringify(translations, null, 2));
|
|
659
|
+
} else if (options.format === "nested" /* NESTED */) {
|
|
660
|
+
const nestedTranslations = dotToNestedObject(translations);
|
|
661
|
+
await writeFile(options.path, JSON.stringify(nestedTranslations, null, 2));
|
|
662
|
+
}
|
|
663
|
+
console.log("Successfully saved translations from Localess");
|
|
664
|
+
});
|
|
665
|
+
|
|
602
666
|
// src/commands/translations/index.ts
|
|
603
|
-
var translationsCommand = new
|
|
667
|
+
var translationsCommand = new import_commander7.Command("translations").description("Manage translations").addCommand(translationsPushCommand).addCommand(translationsPullCommand);
|
|
604
668
|
|
|
605
669
|
// src/program.ts
|
|
606
|
-
var program = new
|
|
670
|
+
var program = new import_commander8.Command();
|
|
607
671
|
program.name("Localess CLI").description("CLI tool for Localess platform management").version("0.0.1");
|
|
608
672
|
program.addCommand(loginCommand);
|
|
609
673
|
program.addCommand(logoutCommand);
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/program.ts
|
|
4
|
-
import { Command as
|
|
4
|
+
import { Command as Command8 } from "commander";
|
|
5
5
|
|
|
6
6
|
// src/commands/login/index.ts
|
|
7
7
|
import { Command } from "commander";
|
|
@@ -9,6 +9,24 @@ import { Command } from "commander";
|
|
|
9
9
|
// src/utils.ts
|
|
10
10
|
var RESET = "\x1B[0m";
|
|
11
11
|
var FG_BLUE = "\x1B[34m";
|
|
12
|
+
function dotToNestedObject(input) {
|
|
13
|
+
const result = {};
|
|
14
|
+
for (const [key, value] of Object.entries(input)) {
|
|
15
|
+
const parts = key.split(".");
|
|
16
|
+
let current = result;
|
|
17
|
+
for (let i = 0; i < parts.length; i++) {
|
|
18
|
+
if (i === parts.length - 1) {
|
|
19
|
+
current[parts[i]] = value;
|
|
20
|
+
} else {
|
|
21
|
+
if (!(parts[i] in current)) {
|
|
22
|
+
current[parts[i]] = {};
|
|
23
|
+
}
|
|
24
|
+
current = current[parts[i]];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
12
30
|
|
|
13
31
|
// src/cache.ts
|
|
14
32
|
var NoCache = class {
|
|
@@ -478,12 +496,15 @@ var logoutCommand = new Command2("logout").description("Logout from Localess CLI
|
|
|
478
496
|
});
|
|
479
497
|
|
|
480
498
|
// src/commands/types/index.ts
|
|
499
|
+
import { Command as Command4 } from "commander";
|
|
500
|
+
|
|
501
|
+
// src/commands/types/generate/index.ts
|
|
481
502
|
import { Command as Command3 } from "commander";
|
|
482
503
|
import openapiTS, { astToString } from "openapi-typescript";
|
|
483
504
|
import { join as join2 } from "path";
|
|
484
505
|
import process3 from "process";
|
|
485
506
|
var TYPES_PATH = join2(process3.cwd(), DEFAULT_CONFIG_DIR, "localess.d.ts");
|
|
486
|
-
var
|
|
507
|
+
var typesGenerateCommand = new Command3("generate").description("Generate types for your schemas").option("-f, --file <path>", "Path to the file where to save the generated types. Default is .localess/localess.d.ts", TYPES_PATH).action(async (options) => {
|
|
487
508
|
console.log("Types in with options:", options);
|
|
488
509
|
const session = await getSession();
|
|
489
510
|
if (!session.isLoggedIn) {
|
|
@@ -507,18 +528,21 @@ var typesCommand = new Command3("types").description("Generate types for your sc
|
|
|
507
528
|
};
|
|
508
529
|
const ast = await openapiTS(minimalSpec, { exportType: true, rootTypes: true, rootTypesNoSchemaPrefix: true });
|
|
509
530
|
const contents = astToString(ast);
|
|
510
|
-
await writeFile(
|
|
511
|
-
console.log(`Types generated successfully at ${
|
|
531
|
+
await writeFile(options.file, contents);
|
|
532
|
+
console.log(`Types generated successfully at ${options.file}`);
|
|
512
533
|
} catch (e) {
|
|
513
534
|
console.error(e);
|
|
514
535
|
}
|
|
515
536
|
});
|
|
516
537
|
|
|
538
|
+
// src/commands/types/index.ts
|
|
539
|
+
var typesCommand = new Command4("types").description("Generate types for your schemas").addCommand(typesGenerateCommand);
|
|
540
|
+
|
|
517
541
|
// src/commands/translations/index.ts
|
|
518
|
-
import { Command as
|
|
542
|
+
import { Command as Command7 } from "commander";
|
|
519
543
|
|
|
520
544
|
// src/commands/translations/push/index.ts
|
|
521
|
-
import { Command as
|
|
545
|
+
import { Command as Command5 } from "commander";
|
|
522
546
|
|
|
523
547
|
// src/models/translations.ts
|
|
524
548
|
var TranslationUpdateType = /* @__PURE__ */ ((TranslationUpdateType2) => {
|
|
@@ -526,6 +550,11 @@ var TranslationUpdateType = /* @__PURE__ */ ((TranslationUpdateType2) => {
|
|
|
526
550
|
TranslationUpdateType2["UPDATE_EXISTING"] = "update-existing";
|
|
527
551
|
return TranslationUpdateType2;
|
|
528
552
|
})(TranslationUpdateType || {});
|
|
553
|
+
var TranslationFileFormat = /* @__PURE__ */ ((TranslationFileFormat2) => {
|
|
554
|
+
TranslationFileFormat2["FLAT"] = "flat";
|
|
555
|
+
TranslationFileFormat2["NESTED"] = "nested";
|
|
556
|
+
return TranslationFileFormat2;
|
|
557
|
+
})(TranslationFileFormat || {});
|
|
529
558
|
|
|
530
559
|
// src/models/translation.zod.ts
|
|
531
560
|
import { z } from "zod";
|
|
@@ -537,7 +566,7 @@ var zTranslationUpdateSchema = z.object({
|
|
|
537
566
|
});
|
|
538
567
|
|
|
539
568
|
// src/commands/translations/push/index.ts
|
|
540
|
-
var translationsPushCommand = new
|
|
569
|
+
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 */).action(async (locale, options) => {
|
|
541
570
|
console.log("Pushing translations with arguments:", locale);
|
|
542
571
|
console.log("Pushing translations with options:", options);
|
|
543
572
|
if (!zTranslationUpdateTypeSchema.safeParse(options.type).success) {
|
|
@@ -555,8 +584,11 @@ var translationsPushCommand = new Command4("push").argument("<locale>", "Locale
|
|
|
555
584
|
spaceId: session.space,
|
|
556
585
|
token: session.token
|
|
557
586
|
});
|
|
558
|
-
|
|
559
|
-
|
|
587
|
+
if (options.format === "nested" /* NESTED */) {
|
|
588
|
+
console.error("Nested format is not implemented yet. Please use flat format for now.");
|
|
589
|
+
}
|
|
590
|
+
console.log("Reading translations file from:", options.path);
|
|
591
|
+
const fileContent = await readFile(options.path);
|
|
560
592
|
const translationValues = JSON.parse(fileContent);
|
|
561
593
|
const pResult = zLocaleTranslationsSchema.safeParse(translationValues);
|
|
562
594
|
if (!pResult.success) {
|
|
@@ -576,11 +608,43 @@ var translationsPushCommand = new Command4("push").argument("<locale>", "Locale
|
|
|
576
608
|
}
|
|
577
609
|
});
|
|
578
610
|
|
|
611
|
+
// src/commands/translations/pull/index.ts
|
|
612
|
+
import { Command as Command6 } from "commander";
|
|
613
|
+
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) => {
|
|
614
|
+
console.log("Pulling translations with arguments:", locale);
|
|
615
|
+
console.log("Pulling translations with options:", options);
|
|
616
|
+
if (!Object.values(TranslationFileFormat).includes(options.format)) {
|
|
617
|
+
console.error("Invalid format provided. Possible values are :", Object.values(TranslationFileFormat));
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
const session = await getSession();
|
|
621
|
+
if (!session.isLoggedIn) {
|
|
622
|
+
console.error("Not logged in");
|
|
623
|
+
console.error('Please log in first using "localess login" command');
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
const client = localessClient({
|
|
627
|
+
origin: session.origin,
|
|
628
|
+
spaceId: session.space,
|
|
629
|
+
token: session.token
|
|
630
|
+
});
|
|
631
|
+
console.log("Pulling translations from Localess for locale:", locale);
|
|
632
|
+
const translations = await client.getTranslations(locale);
|
|
633
|
+
console.log("Saving translations in file:", options.path);
|
|
634
|
+
if (options.format === "flat" /* FLAT */) {
|
|
635
|
+
await writeFile(options.path, JSON.stringify(translations, null, 2));
|
|
636
|
+
} else if (options.format === "nested" /* NESTED */) {
|
|
637
|
+
const nestedTranslations = dotToNestedObject(translations);
|
|
638
|
+
await writeFile(options.path, JSON.stringify(nestedTranslations, null, 2));
|
|
639
|
+
}
|
|
640
|
+
console.log("Successfully saved translations from Localess");
|
|
641
|
+
});
|
|
642
|
+
|
|
579
643
|
// src/commands/translations/index.ts
|
|
580
|
-
var translationsCommand = new
|
|
644
|
+
var translationsCommand = new Command7("translations").description("Manage translations").addCommand(translationsPushCommand).addCommand(translationsPullCommand);
|
|
581
645
|
|
|
582
646
|
// src/program.ts
|
|
583
|
-
var program = new
|
|
647
|
+
var program = new Command8();
|
|
584
648
|
program.name("Localess CLI").description("CLI tool for Localess platform management").version("0.0.1");
|
|
585
649
|
program.addCommand(loginCommand);
|
|
586
650
|
program.addCommand(logoutCommand);
|