gtx-cli 2.5.26 → 2.5.28

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,27 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.5.28
4
+
5
+ ### Patch Changes
6
+
7
+ - [#883](https://github.com/generaltranslation/gt/pull/883) [`e113d8d`](https://github.com/generaltranslation/gt/commit/e113d8d8fb5e37f45a4aa77544e8f4666519bfe8) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Send file paths in translation metadata
8
+
9
+ - [#885](https://github.com/generaltranslation/gt/pull/885) [`22ef3ec`](https://github.com/generaltranslation/gt/commit/22ef3ecb9c2a41a5d982684cc2d45834be11ae5b) Thanks [@brian-lou](https://github.com/brian-lou)! - Add shared flags to CLI save-local command
10
+
11
+ - [#886](https://github.com/generaltranslation/gt/pull/886) [`8ba1edf`](https://github.com/generaltranslation/gt/commit/8ba1edfa838fe9209ae6fa5fe154e7c991be9aa6) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Handle Mintlify anchor IDs containing escaped characters
12
+
13
+ - Updated dependencies [[`e113d8d`](https://github.com/generaltranslation/gt/commit/e113d8d8fb5e37f45a4aa77544e8f4666519bfe8)]:
14
+ - generaltranslation@8.1.3
15
+
16
+ ## 2.5.27
17
+
18
+ ### Patch Changes
19
+
20
+ - [#880](https://github.com/generaltranslation/gt/pull/880) [`3dc7b64`](https://github.com/generaltranslation/gt/commit/3dc7b6460cd05ddcb656a247602f4f50b06312fd) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Hotfix: sending format metadata to the API during build time translation
21
+
22
+ - Updated dependencies [[`3dc7b64`](https://github.com/generaltranslation/gt/commit/3dc7b6460cd05ddcb656a247602f4f50b06312fd)]:
23
+ - generaltranslation@8.1.2
24
+
3
25
  ## 2.5.26
4
26
 
5
27
  ### Patch Changes
package/dist/cli/base.js CHANGED
@@ -15,7 +15,7 @@ import { getPackageManager } from '../utils/packageManager.js';
15
15
  import { retrieveCredentials, setCredentials } from '../utils/credentials.js';
16
16
  import { areCredentialsSet } from '../utils/credentials.js';
17
17
  import { upload } from '../formats/files/upload.js';
18
- import { attachTranslateFlags } from './flags.js';
18
+ import { attachSharedFlags, attachTranslateFlags } from './flags.js';
19
19
  import { handleStage } from './commands/stage.js';
20
20
  import { handleSetupProject } from './commands/setupProject.js';
21
21
  import { handleDownload, handleTranslate, postProcessTranslations, } from './commands/translate.js';
@@ -80,13 +80,11 @@ export class BaseCLI {
80
80
  });
81
81
  }
82
82
  setupSendDiffsCommand() {
83
- this.program
83
+ attachSharedFlags(this.program
84
84
  .command('save-local')
85
- .description('Save local edits for all configured files by sending diffs (no translation enqueued)')
86
- .action(async () => {
85
+ .description('Save local edits for all configured files by sending diffs (no translation enqueued)')).action(async (initOptions) => {
87
86
  displayHeader('Saving local edits...');
88
- const config = findFilepath(['gt.config.json']);
89
- const settings = await generateSettings({ config });
87
+ const settings = await generateSettings(initOptions);
90
88
  await saveLocalEdits(settings);
91
89
  logger.endCommand('Saved local edits');
92
90
  });
@@ -1,3 +1,4 @@
1
1
  import { Command } from 'commander';
2
+ export declare function attachSharedFlags(command: Command): Command;
2
3
  export declare function attachTranslateFlags(command: Command): Command;
3
4
  export declare function attachAdditionalReactTranslateFlags(command: Command): Command;
package/dist/cli/flags.js CHANGED
@@ -1,10 +1,14 @@
1
1
  import findFilepath from '../fs/findFilepath.js';
2
2
  const DEFAULT_TIMEOUT = 600;
3
- export function attachTranslateFlags(command) {
3
+ export function attachSharedFlags(command) {
4
4
  command
5
5
  .option('-c, --config <path>', 'Filepath to config file, by default gt.config.json', findFilepath(['gt.config.json']))
6
6
  .option('--api-key <key>', 'API key for General Translation cloud service')
7
- .option('--project-id <id>', 'General Translation project ID')
7
+ .option('--project-id <id>', 'General Translation project ID');
8
+ return command;
9
+ }
10
+ export function attachTranslateFlags(command) {
11
+ attachSharedFlags(command)
8
12
  .option('--version-id <id>', 'General Translation version ID')
9
13
  .option('--default-language, --default-locale <locale>', 'Default locale (e.g., en)')
10
14
  .option('--new, --locales <locales...>', 'Space-separated list of locales (e.g., en fr es)')
@@ -41,7 +41,7 @@ export async function collectFiles(options, settings, library) {
41
41
  fileFormat: 'GTJSON',
42
42
  formatMetadata: fileMetadata,
43
43
  fileId: TEMPLATE_FILE_ID,
44
- versionId: hashStringSync(JSON.stringify(fileData)),
44
+ versionId: hashStringSync(JSON.stringify({ data: fileData, metadata: fileMetadata })),
45
45
  });
46
46
  }
47
47
  }
@@ -19,6 +19,7 @@ import { handleChildrenWhitespace } from './handleChildrenWhitespace.js';
19
19
  import { isElementNode, } from './types.js';
20
20
  import { multiplyJsxTree } from './multiplication/multiplyJsxTree.js';
21
21
  import { removeNullChildrenFields } from './removeNullChildrenFields.js';
22
+ import path from 'node:path';
22
23
  // Handle CommonJS/ESM interop
23
24
  const traverse = traverseModule.default || traverseModule;
24
25
  // TODO: currently we cover VariableDeclaration and FunctionDeclaration nodes, but are there others we should cover as well?
@@ -365,6 +366,8 @@ export function parseJSXElement({ importAliases, node, originalName, pkgs, updat
365
366
  const componentErrors = [];
366
367
  const componentWarnings = new Set();
367
368
  const metadata = {};
369
+ const relativeFilepath = path.relative(process.cwd(), file);
370
+ metadata.filePaths = [relativeFilepath];
368
371
  // We'll track this flag to know if any unwrapped {variable} is found in children
369
372
  const unwrappedExpressions = [];
370
373
  // Gather <T>'s props
@@ -8,6 +8,7 @@ import traverseModule from '@babel/traverse';
8
8
  const generate = generateModule.default || generateModule;
9
9
  const traverse = traverseModule.default || traverseModule;
10
10
  import fs from 'node:fs';
11
+ import pathModule from 'node:path';
11
12
  import { parse } from '@babel/parser';
12
13
  import { resolveImportPath } from './resolveImportPath.js';
13
14
  import { buildImportMap } from './buildImportMap.js';
@@ -95,6 +96,17 @@ function processTranslationCall(tPath, updates, errors, warnings, file, ignoreAd
95
96
  }
96
97
  });
97
98
  }
99
+ const relativeFilepath = pathModule.relative(process.cwd(), file);
100
+ if (relativeFilepath) {
101
+ if (!metadata.filePaths) {
102
+ metadata.filePaths = [relativeFilepath];
103
+ }
104
+ else if (Array.isArray(metadata.filePaths)) {
105
+ if (!metadata.filePaths.includes(relativeFilepath)) {
106
+ metadata.filePaths.push(relativeFilepath);
107
+ }
108
+ }
109
+ }
98
110
  updates.push({
99
111
  dataFormat: 'ICU',
100
112
  source,
@@ -6,3 +6,4 @@ export declare function createInlineUpdates(pkg: GTLibrary, validate: boolean, f
6
6
  errors: string[];
7
7
  warnings: string[];
8
8
  }>;
9
+ export declare function mergeUpdatesByHash(updates: Updates): void;
@@ -71,6 +71,7 @@ export async function createInlineUpdates(pkg, validate, filePatterns, parsingOp
71
71
  });
72
72
  update.metadata.hash = hash;
73
73
  }));
74
+ mergeUpdatesByHash(updates);
74
75
  return { updates, errors, warnings: [...warnings] };
75
76
  }
76
77
  /**
@@ -80,3 +81,35 @@ export async function createInlineUpdates(pkg, validate, filePatterns, parsingOp
80
81
  function getUpstreamPackages(pkg) {
81
82
  return GT_LIBRARIES_UPSTREAM[pkg];
82
83
  }
84
+ export function mergeUpdatesByHash(updates) {
85
+ const mergedByHash = new Map();
86
+ const noHashUpdates = [];
87
+ for (const update of updates) {
88
+ const hash = update.metadata.hash;
89
+ if (!hash) {
90
+ noHashUpdates.push(update);
91
+ continue;
92
+ }
93
+ const existing = mergedByHash.get(hash);
94
+ if (!existing) {
95
+ mergedByHash.set(hash, update);
96
+ continue;
97
+ }
98
+ const existingPaths = Array.isArray(existing.metadata.filePaths)
99
+ ? existing.metadata.filePaths.slice()
100
+ : [];
101
+ const newPaths = Array.isArray(update.metadata.filePaths)
102
+ ? update.metadata.filePaths
103
+ : [];
104
+ for (const p of newPaths) {
105
+ if (!existingPaths.includes(p)) {
106
+ existingPaths.push(p);
107
+ }
108
+ }
109
+ if (existingPaths.length) {
110
+ existing.metadata.filePaths = existingPaths;
111
+ }
112
+ }
113
+ const mergedUpdates = [...mergedByHash.values(), ...noHashUpdates];
114
+ updates.splice(0, updates.length, ...mergedUpdates);
115
+ }
@@ -37,10 +37,12 @@ export type OpenApiConfig = {
37
37
  export type MintlifyOptions = {
38
38
  openapi?: OpenApiConfig;
39
39
  };
40
- export type TranslateFlags = {
40
+ export type SharedFlags = {
41
41
  config?: string;
42
42
  apiKey?: string;
43
43
  projectId?: string;
44
+ };
45
+ export type TranslateFlags = SharedFlags & {
44
46
  versionId?: string;
45
47
  jsconfig?: string;
46
48
  dictionary?: string;
@@ -6,6 +6,7 @@ import remarkStringify from 'remark-stringify';
6
6
  import { visit } from 'unist-util-visit';
7
7
  import { logger } from '../console/logger.js';
8
8
  import escapeHtmlInTextNodes from 'gt-remark';
9
+ import { decode } from 'html-entities';
9
10
  /**
10
11
  * Generates a slug from heading text
11
12
  */
@@ -379,7 +380,10 @@ function applyDivWrappedIds(translatedContent, translatedHeadings, idMappings) {
379
380
  .replace(/`(.*?)`/g, '$1') // Remove inline code
380
381
  .replace(/\[(.*?)\]\(.*?\)/g, '$1') // Remove links, keep text
381
382
  .trim();
382
- return cleanLineText === heading.text && hl.level === heading.level;
383
+ const normalizedLineText = decode(cleanLineText).trim();
384
+ const normalizedHeadingText = decode(heading.text).trim();
385
+ return (normalizedLineText === normalizedHeadingText &&
386
+ hl.level === heading.level);
383
387
  });
384
388
  if (matchingLine) {
385
389
  headingsToWrap.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "2.5.26",
3
+ "version": "2.5.28",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [
@@ -88,6 +88,7 @@
88
88
  "fast-glob": "^3.3.3",
89
89
  "fast-json-stable-stringify": "^2.1.0",
90
90
  "gt-remark": "^1.0.1",
91
+ "html-entities": "^2.6.0",
91
92
  "json-pointer": "^0.6.2",
92
93
  "jsonpath-plus": "^10.3.0",
93
94
  "jsonpointer": "^5.0.1",
@@ -104,7 +105,7 @@
104
105
  "unified": "^11.0.5",
105
106
  "unist-util-visit": "^5.0.0",
106
107
  "yaml": "^2.8.0",
107
- "generaltranslation": "8.1.1"
108
+ "generaltranslation": "8.1.3"
108
109
  },
109
110
  "devDependencies": {
110
111
  "@babel/types": "^7.28.4",