gtx-cli 2.4.4 → 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,17 @@
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
+
9
+ ## 2.4.5
10
+
11
+ ### Patch Changes
12
+
13
+ - [#759](https://github.com/generaltranslation/gt/pull/759) [`cf04026`](https://github.com/generaltranslation/gt/commit/cf04026df7072af60999f281ba342a1baa58f7ff) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Migrating downloaded-versions.json to gt-lock.json, make .gt and .locadex interchangable
14
+
3
15
  ## 2.4.4
4
16
 
5
17
  ### Patch Changes
package/dist/cli/flags.js CHANGED
@@ -26,7 +26,7 @@ export function attachTranslateFlags(command) {
26
26
  .option('--experimental-flatten-json-files', 'Triggering this will flatten the json files into a single file. This is useful for projects that have a lot of json files.', false)
27
27
  .option('--experimental-localize-static-imports', 'Triggering this will run a script after the cli tool that localizes all static imports in content files. Currently only supported for md and mdx files.', false)
28
28
  .option('--force', 'Force a retranslation, invalidating all existing cached translations if they exist.', false)
29
- .option('--force-download', 'Force download and overwrite local files, bypassing downloaded-versions checks.', false)
29
+ .option('--force-download', 'Force download and overwrite local files, bypassing gt-lock.json checks.', false)
30
30
  .option('--experimental-clear-locale-dirs', 'Clear locale directories before downloading new translations', false);
31
31
  return command;
32
32
  }
@@ -15,6 +15,14 @@ export function resolveConfig(cwd) {
15
15
  config: loadConfig(path.join(cwd, 'src/gt.config.json')),
16
16
  };
17
17
  }
18
+ // Support config under .gt for parity with .locadex
19
+ if (fs.existsSync(path.join(cwd, '.gt/gt.config.json'))) {
20
+ return {
21
+ path: path.join(cwd, '.gt/gt.config.json'),
22
+ config: loadConfig(path.join(cwd, '.gt/gt.config.json')),
23
+ };
24
+ }
25
+ // Backward compatibility: support legacy .locadex directory
18
26
  if (fs.existsSync(path.join(cwd, '.locadex/gt.config.json'))) {
19
27
  return {
20
28
  path: path.join(cwd, '.locadex/gt.config.json'),
@@ -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);
@@ -1,11 +1,22 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { logError } from '../../console/logging.js';
4
- const DOWNLOADED_VERSIONS_FILE = 'downloaded-versions.json';
4
+ // New lock file name, use old name for deletion of legacy lock file
5
+ const GT_LOCK_FILE = 'gt-lock.json';
6
+ const LEGACY_DOWNLOADED_VERSIONS_FILE = 'downloaded-versions.json';
5
7
  export function getDownloadedVersions(configDirectory) {
6
8
  try {
7
- const filepath = path.join(configDirectory, DOWNLOADED_VERSIONS_FILE);
8
- if (!fs.existsSync(filepath))
9
+ // Clean up legacy lock files inside the config directory
10
+ const rootPath = path.join(process.cwd(), GT_LOCK_FILE);
11
+ const legacyPath = path.join(configDirectory, LEGACY_DOWNLOADED_VERSIONS_FILE);
12
+ try {
13
+ if (fs.existsSync(legacyPath)) {
14
+ fs.unlinkSync(legacyPath);
15
+ }
16
+ }
17
+ catch { }
18
+ const filepath = fs.existsSync(rootPath) ? rootPath : null;
19
+ if (!filepath)
9
20
  return { version: 1, entries: {} };
10
21
  const raw = JSON.parse(fs.readFileSync(filepath, 'utf8'));
11
22
  if (raw && typeof raw === 'object' && raw.version && raw.entries) {
@@ -20,11 +31,12 @@ export function getDownloadedVersions(configDirectory) {
20
31
  }
21
32
  export function saveDownloadedVersions(configDirectory, lock) {
22
33
  try {
23
- const filepath = path.join(configDirectory, DOWNLOADED_VERSIONS_FILE);
24
- fs.mkdirSync(configDirectory, { recursive: true });
34
+ // Write the lock file to the repo root
35
+ const filepath = path.join(process.cwd(), GT_LOCK_FILE);
36
+ fs.mkdirSync(path.dirname(filepath), { recursive: true });
25
37
  fs.writeFileSync(filepath, JSON.stringify(lock, null, 2));
26
38
  }
27
39
  catch (error) {
28
- logError(`An error occurred while updating ${DOWNLOADED_VERSIONS_FILE}: ${error}`);
40
+ logError(`An error occurred while updating ${GT_LOCK_FILE}: ${error}`);
29
41
  }
30
42
  }
@@ -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.4",
3
+ "version": "2.4.6",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [