gtx-cli 1.1.2 → 1.1.4
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/base.js +3 -3
- package/dist/cli/react.js +3 -2
- package/dist/console/errors.d.ts +1 -1
- package/dist/console/errors.js +1 -1
- package/dist/formats/files/translate.d.ts +2 -2
- package/dist/formats/files/translate.js +18 -2
- package/dist/fs/config/parseFilesConfig.d.ts +2 -1
- package/dist/fs/config/parseFilesConfig.js +50 -17
- package/dist/types/index.d.ts +12 -0
- package/package.json +1 -1
package/dist/cli/base.js
CHANGED
|
@@ -133,7 +133,7 @@ class BaseCLI {
|
|
|
133
133
|
else {
|
|
134
134
|
dataFormat = 'JSX';
|
|
135
135
|
}
|
|
136
|
-
const { resolvedPaths: sourceFiles, placeholderPaths } = settings.files;
|
|
136
|
+
const { resolvedPaths: sourceFiles, placeholderPaths, transformPaths, } = settings.files;
|
|
137
137
|
// ---- CREATING UPDATES ---- //
|
|
138
138
|
if (sourceFiles.json) {
|
|
139
139
|
// Only translate JSON files if not using gt-react or gt-next
|
|
@@ -158,10 +158,10 @@ class BaseCLI {
|
|
|
158
158
|
}
|
|
159
159
|
if (sourceFiles.mdx || sourceFiles.md) {
|
|
160
160
|
if (sourceFiles.mdx) {
|
|
161
|
-
yield (0, translate_2.translateFiles)(sourceFiles, placeholderPaths, 'MDX', settings);
|
|
161
|
+
yield (0, translate_2.translateFiles)(sourceFiles, placeholderPaths, transformPaths, 'MDX', settings);
|
|
162
162
|
}
|
|
163
163
|
if (sourceFiles.md) {
|
|
164
|
-
yield (0, translate_2.translateFiles)(sourceFiles, placeholderPaths, 'MD', settings);
|
|
164
|
+
yield (0, translate_2.translateFiles)(sourceFiles, placeholderPaths, transformPaths, 'MD', settings);
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
});
|
package/dist/cli/react.js
CHANGED
|
@@ -279,7 +279,7 @@ class ReactCLI extends base_1.BaseCLI {
|
|
|
279
279
|
message: 'What framework are you using?',
|
|
280
280
|
choices: [
|
|
281
281
|
{ value: 'next', name: chalk_1.default.blue('Next.js') },
|
|
282
|
-
{ value: 'vite', name: chalk_1.default.green('Vite') },
|
|
282
|
+
{ value: 'vite', name: chalk_1.default.green('Vite + React') },
|
|
283
283
|
{ value: 'gatsby', name: chalk_1.default.magenta('Gatsby') },
|
|
284
284
|
{ value: 'react', name: chalk_1.default.yellow('React') },
|
|
285
285
|
{ value: 'redwood', name: chalk_1.default.red('RedwoodJS') },
|
|
@@ -456,7 +456,8 @@ class ReactCLI extends base_1.BaseCLI {
|
|
|
456
456
|
}
|
|
457
457
|
}
|
|
458
458
|
else {
|
|
459
|
-
|
|
459
|
+
console.log(chalk_1.default.red(errors_1.noTranslationsError));
|
|
460
|
+
process.exit(0);
|
|
460
461
|
}
|
|
461
462
|
});
|
|
462
463
|
}
|
package/dist/console/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const noTranslationsError = "No
|
|
1
|
+
export declare const noTranslationsError = "No in-line content or dictionaries were found. Are you sure you're running this command in the right directory?";
|
|
2
2
|
export declare const noLocalesError = "No locales found! Please provide a list of locales to translate to, or specify them in your gt.config.json file.";
|
|
3
3
|
export declare const noDefaultLocaleError = "No default locale found! Please provide a default locale, or specify it in your gt.config.json file.";
|
|
4
4
|
export declare const noFilesError = "No files configuration found! Please make sure your files are configured correctly in your gt.config.json file.";
|
package/dist/console/errors.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.noProjectIdError = exports.noApiKeyError = exports.noSupportedDataFormatError = exports.noDataFormatError = exports.noSourceFileError = exports.noFilesError = exports.noDefaultLocaleError = exports.noLocalesError = exports.noTranslationsError = void 0;
|
|
4
|
-
exports.noTranslationsError = `No
|
|
4
|
+
exports.noTranslationsError = `No in-line content or dictionaries were found. Are you sure you're running this command in the right directory?`;
|
|
5
5
|
exports.noLocalesError = `No locales found! Please provide a list of locales to translate to, or specify them in your gt.config.json file.`;
|
|
6
6
|
exports.noDefaultLocaleError = `No default locale found! Please provide a default locale, or specify it in your gt.config.json file.`;
|
|
7
7
|
exports.noFilesError = `No files configuration found! Please make sure your files are configured correctly in your gt.config.json file.`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResolvedFiles, Settings } from '../../types';
|
|
1
|
+
import { ResolvedFiles, Settings, TransformFiles } from '../../types';
|
|
2
2
|
import { FileFormats } from '../../types/data';
|
|
3
3
|
/**
|
|
4
4
|
* Sends an entire file to the API for translation
|
|
@@ -6,4 +6,4 @@ import { FileFormats } from '../../types/data';
|
|
|
6
6
|
* @param options - Translation options including API settings
|
|
7
7
|
* @returns The translated file content or null if translation failed
|
|
8
8
|
*/
|
|
9
|
-
export declare function translateFiles(filePaths: ResolvedFiles, placeholderPaths: ResolvedFiles, fileFormat: FileFormats, options: Settings): Promise<void>;
|
|
9
|
+
export declare function translateFiles(filePaths: ResolvedFiles, placeholderPaths: ResolvedFiles, transformPaths: TransformFiles, fileFormat: FileFormats, options: Settings): Promise<void>;
|
|
@@ -8,19 +8,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.translateFiles = translateFiles;
|
|
13
16
|
const checkFileTranslations_1 = require("../../api/checkFileTranslations");
|
|
14
17
|
const sendFiles_1 = require("../../api/sendFiles");
|
|
15
18
|
const parseFilesConfig_1 = require("../../fs/config/parseFilesConfig");
|
|
16
19
|
const findFilepath_1 = require("../../fs/findFilepath");
|
|
20
|
+
const path_1 = __importDefault(require("path"));
|
|
17
21
|
/**
|
|
18
22
|
* Sends an entire file to the API for translation
|
|
19
23
|
* @param fileContent - The raw content of the file to translate
|
|
20
24
|
* @param options - Translation options including API settings
|
|
21
25
|
* @returns The translated file content or null if translation failed
|
|
22
26
|
*/
|
|
23
|
-
function translateFiles(filePaths, placeholderPaths, fileFormat, options) {
|
|
27
|
+
function translateFiles(filePaths, placeholderPaths, transformPaths, fileFormat, options) {
|
|
24
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
29
|
let typeIndex = 'json';
|
|
26
30
|
if (fileFormat === 'MDX') {
|
|
@@ -52,10 +56,22 @@ function translateFiles(filePaths, placeholderPaths, fileFormat, options) {
|
|
|
52
56
|
const fileMapping = {};
|
|
53
57
|
for (const locale of locales) {
|
|
54
58
|
const translatedPaths = (0, parseFilesConfig_1.resolveLocaleFiles)(placeholderPaths, locale);
|
|
55
|
-
|
|
59
|
+
let translatedFiles = translatedPaths[typeIndex];
|
|
56
60
|
if (!translatedFiles) {
|
|
57
61
|
continue; // shouldn't happen; typing
|
|
58
62
|
}
|
|
63
|
+
const transformPath = transformPaths[typeIndex];
|
|
64
|
+
if (transformPath) {
|
|
65
|
+
translatedFiles = translatedFiles.map((filePath) => {
|
|
66
|
+
const directory = path_1.default.dirname(filePath);
|
|
67
|
+
const fileName = path_1.default.basename(filePath);
|
|
68
|
+
const baseName = fileName.split('.')[0];
|
|
69
|
+
const transformedFileName = transformPath
|
|
70
|
+
.replace('*', baseName)
|
|
71
|
+
.replace('[locale]', locale);
|
|
72
|
+
return path_1.default.join(directory, transformedFileName);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
59
75
|
const localeMapping = {};
|
|
60
76
|
for (let i = 0; i < sourcePaths.length; i++) {
|
|
61
77
|
const sourceFile = (0, findFilepath_1.getRelative)(sourcePaths[i]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FilesOptions, ResolvedFiles } from '../../types';
|
|
1
|
+
import { FilesOptions, ResolvedFiles, TransformFiles } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* Resolves the files from the files object
|
|
4
4
|
* Replaces [locale] with the actual locale in the files
|
|
@@ -19,4 +19,5 @@ export declare function resolveLocaleFiles(files: ResolvedFiles, locale: string)
|
|
|
19
19
|
export declare function resolveFiles(files: FilesOptions, locale: string): {
|
|
20
20
|
resolvedPaths: ResolvedFiles;
|
|
21
21
|
placeholderPaths: ResolvedFiles;
|
|
22
|
+
transformPaths: TransformFiles;
|
|
22
23
|
};
|
|
@@ -35,10 +35,11 @@ function resolveLocaleFiles(files, locale) {
|
|
|
35
35
|
* @returns The resolved files
|
|
36
36
|
*/
|
|
37
37
|
function resolveFiles(files, locale) {
|
|
38
|
-
var _a, _b, _c;
|
|
38
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
39
39
|
// Initialize result object with empty arrays for each file type
|
|
40
40
|
const result = {};
|
|
41
41
|
const placeholderResult = {};
|
|
42
|
+
const transformPaths = {};
|
|
42
43
|
// Process JSON files
|
|
43
44
|
if ((_a = files.json) === null || _a === void 0 ? void 0 : _a.include) {
|
|
44
45
|
if (files.json.include.length > 1) {
|
|
@@ -46,7 +47,7 @@ function resolveFiles(files, locale) {
|
|
|
46
47
|
process.exit(1);
|
|
47
48
|
}
|
|
48
49
|
if (files.json.include.length === 1) {
|
|
49
|
-
const jsonPaths = expandGlobPatterns([files.json.include[0]], locale);
|
|
50
|
+
const jsonPaths = expandGlobPatterns([files.json.include[0]], ((_b = files.json) === null || _b === void 0 ? void 0 : _b.exclude) || [], locale);
|
|
50
51
|
if (jsonPaths.resolvedPaths.length > 1) {
|
|
51
52
|
console.error('JSON glob pattern matched multiple files. Only one JSON file is supported.');
|
|
52
53
|
process.exit(1);
|
|
@@ -56,25 +57,37 @@ function resolveFiles(files, locale) {
|
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
// Process MD files
|
|
59
|
-
if ((
|
|
60
|
-
const mdPaths = expandGlobPatterns(files.md.include, locale);
|
|
60
|
+
if ((_c = files.md) === null || _c === void 0 ? void 0 : _c.include) {
|
|
61
|
+
const mdPaths = expandGlobPatterns(files.md.include, ((_d = files.md) === null || _d === void 0 ? void 0 : _d.exclude) || [], locale);
|
|
61
62
|
result.md = mdPaths.resolvedPaths;
|
|
62
63
|
placeholderResult.md = mdPaths.placeholderPaths;
|
|
63
64
|
}
|
|
64
65
|
// Process MDX files
|
|
65
|
-
if ((
|
|
66
|
-
const mdxPaths = expandGlobPatterns(files.mdx.include, locale);
|
|
66
|
+
if ((_e = files.mdx) === null || _e === void 0 ? void 0 : _e.include) {
|
|
67
|
+
const mdxPaths = expandGlobPatterns(files.mdx.include, ((_f = files.mdx) === null || _f === void 0 ? void 0 : _f.exclude) || [], locale);
|
|
67
68
|
result.mdx = mdxPaths.resolvedPaths;
|
|
68
69
|
placeholderResult.mdx = mdxPaths.placeholderPaths;
|
|
69
70
|
}
|
|
70
|
-
|
|
71
|
+
// ==== TRANSFORMS ==== //
|
|
72
|
+
if (((_g = files.mdx) === null || _g === void 0 ? void 0 : _g.transform) && !Array.isArray(files.mdx.transform)) {
|
|
73
|
+
transformPaths.mdx = files.mdx.transform;
|
|
74
|
+
}
|
|
75
|
+
if (((_h = files.md) === null || _h === void 0 ? void 0 : _h.transform) && !Array.isArray(files.md.transform)) {
|
|
76
|
+
transformPaths.md = files.md.transform;
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
resolvedPaths: result,
|
|
80
|
+
placeholderPaths: placeholderResult,
|
|
81
|
+
transformPaths: transformPaths,
|
|
82
|
+
};
|
|
71
83
|
}
|
|
72
84
|
// Helper function to expand glob patterns
|
|
73
|
-
function expandGlobPatterns(
|
|
85
|
+
function expandGlobPatterns(includePatterns, excludePatterns, locale) {
|
|
74
86
|
// Expand glob patterns to include all matching files
|
|
75
87
|
const resolvedPaths = [];
|
|
76
88
|
const placeholderPaths = [];
|
|
77
|
-
|
|
89
|
+
// Process include patterns
|
|
90
|
+
for (const pattern of includePatterns) {
|
|
78
91
|
// Track positions where [locale] appears in the original pattern
|
|
79
92
|
const localePositions = [];
|
|
80
93
|
let searchIndex = 0;
|
|
@@ -93,8 +106,13 @@ function expandGlobPatterns(patterns, locale) {
|
|
|
93
106
|
expandedPattern.includes('{')) {
|
|
94
107
|
// Resolve the absolute pattern path
|
|
95
108
|
const absolutePattern = path_1.default.resolve(process.cwd(), expandedPattern);
|
|
96
|
-
//
|
|
97
|
-
const
|
|
109
|
+
// Prepare exclude patterns with locale replaced
|
|
110
|
+
const expandedExcludePatterns = excludePatterns.map((p) => path_1.default.resolve(process.cwd(), p.replace(/\[locale\]/g, locale)));
|
|
111
|
+
// Use fast-glob to find all matching files, excluding the patterns
|
|
112
|
+
const matches = fast_glob_1.default.sync(absolutePattern, {
|
|
113
|
+
absolute: true,
|
|
114
|
+
ignore: expandedExcludePatterns,
|
|
115
|
+
});
|
|
98
116
|
resolvedPaths.push(...matches);
|
|
99
117
|
// For each match, create a version with [locale] in the correct positions
|
|
100
118
|
matches.forEach((match) => {
|
|
@@ -124,13 +142,28 @@ function expandGlobPatterns(patterns, locale) {
|
|
|
124
142
|
});
|
|
125
143
|
}
|
|
126
144
|
else {
|
|
127
|
-
// If it's not a glob pattern, just add the resolved path
|
|
145
|
+
// If it's not a glob pattern, just add the resolved path if it's not excluded
|
|
128
146
|
const absolutePath = path_1.default.resolve(process.cwd(), expandedPattern);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
|
|
147
|
+
// Check if this path should be excluded
|
|
148
|
+
const expandedExcludePatterns = excludePatterns.map((p) => path_1.default.resolve(process.cwd(), p.replace(/\[locale\]/g, locale)));
|
|
149
|
+
// Only include if not matched by any exclude pattern
|
|
150
|
+
const shouldExclude = expandedExcludePatterns.some((excludePattern) => {
|
|
151
|
+
if (excludePattern.includes('*') ||
|
|
152
|
+
excludePattern.includes('?') ||
|
|
153
|
+
excludePattern.includes('{')) {
|
|
154
|
+
return fast_glob_1.default
|
|
155
|
+
.sync(excludePattern, { absolute: true })
|
|
156
|
+
.includes(absolutePath);
|
|
157
|
+
}
|
|
158
|
+
return absolutePath === excludePattern;
|
|
159
|
+
});
|
|
160
|
+
if (!shouldExclude) {
|
|
161
|
+
resolvedPaths.push(absolutePath);
|
|
162
|
+
// For non-glob patterns, we can directly replace locale with [locale]
|
|
163
|
+
// at the tracked positions in the resolved path
|
|
164
|
+
let originalPath = path_1.default.resolve(process.cwd(), pattern);
|
|
165
|
+
placeholderPaths.push(originalPath);
|
|
166
|
+
}
|
|
134
167
|
}
|
|
135
168
|
}
|
|
136
169
|
return { resolvedPaths, placeholderPaths };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -62,15 +62,21 @@ export interface ContentScanner {
|
|
|
62
62
|
export type FilesOptions = {
|
|
63
63
|
json?: {
|
|
64
64
|
include: string[];
|
|
65
|
+
exclude?: string[];
|
|
65
66
|
};
|
|
66
67
|
yaml?: {
|
|
67
68
|
include: string[];
|
|
69
|
+
exclude?: string[];
|
|
68
70
|
};
|
|
69
71
|
md?: {
|
|
70
72
|
include: string[];
|
|
73
|
+
exclude?: string[];
|
|
74
|
+
transform?: string;
|
|
71
75
|
};
|
|
72
76
|
mdx?: {
|
|
73
77
|
include: string[];
|
|
78
|
+
exclude?: string[];
|
|
79
|
+
transform?: string;
|
|
74
80
|
};
|
|
75
81
|
};
|
|
76
82
|
export type ResolvedFiles = {
|
|
@@ -78,6 +84,11 @@ export type ResolvedFiles = {
|
|
|
78
84
|
md?: string[];
|
|
79
85
|
mdx?: string[];
|
|
80
86
|
};
|
|
87
|
+
export type TransformFiles = {
|
|
88
|
+
json?: string;
|
|
89
|
+
md?: string;
|
|
90
|
+
mdx?: string;
|
|
91
|
+
};
|
|
81
92
|
export type Settings = {
|
|
82
93
|
config: string;
|
|
83
94
|
baseUrl: string;
|
|
@@ -88,6 +99,7 @@ export type Settings = {
|
|
|
88
99
|
files: {
|
|
89
100
|
resolvedPaths: ResolvedFiles;
|
|
90
101
|
placeholderPaths: ResolvedFiles;
|
|
102
|
+
transformPaths: TransformFiles;
|
|
91
103
|
};
|
|
92
104
|
versionId?: string;
|
|
93
105
|
};
|