gtx-cli 1.2.14 → 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.
Files changed (141) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/package.json +1 -2
  3. package/.env +0 -2
  4. package/dist/api/checkFileTranslations.d.ts +0 -19
  5. package/dist/api/checkFileTranslations.js +0 -244
  6. package/dist/api/downloadFile.d.ts +0 -1
  7. package/dist/api/downloadFile.js +0 -83
  8. package/dist/api/downloadFileBatch.d.ts +0 -16
  9. package/dist/api/downloadFileBatch.js +0 -127
  10. package/dist/api/fetchTranslations.d.ts +0 -10
  11. package/dist/api/fetchTranslations.js +0 -35
  12. package/dist/api/sendFiles.d.ts +0 -24
  13. package/dist/api/sendFiles.js +0 -63
  14. package/dist/api/sendUpdates.d.ts +0 -19
  15. package/dist/api/sendUpdates.js +0 -75
  16. package/dist/api/waitForUpdates.d.ts +0 -11
  17. package/dist/api/waitForUpdates.js +0 -96
  18. package/dist/cli/base.d.ts +0 -28
  19. package/dist/cli/base.js +0 -322
  20. package/dist/cli/next.d.ts +0 -10
  21. package/dist/cli/next.js +0 -27
  22. package/dist/cli/react.d.ts +0 -18
  23. package/dist/cli/react.js +0 -305
  24. package/dist/config/generateSettings.d.ts +0 -7
  25. package/dist/config/generateSettings.js +0 -94
  26. package/dist/config/utils.d.ts +0 -2
  27. package/dist/config/utils.js +0 -7
  28. package/dist/config/validateSettings.d.ts +0 -2
  29. package/dist/config/validateSettings.js +0 -23
  30. package/dist/console/colors.d.ts +0 -5
  31. package/dist/console/colors.js +0 -26
  32. package/dist/console/console.d.ts +0 -1
  33. package/dist/console/console.js +0 -20
  34. package/dist/console/errors.d.ts +0 -1
  35. package/dist/console/errors.js +0 -20
  36. package/dist/console/index.d.ts +0 -19
  37. package/dist/console/index.js +0 -48
  38. package/dist/console/logging.d.ts +0 -55
  39. package/dist/console/logging.js +0 -207
  40. package/dist/console/warnings.d.ts +0 -1
  41. package/dist/console/warnings.js +0 -20
  42. package/dist/formats/files/save.d.ts +0 -5
  43. package/dist/formats/files/save.js +0 -23
  44. package/dist/formats/files/supportedFiles.d.ts +0 -8
  45. package/dist/formats/files/supportedFiles.js +0 -17
  46. package/dist/formats/files/translate.d.ts +0 -14
  47. package/dist/formats/files/translate.js +0 -218
  48. package/dist/formats/gt/save.d.ts +0 -10
  49. package/dist/formats/gt/save.js +0 -34
  50. package/dist/fs/config/loadConfig.d.ts +0 -1
  51. package/dist/fs/config/loadConfig.js +0 -15
  52. package/dist/fs/config/parseFilesConfig.d.ts +0 -23
  53. package/dist/fs/config/parseFilesConfig.js +0 -128
  54. package/dist/fs/config/setupConfig.d.ts +0 -15
  55. package/dist/fs/config/setupConfig.js +0 -51
  56. package/dist/fs/config/updateConfig.d.ts +0 -11
  57. package/dist/fs/config/updateConfig.js +0 -41
  58. package/dist/fs/determineFramework.d.ts +0 -5
  59. package/dist/fs/determineFramework.js +0 -52
  60. package/dist/fs/findFilepath.d.ts +0 -36
  61. package/dist/fs/findFilepath.js +0 -101
  62. package/dist/fs/findJsxFilepath.d.ts +0 -7
  63. package/dist/fs/findJsxFilepath.js +0 -36
  64. package/dist/fs/index.d.ts +0 -1
  65. package/dist/fs/index.js +0 -2
  66. package/dist/fs/loadJSON.d.ts +0 -6
  67. package/dist/fs/loadJSON.js +0 -23
  68. package/dist/fs/saveJSON.d.ts +0 -1
  69. package/dist/fs/saveJSON.js +0 -13
  70. package/dist/fs/utils.d.ts +0 -1
  71. package/dist/fs/utils.js +0 -19
  72. package/dist/hooks/postProcess.d.ts +0 -4
  73. package/dist/hooks/postProcess.js +0 -118
  74. package/dist/index.d.ts +0 -3
  75. package/dist/index.js +0 -24
  76. package/dist/main.d.ts +0 -2
  77. package/dist/main.js +0 -12
  78. package/dist/next/config/parseNextConfig.d.ts +0 -10
  79. package/dist/next/config/parseNextConfig.js +0 -59
  80. package/dist/next/jsx/utils.d.ts +0 -7
  81. package/dist/next/jsx/utils.js +0 -82
  82. package/dist/next/parse/handleInitGT.d.ts +0 -1
  83. package/dist/next/parse/handleInitGT.js +0 -153
  84. package/dist/next/parse/wrapContent.d.ts +0 -11
  85. package/dist/next/parse/wrapContent.js +0 -181
  86. package/dist/react/config/createESBuildConfig.d.ts +0 -2
  87. package/dist/react/config/createESBuildConfig.js +0 -125
  88. package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.d.ts +0 -1
  89. package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.js +0 -87
  90. package/dist/react/jsx/evaluateJsx.d.ts +0 -17
  91. package/dist/react/jsx/evaluateJsx.js +0 -133
  92. package/dist/react/jsx/parse/parseStringFunction.d.ts +0 -12
  93. package/dist/react/jsx/parse/parseStringFunction.js +0 -118
  94. package/dist/react/jsx/trimJsxStringChildren.d.ts +0 -7
  95. package/dist/react/jsx/trimJsxStringChildren.js +0 -100
  96. package/dist/react/jsx/utils/parseAst.d.ts +0 -30
  97. package/dist/react/jsx/utils/parseAst.js +0 -319
  98. package/dist/react/jsx/utils/parseJsx.d.ts +0 -13
  99. package/dist/react/jsx/utils/parseJsx.js +0 -250
  100. package/dist/react/jsx/utils/parseStringFunction.d.ts +0 -12
  101. package/dist/react/jsx/utils/parseStringFunction.js +0 -121
  102. package/dist/react/jsx/wrapJsx.d.ts +0 -51
  103. package/dist/react/jsx/wrapJsx.js +0 -411
  104. package/dist/react/parse/createDictionaryUpdates.d.ts +0 -3
  105. package/dist/react/parse/createDictionaryUpdates.js +0 -78
  106. package/dist/react/parse/createInlineUpdates.d.ts +0 -5
  107. package/dist/react/parse/createInlineUpdates.js +0 -135
  108. package/dist/react/parse/wrapContent.d.ts +0 -11
  109. package/dist/react/parse/wrapContent.js +0 -197
  110. package/dist/react/utils/flattenDictionary.d.ts +0 -20
  111. package/dist/react/utils/flattenDictionary.js +0 -79
  112. package/dist/react/utils/getEntryAndMetadata.d.ts +0 -5
  113. package/dist/react/utils/getEntryAndMetadata.js +0 -14
  114. package/dist/react/utils/getVariableName.d.ts +0 -2
  115. package/dist/react/utils/getVariableName.js +0 -17
  116. package/dist/setup/userInput.d.ts +0 -4
  117. package/dist/setup/userInput.js +0 -35
  118. package/dist/setup/wizard.d.ts +0 -2
  119. package/dist/setup/wizard.js +0 -171
  120. package/dist/translation/parse.d.ts +0 -14
  121. package/dist/translation/parse.js +0 -82
  122. package/dist/translation/stage.d.ts +0 -5
  123. package/dist/translation/stage.js +0 -80
  124. package/dist/translation/translate.d.ts +0 -2
  125. package/dist/translation/translate.js +0 -21
  126. package/dist/types/api.d.ts +0 -6
  127. package/dist/types/api.js +0 -2
  128. package/dist/types/data.d.ts +0 -31
  129. package/dist/types/data.js +0 -2
  130. package/dist/types/index.d.ts +0 -101
  131. package/dist/types/index.js +0 -2
  132. package/dist/utils/constants.d.ts +0 -1
  133. package/dist/utils/constants.js +0 -4
  134. package/dist/utils/credentials.d.ts +0 -12
  135. package/dist/utils/credentials.js +0 -128
  136. package/dist/utils/installPackage.d.ts +0 -2
  137. package/dist/utils/installPackage.js +0 -45
  138. package/dist/utils/packageJson.d.ts +0 -5
  139. package/dist/utils/packageJson.js +0 -78
  140. package/dist/utils/packageManager.d.ts +0 -23
  141. package/dist/utils/packageManager.js +0 -261
@@ -1,181 +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.default = wrapContentNext;
40
- const node_fs_1 = __importDefault(require("node:fs"));
41
- const t = __importStar(require("@babel/types"));
42
- const parser_1 = require("@babel/parser");
43
- const traverse_1 = __importDefault(require("@babel/traverse"));
44
- const generator_1 = __importDefault(require("@babel/generator"));
45
- const findJsxFilepath_1 = require("../../fs/findJsxFilepath");
46
- const evaluateJsx_1 = require("../../react/jsx/evaluateJsx");
47
- const wrapJsx_1 = require("../../react/jsx/wrapJsx");
48
- const findFilepath_1 = require("../../fs/findFilepath");
49
- const utils_1 = require("../jsx/utils");
50
- const parseAst_1 = require("../../react/jsx/utils/parseAst");
51
- const IMPORT_MAP = {
52
- T: { name: 'T', source: 'gt-next' },
53
- Var: { name: 'Var', source: 'gt-next' },
54
- GTT: { name: 'T', source: 'gt-next' },
55
- GTVar: { name: 'Var', source: 'gt-next' },
56
- GTProvider: { name: 'GTProvider', source: 'gt-next' },
57
- getLocale: { name: 'getLocale', source: 'gt-next/server' },
58
- };
59
- /**
60
- * Wraps all JSX elements in the src directory with a <T> tag, with unique ids.
61
- * - Ignores pure strings
62
- *
63
- * @param options - The options object
64
- * @returns An object containing the updates and errors
65
- */
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.`);
104
- return;
105
- }
106
- // Skip if body already has GTProvider
107
- if ((0, utils_1.hasGTProviderChild)(bodyElement)) {
108
- return;
109
- }
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;
128
- }
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');
171
- }
172
- // Write the modified code back to the file
173
- await node_fs_1.default.promises.writeFile(file, processedCode);
174
- filesUpdated.push(file);
175
- }
176
- catch (error) {
177
- errors.push(`Error: Failed to write ${file}: ${error}`);
178
- }
179
- }
180
- return { filesUpdated };
181
- }
@@ -1,2 +0,0 @@
1
- import esbuild from 'esbuild';
2
- export default function createESBuildConfig(config?: Record<string, any>): esbuild.BuildOptions;
@@ -1,125 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = createESBuildConfig;
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const console_1 = require("../../console/console");
10
- function createESBuildConfig(config = {}) {
11
- const esbuildOptions = {
12
- bundle: true,
13
- format: 'cjs',
14
- platform: 'node',
15
- target: 'es2021',
16
- loader: {
17
- '.js': 'jsx',
18
- '.ts': 'ts',
19
- '.css': 'css', // Add CSS loader
20
- },
21
- sourcemap: 'inline',
22
- external: ['server-only'],
23
- define: {
24
- React: 'global.React',
25
- },
26
- plugins: [],
27
- };
28
- // Add the custom plugin to handle 'server-only' imports
29
- esbuildOptions.plugins.push({
30
- name: 'ignore-server-only',
31
- setup(build) {
32
- build.onResolve({ filter: /^server-only$/ }, () => {
33
- return {
34
- path: 'server-only',
35
- namespace: 'ignore-server-only',
36
- };
37
- });
38
- build.onLoad({ filter: /^server-only$/, namespace: 'ignore-server-only' }, () => {
39
- return {
40
- contents: 'module.exports = {};',
41
- loader: 'js',
42
- };
43
- });
44
- },
45
- });
46
- // Add a plugin to handle CSS imports
47
- esbuildOptions.plugins.push({
48
- name: 'css-module',
49
- setup(build) {
50
- build.onResolve({ filter: /\.css$/ }, (args) => {
51
- return {
52
- path: node_path_1.default.resolve(args.resolveDir, args.path),
53
- namespace: 'css-module',
54
- };
55
- });
56
- build.onLoad({ filter: /\.css$/, namespace: 'css-module' }, async (args) => {
57
- const css = await node_fs_1.default.promises.readFile(args.path, 'utf8');
58
- const contents = `
59
- const style = document.createElement('style');
60
- style.textContent = ${JSON.stringify(css)};
61
- document.head.appendChild(style);
62
- `;
63
- return { contents, loader: 'js' };
64
- });
65
- },
66
- });
67
- if (config.compilerOptions) {
68
- if (config.compilerOptions.paths) {
69
- const aliases = {};
70
- const resolvedPaths = [];
71
- for (const [key, value] of Object.entries(config.compilerOptions.paths)) {
72
- if (Array.isArray(value) && typeof value[0] === 'string') {
73
- const resolvedPath = node_path_1.default.resolve(process.cwd(), value[0].replace('/*', ''));
74
- aliases[key.replace('/*', '')] = resolvedPath;
75
- resolvedPaths.push([key, resolvedPath]);
76
- }
77
- }
78
- if (resolvedPaths.length) {
79
- (0, console_1.displayResolvedPaths)(resolvedPaths);
80
- }
81
- esbuildOptions.plugins = esbuildOptions.plugins || [];
82
- esbuildOptions.plugins.push({
83
- name: 'alias',
84
- setup(build) {
85
- build.onResolve({ filter: /.*/ }, (args) => {
86
- for (const [aliasKey, aliasPath] of Object.entries(aliases)) {
87
- if (args.path.startsWith(`${aliasKey}/`)) {
88
- const resolvedPath = node_path_1.default.resolve(aliasPath, args.path.slice(aliasKey.length + 1));
89
- const extensions = ['.js', '.ts', '.css']; // Add .css to extensions
90
- function resolveWithExtensions(basePath) {
91
- for (const ext of extensions) {
92
- const fullPath = `${basePath}${ext}`;
93
- try {
94
- const realPath = node_fs_1.default.realpathSync(fullPath);
95
- return realPath;
96
- }
97
- catch (_) {
98
- continue;
99
- }
100
- }
101
- return null;
102
- }
103
- try {
104
- const realPath = node_fs_1.default.realpathSync(resolvedPath);
105
- return { path: realPath };
106
- }
107
- catch (err) {
108
- const hasExtension = extensions.some((ext) => resolvedPath.endsWith(ext));
109
- if (!hasExtension) {
110
- const resolvedWithExt = resolveWithExtensions(resolvedPath);
111
- if (resolvedWithExt) {
112
- return { path: resolvedWithExt };
113
- }
114
- }
115
- throw new Error(`Unable to resolve path: ${resolvedPath}`);
116
- }
117
- }
118
- }
119
- });
120
- },
121
- });
122
- }
123
- }
124
- return esbuildOptions;
125
- }
@@ -1 +0,0 @@
1
- export default function addGTIdentifierToSyntaxTree(tree: any, startingIndex?: number): any;
@@ -1,87 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = addGTIdentifierToSyntaxTree;
4
- const getVariableName_1 = require("../utils/getVariableName");
5
- const internal_1 = require("generaltranslation/internal");
6
- // recreates addGTIdentifier and writeChildrenAsObjects
7
- function addGTIdentifierToSyntaxTree(tree, startingIndex = 0) {
8
- // Object to keep track of the current index for GT IDs
9
- let indexObject = { index: startingIndex };
10
- const handleSingleChild = (child) => {
11
- if (child && typeof child === 'object') {
12
- const { type, props } = child;
13
- indexObject.index += 1;
14
- let generaltranslation = { id: indexObject.index };
15
- if (type === 'Var') {
16
- return {
17
- variable: 'variable',
18
- id: indexObject.index,
19
- key: (0, getVariableName_1.getVariableName)({ ...props, 'data-_gt': generaltranslation }, 'variable'),
20
- };
21
- }
22
- else if (type === 'Num') {
23
- return {
24
- variable: 'number',
25
- id: indexObject.index,
26
- key: (0, getVariableName_1.getVariableName)({ ...props, 'data-_gt': generaltranslation }, 'number'),
27
- };
28
- }
29
- else if (type === 'Currency') {
30
- return {
31
- variable: 'currency',
32
- id: indexObject.index,
33
- key: (0, getVariableName_1.getVariableName)({ ...props, 'data-_gt': generaltranslation }, 'currency'),
34
- };
35
- }
36
- else if (type === 'DateTime') {
37
- return {
38
- variable: 'datetime',
39
- id: indexObject.index,
40
- key: (0, getVariableName_1.getVariableName)({ ...props, 'data-_gt': generaltranslation }, 'datetime'),
41
- };
42
- }
43
- else if (type === "" || type === "React.Fragment") {
44
- generaltranslation.transformation = 'fragment';
45
- }
46
- if (type === 'Plural') {
47
- generaltranslation.transformation = 'plural';
48
- const pluralBranches = Object.entries(props).reduce((acc, [branchName, branch]) => {
49
- if ((0, internal_1.isAcceptedPluralForm)(branchName)) {
50
- acc[branchName] =
51
- addGTIdentifierToSyntaxTree(branch, indexObject.index);
52
- }
53
- return acc;
54
- }, {});
55
- if (Object.keys(pluralBranches).length)
56
- generaltranslation.branches = pluralBranches;
57
- }
58
- else if (type === 'Branch') {
59
- generaltranslation.transformation = 'branch';
60
- const { children, branch, ...branches } = props;
61
- const resultBranches = Object.entries(branches).reduce((acc, [branchName, branch]) => {
62
- acc[branchName] =
63
- addGTIdentifierToSyntaxTree(branch, indexObject.index);
64
- return acc;
65
- }, {});
66
- if (Object.keys(resultBranches).length)
67
- generaltranslation.branches = resultBranches;
68
- }
69
- return {
70
- type: type || `C${generaltranslation.id}`,
71
- props: {
72
- 'data-_gt': generaltranslation,
73
- ...(typeof props.children !== 'undefined' && {
74
- children: handleChildren(props.children),
75
- }),
76
- },
77
- };
78
- }
79
- return child.toString();
80
- };
81
- const handleChildren = (children) => {
82
- return Array.isArray(children)
83
- ? children.map(handleSingleChild)
84
- : handleSingleChild(children);
85
- };
86
- return handleChildren(tree);
87
- }
@@ -1,17 +0,0 @@
1
- import * as t from '@babel/types';
2
- /**
3
- * Checks if a node is meaningful. Does not recurse into children.
4
- * @param node - The node to check
5
- * @returns Whether the node is meaningful
6
- */
7
- export declare function isMeaningful(node: t.Node): boolean;
8
- /**
9
- * Checks if an expression is static (does not contain any variables which could change at runtime).
10
- * @param expr - The expression to check
11
- * @returns An object containing the result of the static check
12
- */
13
- export declare function isStaticExpression(expr: t.Expression | t.JSXEmptyExpression): {
14
- isStatic: boolean;
15
- value?: string;
16
- };
17
- export declare function isStaticValue(expr: t.Expression | t.JSXEmptyExpression): boolean;
@@ -1,133 +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
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.isMeaningful = isMeaningful;
37
- exports.isStaticExpression = isStaticExpression;
38
- exports.isStaticValue = isStaticValue;
39
- const t = __importStar(require("@babel/types"));
40
- const MEANINGFUL_REGEX = /[\p{L}\p{N}]/u;
41
- /**
42
- * Checks if a node is meaningful. Does not recurse into children.
43
- * @param node - The node to check
44
- * @returns Whether the node is meaningful
45
- */
46
- function isMeaningful(node) {
47
- if (t.isStringLiteral(node) || t.isJSXText(node)) {
48
- return MEANINGFUL_REGEX.test(node.value);
49
- }
50
- // Handle template literals without expressions
51
- if (t.isTemplateLiteral(node) && node.expressions.length === 0) {
52
- return MEANINGFUL_REGEX.test(node.quasis[0].value.raw);
53
- }
54
- if (t.isJSXExpressionContainer(node)) {
55
- const value = isStaticExpression(node.expression);
56
- if (value.isStatic && value.value) {
57
- return MEANINGFUL_REGEX.test(value.value);
58
- }
59
- }
60
- if (t.isBinaryExpression(node)) {
61
- if (node.operator === '+') {
62
- return isMeaningful(node.left) || isMeaningful(node.right);
63
- }
64
- }
65
- return false;
66
- }
67
- /**
68
- * Checks if an expression is static (does not contain any variables which could change at runtime).
69
- * @param expr - The expression to check
70
- * @returns An object containing the result of the static check
71
- */
72
- function isStaticExpression(expr) {
73
- // Handle empty expressions
74
- if (t.isJSXEmptyExpression(expr)) {
75
- return { isStatic: true, value: '' };
76
- }
77
- // Handle direct string literals
78
- if (t.isStringLiteral(expr)) {
79
- return { isStatic: true, value: expr.value };
80
- }
81
- // Handle template literals without expressions
82
- if (t.isTemplateLiteral(expr) && expr.expressions.length === 0) {
83
- return { isStatic: true, value: expr.quasis[0].value.raw };
84
- }
85
- // Handle binary expressions (string concatenation)
86
- if (t.isBinaryExpression(expr)) {
87
- // Only handle string concatenation
88
- if (expr.operator !== '+') {
89
- return { isStatic: false };
90
- }
91
- // Type guard to ensure we only process Expression types
92
- if (t.isExpression(expr.left) && t.isExpression(expr.right)) {
93
- const left = isStaticExpression(expr.left);
94
- const right = isStaticExpression(expr.right);
95
- if (left.isStatic &&
96
- right.isStatic &&
97
- left.value !== undefined &&
98
- right.value !== undefined) {
99
- return { isStatic: true, value: left.value + right.value };
100
- }
101
- }
102
- }
103
- // Handle parenthesized expressions
104
- if (t.isParenthesizedExpression(expr)) {
105
- return isStaticExpression(expr.expression);
106
- }
107
- // Handle numeric literals by converting them to strings
108
- if (t.isNumericLiteral(expr)) {
109
- return { isStatic: true, value: String(expr.value) };
110
- }
111
- // Handle boolean literals by converting them to strings
112
- if (t.isBooleanLiteral(expr)) {
113
- return { isStatic: true, value: String(expr.value) };
114
- }
115
- // Handle null literal
116
- if (t.isNullLiteral(expr)) {
117
- return { isStatic: true, value: 'null' };
118
- }
119
- // Not a static expression
120
- return { isStatic: false };
121
- }
122
- function isStaticValue(expr) {
123
- if (t.isStringLiteral(expr)) {
124
- return true;
125
- }
126
- if (t.isNumericLiteral(expr)) {
127
- return true;
128
- }
129
- if (t.isTemplateLiteral(expr)) {
130
- return true;
131
- }
132
- return false;
133
- }
@@ -1,12 +0,0 @@
1
- import { NodePath } from '@babel/traverse';
2
- import { Updates } from '../../../types';
3
- export declare const attributes: string[];
4
- /**
5
- * For the following example code:
6
- * const tx = useGT();
7
- * tx('string to translate', { id: 'exampleId', context: 'exampleContext' });
8
- *
9
- * This function will find all call expressions of useGT(), then find all call expressions
10
- * of the subsequent tx() calls, and append the content and metadata to the updates array.
11
- */
12
- export declare function parseStrings(importName: string, path: NodePath, updates: Updates, errors: string[], file: string): void;