gtx-cli 2.3.3 → 2.3.5

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.3.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#687](https://github.com/generaltranslation/gt/pull/687) [`99a1958`](https://github.com/generaltranslation/gt/commit/99a1958124d532bb3817f76a69d5232d9eb26f76) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - fix: showing superfluous warning for composite json paths
8
+
9
+ ## 2.3.4
10
+
11
+ ### Patch Changes
12
+
13
+ - [#671](https://github.com/generaltranslation/gt/pull/671) [`b8c19d1`](https://github.com/generaltranslation/gt/commit/b8c19d13c0ab18a3f9376ebb940d9985cee6d961) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Fixing --force command in gtx-cli
14
+
3
15
  ## 2.3.3
4
16
 
5
17
  ### Patch Changes
@@ -20,4 +20,4 @@ export declare function checkFileTranslations(data: {
20
20
  versionId: string;
21
21
  fileName: string;
22
22
  };
23
- }, locales: string[], timeoutDuration: number, resolveOutputPath: (sourcePath: string, locale: string) => string | null, options: Settings): Promise<boolean>;
23
+ }, locales: string[], timeoutDuration: number, resolveOutputPath: (sourcePath: string, locale: string) => string | null, options: Settings, forceRetranslation?: boolean): Promise<boolean>;
@@ -14,11 +14,14 @@ import { TEMPLATE_FILE_NAME } from '../cli/commands/stage.js';
14
14
  * @param timeoutDuration - The timeout duration for the wait in seconds
15
15
  * @returns True if all translations are deployed, false otherwise
16
16
  */
17
- export async function checkFileTranslations(data, locales, timeoutDuration, resolveOutputPath, options) {
17
+ export async function checkFileTranslations(data, locales, timeoutDuration, resolveOutputPath, options, forceRetranslation) {
18
18
  const startTime = Date.now();
19
19
  console.log();
20
20
  const spinner = await createOraSpinner();
21
- spinner.start('Waiting for translation...');
21
+ const spinnerMessage = forceRetranslation
22
+ ? 'Waiting for retranslation...'
23
+ : 'Waiting for translation...';
24
+ spinner.start(spinnerMessage);
22
25
  // Initialize the query data
23
26
  const fileQueryData = prepareFileQueryData(data, locales);
24
27
  const downloadStatus = {
@@ -26,11 +29,13 @@ export async function checkFileTranslations(data, locales, timeoutDuration, reso
26
29
  failed: new Set(),
27
30
  skipped: new Set(),
28
31
  };
29
- // Do first check immediately
30
- const initialCheck = await checkTranslationDeployment(fileQueryData, downloadStatus, spinner, resolveOutputPath, options);
31
- if (initialCheck) {
32
- spinner.succeed(chalk.green('Files translated!'));
33
- return true;
32
+ // Do first check immediately, but skip if force retranslation is enabled
33
+ if (!forceRetranslation) {
34
+ const initialCheck = await checkTranslationDeployment(fileQueryData, downloadStatus, spinner, resolveOutputPath, options);
35
+ if (initialCheck) {
36
+ spinner.succeed(chalk.green('Files translated!'));
37
+ return true;
38
+ }
34
39
  }
35
40
  // Calculate time until next 5-second interval since startTime
36
41
  const msUntilNextInterval = Math.max(0, 5000 - ((Date.now() - startTime) % 5000));
@@ -15,7 +15,7 @@ export async function handleTranslate(options, settings, filesTranslationRespons
15
15
  const fileMapping = createFileMapping(resolvedPaths, placeholderPaths, transformPaths, settings.locales, settings.defaultLocale);
16
16
  const { data } = filesTranslationResponse;
17
17
  // Check for remaining translations
18
- await checkFileTranslations(data, settings.locales, options.timeout, (sourcePath, locale) => fileMapping[locale][sourcePath] ?? null, settings);
18
+ await checkFileTranslations(data, settings.locales, options.timeout, (sourcePath, locale) => fileMapping[locale][sourcePath] ?? null, settings, options.force);
19
19
  }
20
20
  }
21
21
  // Downloads translations that were originally staged
@@ -33,7 +33,8 @@ export async function handleDownload(options, settings) {
33
33
  const fileMapping = createFileMapping(resolvedPaths, placeholderPaths, transformPaths, settings.locales, settings.defaultLocale);
34
34
  const stagedVersionData = await getStagedVersions(settings.configDirectory);
35
35
  // Check for remaining translations
36
- await checkFileTranslations(stagedVersionData, settings.locales, options.timeout, (sourcePath, locale) => fileMapping[locale][sourcePath] ?? null, settings);
36
+ await checkFileTranslations(stagedVersionData, settings.locales, options.timeout, (sourcePath, locale) => fileMapping[locale][sourcePath] ?? null, settings, false // force is not applicable for downloading staged translations
37
+ );
37
38
  }
38
39
  export async function postProcessTranslations(settings) {
39
40
  // Localize static urls (/docs -> /[locale]/docs) and preserve anchor IDs for non-default locales
@@ -108,8 +108,13 @@ export async function generateSettings(options, cwd = process.cwd()) {
108
108
  // Populate src if not provided
109
109
  mergedOptions.src = mergedOptions.src || DEFAULT_SRC_PATTERNS;
110
110
  // Resolve all glob patterns in the files object
111
+ const compositePatterns = [
112
+ ...Object.entries(mergedOptions.options?.jsonSchema || {}),
113
+ ]
114
+ .filter(([, schema]) => schema.composite)
115
+ .map(([key]) => key);
111
116
  mergedOptions.files = mergedOptions.files
112
- ? resolveFiles(mergedOptions.files, mergedOptions.defaultLocale, mergedOptions.locales, cwd)
117
+ ? resolveFiles(mergedOptions.files, mergedOptions.defaultLocale, mergedOptions.locales, cwd, compositePatterns)
113
118
  : undefined;
114
119
  mergedOptions.options = {
115
120
  ...(mergedOptions.options || {}),
@@ -16,12 +16,12 @@ export declare function resolveLocaleFiles(files: ResolvedFiles, locale: string)
16
16
  * @param files - The files object
17
17
  * @returns The resolved files
18
18
  */
19
- export declare function resolveFiles(files: FilesOptions, locale: string, locales: string[], cwd: string): {
19
+ export declare function resolveFiles(files: FilesOptions, locale: string, locales: string[], cwd: string, compositePatterns?: string[]): {
20
20
  resolvedPaths: ResolvedFiles;
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): {
24
+ export declare function expandGlobPatterns(cwd: string, includePatterns: string[], excludePatterns: string[], locale: string, locales: string[], transformPatterns?: TransformOption | string, compositePatterns?: string[]): {
25
25
  resolvedPaths: string[];
26
26
  placeholderPaths: string[];
27
27
  };
@@ -28,7 +28,7 @@ export function resolveLocaleFiles(files, locale) {
28
28
  * @param files - The files object
29
29
  * @returns The resolved files
30
30
  */
31
- export function resolveFiles(files, locale, locales, cwd) {
31
+ export function resolveFiles(files, locale, locales, cwd, compositePatterns) {
32
32
  // Initialize result object with empty arrays for each file type
33
33
  const result = {};
34
34
  const placeholderResult = {};
@@ -47,7 +47,7 @@ export function resolveFiles(files, locale, locales, cwd) {
47
47
  }
48
48
  // ==== PLACEHOLDERS ==== //
49
49
  if (files[fileType]?.include) {
50
- const filePaths = expandGlobPatterns(cwd, files[fileType].include, files[fileType]?.exclude || [], locale, locales, transformPaths[fileType] || undefined);
50
+ const filePaths = expandGlobPatterns(cwd, files[fileType].include, files[fileType]?.exclude || [], locale, locales, transformPaths[fileType] || undefined, compositePatterns);
51
51
  result[fileType] = filePaths.resolvedPaths;
52
52
  placeholderResult[fileType] = filePaths.placeholderPaths;
53
53
  }
@@ -59,7 +59,7 @@ export function resolveFiles(files, locale, locales, cwd) {
59
59
  };
60
60
  }
61
61
  // Helper function to expand glob patterns
62
- export function expandGlobPatterns(cwd, includePatterns, excludePatterns, locale, locales, transformPatterns) {
62
+ export function expandGlobPatterns(cwd, includePatterns, excludePatterns, locale, locales, transformPatterns, compositePatterns) {
63
63
  // Expand glob patterns to include all matching files
64
64
  const resolvedPaths = [];
65
65
  const placeholderPaths = [];
@@ -68,7 +68,10 @@ export function expandGlobPatterns(cwd, includePatterns, excludePatterns, locale
68
68
  // Track positions where [locale] appears in the original pattern
69
69
  // It must be included in the pattern, otherwise the CLI tool will not be able to find the correct output path
70
70
  // Warn if it's not included
71
- if (!pattern.includes('[locale]') && !transformPatterns) {
71
+ // Ignore if is composite pattern
72
+ if (!pattern.includes('[locale]') &&
73
+ !transformPatterns &&
74
+ !compositePatterns?.includes(pattern)) {
72
75
  logWarning(chalk.yellow(`Pattern "${pattern}" does not include [locale], so the CLI tool may incorrectly save translated files.`));
73
76
  }
74
77
  const localePositions = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "2.3.3",
3
+ "version": "2.3.5",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [