@transi-store/cli 1.0.5 → 1.1.0

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/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  npm install -g @transi-store/cli
7
7
  ```
8
8
 
9
- ## Usage
9
+ ## Download translations
10
10
 
11
11
  ### With configuration file
12
12
 
@@ -62,6 +62,25 @@ transi-store download --org <orgSlug> \
62
62
  --format <format>
63
63
  ```
64
64
 
65
+ ## Upload translations
66
+
67
+ To upload translations, you can use the following command:
68
+
69
+ ```bash
70
+ transi-store upload --org <orgSlug> \
71
+ --project <projectSlug> \
72
+ --locale <locale> \
73
+ --input <inputPath> \
74
+ --format <format>
75
+ ```
76
+
77
+ Optional parameters:
78
+
79
+ - `--domain-root`: The root directory for the domain. This is used to determine the domain of the translations based on the input file path. Defaults to "https://transi-store.com".
80
+ - `--strategy`: eiher "overwrite" (default) or "skip". Determines how to handle existing translations. "overwrite" will replace existing translations with the new ones, while "skip" will keep existing translations and only add new ones.
81
+
82
+ You must also provide the `TRANSI_STORE_API_KEY` environment variable with your Transi-Store API key to authenticate the requests.
83
+
65
84
  ## Contributing
66
85
 
67
86
  ### Publish package
@@ -69,7 +88,7 @@ transi-store download --org <orgSlug> \
69
88
  To publish a new version of the CLI package, follow these steps:
70
89
 
71
90
  1. Update the version number in `packages/cli/package.json`.
72
- 2. Commit the changes with a message like `chore(cli): publish version x.y.z
91
+ 2. Commit the changes with a message like `chore(cli): publish version x.y.z`
73
92
  3. Run the publish script from the root of the monorepo:
74
93
 
75
94
  ```bash
package/dist/cli.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command, Option } from "@commander-js/extra-typings";
3
3
  import { DEFAULT_DOMAIN_ROOT, fetchForConfig, fetchTranslations, } from "./fetchTranslations.js";
4
+ import { ImportStrategy, uploadTranslations, } from "./uploadTranslations.js";
4
5
  const program = new Command();
5
6
  const apiKeyOption = new Option("-k, --api-key <apiKey>", "API key for authentication")
6
7
  .env("TRANSI_STORE_API_KEY")
@@ -18,6 +19,29 @@ program
18
19
  .action((options) => {
19
20
  fetchTranslations(options);
20
21
  });
22
+ program
23
+ .command("upload")
24
+ .description("Upload translations for a project")
25
+ .addOption(apiKeyOption)
26
+ .requiredOption("-d, --domain-root <domainRoot>", "Root domain to upload translations to (default is https://transi-store.com)", DEFAULT_DOMAIN_ROOT)
27
+ .requiredOption("-o, --org <org>", "Organization slug")
28
+ .requiredOption("-p, --project <project>", "Project slug")
29
+ .requiredOption("-l, --locale <locale>", "Target locale")
30
+ .requiredOption("-I, --input <input>", "Input file path (JSON or XLIFF)")
31
+ .option("-s, --strategy <strategy>", `Import strategy: '${ImportStrategy.OVERWRITE}' or '${ImportStrategy.SKIP}' existing translations`, ImportStrategy.SKIP)
32
+ .option("-f, --format <format>", "File format (json or xliff). Auto-detected from extension if omitted")
33
+ .action((options) => {
34
+ const strategy = options.strategy;
35
+ if (strategy !== ImportStrategy.OVERWRITE &&
36
+ strategy !== ImportStrategy.SKIP) {
37
+ console.error(`Invalid strategy. Use '${ImportStrategy.OVERWRITE}' or '${ImportStrategy.SKIP}'.`);
38
+ process.exit(1);
39
+ }
40
+ uploadTranslations({
41
+ ...options,
42
+ strategy,
43
+ });
44
+ });
21
45
  program
22
46
  .command("config", { isDefault: true })
23
47
  .description("Use configuration from config file")
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,iBAAiB,GAElB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,MAAM,YAAY,GAAG,IAAI,MAAM,CAC7B,wBAAwB,EACxB,4BAA4B,CAC7B;KACE,GAAG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AE,EAAE;IAClB,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAClC,IACE,QAAQ,KAAK,cAAc,CAAC,SAAS;QACrC,QAAQ,KAAK,cAAc,CAAC,IAAI,EAChC,CAAC;QACD,OAAO,CAAC,KAAK,CACX,0BAA0B,cAAc,CAAC,SAAS,SAAS,cAAc,CAAC,IAAI,IAAI,CACnF,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,kBAAkB,CAAC;QACjB,GAAG,OAAO;QACV,QAAQ;KACc,CAAC,CAAC;AAC5B,CAAC,CAAC,CAAC;AAEL,OAAO;KACJ,OAAO,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;KACtC,WAAW,CAAC,oCAAoC,CAAC;KACjD,MAAM,CACL,uBAAuB,EACvB,qBAAqB,EACrB,0BAA0B,CAC3B;KACA,SAAS,CAAC,YAAY,CAAC;KACvB,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;IAClB,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;AACjD,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,16 @@
1
+ export declare enum ImportStrategy {
2
+ OVERWRITE = "overwrite",
3
+ SKIP = "skip"
4
+ }
5
+ export type UploadConfig = {
6
+ domainRoot: string;
7
+ org: string;
8
+ project: string;
9
+ apiKey: string;
10
+ locale: string;
11
+ input: string;
12
+ strategy: ImportStrategy;
13
+ format?: string;
14
+ };
15
+ export declare function uploadTranslations({ domainRoot, apiKey, org, project, locale, input, strategy, format, }: UploadConfig): Promise<void>;
16
+ //# sourceMappingURL=uploadTranslations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploadTranslations.d.ts","sourceRoot":"","sources":["../src/uploadTranslations.ts"],"names":[],"mappings":"AAGA,oBAAY,cAAc;IACxB,SAAS,cAAc;IACvB,IAAI,SAAS;CACd;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,cAAc,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,wBAAsB,kBAAkB,CAAC,EACvC,UAAU,EACV,MAAM,EACN,GAAG,EACH,OAAO,EACP,MAAM,EACN,KAAK,EACL,QAAQ,EACR,MAAM,GACP,EAAE,YAAY,iBAsDd"}
@@ -0,0 +1,49 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ export var ImportStrategy;
4
+ (function (ImportStrategy) {
5
+ ImportStrategy["OVERWRITE"] = "overwrite";
6
+ ImportStrategy["SKIP"] = "skip";
7
+ })(ImportStrategy || (ImportStrategy = {}));
8
+ export async function uploadTranslations({ domainRoot, apiKey, org, project, locale, input, strategy, format, }) {
9
+ const url = `${domainRoot}/api/orgs/${org}/projects/${project}/import`;
10
+ const filePath = path.resolve(input);
11
+ if (!fs.existsSync(filePath)) {
12
+ console.error(`File not found: ${input}`);
13
+ process.exit(1);
14
+ }
15
+ const fileContent = fs.readFileSync(filePath);
16
+ const fileName = path.basename(filePath);
17
+ const formData = new FormData();
18
+ formData.append("file", new Blob([fileContent]), fileName);
19
+ formData.append("locale", locale);
20
+ formData.append("strategy", strategy);
21
+ if (format) {
22
+ formData.append("format", format);
23
+ }
24
+ try {
25
+ const response = await fetch(url, {
26
+ method: "POST",
27
+ headers: {
28
+ Authorization: `Bearer ${apiKey}`,
29
+ },
30
+ body: formData,
31
+ });
32
+ const data = await response.json();
33
+ if (!response.ok) {
34
+ console.error(`Failed to import translations: ${response.status} ${response.statusText}\n`, data.error, data.details ? `\nDetails: ${data.details}` : "");
35
+ process.exit(1);
36
+ }
37
+ console.log(`Translations imported for project "${project}" locale "${locale}":`);
38
+ console.log(` Total keys: ${data.stats.total}`);
39
+ console.log(` Keys created: ${data.stats.keysCreated}`);
40
+ console.log(` Translations created: ${data.stats.translationsCreated}`);
41
+ console.log(` Translations updated: ${data.stats.translationsUpdated}`);
42
+ console.log(` Translations skipped: ${data.stats.translationsSkipped}`);
43
+ }
44
+ catch (error) {
45
+ console.error("Error importing translations:", error);
46
+ process.exit(1);
47
+ }
48
+ }
49
+ //# sourceMappingURL=uploadTranslations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploadTranslations.js","sourceRoot":"","sources":["../src/uploadTranslations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,yCAAuB,CAAA;IACvB,+BAAa,CAAA;AACf,CAAC,EAHW,cAAc,KAAd,cAAc,QAGzB;AAaD,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,EACvC,UAAU,EACV,MAAM,EACN,GAAG,EACH,OAAO,EACP,MAAM,EACN,KAAK,EACL,QAAQ,EACR,MAAM,GACO;IACb,MAAM,GAAG,GAAG,GAAG,UAAU,aAAa,GAAG,aAAa,OAAO,SAAS,CAAC;IAEvE,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAErC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7B,OAAO,CAAC,KAAK,CAAC,mBAAmB,KAAK,EAAE,CAAC,CAAC;QAC1C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC9C,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,C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