gtx-cli 1.2.18 → 1.2.20

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,20 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 1.2.20
4
+
5
+ ### Patch Changes
6
+
7
+ - [#318](https://github.com/generaltranslation/gt/pull/318) [`5e6fabd`](https://github.com/generaltranslation/gt/commit/5e6fabdecd692ea26b1e709cc9a3dc5d22387410) Thanks [@brian-lou](https://github.com/brian-lou)! - Fix wrapping behavior for JSX fragments
8
+
9
+ ## 1.2.19
10
+
11
+ ### Patch Changes
12
+
13
+ - [#311](https://github.com/generaltranslation/gt/pull/311) [`d2bb9f5`](https://github.com/generaltranslation/gt/commit/d2bb9f5caa5b7366af3d3f8110a9f1586c9f58e7) Thanks [@michellee-wang](https://github.com/michellee-wang)! - added qbr and emojis + bumped verison
14
+
15
+ - Updated dependencies [[`d2bb9f5`](https://github.com/generaltranslation/gt/commit/d2bb9f5caa5b7366af3d3f8110a9f1586c9f58e7)]:
16
+ - generaltranslation@6.2.9
17
+
3
18
  ## 1.2.18
4
19
 
5
20
  ### Patch Changes
package/dist/cli/react.js CHANGED
@@ -236,8 +236,8 @@ class ReactCLI extends base_1.BaseCLI {
236
236
  defaultValue: true,
237
237
  });
238
238
  options.disableIds = !includeTId;
239
- let errors = [];
240
- let warnings = [];
239
+ const errors = [];
240
+ const warnings = [];
241
241
  // Wrap all JSX elements in the src directory with a <T> tag, with unique ids
242
242
  const { filesUpdated } = await this.wrapContent(options, 'react', errors, warnings);
243
243
  if (errors.length > 0) {
@@ -10,7 +10,7 @@ const node_fs_1 = __importDefault(require("node:fs"));
10
10
  const console_1 = require("../console");
11
11
  function determineLibrary() {
12
12
  let library = 'base';
13
- let additionalModules = [];
13
+ const additionalModules = [];
14
14
  try {
15
15
  // Get the current working directory (where the CLI is being run)
16
16
  const cwd = process.cwd();
@@ -85,8 +85,8 @@ async function wrapContentNext(options, pkg, errors, warnings) {
85
85
  continue;
86
86
  }
87
87
  let modified = false;
88
- let usedImports = [];
89
- let { importAlias, initialImports } = (0, parseAst_1.generateImportMap)(ast, pkg);
88
+ const usedImports = [];
89
+ const { importAlias, initialImports } = (0, parseAst_1.generateImportMap)(ast, pkg);
90
90
  // If the file already has a T import, skip processing it
91
91
  if (initialImports.includes(IMPORT_MAP.T.name)) {
92
92
  continue;
@@ -127,8 +127,8 @@ async function wrapContentNext(options, pkg, errors, warnings) {
127
127
  return;
128
128
  }
129
129
  // Check if this JSX element has any JSX element ancestors
130
- let currentPath = path;
131
- if (t.isJSXElement(currentPath.parentPath?.node)) {
130
+ if (t.isJSXElement(path.parentPath?.node) ||
131
+ t.isJSXExpressionContainer(path.parentPath?.node)) {
132
132
  // If we found a JSX parent, skip processing this node
133
133
  return;
134
134
  }
@@ -152,7 +152,7 @@ async function wrapContentNext(options, pkg, errors, warnings) {
152
152
  });
153
153
  if (!modified)
154
154
  continue;
155
- let needsImport = usedImports.filter((imp) => !initialImports.includes(imp));
155
+ const needsImport = usedImports.filter((imp) => !initialImports.includes(imp));
156
156
  if (needsImport.length > 0) {
157
157
  (0, parseAst_1.createImports)(ast, needsImport, IMPORT_MAP);
158
158
  }
@@ -81,7 +81,7 @@ function parseStrings(importName, path, updates, errors, file) {
81
81
  const content = (0, generaltranslation_1.splitStringToContent)(source);
82
82
  // get metadata and id from options
83
83
  const options = tPath.parent.arguments[1];
84
- let metadata = {};
84
+ const metadata = {};
85
85
  if (options && options.type === 'ObjectExpression') {
86
86
  options.properties.forEach((prop) => {
87
87
  if (prop.type === 'ObjectProperty' &&
@@ -104,7 +104,7 @@ function generateImports(needsImport, isESM, importMap) {
104
104
  * It also records the import aliases for the T and Var components. (in case of conflicts)
105
105
  */
106
106
  function generateImportMap(ast, pkg) {
107
- let importAlias = { TComponent: 'T', VarComponent: 'Var' };
107
+ const importAlias = { TComponent: 'T', VarComponent: 'Var' };
108
108
  // Check existing imports
109
109
  let initialImports = [];
110
110
  (0, traverse_1.default)(ast, {
@@ -79,7 +79,7 @@ function buildJSXTree(importAliases, node, unwrappedExpressions, updates, errors
79
79
  else if (t.isJSXText(node)) {
80
80
  // Updated JSX Text handling
81
81
  // JSX Text handling following React's rules
82
- let text = node.value;
82
+ const text = node.value;
83
83
  return text;
84
84
  }
85
85
  else if (t.isJSXElement(node)) {
@@ -81,7 +81,7 @@ function parseStrings(importName, path, updates, errors, file) {
81
81
  const content = (0, generaltranslation_1.splitStringToContent)(source);
82
82
  // get metadata and id from options
83
83
  const options = tPath.parent.arguments[1];
84
- let metadata = {};
84
+ const metadata = {};
85
85
  if (options && options.type === 'ObjectExpression') {
86
86
  options.properties.forEach((prop) => {
87
87
  if (prop.type === 'ObjectProperty' &&
@@ -42,7 +42,7 @@ function wrapJsxExpression(node, options, isMeaningful, mark) {
42
42
  const expression = t.isParenthesizedExpression(node.expression)
43
43
  ? node.expression.expression
44
44
  : node.expression;
45
- // Ignore all template literals - they should not be counted as meaningful
45
+ // Ignore template literals containing quasis - they should not be counted as meaningful
46
46
  if (t.isTemplateLiteral(expression) && expression.expressions.length > 0) {
47
47
  return {
48
48
  node,
@@ -51,19 +51,30 @@ function wrapJsxExpression(node, options, isMeaningful, mark) {
51
51
  };
52
52
  }
53
53
  // Handle both JSX Elements and Fragments
54
- if (t.isJSXElement(expression) || t.isJSXFragment(expression)) {
55
- const result = wrapJsxElement(expression, options, isMeaningful, mark);
56
- // re-wrap the result in a JSXExpressionContainer
57
- if (t.isParenthesizedExpression(node.expression)) {
58
- node.expression.expression = result.node;
59
- }
60
- else {
61
- node.expression = result.node;
54
+ if (t.isJSXElement(expression) ||
55
+ t.isJSXFragment(expression) ||
56
+ t.isStringLiteral(expression) ||
57
+ t.isJSXText(expression) ||
58
+ t.isTemplateLiteral(expression)) {
59
+ if (t.isJSXElement(expression) || t.isJSXFragment(expression)) {
60
+ const result = wrapJsxElement(expression, options, isMeaningful, mark);
61
+ // re-wrap the result in a JSXExpressionContainer
62
+ if (t.isParenthesizedExpression(node.expression)) {
63
+ node.expression.expression = result.node;
64
+ }
65
+ else {
66
+ node.expression = result.node;
67
+ }
68
+ return {
69
+ node,
70
+ hasMeaningfulContent: result.hasMeaningfulContent,
71
+ wrappedInT: result.wrappedInT,
72
+ };
62
73
  }
63
74
  return {
64
75
  node,
65
- hasMeaningfulContent: result.hasMeaningfulContent,
66
- wrappedInT: result.wrappedInT,
76
+ hasMeaningfulContent: isMeaningful(expression),
77
+ wrappedInT: false,
67
78
  };
68
79
  }
69
80
  // Handle conditional expressions (ternary)
@@ -316,6 +327,8 @@ function wrapJsxElement(node, options, isMeaningful, mark) {
316
327
  if (t.isJSXExpressionContainer(child)) {
317
328
  const result = wrapJsxExpression(child, options, isMeaningful, mark);
318
329
  wrappedInT = wrappedInT || result.wrappedInT;
330
+ hasMeaningfulContent =
331
+ hasMeaningfulContent || result.hasMeaningfulContent;
319
332
  // Expressions are never meaningful because they will either:
320
333
  // 1. be sub-wrapped in a T (if they contain meaningful content)
321
334
  // 2. be wrapped in a Var (if they are not static)
@@ -51,9 +51,9 @@ async function createDictionaryUpdates(options, dictionaryPath, esbuildConfig) {
51
51
  (0, console_1.logErrorAndExit)(`Dictionary filepath provided: "${options.dictionary}", but no entries found.`);
52
52
  }
53
53
  // ----- CREATE PARTIAL UPDATES ----- //
54
- let updates = [];
54
+ const updates = [];
55
55
  for (const id of Object.keys(dictionary)) {
56
- let { entry, metadata: props, // context, etc.
56
+ const { entry, metadata: props, // context, etc.
57
57
  } = (0, getEntryAndMetadata_1.default)(dictionary[id]);
58
58
  const source = (0, generaltranslation_1.splitStringToContent)(entry);
59
59
  const context = props?.context;
@@ -91,8 +91,8 @@ async function wrapContentReact(options, pkg, framework, errors, warnings) {
91
91
  continue;
92
92
  }
93
93
  let modified = false;
94
- let usedImports = [];
95
- let { importAlias, initialImports } = (0, parseAst_1.generateImportMap)(ast, pkg);
94
+ const usedImports = [];
95
+ const { importAlias, initialImports } = (0, parseAst_1.generateImportMap)(ast, pkg);
96
96
  // If the file already has a T import, skip processing it
97
97
  if (initialImports.includes(IMPORT_MAP.T.name)) {
98
98
  continue;
@@ -141,9 +141,9 @@ async function wrapContentReact(options, pkg, framework, errors, warnings) {
141
141
  }
142
142
  }
143
143
  // Check if this JSX element has any JSX element ancestors
144
- let currentPath = path;
145
- if (t.isJSXElement(currentPath.parentPath?.node)) {
146
- // If we found a JSX parent, skip processing this node
144
+ if (t.isJSXElement(path.parentPath?.node) ||
145
+ t.isJSXExpressionContainer(path.parentPath?.node)) {
146
+ // If we're nested inside JSX, skip processing this node
147
147
  return;
148
148
  }
149
149
  // At this point, we're only processing top-level JSX elements
@@ -166,7 +166,7 @@ async function wrapContentReact(options, pkg, framework, errors, warnings) {
166
166
  });
167
167
  if (!modified)
168
168
  continue;
169
- let needsImport = usedImports.filter((imp) => typeof imp === 'string'
169
+ const needsImport = usedImports.filter((imp) => typeof imp === 'string'
170
170
  ? !initialImports.includes(imp)
171
171
  : !initialImports.includes(imp.local));
172
172
  if (needsImport.length > 0) {
@@ -72,8 +72,8 @@ Please let us know what you would like to see supported at https://github.com/ge
72
72
  await (0, installPackage_1.installPackage)('gt-react', packageManager);
73
73
  spinner.stop(chalk_1.default.green('Automatically installed gt-react.'));
74
74
  }
75
- let errors = [];
76
- let warnings = [];
75
+ const errors = [];
76
+ const warnings = [];
77
77
  let filesUpdated = [];
78
78
  if (frameworkType === 'next-app') {
79
79
  // Check if they have a next.config.js file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "1.2.18",
3
+ "version": "1.2.20",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [
@@ -10,6 +10,10 @@
10
10
  "scripts": {
11
11
  "build": "tsc",
12
12
  "build:clean": "rm -rf dist; npm run build",
13
+ "lint": "eslint \"src/**/*.{js,ts}\" \"__tests__/**/*.{js,ts}\"",
14
+ "lint:fix": "eslint \"src/**/*.{js,ts}\" \"__tests__/**/*.{js,ts}\" --fix",
15
+ "test": "vitest run",
16
+ "test:watch": "vitest",
13
17
  "release": "npm run build:clean && npm publish",
14
18
  "release:alpha": "npm run build:clean && npm publish --tag alpha",
15
19
  "release:beta": "npm run build:clean && npm publish --tag beta",
@@ -75,7 +79,7 @@
75
79
  "esbuild": "^0.25.4",
76
80
  "fast-glob": "^3.3.3",
77
81
  "form-data": "^4.0.2",
78
- "generaltranslation": "^6.2.8",
82
+ "generaltranslation": "^6.2.9",
79
83
  "open": "^10.1.1",
80
84
  "ora": "^8.2.0"
81
85
  },