gtx-cli 1.2.19 → 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 +6 -0
- package/dist/cli/react.js +2 -2
- package/dist/fs/determineFramework.js +1 -1
- package/dist/next/parse/wrapContent.js +5 -5
- package/dist/react/jsx/parse/parseStringFunction.js +1 -1
- package/dist/react/jsx/utils/parseAst.js +1 -1
- package/dist/react/jsx/utils/parseJsx.js +1 -1
- package/dist/react/jsx/utils/parseStringFunction.js +1 -1
- package/dist/react/jsx/wrapJsx.js +24 -11
- package/dist/react/parse/createDictionaryUpdates.js +2 -2
- package/dist/react/parse/wrapContent.js +6 -6
- package/dist/setup/wizard.js +2 -2
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
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
|
+
|
|
3
9
|
## 1.2.19
|
|
4
10
|
|
|
5
11
|
### 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
|
-
|
|
240
|
-
|
|
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
|
-
|
|
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
|
-
|
|
89
|
-
|
|
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
|
-
|
|
131
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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) ||
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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:
|
|
66
|
-
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
|
-
|
|
54
|
+
const updates = [];
|
|
55
55
|
for (const id of Object.keys(dictionary)) {
|
|
56
|
-
|
|
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
|
-
|
|
95
|
-
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
// If we
|
|
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
|
-
|
|
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) {
|
package/dist/setup/wizard.js
CHANGED
|
@@ -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
|
-
|
|
76
|
-
|
|
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.
|
|
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",
|