gtx-cli 2.4.5 → 2.4.6

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.4.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#763](https://github.com/generaltranslation/gt/pull/763) [`b6a79a8`](https://github.com/generaltranslation/gt/commit/b6a79a868630725eb1106faaa2c385c305891e9c) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Allow lists for overrides in gt.config.json
8
+
3
9
  ## 2.4.5
4
10
 
5
11
  ### Patch Changes
@@ -44,6 +44,39 @@ export function createFileMapping(filePaths, placeholderPaths, transformPaths, t
44
44
  return path.join(directory, transformedFileName);
45
45
  });
46
46
  }
47
+ else if (Array.isArray(transformPath)) {
48
+ // transformPath is an array of TransformOption objects
49
+ const targetLocaleProperties = getLocaleProperties(locale);
50
+ const defaultLocaleProperties = getLocaleProperties(defaultLocale);
51
+ translatedFiles = translatedFiles.map((filePath) => {
52
+ const relativePath = getRelative(filePath);
53
+ // Try each transform in order until one matches
54
+ for (const transform of transformPath) {
55
+ if (!transform.replace || typeof transform.replace !== 'string') {
56
+ continue;
57
+ }
58
+ // Replace all locale property placeholders in the replace string
59
+ const replaceString = replaceLocalePlaceholders(transform.replace, targetLocaleProperties);
60
+ if (transform.match && typeof transform.match === 'string') {
61
+ // Replace locale placeholders in the match string using defaultLocale properties
62
+ let matchString = transform.match;
63
+ matchString = replaceLocalePlaceholders(matchString, defaultLocaleProperties);
64
+ const regex = new RegExp(matchString);
65
+ if (regex.test(relativePath)) {
66
+ // This transform matches, apply it and break
67
+ const transformedPath = relativePath.replace(new RegExp(matchString, 'g'), replaceString);
68
+ return path.resolve(transformedPath);
69
+ }
70
+ }
71
+ else {
72
+ // No match provided: treat as a direct replacement (override)
73
+ return path.resolve(replaceString);
74
+ }
75
+ }
76
+ // If no transforms matched, return the original path
77
+ return filePath;
78
+ });
79
+ }
47
80
  else {
48
81
  // transformPath is an object
49
82
  const targetLocaleProperties = getLocaleProperties(locale);
@@ -21,7 +21,7 @@ export declare function resolveFiles(files: FilesOptions, locale: string, locale
21
21
  placeholderPaths: ResolvedFiles;
22
22
  transformPaths: TransformFiles;
23
23
  };
24
- export declare function expandGlobPatterns(cwd: string, includePatterns: string[], excludePatterns: string[], locale: string, locales: string[], transformPatterns?: TransformOption | string, compositePatterns?: string[]): {
24
+ export declare function expandGlobPatterns(cwd: string, includePatterns: string[], excludePatterns: string[], locale: string, locales: string[], transformPatterns?: TransformOption | string | TransformOption[], compositePatterns?: string[]): {
25
25
  resolvedPaths: string[];
26
26
  placeholderPaths: string[];
27
27
  };
@@ -41,8 +41,9 @@ export function resolveFiles(files, locale, locales, cwd, compositePatterns) {
41
41
  // ==== TRANSFORMS ==== //
42
42
  const transform = files[fileType]?.transform;
43
43
  if (transform &&
44
- !Array.isArray(transform) &&
45
- (typeof transform === 'string' || typeof transform === 'object')) {
44
+ (typeof transform === 'string' ||
45
+ typeof transform === 'object' ||
46
+ Array.isArray(transform))) {
46
47
  transformPaths[fileType] = transform;
47
48
  }
48
49
  // ==== PLACEHOLDERS ==== //
@@ -93,13 +93,13 @@ export type TransformOption = {
93
93
  replace: string;
94
94
  };
95
95
  export type TransformFiles = {
96
- [K in SupportedFileExtension]?: TransformOption | string;
96
+ [K in SupportedFileExtension]?: TransformOption | string | TransformOption[];
97
97
  };
98
98
  export type FilesOptions = {
99
99
  [K in SupportedFileExtension]?: {
100
100
  include: string[];
101
101
  exclude?: string[];
102
- transform?: string | TransformOption;
102
+ transform?: string | TransformOption | TransformOption[];
103
103
  };
104
104
  } & {
105
105
  gt?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "2.4.5",
3
+ "version": "2.4.6",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [