gtx-cli 1.2.13 → 1.2.15
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 +7 -0
- package/package.json +1 -2
- package/.env +0 -2
- package/dist/api/checkFileTranslations.d.ts +0 -19
- package/dist/api/checkFileTranslations.js +0 -244
- package/dist/api/downloadFile.d.ts +0 -1
- package/dist/api/downloadFile.js +0 -83
- package/dist/api/downloadFileBatch.d.ts +0 -16
- package/dist/api/downloadFileBatch.js +0 -127
- package/dist/api/fetchTranslations.d.ts +0 -10
- package/dist/api/fetchTranslations.js +0 -35
- package/dist/api/sendFiles.d.ts +0 -24
- package/dist/api/sendFiles.js +0 -63
- package/dist/api/sendUpdates.d.ts +0 -19
- package/dist/api/sendUpdates.js +0 -75
- package/dist/api/waitForUpdates.d.ts +0 -11
- package/dist/api/waitForUpdates.js +0 -96
- package/dist/cli/base.d.ts +0 -28
- package/dist/cli/base.js +0 -322
- package/dist/cli/next.d.ts +0 -10
- package/dist/cli/next.js +0 -27
- package/dist/cli/react.d.ts +0 -18
- package/dist/cli/react.js +0 -305
- package/dist/config/generateSettings.d.ts +0 -7
- package/dist/config/generateSettings.js +0 -94
- package/dist/config/utils.d.ts +0 -2
- package/dist/config/utils.js +0 -7
- package/dist/config/validateSettings.d.ts +0 -2
- package/dist/config/validateSettings.js +0 -23
- package/dist/console/colors.d.ts +0 -5
- package/dist/console/colors.js +0 -26
- package/dist/console/console.d.ts +0 -1
- package/dist/console/console.js +0 -20
- package/dist/console/errors.d.ts +0 -1
- package/dist/console/errors.js +0 -20
- package/dist/console/index.d.ts +0 -19
- package/dist/console/index.js +0 -48
- package/dist/console/logging.d.ts +0 -55
- package/dist/console/logging.js +0 -207
- package/dist/console/warnings.d.ts +0 -1
- package/dist/console/warnings.js +0 -20
- package/dist/formats/files/save.d.ts +0 -5
- package/dist/formats/files/save.js +0 -23
- package/dist/formats/files/supportedFiles.d.ts +0 -8
- package/dist/formats/files/supportedFiles.js +0 -17
- package/dist/formats/files/translate.d.ts +0 -14
- package/dist/formats/files/translate.js +0 -218
- package/dist/formats/gt/save.d.ts +0 -10
- package/dist/formats/gt/save.js +0 -34
- package/dist/fs/config/loadConfig.d.ts +0 -1
- package/dist/fs/config/loadConfig.js +0 -15
- package/dist/fs/config/parseFilesConfig.d.ts +0 -23
- package/dist/fs/config/parseFilesConfig.js +0 -128
- package/dist/fs/config/setupConfig.d.ts +0 -15
- package/dist/fs/config/setupConfig.js +0 -51
- package/dist/fs/config/updateConfig.d.ts +0 -11
- package/dist/fs/config/updateConfig.js +0 -41
- package/dist/fs/determineFramework.d.ts +0 -5
- package/dist/fs/determineFramework.js +0 -52
- package/dist/fs/findFilepath.d.ts +0 -36
- package/dist/fs/findFilepath.js +0 -101
- package/dist/fs/findJsxFilepath.d.ts +0 -7
- package/dist/fs/findJsxFilepath.js +0 -36
- package/dist/fs/index.d.ts +0 -1
- package/dist/fs/index.js +0 -2
- package/dist/fs/loadJSON.d.ts +0 -6
- package/dist/fs/loadJSON.js +0 -23
- package/dist/fs/saveJSON.d.ts +0 -1
- package/dist/fs/saveJSON.js +0 -13
- package/dist/fs/utils.d.ts +0 -1
- package/dist/fs/utils.js +0 -19
- package/dist/hooks/postProcess.d.ts +0 -4
- package/dist/hooks/postProcess.js +0 -118
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -24
- package/dist/main.d.ts +0 -2
- package/dist/main.js +0 -12
- package/dist/next/config/parseNextConfig.d.ts +0 -10
- package/dist/next/config/parseNextConfig.js +0 -59
- package/dist/next/jsx/utils.d.ts +0 -7
- package/dist/next/jsx/utils.js +0 -82
- package/dist/next/parse/handleInitGT.d.ts +0 -1
- package/dist/next/parse/handleInitGT.js +0 -153
- package/dist/next/parse/wrapContent.d.ts +0 -11
- package/dist/next/parse/wrapContent.js +0 -181
- package/dist/react/config/createESBuildConfig.d.ts +0 -2
- package/dist/react/config/createESBuildConfig.js +0 -125
- package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.d.ts +0 -1
- package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.js +0 -84
- package/dist/react/jsx/evaluateJsx.d.ts +0 -17
- package/dist/react/jsx/evaluateJsx.js +0 -133
- package/dist/react/jsx/parse/parseStringFunction.d.ts +0 -12
- package/dist/react/jsx/parse/parseStringFunction.js +0 -118
- package/dist/react/jsx/trimJsxStringChildren.d.ts +0 -7
- package/dist/react/jsx/trimJsxStringChildren.js +0 -100
- package/dist/react/jsx/utils/parseAst.d.ts +0 -30
- package/dist/react/jsx/utils/parseAst.js +0 -319
- package/dist/react/jsx/utils/parseJsx.d.ts +0 -13
- package/dist/react/jsx/utils/parseJsx.js +0 -245
- package/dist/react/jsx/utils/parseStringFunction.d.ts +0 -12
- package/dist/react/jsx/utils/parseStringFunction.js +0 -121
- package/dist/react/jsx/wrapJsx.d.ts +0 -51
- package/dist/react/jsx/wrapJsx.js +0 -411
- package/dist/react/parse/createDictionaryUpdates.d.ts +0 -3
- package/dist/react/parse/createDictionaryUpdates.js +0 -78
- package/dist/react/parse/createInlineUpdates.d.ts +0 -5
- package/dist/react/parse/createInlineUpdates.js +0 -135
- package/dist/react/parse/wrapContent.d.ts +0 -11
- package/dist/react/parse/wrapContent.js +0 -197
- package/dist/react/utils/flattenDictionary.d.ts +0 -20
- package/dist/react/utils/flattenDictionary.js +0 -79
- package/dist/react/utils/getEntryAndMetadata.d.ts +0 -5
- package/dist/react/utils/getEntryAndMetadata.js +0 -14
- package/dist/react/utils/getVariableName.d.ts +0 -2
- package/dist/react/utils/getVariableName.js +0 -17
- package/dist/setup/userInput.d.ts +0 -4
- package/dist/setup/userInput.js +0 -35
- package/dist/setup/wizard.d.ts +0 -2
- package/dist/setup/wizard.js +0 -171
- package/dist/translation/parse.d.ts +0 -14
- package/dist/translation/parse.js +0 -82
- package/dist/translation/stage.d.ts +0 -5
- package/dist/translation/stage.js +0 -80
- package/dist/translation/translate.d.ts +0 -2
- package/dist/translation/translate.js +0 -21
- package/dist/types/api.d.ts +0 -6
- package/dist/types/api.js +0 -2
- package/dist/types/data.d.ts +0 -31
- package/dist/types/data.js +0 -2
- package/dist/types/index.d.ts +0 -101
- package/dist/types/index.js +0 -2
- package/dist/utils/constants.d.ts +0 -1
- package/dist/utils/constants.js +0 -4
- package/dist/utils/credentials.d.ts +0 -12
- package/dist/utils/credentials.js +0 -128
- package/dist/utils/installPackage.d.ts +0 -2
- package/dist/utils/installPackage.js +0 -45
- package/dist/utils/packageJson.d.ts +0 -5
- package/dist/utils/packageJson.js +0 -78
- package/dist/utils/packageManager.d.ts +0 -23
- package/dist/utils/packageManager.js +0 -261
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.attributes = void 0;
|
|
40
|
-
exports.parseStrings = parseStrings;
|
|
41
|
-
const generaltranslation_1 = require("generaltranslation");
|
|
42
|
-
const t = __importStar(require("@babel/types"));
|
|
43
|
-
const evaluateJsx_1 = require("../evaluateJsx");
|
|
44
|
-
const console_1 = require("../../../console");
|
|
45
|
-
const generator_1 = __importDefault(require("@babel/generator"));
|
|
46
|
-
exports.attributes = ['id', 'context'];
|
|
47
|
-
/**
|
|
48
|
-
* For the following example code:
|
|
49
|
-
* const tx = useGT();
|
|
50
|
-
* tx('string to translate', { id: 'exampleId', context: 'exampleContext' });
|
|
51
|
-
*
|
|
52
|
-
* This function will find all call expressions of useGT(), then find all call expressions
|
|
53
|
-
* of the subsequent tx() calls, and append the content and metadata to the updates array.
|
|
54
|
-
*/
|
|
55
|
-
function parseStrings(importName, path, updates, errors, file) {
|
|
56
|
-
path.scope.bindings[importName]?.referencePaths.forEach((refPath) => {
|
|
57
|
-
// Find call expressions of useGT() / await getGT()
|
|
58
|
-
const callExpr = refPath.findParent((p) => p.isCallExpression());
|
|
59
|
-
if (callExpr) {
|
|
60
|
-
// Get the parent, handling both await and non-await cases
|
|
61
|
-
const parentPath = callExpr.parentPath;
|
|
62
|
-
const effectiveParent = parentPath?.node.type === 'AwaitExpression'
|
|
63
|
-
? parentPath.parentPath
|
|
64
|
-
: parentPath;
|
|
65
|
-
if (effectiveParent &&
|
|
66
|
-
effectiveParent.node.type === 'VariableDeclarator' &&
|
|
67
|
-
effectiveParent.node.id.type === 'Identifier') {
|
|
68
|
-
const tFuncName = effectiveParent.node.id.name;
|
|
69
|
-
// Get the scope from the variable declaration
|
|
70
|
-
const variableScope = effectiveParent.scope;
|
|
71
|
-
variableScope.bindings[tFuncName]?.referencePaths.forEach((tPath) => {
|
|
72
|
-
if (tPath.parent.type === 'CallExpression' &&
|
|
73
|
-
tPath.parent.arguments.length > 0) {
|
|
74
|
-
const arg = tPath.parent.arguments[0];
|
|
75
|
-
if (arg.type === 'StringLiteral' ||
|
|
76
|
-
(t.isTemplateLiteral(arg) && arg.expressions.length === 0)) {
|
|
77
|
-
const source = arg.type === 'StringLiteral'
|
|
78
|
-
? arg.value
|
|
79
|
-
: arg.quasis[0].value.raw;
|
|
80
|
-
// split the string into content (same as runtime behavior)
|
|
81
|
-
const content = (0, generaltranslation_1.splitStringToContent)(source);
|
|
82
|
-
// get metadata and id from options
|
|
83
|
-
const options = tPath.parent.arguments[1];
|
|
84
|
-
let metadata = {};
|
|
85
|
-
if (options && options.type === 'ObjectExpression') {
|
|
86
|
-
options.properties.forEach((prop) => {
|
|
87
|
-
if (prop.type === 'ObjectProperty' &&
|
|
88
|
-
prop.key.type === 'Identifier') {
|
|
89
|
-
const attribute = prop.key.name;
|
|
90
|
-
if (exports.attributes.includes(attribute) &&
|
|
91
|
-
t.isExpression(prop.value)) {
|
|
92
|
-
const result = (0, evaluateJsx_1.isStaticExpression)(prop.value);
|
|
93
|
-
if (!result.isStatic) {
|
|
94
|
-
errors.push((0, console_1.warnNonStaticExpressionSync)(file, attribute, (0, generator_1.default)(prop.value).code, `${prop.loc?.start?.line}:${prop.loc?.start?.column}`));
|
|
95
|
-
}
|
|
96
|
-
if (result.isStatic && result.value) {
|
|
97
|
-
metadata[attribute] = result.value;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
updates.push({
|
|
104
|
-
dataFormat: 'JSX',
|
|
105
|
-
source: content,
|
|
106
|
-
metadata,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
else if (t.isTemplateLiteral(arg)) {
|
|
110
|
-
// warn if template literal
|
|
111
|
-
errors.push((0, console_1.warnTemplateLiteralSync)(file, (0, generator_1.default)(arg).code, `${arg.loc?.start?.line}:${arg.loc?.start?.column}`));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare function trimJsxStringChild(child: string, index: number, childrenTypes: ('expression' | 'text' | 'element')[]): string;
|
|
2
|
-
/**
|
|
3
|
-
* Handles whitespace in children of a JSX element.
|
|
4
|
-
* @param currentTree - The current tree to handle
|
|
5
|
-
* @returns The processed tree with whitespace handled
|
|
6
|
-
*/
|
|
7
|
-
export declare const handleChildrenWhitespace: (currentTree: any) => any;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleChildrenWhitespace = void 0;
|
|
4
|
-
exports.trimJsxStringChild = trimJsxStringChild;
|
|
5
|
-
const internal_1 = require("generaltranslation/internal");
|
|
6
|
-
function trimJsxStringChild(child, index, childrenTypes) {
|
|
7
|
-
// Normalize line endings to \n for consistency across platforms
|
|
8
|
-
let result = child.replace(/\r\n|\r/g, '\n');
|
|
9
|
-
// Collapse multiple spaces/tabs into a single space
|
|
10
|
-
result = result.replace(/[\t ]+/g, ' ');
|
|
11
|
-
let newResult = '';
|
|
12
|
-
let newline = false;
|
|
13
|
-
for (const char of result) {
|
|
14
|
-
if (char === '\n') {
|
|
15
|
-
if (newResult.trim())
|
|
16
|
-
newResult += ' ';
|
|
17
|
-
else
|
|
18
|
-
newResult = '';
|
|
19
|
-
newline = true;
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
if (!newline) {
|
|
23
|
-
newResult += char;
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
if (char.trim() === '')
|
|
27
|
-
continue;
|
|
28
|
-
newResult += char;
|
|
29
|
-
newline = false;
|
|
30
|
-
}
|
|
31
|
-
if (newline)
|
|
32
|
-
newResult = newResult.trimEnd();
|
|
33
|
-
result = newResult;
|
|
34
|
-
// Collapse multiple spaces/tabs into a single space
|
|
35
|
-
result = result.replace(/[\t ]+/g, ' ');
|
|
36
|
-
return result;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Handles whitespace in children of a JSX element.
|
|
40
|
-
* @param currentTree - The current tree to handle
|
|
41
|
-
* @returns The processed tree with whitespace handled
|
|
42
|
-
*/
|
|
43
|
-
const handleChildrenWhitespace = (currentTree) => {
|
|
44
|
-
if (Array.isArray(currentTree)) {
|
|
45
|
-
const childrenTypes = currentTree.map((child) => {
|
|
46
|
-
if (typeof child === 'string')
|
|
47
|
-
return 'text';
|
|
48
|
-
if (typeof child === 'object' && 'expression' in child)
|
|
49
|
-
return 'expression';
|
|
50
|
-
return 'element';
|
|
51
|
-
});
|
|
52
|
-
const newChildren = [];
|
|
53
|
-
currentTree.forEach((child, index) => {
|
|
54
|
-
if (childrenTypes[index] === 'text') {
|
|
55
|
-
const string = trimJsxStringChild(child, index, childrenTypes);
|
|
56
|
-
if (string)
|
|
57
|
-
newChildren.push(string);
|
|
58
|
-
}
|
|
59
|
-
else if (childrenTypes[index] === 'expression') {
|
|
60
|
-
newChildren.push(child.result);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
newChildren.push((0, exports.handleChildrenWhitespace)(child));
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
return newChildren.length === 1 ? newChildren[0] : newChildren;
|
|
67
|
-
}
|
|
68
|
-
else if (currentTree?.props) {
|
|
69
|
-
// Process all props recursively
|
|
70
|
-
const elementIsPlural = currentTree.type === 'Plural';
|
|
71
|
-
const elementIsBranch = currentTree.type === 'Branch';
|
|
72
|
-
const processedProps = Object.fromEntries(Object.entries(currentTree.props).map(([key, value]) => {
|
|
73
|
-
let shouldProcess = false;
|
|
74
|
-
if (key === 'children')
|
|
75
|
-
shouldProcess = true;
|
|
76
|
-
if (elementIsPlural && (0, internal_1.isAcceptedPluralForm)(key))
|
|
77
|
-
shouldProcess = true;
|
|
78
|
-
if (elementIsBranch && key !== 'branch')
|
|
79
|
-
shouldProcess = true;
|
|
80
|
-
// Add your validation logic here
|
|
81
|
-
if (shouldProcess) {
|
|
82
|
-
return [key, (0, exports.handleChildrenWhitespace)(value)];
|
|
83
|
-
}
|
|
84
|
-
return [key, value];
|
|
85
|
-
}));
|
|
86
|
-
return {
|
|
87
|
-
...currentTree,
|
|
88
|
-
props: processedProps,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
else if (typeof currentTree === 'object' &&
|
|
92
|
-
'expression' in currentTree === true) {
|
|
93
|
-
return currentTree.result;
|
|
94
|
-
}
|
|
95
|
-
else if (typeof currentTree === 'string') {
|
|
96
|
-
return trimJsxStringChild(currentTree, 0, ['text']);
|
|
97
|
-
}
|
|
98
|
-
return currentTree;
|
|
99
|
-
};
|
|
100
|
-
exports.handleChildrenWhitespace = handleChildrenWhitespace;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as t from '@babel/types';
|
|
2
|
-
import { ParseResult } from '@babel/parser';
|
|
3
|
-
import { ImportDeclaration, VariableDeclaration } from '@babel/types';
|
|
4
|
-
export declare function determineModuleType(ast: ParseResult<t.File>): boolean;
|
|
5
|
-
export type ImportItem = string | {
|
|
6
|
-
local: string;
|
|
7
|
-
imported: string;
|
|
8
|
-
source: string;
|
|
9
|
-
};
|
|
10
|
-
export declare function generateImports(needsImport: ImportItem[], isESM: boolean, importMap: Record<string, {
|
|
11
|
-
name: string;
|
|
12
|
-
source: string;
|
|
13
|
-
}>): (t.ImportDeclaration | t.VariableDeclaration)[];
|
|
14
|
-
export declare function generateImportMap(ast: ParseResult<t.File>, pkg: string): {
|
|
15
|
-
initialImports: string[];
|
|
16
|
-
importAlias: {
|
|
17
|
-
TComponent: string;
|
|
18
|
-
VarComponent: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
export declare function insertImports(ast: ParseResult<t.File>, importNodes: (t.ImportDeclaration | t.VariableDeclaration)[]): void;
|
|
22
|
-
export declare function createImports(ast: ParseResult<t.File>, needsImport: ImportItem[], importMap: Record<string, {
|
|
23
|
-
name: string;
|
|
24
|
-
source: string;
|
|
25
|
-
}>): void;
|
|
26
|
-
export interface ImportNameResult {
|
|
27
|
-
local: string;
|
|
28
|
-
original: string;
|
|
29
|
-
}
|
|
30
|
-
export declare function extractImportName(node: ImportDeclaration | VariableDeclaration, pkg: string, translationFuncs: string[]): ImportNameResult[];
|
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.determineModuleType = determineModuleType;
|
|
40
|
-
exports.generateImports = generateImports;
|
|
41
|
-
exports.generateImportMap = generateImportMap;
|
|
42
|
-
exports.insertImports = insertImports;
|
|
43
|
-
exports.createImports = createImports;
|
|
44
|
-
exports.extractImportName = extractImportName;
|
|
45
|
-
const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
46
|
-
const babel = __importStar(require("@babel/types"));
|
|
47
|
-
function determineModuleType(ast) {
|
|
48
|
-
let isESM = false;
|
|
49
|
-
(0, traverse_1.default)(ast, {
|
|
50
|
-
ImportDeclaration() {
|
|
51
|
-
isESM = true;
|
|
52
|
-
},
|
|
53
|
-
ExportDefaultDeclaration() {
|
|
54
|
-
isESM = true;
|
|
55
|
-
},
|
|
56
|
-
ExportNamedDeclaration() {
|
|
57
|
-
isESM = true;
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
return isESM;
|
|
61
|
-
}
|
|
62
|
-
function generateImports(needsImport, isESM, importMap) {
|
|
63
|
-
// Group imports by their source
|
|
64
|
-
const importsBySource = needsImport.reduce((acc, imp) => {
|
|
65
|
-
if (typeof imp === 'string') {
|
|
66
|
-
// Handle standard GT component imports
|
|
67
|
-
const importInfo = importMap[imp];
|
|
68
|
-
const source = importInfo.source;
|
|
69
|
-
if (!acc[source])
|
|
70
|
-
acc[source] = [];
|
|
71
|
-
acc[source].push({ local: imp, imported: importInfo.name });
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
// Handle custom imports (like config)
|
|
75
|
-
const source = imp.source;
|
|
76
|
-
if (!acc[source])
|
|
77
|
-
acc[source] = [];
|
|
78
|
-
acc[source].push({ local: imp.local, imported: imp.imported });
|
|
79
|
-
}
|
|
80
|
-
return acc;
|
|
81
|
-
}, {});
|
|
82
|
-
// Generate import nodes for each source
|
|
83
|
-
const importNodes = Object.entries(importsBySource).map(([source, imports]) => {
|
|
84
|
-
if (isESM) {
|
|
85
|
-
return babel.importDeclaration(imports.map((imp) => imp.imported === 'default'
|
|
86
|
-
? babel.importDefaultSpecifier(babel.identifier(imp.local))
|
|
87
|
-
: babel.importSpecifier(babel.identifier(imp.local), babel.identifier(imp.imported))), babel.stringLiteral(source));
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
// For CommonJS, handle default imports differently
|
|
91
|
-
return babel.variableDeclaration('const', [
|
|
92
|
-
babel.variableDeclarator(imports.some((imp) => imp.imported === 'default')
|
|
93
|
-
? babel.identifier(imports[0].local)
|
|
94
|
-
: babel.objectPattern(imports.map((imp) => babel.objectProperty(babel.identifier(imp.local), babel.identifier(imp.imported), false, imp.local === imp.imported))), babel.callExpression(babel.identifier('require'), [
|
|
95
|
-
babel.stringLiteral(source),
|
|
96
|
-
])),
|
|
97
|
-
]);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
return importNodes;
|
|
101
|
-
}
|
|
102
|
-
/*
|
|
103
|
-
* This function traverses the AST and records the relevant imports for the pkg.
|
|
104
|
-
* It also records the import aliases for the T and Var components. (in case of conflicts)
|
|
105
|
-
*/
|
|
106
|
-
function generateImportMap(ast, pkg) {
|
|
107
|
-
let importAlias = { TComponent: 'T', VarComponent: 'Var' };
|
|
108
|
-
// Check existing imports
|
|
109
|
-
let initialImports = [];
|
|
110
|
-
(0, traverse_1.default)(ast, {
|
|
111
|
-
ImportDeclaration(path) {
|
|
112
|
-
const source = path.node.source.value;
|
|
113
|
-
if (source === pkg) {
|
|
114
|
-
initialImports = [
|
|
115
|
-
...initialImports,
|
|
116
|
-
...path.node.specifiers.map((spec) => {
|
|
117
|
-
// For named imports (import { x as y }), use the original name
|
|
118
|
-
if (babel.isImportSpecifier(spec)) {
|
|
119
|
-
return babel.isIdentifier(spec.imported)
|
|
120
|
-
? spec.imported.name
|
|
121
|
-
: spec.imported.value;
|
|
122
|
-
}
|
|
123
|
-
// For default imports, fall back to local name
|
|
124
|
-
return spec.local.name;
|
|
125
|
-
}),
|
|
126
|
-
];
|
|
127
|
-
}
|
|
128
|
-
// Check for conflicting imports only if they're not from gt libraries
|
|
129
|
-
if (source !== pkg) {
|
|
130
|
-
path.node.specifiers.forEach((spec) => {
|
|
131
|
-
if (babel.isImportSpecifier(spec) ||
|
|
132
|
-
babel.isImportDefaultSpecifier(spec)) {
|
|
133
|
-
if (spec.local.name === 'T')
|
|
134
|
-
importAlias.TComponent = 'GTT';
|
|
135
|
-
if (spec.local.name === 'Var')
|
|
136
|
-
importAlias.VarComponent = 'GTVar';
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
VariableDeclaration(path) {
|
|
142
|
-
const declaration = path.node.declarations[0];
|
|
143
|
-
if (!declaration)
|
|
144
|
-
return;
|
|
145
|
-
// Handle const { T, Var } = require('pkg')
|
|
146
|
-
if (babel.isCallExpression(declaration.init) &&
|
|
147
|
-
babel.isIdentifier(declaration.init.callee) &&
|
|
148
|
-
declaration.init.callee.name === 'require' &&
|
|
149
|
-
babel.isStringLiteral(declaration.init.arguments[0]) &&
|
|
150
|
-
declaration.init.arguments[0].value === pkg &&
|
|
151
|
-
babel.isObjectPattern(declaration.id)) {
|
|
152
|
-
initialImports = [
|
|
153
|
-
...initialImports,
|
|
154
|
-
...declaration.id.properties
|
|
155
|
-
.map((prop) => {
|
|
156
|
-
if (babel.isObjectProperty(prop) &&
|
|
157
|
-
babel.isIdentifier(prop.key)) {
|
|
158
|
-
return prop.key.name;
|
|
159
|
-
}
|
|
160
|
-
return '';
|
|
161
|
-
})
|
|
162
|
-
.filter(Boolean),
|
|
163
|
-
];
|
|
164
|
-
}
|
|
165
|
-
// Handle const temp = require('pkg') followed by const { T, Var } = temp
|
|
166
|
-
if (babel.isCallExpression(declaration.init) &&
|
|
167
|
-
babel.isIdentifier(declaration.init.callee) &&
|
|
168
|
-
declaration.init.callee.name === 'require' &&
|
|
169
|
-
babel.isStringLiteral(declaration.init.arguments[0]) &&
|
|
170
|
-
declaration.init.arguments[0].value === pkg &&
|
|
171
|
-
babel.isIdentifier(declaration.id)) {
|
|
172
|
-
const requireVarName = declaration.id.name;
|
|
173
|
-
const parentBody = babel.isProgram(path.parent) || babel.isBlockStatement(path.parent)
|
|
174
|
-
? path.parent.body
|
|
175
|
-
: [];
|
|
176
|
-
// Look for subsequent destructuring
|
|
177
|
-
for (const node of parentBody) {
|
|
178
|
-
if (babel.isVariableDeclaration(node) &&
|
|
179
|
-
node.declarations[0] &&
|
|
180
|
-
babel.isObjectPattern(node.declarations[0].id) &&
|
|
181
|
-
babel.isMemberExpression(node.declarations[0].init) &&
|
|
182
|
-
babel.isIdentifier(node.declarations[0].init.object) &&
|
|
183
|
-
node.declarations[0].init.object.name === requireVarName) {
|
|
184
|
-
initialImports = [
|
|
185
|
-
...initialImports,
|
|
186
|
-
...node.declarations[0].id.properties
|
|
187
|
-
.map((prop) => {
|
|
188
|
-
if (babel.isObjectProperty(prop) &&
|
|
189
|
-
babel.isIdentifier(prop.key)) {
|
|
190
|
-
return prop.key.name;
|
|
191
|
-
}
|
|
192
|
-
return '';
|
|
193
|
-
})
|
|
194
|
-
.filter(Boolean),
|
|
195
|
-
];
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
// Check for conflicting requires
|
|
200
|
-
if (babel.isCallExpression(declaration.init) &&
|
|
201
|
-
babel.isIdentifier(declaration.init.callee) &&
|
|
202
|
-
declaration.init.callee.name === 'require' &&
|
|
203
|
-
babel.isStringLiteral(declaration.init.arguments[0]) &&
|
|
204
|
-
declaration.init.arguments[0].value !== pkg &&
|
|
205
|
-
babel.isObjectPattern(declaration.id)) {
|
|
206
|
-
declaration.id.properties.forEach((prop) => {
|
|
207
|
-
if (babel.isObjectProperty(prop) && babel.isIdentifier(prop.value)) {
|
|
208
|
-
if (prop.value.name === 'T')
|
|
209
|
-
importAlias.TComponent = 'GTT';
|
|
210
|
-
if (prop.value.name === 'Var')
|
|
211
|
-
importAlias.VarComponent = 'GTVar';
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
// Add check for intermediate variable conflict
|
|
216
|
-
if (babel.isIdentifier(declaration.id)) {
|
|
217
|
-
if (declaration.id.name === 'T')
|
|
218
|
-
importAlias.TComponent = 'GTT';
|
|
219
|
-
if (declaration.id.name === 'Var')
|
|
220
|
-
importAlias.VarComponent = 'GTVar';
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
});
|
|
224
|
-
return { initialImports, importAlias };
|
|
225
|
-
}
|
|
226
|
-
function insertImports(ast, importNodes) {
|
|
227
|
-
// Find the best position to insert the imports
|
|
228
|
-
let insertIndex = 0;
|
|
229
|
-
for (let i = 0; i < ast.program.body.length; i++) {
|
|
230
|
-
if (!babel.isImportDeclaration(ast.program.body[i])) {
|
|
231
|
-
insertIndex = i;
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
insertIndex = i + 1;
|
|
235
|
-
}
|
|
236
|
-
// Insert all import nodes
|
|
237
|
-
ast.program.body.splice(insertIndex, 0, ...importNodes);
|
|
238
|
-
}
|
|
239
|
-
function createImports(ast, needsImport, importMap) {
|
|
240
|
-
const isESM = determineModuleType(ast);
|
|
241
|
-
const importNodes = generateImports(needsImport, isESM, importMap);
|
|
242
|
-
insertImports(ast, importNodes);
|
|
243
|
-
}
|
|
244
|
-
function extractImportName(node, pkg, translationFuncs) {
|
|
245
|
-
const results = [];
|
|
246
|
-
if (node.type === 'ImportDeclaration') {
|
|
247
|
-
// Handle ES6 imports
|
|
248
|
-
if (node.source.value.startsWith(pkg)) {
|
|
249
|
-
for (const specifier of node.specifiers) {
|
|
250
|
-
if (specifier.type === 'ImportSpecifier' &&
|
|
251
|
-
'name' in specifier.imported &&
|
|
252
|
-
translationFuncs.includes(specifier.imported.name)) {
|
|
253
|
-
results.push({
|
|
254
|
-
local: specifier.local.name,
|
|
255
|
-
original: specifier.imported.name,
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
else if (node.type === 'VariableDeclaration') {
|
|
262
|
-
// Handle CJS requires
|
|
263
|
-
for (const declaration of node.declarations) {
|
|
264
|
-
// Handle direct require with destructuring
|
|
265
|
-
if (declaration.init?.type === 'CallExpression' &&
|
|
266
|
-
declaration.init.callee.type === 'Identifier' &&
|
|
267
|
-
declaration.init.callee.name === 'require' &&
|
|
268
|
-
declaration.init.arguments[0]?.type === 'StringLiteral' &&
|
|
269
|
-
declaration.init.arguments[0].value.startsWith(pkg)) {
|
|
270
|
-
// Handle destructuring case: const { T } = require('gt-next')
|
|
271
|
-
if (declaration.id.type === 'ObjectPattern') {
|
|
272
|
-
for (const prop of declaration.id.properties) {
|
|
273
|
-
if (prop.type === 'ObjectProperty' &&
|
|
274
|
-
prop.key.type === 'Identifier' &&
|
|
275
|
-
translationFuncs.includes(prop.key.name) &&
|
|
276
|
-
prop.value.type === 'Identifier') {
|
|
277
|
-
results.push({
|
|
278
|
-
local: prop.value.name,
|
|
279
|
-
original: prop.key.name,
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
// Handle intermediate variable case: const temp = require('gt-next')
|
|
285
|
-
else if (declaration.id.type === 'Identifier') {
|
|
286
|
-
const requireVarName = declaration.id.name;
|
|
287
|
-
const parentBody = node.parent?.body;
|
|
288
|
-
if (parentBody) {
|
|
289
|
-
for (let i = 0; i < parentBody.length; i++) {
|
|
290
|
-
const stmt = parentBody[i];
|
|
291
|
-
if (stmt.type === 'VariableDeclaration' &&
|
|
292
|
-
stmt.declarations[0]?.init?.type === 'MemberExpression' &&
|
|
293
|
-
stmt.declarations[0].init.object.type === 'Identifier' &&
|
|
294
|
-
stmt.declarations[0].init.object.name === requireVarName &&
|
|
295
|
-
stmt.declarations[0].init.property.type === 'Identifier' &&
|
|
296
|
-
translationFuncs.includes(stmt.declarations[0].init.property.name)) {
|
|
297
|
-
results.push({
|
|
298
|
-
local: stmt.declarations[0].id.name,
|
|
299
|
-
original: stmt.declarations[0].init.property.name,
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
// Handle member expression assignment: const TranslateFunc = temp.T
|
|
307
|
-
if (declaration.init?.type === 'MemberExpression' &&
|
|
308
|
-
declaration.init.property.type === 'Identifier' &&
|
|
309
|
-
translationFuncs.includes(declaration.init.property.name) &&
|
|
310
|
-
declaration.id.type === 'Identifier') {
|
|
311
|
-
results.push({
|
|
312
|
-
local: declaration.id.name,
|
|
313
|
-
original: declaration.init.property.name,
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
return results;
|
|
319
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Updates } from '../../../types';
|
|
2
|
-
import * as t from '@babel/types';
|
|
3
|
-
/**
|
|
4
|
-
* Builds a JSX tree from a given node, recursively handling children.
|
|
5
|
-
* @param node - The node to build the tree from
|
|
6
|
-
* @param unwrappedExpressions - An array to store unwrapped expressions
|
|
7
|
-
* @param updates - The updates array
|
|
8
|
-
* @param errors - The errors array
|
|
9
|
-
* @param file - The file name
|
|
10
|
-
* @returns The built JSX tree
|
|
11
|
-
*/
|
|
12
|
-
export declare function buildJSXTree(importAliases: Record<string, string>, node: any, unwrappedExpressions: string[], updates: Updates, errors: string[], file: string): any;
|
|
13
|
-
export declare function parseJSXElement(importAliases: Record<string, string>, node: t.JSXElement, updates: Updates, errors: string[], file: string): void;
|