@transi-store/cli 0.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/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +25 -0
- package/dist/cli.js.map +1 -0
- package/dist/fetchTranslations.d.ts +11 -0
- package/dist/fetchTranslations.d.ts.map +1 -0
- package/dist/fetchTranslations.js +68 -0
- package/dist/fetchTranslations.js.map +1 -0
- package/dist/schema.d.ts +18 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +22 -0
- package/dist/schema.js.map +1 -0
- package/package.json +23 -0
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// CLI command to export translations
|
|
2
|
+
import { Command } from "@commander-js/extra-typings";
|
|
3
|
+
import { fetchForConfig, fetchTranslations, } from "./fetchTranslations.js";
|
|
4
|
+
const program = new Command();
|
|
5
|
+
program
|
|
6
|
+
.command("download")
|
|
7
|
+
.description("Download translations for a project")
|
|
8
|
+
.requiredOption("-o, --org <org>", "Organization slug")
|
|
9
|
+
.requiredOption("-p, --project <project>", "Project slug")
|
|
10
|
+
.requiredOption("-k, --api-key <apiKey>", "API key for authentication")
|
|
11
|
+
.requiredOption("-l, --locale <locale>", "Locale to export")
|
|
12
|
+
.requiredOption("-O, --output <output>", "Output file path")
|
|
13
|
+
.option("-f, --format <format>", "Export format (json, csv, etc.)", "json")
|
|
14
|
+
.action((options) => {
|
|
15
|
+
fetchTranslations(options);
|
|
16
|
+
});
|
|
17
|
+
program
|
|
18
|
+
.command("config", { isDefault: true })
|
|
19
|
+
.description("Use configuration from config file")
|
|
20
|
+
.option("-c, --config <config>", "Path to config file", "transi-store.config.json")
|
|
21
|
+
.action((options) => {
|
|
22
|
+
fetchForConfig(options.config);
|
|
23
|
+
});
|
|
24
|
+
program.parse();
|
|
25
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,EACL,cAAc,EACd,iBAAiB,GAElB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,OAAO,CAAC,UAAU,CAAC;KACnB,WAAW,CAAC,qCAAqC,CAAC;KAClD,cAAc,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;KACtD,cAAc,CAAC,yBAAyB,EAAE,cAAc,CAAC;KACzD,cAAc,CAAC,wBAAwB,EAAE,4BAA4B,CAAC;KACtE,cAAc,CAAC,uBAAuB,EAAE,kBAAkB,CAAC;KAC3D,cAAc,CAAC,uBAAuB,EAAE,kBAAkB,CAAC;KAC3D,MAAM,CAAC,uBAAuB,EAAE,iCAAiC,EAAE,MAAM,CAAC;KAC1E,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;IAClB,iBAAiB,CAAC,OAAwB,CAAC,CAAC;AAC9C,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,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;IAClB,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Config = {
|
|
2
|
+
org: string;
|
|
3
|
+
project: string;
|
|
4
|
+
apiKey: string;
|
|
5
|
+
format: string;
|
|
6
|
+
locale: string;
|
|
7
|
+
output: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function fetchTranslations({ org, project, apiKey, format, locale, output, }: Config): Promise<void>;
|
|
10
|
+
export declare function fetchForConfig(configPath: string): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=fetchTranslations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchTranslations.d.ts","sourceRoot":"","sources":["../src/fetchTranslations.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,MAAM,GAAG;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAsB,iBAAiB,CAAC,EACtC,GAAG,EACH,OAAO,EACP,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,GACP,EAAE,MAAM,iBA+BR;AAED,wBAAsB,cAAc,CAAC,UAAU,EAAE,MAAM,iBAoCtD"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import fs from "node:fs";
|
|
10
|
+
import z from "zod";
|
|
11
|
+
import schema from "./schema.js";
|
|
12
|
+
export async function fetchTranslations({ org, project, apiKey, format, locale, output, }) {
|
|
13
|
+
const url = `https://transi-store.mapado.com/api/orgs/${org}/projects/${project}/export?format=${format}&locale=${locale}`;
|
|
14
|
+
try {
|
|
15
|
+
const content = await fetch(url, {
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: `Bearer ${apiKey}`,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
const data = await content.json();
|
|
21
|
+
if (!content.ok) {
|
|
22
|
+
console.error(`Failed to fetch translations: ${content.status} ${content.statusText}\n`, data.error);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
// create directory if not exists
|
|
26
|
+
const dir = output.substring(0, output.lastIndexOf("/"));
|
|
27
|
+
if (!fs.existsSync(dir)) {
|
|
28
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
29
|
+
}
|
|
30
|
+
fs.writeFileSync(output, JSON.stringify(data, null, 2), "utf-8");
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
console.error("Error exporting translations:", error);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export async function fetchForConfig(configPath) {
|
|
38
|
+
const cwd = process.cwd();
|
|
39
|
+
const fullPath = `${cwd}/${configPath}`;
|
|
40
|
+
if (!fs.existsSync(fullPath)) {
|
|
41
|
+
console.error(`Config file not found: ${configPath}`);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
const config = (await import(__rewriteRelativeImportExtension(fullPath), { with: { type: "json" } })).default;
|
|
45
|
+
const result = schema.safeParse(config);
|
|
46
|
+
if (!result.success) {
|
|
47
|
+
const pretty = z.prettifyError(result.error);
|
|
48
|
+
console.error("Config validation error:", pretty);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
for (const configItem of result.data) {
|
|
52
|
+
for (const locale of configItem.langs) {
|
|
53
|
+
const options = {
|
|
54
|
+
org: configItem.org,
|
|
55
|
+
project: configItem.project,
|
|
56
|
+
apiKey: configItem.apiKey,
|
|
57
|
+
format: configItem.format,
|
|
58
|
+
locale,
|
|
59
|
+
output: configItem.output
|
|
60
|
+
.replace("<lang>", locale)
|
|
61
|
+
.replace("<project>", configItem.project)
|
|
62
|
+
.replace("<format>", configItem.format),
|
|
63
|
+
};
|
|
64
|
+
fetchTranslations(options);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=fetchTranslations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchTranslations.js","sourceRoot":"","sources":["../src/fetchTranslations.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,MAAM,MAAM,aAAa,CAAC;AAWjC,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,EACtC,GAAG,EACH,OAAO,EACP,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,GACC;IACP,MAAM,GAAG,GAAG,4CAA4C,GAAG,aAAa,OAAO,kBAAkB,MAAM,WAAW,MAAM,EAAE,CAAC;IAE3H,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAC/B,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,MAAM,EAAE;aAClC;SACF,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;QAElC,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;YAChB,OAAO,CAAC,KAAK,CACX,iCAAiC,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,UAAU,IAAI,EACzE,IAAI,CAAC,KAAK,CACX,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,iCAAiC;QACjC,MAAM,GAA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KAAK,CAAC,CAAC;QAC7C,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,MAAM,CAAC,CAAC;QAClD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QACrC,KAAK,MAAM,MAAM,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;YACtC,MAAM,OAAO,GAAG;gBACd,GAAG,EAAE,UAAU,CAAC,GAAG;gBACnB,OAAO,EAAE,UAAU,CAAC,OAAO;gBAC3B,MAAM,EAAE,UAAU,CAAC,MAAM;gBACzB,MAAM,EAAE,UAAU,CAAC,MAAM;gBACzB,MAAM;gBACN,MAAM,EAAE,UAAU,CAAC,MAAM;qBACtB,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC;qBACzB,OAAO,CAAC,WAAW,EAAE,UAAU,CAAC,OAAO,CAAC;qBACxC,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC;aACzB,CAAC;YAEnB,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
declare const schema: z.ZodArray<z.ZodObject<{
|
|
3
|
+
org: z.ZodString;
|
|
4
|
+
project: z.ZodString;
|
|
5
|
+
apiKey: z.ZodString;
|
|
6
|
+
langs: z.ZodArray<z.ZodString>;
|
|
7
|
+
format: z.ZodEnum<{
|
|
8
|
+
json: "json";
|
|
9
|
+
yaml: "yaml";
|
|
10
|
+
po: "po";
|
|
11
|
+
xlf: "xlf";
|
|
12
|
+
xliff: "xliff";
|
|
13
|
+
csv: "csv";
|
|
14
|
+
}>;
|
|
15
|
+
output: z.ZodString;
|
|
16
|
+
}, z.z.core.$strip>>;
|
|
17
|
+
export default schema;
|
|
18
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAqBpB,QAAA,MAAM,MAAM;;;;;;;;;;;;;;oBAAmC,CAAC;AAEhD,eAAe,MAAM,CAAC"}
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
const configItemSchema = z.object({
|
|
3
|
+
org: z.string().min(1),
|
|
4
|
+
project: z.string().min(1),
|
|
5
|
+
apiKey: z.string().min(1),
|
|
6
|
+
langs: z
|
|
7
|
+
.array(z.string().regex(/^[a-z]{2}(?:-[A-Za-z]{2,})?$/))
|
|
8
|
+
.min(1)
|
|
9
|
+
.refine((arr) => new Set(arr).size === arr.length, {
|
|
10
|
+
message: "langs must contain unique items",
|
|
11
|
+
}),
|
|
12
|
+
format: z.enum(["json", "yaml", "po", "xlf", "xliff", "csv"]),
|
|
13
|
+
output: z
|
|
14
|
+
.string()
|
|
15
|
+
.min(1)
|
|
16
|
+
.refine((s) => s.includes("<lang>"), {
|
|
17
|
+
message: "output must contain '<lang>' placeholder",
|
|
18
|
+
}),
|
|
19
|
+
});
|
|
20
|
+
const schema = z.array(configItemSchema).min(1);
|
|
21
|
+
export default schema;
|
|
22
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACtB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACzB,KAAK,EAAE,CAAC;SACL,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACvD,GAAG,CAAC,CAAC,CAAC;SACN,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,MAAM,EAAE;QACjD,OAAO,EAAE,iCAAiC;KAC3C,CAAC;IACJ,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IAC7D,MAAM,EAAE,CAAC;SACN,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;QACnC,OAAO,EAAE,0CAA0C;KACpD,CAAC;CACL,CAAC,CAAC;AAEH,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAEhD,eAAe,MAAM,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@transi-store/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@commander-js/extra-typings": "^14.0.0",
|
|
11
|
+
"commander": "^14.0.3",
|
|
12
|
+
"zod": "^4.3.6"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"typescript": "^5.7.3"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
]
|
|
23
|
+
}
|