gtx-cli 2.4.0 → 2.4.1

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,14 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#751](https://github.com/generaltranslation/gt/pull/751) [`7114780`](https://github.com/generaltranslation/gt/commit/71147803bf3e4cf21556ffb9b5f77756e283a32a) Thanks [@SamEggert](https://github.com/SamEggert)! - transform for yaml files -- retrieve file format in downloadFileBatch
8
+
9
+ - Updated dependencies [[`7114780`](https://github.com/generaltranslation/gt/commit/71147803bf3e4cf21556ffb9b5f77756e283a32a)]:
10
+ - generaltranslation@7.7.1
11
+
3
12
  ## 2.4.0
4
13
 
5
14
  ### Minor Changes
@@ -8,6 +8,7 @@ import { mergeJson } from '../formats/json/mergeJson.js';
8
8
  import mergeYaml from '../formats/yaml/mergeYaml.js';
9
9
  import { getDownloadedVersions, saveDownloadedVersions, } from '../fs/config/downloadedVersions.js';
10
10
  import { recordDownloaded } from '../state/recentDownloads.js';
11
+ import stringify from 'fast-json-stable-stringify';
11
12
  /**
12
13
  * Downloads multiple translation files in a single batch request
13
14
  * @param files - Array of files to download with their output paths
@@ -92,10 +93,22 @@ export async function downloadFileBatch(files, options, maxRetries = 3, retryDel
92
93
  translatedContent: file.data,
93
94
  targetLocale: locale,
94
95
  },
95
- ])[0];
96
+ ], options.defaultLocale)[0];
96
97
  }
97
98
  }
98
99
  }
100
+ // If the file is a GTJSON file, stable sort the order and format the data
101
+ if (file.fileFormat === 'GTJSON') {
102
+ try {
103
+ const jsonData = JSON.parse(data);
104
+ const sortedData = stringify(jsonData); // stably sort with fast-json-stable-stringify
105
+ const sortedJsonData = JSON.parse(sortedData);
106
+ data = JSON.stringify(sortedJsonData, null, 2); // format the data
107
+ }
108
+ catch (error) {
109
+ logWarning(`Failed to sort GTJson file: ${file.id}: ` + error);
110
+ }
111
+ }
99
112
  // Write the file to disk
100
113
  await fs.promises.writeFile(outputPath, data);
101
114
  // Track as downloaded
@@ -2,4 +2,4 @@ import { AdditionalOptions } from '../../types/index.js';
2
2
  export default function mergeYaml(originalContent: string, inputPath: string, options: AdditionalOptions, targets: {
3
3
  translatedContent: string;
4
4
  targetLocale: string;
5
- }[]): string[];
5
+ }[], defaultLocale: string): string[];
@@ -2,7 +2,8 @@ import JSONPointer from 'jsonpointer';
2
2
  import { exit, logError } from '../../console/logging.js';
3
3
  import { validateYamlSchema } from './utils.js';
4
4
  import YAML from 'yaml';
5
- export default function mergeYaml(originalContent, inputPath, options, targets) {
5
+ import { applyTransformations } from '../json/mergeJson.js';
6
+ export default function mergeYaml(originalContent, inputPath, options, targets, defaultLocale) {
6
7
  const yamlSchema = validateYamlSchema(options, inputPath);
7
8
  if (!yamlSchema) {
8
9
  return targets.map((target) => target.translatedContent);
@@ -46,6 +47,10 @@ export default function mergeYaml(originalContent, inputPath, options, targets)
46
47
  // Silently ignore invalid or non-existent JSON pointers
47
48
  }
48
49
  }
50
+ // Apply transformations if they exist
51
+ if (yamlSchema.transform) {
52
+ applyTransformations(mergedYaml, yamlSchema.transform, target.targetLocale, defaultLocale);
53
+ }
49
54
  output.push(YAML.stringify(mergedYaml));
50
55
  }
51
56
  if (!output.length) {
@@ -163,6 +163,7 @@ export type JsonSchema = {
163
163
  export type YamlSchema = {
164
164
  preset?: 'mintlify';
165
165
  include?: string[];
166
+ transform?: TransformOptions;
166
167
  };
167
168
  export type SourceObjectOptions = {
168
169
  type: 'array' | 'object';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [
@@ -73,6 +73,7 @@
73
73
  "dotenv": "^16.4.5",
74
74
  "esbuild": "^0.25.4",
75
75
  "fast-glob": "^3.3.3",
76
+ "fast-json-stable-stringify": "^2.1.0",
76
77
  "form-data": "^4.0.4",
77
78
  "gt-remark": "^1.0.1",
78
79
  "json-pointer": "^0.6.2",
@@ -91,7 +92,7 @@
91
92
  "unified": "^11.0.5",
92
93
  "unist-util-visit": "^5.0.0",
93
94
  "yaml": "^2.8.0",
94
- "generaltranslation": "7.7.0"
95
+ "generaltranslation": "7.7.1"
95
96
  },
96
97
  "devDependencies": {
97
98
  "@babel/types": "^7.28.4",