gtx-cli 1.1.8 → 1.1.9
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/formats/files/supportedFiles.d.ts +1 -0
- package/dist/formats/files/supportedFiles.js +10 -0
- package/dist/formats/files/translate.js +18 -28
- package/dist/fs/config/parseFilesConfig.js +18 -34
- package/dist/types/data.d.ts +1 -2
- package/dist/types/index.d.ts +14 -28
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SUPPORTED_FILE_EXTENSIONS: readonly ["json", "mdx", "md", "ts", "js"];
|
|
@@ -23,6 +23,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
23
23
|
const downloadFile_1 = require("../../api/downloadFile");
|
|
24
24
|
const downloadFileBatch_1 = require("../../api/downloadFileBatch");
|
|
25
25
|
const console_1 = require("../../console/console");
|
|
26
|
+
const supportedFiles_1 = require("./supportedFiles");
|
|
26
27
|
const SUPPORTED_DATA_FORMATS = ['JSX', 'ICU', 'I18NEXT'];
|
|
27
28
|
/**
|
|
28
29
|
* Sends multiple files to the API for translation
|
|
@@ -59,33 +60,22 @@ function translateFiles(filePaths_1, placeholderPaths_1, transformPaths_1) {
|
|
|
59
60
|
});
|
|
60
61
|
allFiles.push(...jsonFiles);
|
|
61
62
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const mdFiles = filePaths.md.map((filePath) => {
|
|
79
|
-
const content = (0, findFilepath_1.readFile)(filePath);
|
|
80
|
-
const relativePath = (0, findFilepath_1.getRelative)(filePath);
|
|
81
|
-
return {
|
|
82
|
-
content,
|
|
83
|
-
fileName: relativePath,
|
|
84
|
-
fileFormat: 'MD',
|
|
85
|
-
dataFormat,
|
|
86
|
-
};
|
|
87
|
-
});
|
|
88
|
-
allFiles.push(...mdFiles);
|
|
63
|
+
for (const fileType of supportedFiles_1.SUPPORTED_FILE_EXTENSIONS) {
|
|
64
|
+
if (fileType === 'json')
|
|
65
|
+
continue;
|
|
66
|
+
if (filePaths[fileType]) {
|
|
67
|
+
const files = filePaths[fileType].map((filePath) => {
|
|
68
|
+
const content = (0, findFilepath_1.readFile)(filePath);
|
|
69
|
+
const relativePath = (0, findFilepath_1.getRelative)(filePath);
|
|
70
|
+
return {
|
|
71
|
+
content,
|
|
72
|
+
fileName: relativePath,
|
|
73
|
+
fileFormat: fileType.toUpperCase(),
|
|
74
|
+
dataFormat,
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
allFiles.push(...files);
|
|
78
|
+
}
|
|
89
79
|
}
|
|
90
80
|
if (allFiles.length === 0) {
|
|
91
81
|
console.error('No files to translate');
|
|
@@ -117,7 +107,7 @@ function createFileMapping(filePaths, placeholderPaths, transformPaths, locales)
|
|
|
117
107
|
const translatedPaths = (0, parseFilesConfig_1.resolveLocaleFiles)(placeholderPaths, locale);
|
|
118
108
|
const localeMapping = {};
|
|
119
109
|
// Process each file type
|
|
120
|
-
for (const typeIndex of
|
|
110
|
+
for (const typeIndex of supportedFiles_1.SUPPORTED_FILE_EXTENSIONS) {
|
|
121
111
|
if (!filePaths[typeIndex] || !translatedPaths[typeIndex])
|
|
122
112
|
continue;
|
|
123
113
|
const sourcePaths = filePaths[typeIndex];
|
|
@@ -7,6 +7,7 @@ exports.resolveLocaleFiles = resolveLocaleFiles;
|
|
|
7
7
|
exports.resolveFiles = resolveFiles;
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
10
|
+
const supportedFiles_1 = require("../../formats/files/supportedFiles");
|
|
10
11
|
/**
|
|
11
12
|
* Resolves the files from the files object
|
|
12
13
|
* Replaces [locale] with the actual locale in the files
|
|
@@ -16,16 +17,13 @@ const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
|
16
17
|
* @returns The resolved files
|
|
17
18
|
*/
|
|
18
19
|
function resolveLocaleFiles(files, locale) {
|
|
19
|
-
var _a, _b
|
|
20
|
+
var _a, _b;
|
|
20
21
|
const result = {};
|
|
22
|
+
for (const fileType of supportedFiles_1.SUPPORTED_FILE_EXTENSIONS) {
|
|
23
|
+
result[fileType] = (_a = files[fileType]) === null || _a === void 0 ? void 0 : _a.map((filepath) => filepath.replace(/\[locale\]/g, locale));
|
|
24
|
+
}
|
|
21
25
|
// Replace [locale] with locale in all paths
|
|
22
|
-
result.
|
|
23
|
-
// Replace [locale] with locale in all paths
|
|
24
|
-
result.md = (_b = files.md) === null || _b === void 0 ? void 0 : _b.map((filepath) => filepath.replace(/\[locale\]/g, locale));
|
|
25
|
-
// Replace [locale] with locale in all paths
|
|
26
|
-
result.mdx = (_c = files.mdx) === null || _c === void 0 ? void 0 : _c.map((filepath) => filepath.replace(/\[locale\]/g, locale));
|
|
27
|
-
// Replace [locale] with locale in all paths
|
|
28
|
-
result.gt = (_d = files.gt) === null || _d === void 0 ? void 0 : _d.replace(/\[locale\]/g, locale);
|
|
26
|
+
result.gt = (_b = files.gt) === null || _b === void 0 ? void 0 : _b.replace(/\[locale\]/g, locale);
|
|
29
27
|
return result;
|
|
30
28
|
}
|
|
31
29
|
/**
|
|
@@ -37,7 +35,7 @@ function resolveLocaleFiles(files, locale) {
|
|
|
37
35
|
* @returns The resolved files
|
|
38
36
|
*/
|
|
39
37
|
function resolveFiles(files, locale) {
|
|
40
|
-
var _a, _b, _c, _d
|
|
38
|
+
var _a, _b, _c, _d;
|
|
41
39
|
// Initialize result object with empty arrays for each file type
|
|
42
40
|
const result = {};
|
|
43
41
|
const placeholderResult = {};
|
|
@@ -46,33 +44,19 @@ function resolveFiles(files, locale) {
|
|
|
46
44
|
if ((_a = files.gt) === null || _a === void 0 ? void 0 : _a.output) {
|
|
47
45
|
placeholderResult.gt = files.gt.output;
|
|
48
46
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// Process MD files
|
|
56
|
-
if ((_d = files.md) === null || _d === void 0 ? void 0 : _d.include) {
|
|
57
|
-
const mdPaths = expandGlobPatterns(files.md.include, ((_e = files.md) === null || _e === void 0 ? void 0 : _e.exclude) || [], locale);
|
|
58
|
-
result.md = mdPaths.resolvedPaths;
|
|
59
|
-
placeholderResult.md = mdPaths.placeholderPaths;
|
|
60
|
-
}
|
|
61
|
-
// Process MDX files
|
|
62
|
-
if ((_f = files.mdx) === null || _f === void 0 ? void 0 : _f.include) {
|
|
63
|
-
const mdxPaths = expandGlobPatterns(files.mdx.include, ((_g = files.mdx) === null || _g === void 0 ? void 0 : _g.exclude) || [], locale);
|
|
64
|
-
result.mdx = mdxPaths.resolvedPaths;
|
|
65
|
-
placeholderResult.mdx = mdxPaths.placeholderPaths;
|
|
47
|
+
for (const fileType of supportedFiles_1.SUPPORTED_FILE_EXTENSIONS) {
|
|
48
|
+
if ((_b = files[fileType]) === null || _b === void 0 ? void 0 : _b.include) {
|
|
49
|
+
const filePaths = expandGlobPatterns(files[fileType].include, ((_c = files[fileType]) === null || _c === void 0 ? void 0 : _c.exclude) || [], locale);
|
|
50
|
+
result[fileType] = filePaths.resolvedPaths;
|
|
51
|
+
placeholderResult[fileType] = filePaths.placeholderPaths;
|
|
52
|
+
}
|
|
66
53
|
}
|
|
67
54
|
// ==== TRANSFORMS ==== //
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
if (((_k = files.md) === null || _k === void 0 ? void 0 : _k.transform) && !Array.isArray(files.md.transform)) {
|
|
75
|
-
transformPaths.md = files.md.transform;
|
|
55
|
+
for (const fileType of supportedFiles_1.SUPPORTED_FILE_EXTENSIONS) {
|
|
56
|
+
if (((_d = files[fileType]) === null || _d === void 0 ? void 0 : _d.transform) &&
|
|
57
|
+
!Array.isArray(files[fileType].transform)) {
|
|
58
|
+
transformPaths[fileType] = files[fileType].transform;
|
|
59
|
+
}
|
|
76
60
|
}
|
|
77
61
|
return {
|
|
78
62
|
resolvedPaths: result,
|
package/dist/types/data.d.ts
CHANGED
|
@@ -18,8 +18,7 @@ export type FlattenedJSONDictionary = {
|
|
|
18
18
|
[key: string]: string;
|
|
19
19
|
};
|
|
20
20
|
export type DataFormat = 'JSX' | 'ICU' | 'I18NEXT';
|
|
21
|
-
export type
|
|
22
|
-
export type FileFormats = 'JSON' | 'YAML' | 'MDX' | 'MD';
|
|
21
|
+
export type FileFormats = 'JSON' | 'YAML' | 'MDX' | 'MD' | 'TS' | 'JS';
|
|
23
22
|
export type JsxChildren = string | string[] | any;
|
|
24
23
|
export type Translations = {
|
|
25
24
|
[key: string]: JsxChildren;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { JsxChildren } from 'generaltranslation/internal';
|
|
2
|
+
import { SUPPORTED_FILE_EXTENSIONS } from '../formats/files/supportedFiles';
|
|
2
3
|
export type Updates = ({
|
|
3
4
|
metadata: Record<string, any>;
|
|
4
5
|
} & ({
|
|
@@ -59,41 +60,26 @@ export interface ContentScanner {
|
|
|
59
60
|
warnings: string[];
|
|
60
61
|
}>;
|
|
61
62
|
}
|
|
63
|
+
export type SupportedFileExtension = (typeof SUPPORTED_FILE_EXTENSIONS)[number];
|
|
64
|
+
export type ResolvedFiles = {
|
|
65
|
+
[K in SupportedFileExtension]?: string[];
|
|
66
|
+
} & {
|
|
67
|
+
gt?: string;
|
|
68
|
+
};
|
|
69
|
+
export type TransformFiles = {
|
|
70
|
+
[K in SupportedFileExtension]?: string;
|
|
71
|
+
};
|
|
62
72
|
export type FilesOptions = {
|
|
63
|
-
|
|
64
|
-
output: string;
|
|
65
|
-
};
|
|
66
|
-
json?: {
|
|
73
|
+
[K in SupportedFileExtension]?: {
|
|
67
74
|
include: string[];
|
|
68
75
|
exclude?: string[];
|
|
69
76
|
transform?: string;
|
|
70
77
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
};
|
|
75
|
-
md?: {
|
|
76
|
-
include: string[];
|
|
77
|
-
exclude?: string[];
|
|
78
|
-
transform?: string;
|
|
79
|
-
};
|
|
80
|
-
mdx?: {
|
|
81
|
-
include: string[];
|
|
82
|
-
exclude?: string[];
|
|
83
|
-
transform?: string;
|
|
78
|
+
} & {
|
|
79
|
+
gt?: {
|
|
80
|
+
output: string;
|
|
84
81
|
};
|
|
85
82
|
};
|
|
86
|
-
export type ResolvedFiles = {
|
|
87
|
-
json?: string[];
|
|
88
|
-
md?: string[];
|
|
89
|
-
mdx?: string[];
|
|
90
|
-
gt?: string;
|
|
91
|
-
};
|
|
92
|
-
export type TransformFiles = {
|
|
93
|
-
json?: string;
|
|
94
|
-
md?: string;
|
|
95
|
-
mdx?: string;
|
|
96
|
-
};
|
|
97
83
|
export type Settings = {
|
|
98
84
|
config: string;
|
|
99
85
|
baseUrl: string;
|