gtx-cli 1.2.4 → 1.2.5-alpha.2
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/dist/api/checkFileTranslations.js +107 -118
- package/dist/api/downloadFile.js +38 -47
- package/dist/api/downloadFileBatch.js +69 -77
- package/dist/api/fetchTranslations.js +17 -25
- package/dist/api/sendFiles.js +47 -56
- package/dist/api/sendUpdates.js +48 -45
- package/dist/api/waitForUpdates.js +15 -21
- package/dist/cli/base.js +133 -148
- package/dist/cli/react.js +149 -166
- package/dist/config/generateSettings.js +71 -83
- package/dist/config/validateSettings.js +1 -2
- package/dist/console/logging.d.ts +1 -1
- package/dist/console/logging.js +62 -115
- package/dist/formats/files/save.js +10 -21
- package/dist/formats/files/translate.js +127 -136
- package/dist/formats/gt/save.js +16 -27
- package/dist/fs/config/parseFilesConfig.js +6 -8
- package/dist/fs/config/setupConfig.js +32 -36
- package/dist/fs/config/updateConfig.js +27 -30
- package/dist/fs/determineFramework.js +4 -1
- package/dist/fs/findFilepath.js +1 -2
- package/dist/fs/index.d.ts +1 -0
- package/dist/fs/index.js +1 -0
- package/dist/fs/saveJSON.js +4 -15
- package/dist/hooks/postProcess.js +97 -107
- package/dist/next/config/parseNextConfig.js +44 -51
- package/dist/next/parse/handleInitGT.js +101 -112
- package/dist/next/parse/wrapContent.js +108 -112
- package/dist/react/config/createESBuildConfig.js +3 -12
- package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.js +11 -19
- package/dist/react/jsx/parse/parseStringFunction.js +3 -5
- package/dist/react/jsx/trimJsxStringChildren.js +5 -2
- package/dist/react/jsx/utils/parseAst.js +5 -6
- package/dist/react/jsx/utils/parseJsx.js +1 -1
- package/dist/react/jsx/utils/parseStringFunction.js +3 -5
- package/dist/react/parse/createDictionaryUpdates.js +58 -56
- package/dist/react/parse/createInlineUpdates.js +111 -118
- package/dist/react/parse/wrapContent.js +124 -128
- package/dist/react/utils/getVariableName.js +1 -2
- package/dist/setup/userInput.js +22 -33
- package/dist/setup/wizard.js +133 -134
- package/dist/translation/parse.js +52 -63
- package/dist/translation/stage.js +61 -68
- package/dist/translation/translate.js +13 -24
- package/dist/utils/credentials.js +75 -89
- package/dist/utils/installPackage.js +30 -41
- package/dist/utils/packageJson.js +49 -58
- package/dist/utils/packageManager.js +82 -54
- package/package.json +28 -11
- package/tsconfig.json +3 -3
|
@@ -32,15 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
37
|
};
|
|
@@ -52,113 +43,111 @@ const generator_1 = __importDefault(require("@babel/generator"));
|
|
|
52
43
|
const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
53
44
|
const t = __importStar(require("@babel/types"));
|
|
54
45
|
const console_1 = require("../../console");
|
|
55
|
-
function handleInitGT(filepath, errors, warnings, filesUpdated) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (
|
|
75
|
-
if (spec.local.name === 'withGTConfig')
|
|
76
|
-
hasGTConfig = true;
|
|
77
|
-
if (spec.local.name === 'initGT')
|
|
78
|
-
hasInitGT = true;
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
VariableDeclaration(path) {
|
|
84
|
-
path.node.declarations.forEach((dec) => {
|
|
85
|
-
if (t.isVariableDeclarator(dec) &&
|
|
86
|
-
t.isCallExpression(dec.init) &&
|
|
87
|
-
t.isIdentifier(dec.init.callee, { name: 'require' }) &&
|
|
88
|
-
t.isStringLiteral(dec.init.arguments[0], {
|
|
89
|
-
value: 'gt-next/config',
|
|
90
|
-
})) {
|
|
91
|
-
if (t.isIdentifier(dec.id, { name: 'withGTConfig' }))
|
|
46
|
+
async function handleInitGT(filepath, errors, warnings, filesUpdated) {
|
|
47
|
+
const code = await node_fs_1.default.promises.readFile(filepath, 'utf8');
|
|
48
|
+
let ast;
|
|
49
|
+
try {
|
|
50
|
+
ast = (0, parser_1.parse)(code, {
|
|
51
|
+
sourceType: 'module',
|
|
52
|
+
plugins: ['jsx', 'typescript'],
|
|
53
|
+
tokens: true,
|
|
54
|
+
createParenthesizedExpressions: true,
|
|
55
|
+
});
|
|
56
|
+
const needsCJS = filepath.endsWith('.js');
|
|
57
|
+
// Check if withGTConfig or initGT is already imported/required
|
|
58
|
+
let hasGTConfig = false;
|
|
59
|
+
let hasInitGT = false;
|
|
60
|
+
(0, traverse_1.default)(ast, {
|
|
61
|
+
ImportDeclaration(path) {
|
|
62
|
+
if (path.node.source.value === 'gt-next/config') {
|
|
63
|
+
path.node.specifiers.forEach((spec) => {
|
|
64
|
+
if (t.isImportSpecifier(spec)) {
|
|
65
|
+
if (spec.local.name === 'withGTConfig')
|
|
92
66
|
hasGTConfig = true;
|
|
93
|
-
if (
|
|
67
|
+
if (spec.local.name === 'initGT')
|
|
94
68
|
hasInitGT = true;
|
|
95
69
|
}
|
|
96
70
|
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
], t.stringLiteral('gt-next/config')));
|
|
112
|
-
// Find and transform the default export
|
|
113
|
-
(0, traverse_1.default)(ast, {
|
|
114
|
-
ExportDefaultDeclaration(path) {
|
|
115
|
-
const oldExport = path.node.declaration;
|
|
116
|
-
let exportExpression;
|
|
117
|
-
if (t.isFunctionDeclaration(oldExport)) {
|
|
118
|
-
exportExpression = t.functionExpression(oldExport.id, oldExport.params, oldExport.body, oldExport.generator, oldExport.async);
|
|
119
|
-
}
|
|
120
|
-
else if (t.isClassDeclaration(oldExport)) {
|
|
121
|
-
exportExpression = t.classExpression(oldExport.id, oldExport.superClass, oldExport.body, oldExport.decorators);
|
|
122
|
-
}
|
|
123
|
-
else if (t.isTSDeclareFunction(oldExport)) {
|
|
124
|
-
// For TypeScript declare functions, create an empty function expression
|
|
125
|
-
// since declare functions don't have a runtime implementation
|
|
126
|
-
warnings.push(`Found TypeScript declare function in ${filepath}. Converting to empty function.`);
|
|
127
|
-
exportExpression = t.functionExpression(oldExport.id, oldExport.params, t.blockStatement([]), false, false);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
exportExpression = oldExport;
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
VariableDeclaration(path) {
|
|
74
|
+
path.node.declarations.forEach((dec) => {
|
|
75
|
+
if (t.isVariableDeclarator(dec) &&
|
|
76
|
+
t.isCallExpression(dec.init) &&
|
|
77
|
+
t.isIdentifier(dec.init.callee, { name: 'require' }) &&
|
|
78
|
+
t.isStringLiteral(dec.init.arguments[0], {
|
|
79
|
+
value: 'gt-next/config',
|
|
80
|
+
})) {
|
|
81
|
+
if (t.isIdentifier(dec.id, { name: 'withGTConfig' }))
|
|
82
|
+
hasGTConfig = true;
|
|
83
|
+
if (t.isIdentifier(dec.id, { name: 'initGT' }))
|
|
84
|
+
hasInitGT = true;
|
|
131
85
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
path.node.declaration = t.callExpression(t.identifier('withGTConfig'), [
|
|
139
|
-
exportExpression,
|
|
140
|
-
t.objectExpression([]),
|
|
141
|
-
]);
|
|
142
|
-
},
|
|
143
|
-
});
|
|
144
|
-
// Generate the modified code
|
|
145
|
-
const output = (0, generator_1.default)(ast, {
|
|
146
|
-
retainLines: true,
|
|
147
|
-
retainFunctionParens: true,
|
|
148
|
-
comments: true,
|
|
149
|
-
compact: 'auto',
|
|
150
|
-
}, code);
|
|
151
|
-
// Post-process the output to fix import spacing
|
|
152
|
-
let processedCode = output.code;
|
|
153
|
-
// Add newline after the comment only
|
|
154
|
-
processedCode = processedCode.replace(/((?:import\s*{\s*withGTConfig\s*}\s*from|const\s*{\s*withGTConfig\s*}\s*=\s*require)\s*['"]gt-next\/config['"];?)/, '$1\n');
|
|
155
|
-
// Write the modified code back to the file
|
|
156
|
-
yield node_fs_1.default.promises.writeFile(filepath, processedCode);
|
|
157
|
-
filesUpdated.push(filepath);
|
|
158
|
-
}
|
|
159
|
-
catch (error) {
|
|
160
|
-
(0, console_1.logError)(`Error parsing file ${filepath}: ${error}`);
|
|
161
|
-
errors.push(`Failed to parse ${filepath}: ${error}`);
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
// Return early if either withGTConfig or initGT is already present
|
|
90
|
+
if (hasGTConfig || hasInitGT) {
|
|
91
|
+
return;
|
|
162
92
|
}
|
|
163
|
-
|
|
93
|
+
ast.program.body.unshift(needsCJS
|
|
94
|
+
? t.variableDeclaration('const', [
|
|
95
|
+
t.variableDeclarator(t.identifier('withGTConfig'), t.memberExpression(t.callExpression(t.identifier('require'), [
|
|
96
|
+
t.stringLiteral('gt-next/config'),
|
|
97
|
+
]), t.identifier('withGTConfig'))),
|
|
98
|
+
])
|
|
99
|
+
: t.importDeclaration([
|
|
100
|
+
t.importSpecifier(t.identifier('withGTConfig'), t.identifier('withGTConfig')),
|
|
101
|
+
], t.stringLiteral('gt-next/config')));
|
|
102
|
+
// Find and transform the default export
|
|
103
|
+
(0, traverse_1.default)(ast, {
|
|
104
|
+
ExportDefaultDeclaration(path) {
|
|
105
|
+
const oldExport = path.node.declaration;
|
|
106
|
+
let exportExpression;
|
|
107
|
+
if (t.isFunctionDeclaration(oldExport)) {
|
|
108
|
+
exportExpression = t.functionExpression(oldExport.id, oldExport.params, oldExport.body, oldExport.generator, oldExport.async);
|
|
109
|
+
}
|
|
110
|
+
else if (t.isClassDeclaration(oldExport)) {
|
|
111
|
+
exportExpression = t.classExpression(oldExport.id, oldExport.superClass, oldExport.body, oldExport.decorators);
|
|
112
|
+
}
|
|
113
|
+
else if (t.isTSDeclareFunction(oldExport)) {
|
|
114
|
+
// For TypeScript declare functions, create an empty function expression
|
|
115
|
+
// since declare functions don't have a runtime implementation
|
|
116
|
+
warnings.push(`Found TypeScript declare function in ${filepath}. Converting to empty function.`);
|
|
117
|
+
exportExpression = t.functionExpression(oldExport.id, oldExport.params, t.blockStatement([]), false, false);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
exportExpression = oldExport;
|
|
121
|
+
}
|
|
122
|
+
// Validate that we have a valid Next.js config export
|
|
123
|
+
if (!t.isObjectExpression(exportExpression) &&
|
|
124
|
+
!t.isFunctionExpression(exportExpression) &&
|
|
125
|
+
!t.isArrowFunctionExpression(exportExpression)) {
|
|
126
|
+
warnings.push(`Unexpected export type in ${filepath}. Next.js config should export an object or a function returning an object.`);
|
|
127
|
+
}
|
|
128
|
+
path.node.declaration = t.callExpression(t.identifier('withGTConfig'), [
|
|
129
|
+
exportExpression,
|
|
130
|
+
t.objectExpression([]),
|
|
131
|
+
]);
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
// Generate the modified code
|
|
135
|
+
const output = (0, generator_1.default)(ast, {
|
|
136
|
+
retainLines: true,
|
|
137
|
+
retainFunctionParens: true,
|
|
138
|
+
comments: true,
|
|
139
|
+
compact: 'auto',
|
|
140
|
+
}, code);
|
|
141
|
+
// Post-process the output to fix import spacing
|
|
142
|
+
let processedCode = output.code;
|
|
143
|
+
// Add newline after the comment only
|
|
144
|
+
processedCode = processedCode.replace(/((?:import\s*{\s*withGTConfig\s*}\s*from|const\s*{\s*withGTConfig\s*}\s*=\s*require)\s*['"]gt-next\/config['"];?)/, '$1\n');
|
|
145
|
+
// Write the modified code back to the file
|
|
146
|
+
await node_fs_1.default.promises.writeFile(filepath, processedCode);
|
|
147
|
+
filesUpdated.push(filepath);
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
(0, console_1.logError)(`Error parsing file ${filepath}: ${error}`);
|
|
151
|
+
errors.push(`Failed to parse ${filepath}: ${error}`);
|
|
152
|
+
}
|
|
164
153
|
}
|
|
@@ -32,15 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
37
|
};
|
|
@@ -72,114 +63,119 @@ const IMPORT_MAP = {
|
|
|
72
63
|
* @param options - The options object
|
|
73
64
|
* @returns An object containing the updates and errors
|
|
74
65
|
*/
|
|
75
|
-
function wrapContentNext(options, pkg, errors, warnings) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (!bodyElement) {
|
|
114
|
-
warnings.push(`File ${file} has a <html> tag without a <body> tag. Skipping GTProvider insertion.`);
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
// Skip if body already has GTProvider
|
|
118
|
-
if ((0, utils_1.hasGTProviderChild)(bodyElement)) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
// Handle lang attribute for html tag
|
|
122
|
-
const langAttr = path.node.openingElement.attributes.find((attr) => t.isJSXAttribute(attr) &&
|
|
123
|
-
t.isJSXIdentifier(attr.name) &&
|
|
124
|
-
t.isStringLiteral(attr.value) &&
|
|
125
|
-
attr.name.name === 'lang');
|
|
126
|
-
if (langAttr) {
|
|
127
|
-
(0, utils_1.makeParentFunctionAsync)(path);
|
|
128
|
-
(0, utils_1.addDynamicLangAttribute)(path.node.openingElement);
|
|
129
|
-
usedImports.push('getLocale');
|
|
130
|
-
}
|
|
131
|
-
// Wrap body children with GTProvider
|
|
132
|
-
const bodyChildren = bodyElement.children;
|
|
133
|
-
const gtProviderElement = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier('GTProvider'), [], false), t.jsxClosingElement(t.jsxIdentifier('GTProvider')), bodyChildren, false);
|
|
134
|
-
bodyElement.children = [gtProviderElement];
|
|
135
|
-
usedImports.push('GTProvider');
|
|
136
|
-
modified = true;
|
|
137
|
-
path.skip();
|
|
66
|
+
async function wrapContentNext(options, pkg, errors, warnings) {
|
|
67
|
+
const srcDirectory = options.src || ['./'];
|
|
68
|
+
const files = srcDirectory.flatMap((dir) => (0, findJsxFilepath_1.getFiles)(dir));
|
|
69
|
+
const filesUpdated = [];
|
|
70
|
+
for (const file of files) {
|
|
71
|
+
const code = await node_fs_1.default.promises.readFile(file, 'utf8');
|
|
72
|
+
// Create relative path from src directory and remove extension
|
|
73
|
+
const relativePath = (0, findFilepath_1.getRelativePath)(file, srcDirectory[0]);
|
|
74
|
+
let ast;
|
|
75
|
+
try {
|
|
76
|
+
ast = (0, parser_1.parse)(code, {
|
|
77
|
+
sourceType: 'module',
|
|
78
|
+
plugins: ['jsx', 'typescript'],
|
|
79
|
+
tokens: true,
|
|
80
|
+
createParenthesizedExpressions: true,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
errors.push(`Error: Failed to parse ${file}: ${error}`);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
let modified = false;
|
|
88
|
+
let usedImports = [];
|
|
89
|
+
let { importAlias, initialImports } = (0, parseAst_1.generateImportMap)(ast, pkg);
|
|
90
|
+
// If the file already has a T import, skip processing it
|
|
91
|
+
if (initialImports.includes(IMPORT_MAP.T.name)) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
let globalId = 0;
|
|
95
|
+
(0, traverse_1.default)(ast, {
|
|
96
|
+
JSXElement(path) {
|
|
97
|
+
if (pkg === 'gt-next' &&
|
|
98
|
+
options.addGTProvider &&
|
|
99
|
+
(0, utils_1.isHtmlElement)(path.node.openingElement)) {
|
|
100
|
+
// Find the body element in the HTML children
|
|
101
|
+
const bodyElement = path.node.children.find((child) => t.isJSXElement(child) && (0, utils_1.isBodyElement)(child.openingElement));
|
|
102
|
+
if (!bodyElement) {
|
|
103
|
+
warnings.push(`File ${file} has a <html> tag without a <body> tag. Skipping GTProvider insertion.`);
|
|
138
104
|
return;
|
|
139
105
|
}
|
|
140
|
-
//
|
|
141
|
-
|
|
142
|
-
if (t.isJSXElement((_a = currentPath.parentPath) === null || _a === void 0 ? void 0 : _a.node)) {
|
|
143
|
-
// If we found a JSX parent, skip processing this node
|
|
106
|
+
// Skip if body already has GTProvider
|
|
107
|
+
if ((0, utils_1.hasGTProviderChild)(bodyElement)) {
|
|
144
108
|
return;
|
|
145
109
|
}
|
|
146
|
-
//
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
retainLines: true,
|
|
165
|
-
retainFunctionParens: true,
|
|
166
|
-
comments: true,
|
|
167
|
-
compact: 'auto',
|
|
168
|
-
}, code);
|
|
169
|
-
// Post-process the output to fix import spacing
|
|
170
|
-
let processedCode = output.code;
|
|
171
|
-
if (needsImport.length > 0) {
|
|
172
|
-
// Add newline after the comment only
|
|
173
|
-
processedCode = processedCode.replace(/((?:import\s*{\s*(?:T|GTT|Var|GTVar|GTProvider|getLocale)(?:\s*,\s*(?:T|GTT|Var|GTVar|GTProvider|getLocale))*\s*}\s*from|const\s*{\s*(?:T|GTT|Var|GTVar|GTProvider|getLocale)(?:\s*,\s*(?:T|GTT|Var|GTVar|GTProvider|getLocale))*\s*}\s*=\s*require)\s*['"]gt-(?:next|react)(?:\/server)?['"];?)/, '\n$1\n');
|
|
110
|
+
// Handle lang attribute for html tag
|
|
111
|
+
const langAttr = path.node.openingElement.attributes.find((attr) => t.isJSXAttribute(attr) &&
|
|
112
|
+
t.isJSXIdentifier(attr.name) &&
|
|
113
|
+
t.isStringLiteral(attr.value) &&
|
|
114
|
+
attr.name.name === 'lang');
|
|
115
|
+
if (langAttr) {
|
|
116
|
+
(0, utils_1.makeParentFunctionAsync)(path);
|
|
117
|
+
(0, utils_1.addDynamicLangAttribute)(path.node.openingElement);
|
|
118
|
+
usedImports.push('getLocale');
|
|
119
|
+
}
|
|
120
|
+
// Wrap body children with GTProvider
|
|
121
|
+
const bodyChildren = bodyElement.children;
|
|
122
|
+
const gtProviderElement = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier('GTProvider'), [], false), t.jsxClosingElement(t.jsxIdentifier('GTProvider')), bodyChildren, false);
|
|
123
|
+
bodyElement.children = [gtProviderElement];
|
|
124
|
+
usedImports.push('GTProvider');
|
|
125
|
+
modified = true;
|
|
126
|
+
path.skip();
|
|
127
|
+
return;
|
|
174
128
|
}
|
|
175
|
-
//
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
129
|
+
// Check if this JSX element has any JSX element ancestors
|
|
130
|
+
let currentPath = path;
|
|
131
|
+
if (t.isJSXElement(currentPath.parentPath?.node)) {
|
|
132
|
+
// If we found a JSX parent, skip processing this node
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
// At this point, we're only processing top-level JSX elements
|
|
136
|
+
const opts = {
|
|
137
|
+
...importAlias,
|
|
138
|
+
idPrefix: relativePath,
|
|
139
|
+
idCount: globalId,
|
|
140
|
+
usedImports,
|
|
141
|
+
modified: false,
|
|
142
|
+
createIds: !options.disableIds,
|
|
143
|
+
warnings,
|
|
144
|
+
file,
|
|
145
|
+
};
|
|
146
|
+
const wrapped = (0, wrapJsx_1.handleJsxElement)(path.node, opts, evaluateJsx_1.isMeaningful);
|
|
147
|
+
path.replaceWith(wrapped.node);
|
|
148
|
+
// Update global counters
|
|
149
|
+
modified = modified || opts.modified;
|
|
150
|
+
globalId = opts.idCount;
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
if (!modified)
|
|
154
|
+
continue;
|
|
155
|
+
let needsImport = usedImports.filter((imp) => !initialImports.includes(imp));
|
|
156
|
+
if (needsImport.length > 0) {
|
|
157
|
+
(0, parseAst_1.createImports)(ast, needsImport, IMPORT_MAP);
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
const output = (0, generator_1.default)(ast, {
|
|
161
|
+
retainLines: true,
|
|
162
|
+
retainFunctionParens: true,
|
|
163
|
+
comments: true,
|
|
164
|
+
compact: 'auto',
|
|
165
|
+
}, code);
|
|
166
|
+
// Post-process the output to fix import spacing
|
|
167
|
+
let processedCode = output.code;
|
|
168
|
+
if (needsImport.length > 0) {
|
|
169
|
+
// Add newline after the comment only
|
|
170
|
+
processedCode = processedCode.replace(/((?:import\s*{\s*(?:T|GTT|Var|GTVar|GTProvider|getLocale)(?:\s*,\s*(?:T|GTT|Var|GTVar|GTProvider|getLocale))*\s*}\s*from|const\s*{\s*(?:T|GTT|Var|GTVar|GTProvider|getLocale)(?:\s*,\s*(?:T|GTT|Var|GTVar|GTProvider|getLocale))*\s*}\s*=\s*require)\s*['"]gt-(?:next|react)(?:\/server)?['"];?)/, '\n$1\n');
|
|
181
171
|
}
|
|
172
|
+
// Write the modified code back to the file
|
|
173
|
+
await node_fs_1.default.promises.writeFile(file, processedCode);
|
|
174
|
+
filesUpdated.push(file);
|
|
182
175
|
}
|
|
183
|
-
|
|
184
|
-
|
|
176
|
+
catch (error) {
|
|
177
|
+
errors.push(`Error: Failed to write ${file}: ${error}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return { filesUpdated };
|
|
185
181
|
}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -62,15 +53,15 @@ function createESBuildConfig(config = {}) {
|
|
|
62
53
|
namespace: 'css-module',
|
|
63
54
|
};
|
|
64
55
|
});
|
|
65
|
-
build.onLoad({ filter: /\.css$/, namespace: 'css-module' }, (args) =>
|
|
66
|
-
const css =
|
|
56
|
+
build.onLoad({ filter: /\.css$/, namespace: 'css-module' }, async (args) => {
|
|
57
|
+
const css = await node_fs_1.default.promises.readFile(args.path, 'utf8');
|
|
67
58
|
const contents = `
|
|
68
59
|
const style = document.createElement('style');
|
|
69
60
|
style.textContent = ${JSON.stringify(css)};
|
|
70
61
|
document.head.appendChild(style);
|
|
71
62
|
`;
|
|
72
63
|
return { contents, loader: 'js' };
|
|
73
|
-
})
|
|
64
|
+
});
|
|
74
65
|
},
|
|
75
66
|
});
|
|
76
67
|
if (config.compilerOptions) {
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.default = addGTIdentifierToSyntaxTree;
|
|
15
4
|
const getVariableName_1 = require("../utils/getVariableName");
|
|
@@ -27,28 +16,28 @@ function addGTIdentifierToSyntaxTree(tree, startingIndex = 0) {
|
|
|
27
16
|
return {
|
|
28
17
|
variable: 'variable',
|
|
29
18
|
id: indexObject.index,
|
|
30
|
-
key: (0, getVariableName_1.getVariableName)(
|
|
19
|
+
key: (0, getVariableName_1.getVariableName)({ ...props, 'data-_gt': generaltranslation }, 'variable'),
|
|
31
20
|
};
|
|
32
21
|
}
|
|
33
22
|
else if (type === 'Num') {
|
|
34
23
|
return {
|
|
35
24
|
variable: 'number',
|
|
36
25
|
id: indexObject.index,
|
|
37
|
-
key: (0, getVariableName_1.getVariableName)(
|
|
26
|
+
key: (0, getVariableName_1.getVariableName)({ ...props, 'data-_gt': generaltranslation }, 'number'),
|
|
38
27
|
};
|
|
39
28
|
}
|
|
40
29
|
else if (type === 'Currency') {
|
|
41
30
|
return {
|
|
42
31
|
variable: 'currency',
|
|
43
32
|
id: indexObject.index,
|
|
44
|
-
key: (0, getVariableName_1.getVariableName)(
|
|
33
|
+
key: (0, getVariableName_1.getVariableName)({ ...props, 'data-_gt': generaltranslation }, 'currency'),
|
|
45
34
|
};
|
|
46
35
|
}
|
|
47
36
|
else if (type === 'DateTime') {
|
|
48
37
|
return {
|
|
49
38
|
variable: 'datetime',
|
|
50
39
|
id: indexObject.index,
|
|
51
|
-
key: (0, getVariableName_1.getVariableName)(
|
|
40
|
+
key: (0, getVariableName_1.getVariableName)({ ...props, 'data-_gt': generaltranslation }, 'datetime'),
|
|
52
41
|
};
|
|
53
42
|
}
|
|
54
43
|
if (type === 'Plural') {
|
|
@@ -65,7 +54,7 @@ function addGTIdentifierToSyntaxTree(tree, startingIndex = 0) {
|
|
|
65
54
|
}
|
|
66
55
|
else if (type === 'Branch') {
|
|
67
56
|
generaltranslation.transformation = 'branch';
|
|
68
|
-
const { children, branch
|
|
57
|
+
const { children, branch, ...branches } = props;
|
|
69
58
|
const resultBranches = Object.entries(branches).reduce((acc, [branchName, branch]) => {
|
|
70
59
|
acc[branchName] =
|
|
71
60
|
addGTIdentifierToSyntaxTree(branch, indexObject.index);
|
|
@@ -76,9 +65,12 @@ function addGTIdentifierToSyntaxTree(tree, startingIndex = 0) {
|
|
|
76
65
|
}
|
|
77
66
|
return {
|
|
78
67
|
type: type || `C${generaltranslation.id}`,
|
|
79
|
-
props:
|
|
80
|
-
|
|
81
|
-
|
|
68
|
+
props: {
|
|
69
|
+
'data-_gt': generaltranslation,
|
|
70
|
+
...(typeof props.children !== 'undefined' && {
|
|
71
|
+
children: handleChildren(props.children),
|
|
72
|
+
}),
|
|
73
|
+
},
|
|
82
74
|
};
|
|
83
75
|
}
|
|
84
76
|
return child.toString();
|
|
@@ -53,15 +53,13 @@ exports.attributes = ['id', 'context'];
|
|
|
53
53
|
* of the subsequent tx() calls, and append the content and metadata to the updates array.
|
|
54
54
|
*/
|
|
55
55
|
function parseStrings(importName, path, updates, errors, file) {
|
|
56
|
-
|
|
57
|
-
(_a = path.scope.bindings[importName]) === null || _a === void 0 ? void 0 : _a.referencePaths.forEach((refPath) => {
|
|
58
|
-
var _a;
|
|
56
|
+
path.scope.bindings[importName]?.referencePaths.forEach((refPath) => {
|
|
59
57
|
// Find call expressions of useGT() / await getGT()
|
|
60
58
|
const callExpr = refPath.findParent((p) => p.isCallExpression());
|
|
61
59
|
if (callExpr) {
|
|
62
60
|
// Get the parent, handling both await and non-await cases
|
|
63
61
|
const parentPath = callExpr.parentPath;
|
|
64
|
-
const effectiveParent =
|
|
62
|
+
const effectiveParent = parentPath?.node.type === 'AwaitExpression'
|
|
65
63
|
? parentPath.parentPath
|
|
66
64
|
: parentPath;
|
|
67
65
|
if (effectiveParent &&
|
|
@@ -70,7 +68,7 @@ function parseStrings(importName, path, updates, errors, file) {
|
|
|
70
68
|
const tFuncName = effectiveParent.node.id.name;
|
|
71
69
|
// Get the scope from the variable declaration
|
|
72
70
|
const variableScope = effectiveParent.scope;
|
|
73
|
-
|
|
71
|
+
variableScope.bindings[tFuncName]?.referencePaths.forEach((tPath) => {
|
|
74
72
|
if (tPath.parent.type === 'CallExpression' &&
|
|
75
73
|
tPath.parent.arguments.length > 0) {
|
|
76
74
|
const arg = tPath.parent.arguments[0];
|
|
@@ -65,7 +65,7 @@ const handleChildrenWhitespace = (currentTree) => {
|
|
|
65
65
|
});
|
|
66
66
|
return newChildren.length === 1 ? newChildren[0] : newChildren;
|
|
67
67
|
}
|
|
68
|
-
else if (currentTree
|
|
68
|
+
else if (currentTree?.props) {
|
|
69
69
|
// Process all props recursively
|
|
70
70
|
const elementIsPlural = currentTree.type === 'Plural';
|
|
71
71
|
const elementIsBranch = currentTree.type === 'Branch';
|
|
@@ -83,7 +83,10 @@ const handleChildrenWhitespace = (currentTree) => {
|
|
|
83
83
|
}
|
|
84
84
|
return [key, value];
|
|
85
85
|
}));
|
|
86
|
-
return
|
|
86
|
+
return {
|
|
87
|
+
...currentTree,
|
|
88
|
+
props: processedProps,
|
|
89
|
+
};
|
|
87
90
|
}
|
|
88
91
|
else if (typeof currentTree === 'object' &&
|
|
89
92
|
'expression' in currentTree === true) {
|