gtx-cli 2.0.3 → 2.0.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,19 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#467](https://github.com/generaltranslation/gt/pull/467) [`e043f07`](https://github.com/generaltranslation/gt/commit/e043f07decb426c2b275b67ad955b4ddca7d20ee) Thanks [@brian-lou](https://github.com/brian-lou)! - Add async errors for useGT/getGT to translate
8
+
9
+ ## 2.0.4
10
+
11
+ ### Patch Changes
12
+
13
+ - [#464](https://github.com/generaltranslation/gt/pull/464) [`a10331c`](https://github.com/generaltranslation/gt/commit/a10331c6854d60f3328d4ce6c307acc0c28e8ef4) Thanks [@brian-lou](https://github.com/brian-lou)! - Add success message for validate
14
+
15
+ - [#464](https://github.com/generaltranslation/gt/pull/464) [`a10331c`](https://github.com/generaltranslation/gt/commit/a10331c6854d60f3328d4ce6c307acc0c28e8ef4) Thanks [@brian-lou](https://github.com/brian-lou)! - Fix glob pattern for validate files
16
+
3
17
  ## 2.0.3
4
18
 
5
19
  ### Patch Changes
@@ -1,2 +1 @@
1
- export declare const IGNORED_PATTERNS: string[];
2
1
  export declare function matchFiles(cwd: string, patterns: string[]): string[];
@@ -1,10 +1,8 @@
1
1
  import fg from 'fast-glob';
2
- export const IGNORED_PATTERNS = ['**/.*', '**/.*/**'];
3
2
  export function matchFiles(cwd, patterns) {
4
3
  return fg.sync(patterns, {
5
4
  cwd,
6
5
  absolute: true,
7
6
  onlyFiles: true,
8
- ignore: IGNORED_PATTERNS,
9
7
  });
10
8
  }
@@ -13,4 +13,4 @@ import { Updates } from '../../../types/index.js';
13
13
  * - const { home } = getInfo(t); // getInfo is imported from './constants'
14
14
  * - This will parse constants.ts to find translation calls within getInfo function
15
15
  */
16
- export declare function parseStrings(importName: string, path: NodePath, updates: Updates, errors: string[], file: string): void;
16
+ export declare function parseStrings(importName: string, originalName: string, path: NodePath, updates: Updates, errors: string[], file: string): void;
@@ -1,7 +1,7 @@
1
1
  import * as t from '@babel/types';
2
2
  import { isStaticExpression } from '../evaluateJsx.js';
3
3
  import { GT_ATTRIBUTES_WITH_SUGAR, mapAttributeName } from './constants.js';
4
- import { warnNonStaticExpressionSync, warnNonStringSync, warnTemplateLiteralSync, } from '../../../console/index.js';
4
+ import { warnNonStaticExpressionSync, warnNonStringSync, warnTemplateLiteralSync, warnAsyncUseGT, warnSyncGetGT, } from '../../../console/index.js';
5
5
  import generateModule from '@babel/generator';
6
6
  import traverseModule from '@babel/traverse';
7
7
  // Handle CommonJS/ESM interop
@@ -343,7 +343,7 @@ function findFunctionInFile(filePath, functionName, argIndex, updates, errors) {
343
343
  * - const { home } = getInfo(t); // getInfo is imported from './constants'
344
344
  * - This will parse constants.ts to find translation calls within getInfo function
345
345
  */
346
- export function parseStrings(importName, path, updates, errors, file) {
346
+ export function parseStrings(importName, originalName, path, updates, errors, file) {
347
347
  // First, collect all imports in this file to track cross-file function calls
348
348
  const importMap = buildImportMap(path.scope.getProgramParent().path);
349
349
  const referencePaths = path.scope.bindings[importName]?.referencePaths || [];
@@ -353,6 +353,16 @@ export function parseStrings(importName, path, updates, errors, file) {
353
353
  if (callExpr) {
354
354
  // Get the parent, handling both await and non-await cases
355
355
  const parentPath = callExpr.parentPath;
356
+ const parentFunction = refPath.getFunctionParent();
357
+ const asyncScope = parentFunction?.node.async;
358
+ if (asyncScope && originalName === 'useGT') {
359
+ errors.push(warnAsyncUseGT(file, `${refPath.node.loc?.start?.line}:${refPath.node.loc?.start?.column}`));
360
+ return;
361
+ }
362
+ else if (!asyncScope && originalName === 'getGT') {
363
+ errors.push(warnSyncGetGT(file, `${refPath.node.loc?.start?.line}:${refPath.node.loc?.start?.column}`));
364
+ return;
365
+ }
356
366
  const effectiveParent = parentPath?.node.type === 'AwaitExpression'
357
367
  ? parentPath.parentPath
358
368
  : parentPath;
@@ -8,7 +8,6 @@ import { parseJSXElement } from '../jsx/utils/parseJsx.js';
8
8
  import { parseStrings } from '../jsx/utils/parseStringFunction.js';
9
9
  import { extractImportName } from '../jsx/utils/parseAst.js';
10
10
  import { logError } from '../../console/logging.js';
11
- import { validateStringFunction } from '../jsx/utils/validateStringFunction.js';
12
11
  import { GT_TRANSLATION_FUNCS } from '../jsx/utils/constants.js';
13
12
  import { matchFiles } from '../../fs/matchFiles.js';
14
13
  import { DEFAULT_SRC_PATTERNS } from '../../config/generateSettings.js';
@@ -82,8 +81,8 @@ export async function createInlineUpdates(pkg, validate, filePatterns) {
82
81
  },
83
82
  });
84
83
  // Process translation functions asynchronously
85
- for (const { localName: name, path } of translationPaths) {
86
- parseStrings(name, path, updates, errors, file);
84
+ for (const { localName: name, originalName, path } of translationPaths) {
85
+ parseStrings(name, originalName, path, updates, errors, file);
87
86
  }
88
87
  // Parse <T> components
89
88
  traverse(ast, {
@@ -92,11 +91,12 @@ export async function createInlineUpdates(pkg, validate, filePatterns) {
92
91
  },
93
92
  });
94
93
  // Extra validation (for Locadex)
95
- if (validate) {
96
- for (const { localName: name, path, originalName } of translationPaths) {
97
- validateStringFunction(name, path, updates, errors, file, originalName);
98
- }
99
- }
94
+ // Done in parseStrings() atm
95
+ // if (validate) {
96
+ // for (const { localName: name, path, originalName } of translationPaths) {
97
+ // validateStringFunction(name, path, updates, errors, file, originalName);
98
+ // }
99
+ // }
100
100
  }
101
101
  // Post-process to add a hash to each update
102
102
  await Promise.all(updates.map(async (update) => {
@@ -7,13 +7,14 @@ import { createInlineUpdates } from '../react/parse/createInlineUpdates.js';
7
7
  export async function validateProject(settings, pkg, files) {
8
8
  if (files && files.length > 0) {
9
9
  // Validate specific files using createInlineUpdates
10
- const { errors } = await createInlineUpdates(pkg, true, files);
10
+ const { errors, updates } = await createInlineUpdates(pkg, true, files);
11
11
  if (errors.length > 0) {
12
12
  logErrorAndExit(chalk.red(`Error: CLI tool encountered ${errors.length} syntax errors:\n` +
13
13
  errors
14
14
  .map((error) => chalk.red('• ') + chalk.white(error) + '\n')
15
15
  .join('')));
16
16
  }
17
+ logSuccess(chalk.green(`Success! Found ${updates.length} translatable entries.`));
17
18
  return;
18
19
  }
19
20
  if (!settings.dictionary) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [