gtx-cli 2.5.42 → 2.5.43

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.5.43
4
+
5
+ ### Patch Changes
6
+
7
+ - [#933](https://github.com/generaltranslation/gt/pull/933) [`a9aae8c`](https://github.com/generaltranslation/gt/commit/a9aae8c7d22a074ef490b4f4a563a64ae50cd444) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Fixing handling of [locale] placeholder in blob patterns
8
+
3
9
  ## 2.5.42
4
10
 
5
11
  ### Patch Changes
@@ -3,6 +3,7 @@ import fg from 'fast-glob';
3
3
  import { SUPPORTED_FILE_EXTENSIONS } from '../../formats/files/supportedFiles.js';
4
4
  import { logger } from '../../console/logger.js';
5
5
  import chalk from 'chalk';
6
+ import micromatch from 'micromatch';
6
7
  /**
7
8
  * Resolves the files from the files object
8
9
  * Replaces [locale] with the actual locale in the files
@@ -100,31 +101,50 @@ export function expandGlobPatterns(cwd, includePatterns, excludePatterns, locale
100
101
  resolvedPaths.push(...matches);
101
102
  // For each match, create a version with [locale] in the correct positions
102
103
  matches.forEach((match) => {
103
- // Convert to absolute path to make replacement easier
104
104
  const absolutePath = path.resolve(cwd, match);
105
105
  const patternPath = path.resolve(cwd, pattern);
106
106
  let originalAbsolutePath = absolutePath;
107
107
  if (localePositions.length > 0) {
108
- // Replace all instances of [locale]
109
- // but only in path segments where we expect it based on the original pattern
110
- const pathParts = absolutePath.split(path.sep);
111
- const patternParts = patternPath.split(path.sep);
112
- for (let i = 0; i < pathParts.length; i++) {
113
- if (i < patternParts.length) {
114
- if (patternParts[i].includes(localeTag)) {
115
- // This segment should have the locale replaced
116
- // Create regex from pattern to match the actual path structure
117
- const regexPattern = patternParts[i].replace(/\[locale\]/g, `(${locale.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')})`);
118
- const regex = new RegExp(regexPattern);
119
- pathParts[i] = pathParts[i].replace(regex, patternParts[i].replace(/\[locale\]/g, localeTag));
120
- }
121
- }
122
- }
123
- originalAbsolutePath = pathParts.join(path.sep);
108
+ const placeholderPath = buildPlaceholderPathFromPattern(patternPath, absolutePath, localeTag);
109
+ originalAbsolutePath = placeholderPath;
124
110
  }
125
- // Convert back to absolute path
126
111
  placeholderPaths.push(originalAbsolutePath);
127
112
  });
128
113
  }
129
114
  return { resolvedPaths, placeholderPaths };
130
115
  }
116
+ function buildPlaceholderPathFromPattern(patternPath, absolutePath, localeTag) {
117
+ if (!patternPath.includes(localeTag)) {
118
+ return absolutePath;
119
+ }
120
+ const posixPattern = toPosixPath(patternPath);
121
+ const posixPath = toPosixPath(absolutePath);
122
+ const baseRegex = micromatch.makeRe(posixPattern, {
123
+ literalBrackets: true,
124
+ });
125
+ const localeRegexSource = baseRegex.source.replace(/\\\[locale\\\]/g, '([^/]+)');
126
+ const flags = baseRegex.flags.includes('d')
127
+ ? baseRegex.flags
128
+ : `${baseRegex.flags}d`;
129
+ const matcher = new RegExp(localeRegexSource, flags);
130
+ const match = matcher.exec(posixPath);
131
+ const matchWithIndices = match;
132
+ if (!match || !matchWithIndices.indices) {
133
+ return absolutePath;
134
+ }
135
+ let placeholderPosixPath = posixPath;
136
+ const indices = matchWithIndices.indices;
137
+ for (let i = indices.length - 1; i >= 1; i--) {
138
+ const [start, end] = indices[i];
139
+ if (start === -1 || end === -1)
140
+ continue;
141
+ placeholderPosixPath =
142
+ placeholderPosixPath.slice(0, start) +
143
+ localeTag +
144
+ placeholderPosixPath.slice(end);
145
+ }
146
+ return path.normalize(placeholderPosixPath);
147
+ }
148
+ function toPosixPath(value) {
149
+ return value.split(path.sep).join(path.posix.sep);
150
+ }
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "2.5.42";
1
+ export declare const PACKAGE_VERSION = "2.5.43";
@@ -1,2 +1,2 @@
1
1
  // This file is auto-generated. Do not edit manually.
2
- export const PACKAGE_VERSION = '2.5.42';
2
+ export const PACKAGE_VERSION = '2.5.43';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "2.5.42",
3
+ "version": "2.5.43",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [