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,197 +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 = wrapContentReact;
40
- const node_fs_1 = __importDefault(require("node:fs"));
41
- const node_path_1 = __importDefault(require("node:path"));
42
- const t = __importStar(require("@babel/types"));
43
- const parser_1 = require("@babel/parser");
44
- const traverse_1 = __importDefault(require("@babel/traverse"));
45
- const generator_1 = __importDefault(require("@babel/generator"));
46
- const findJsxFilepath_1 = require("../../fs/findJsxFilepath");
47
- const evaluateJsx_1 = require("../jsx/evaluateJsx");
48
- const wrapJsx_1 = require("../jsx/wrapJsx");
49
- const findFilepath_1 = require("../../fs/findFilepath");
50
- const parseAst_1 = require("../jsx/utils/parseAst");
51
- const IMPORT_MAP = {
52
- T: { name: 'T', source: 'gt-react' },
53
- Var: { name: 'Var', source: 'gt-react' },
54
- GTT: { name: 'T', source: 'gt-react' },
55
- GTVar: { name: 'Var', source: 'gt-react' },
56
- GTProvider: { name: 'GTProvider', source: 'gt-react' },
57
- // getLocale: { name: 'getLocale', source: 'gt-react/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 wrapContentReact(options, pkg, framework, 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 baseFileName = node_path_1.default.basename(file);
72
- const configPath = node_path_1.default.relative(node_path_1.default.dirname(file), node_path_1.default.resolve(process.cwd(), options.config));
73
- // Ensure the path starts with ./ or ../
74
- const normalizedConfigPath = configPath.startsWith('.')
75
- ? configPath
76
- : './' + configPath;
77
- const code = await node_fs_1.default.promises.readFile(file, 'utf8');
78
- // Create relative path from src directory and remove extension
79
- const relativePath = (0, findFilepath_1.getRelativePath)(file, srcDirectory[0]);
80
- let ast;
81
- try {
82
- ast = (0, parser_1.parse)(code, {
83
- sourceType: 'module',
84
- plugins: ['jsx', 'typescript'],
85
- tokens: true,
86
- createParenthesizedExpressions: true,
87
- });
88
- }
89
- catch (error) {
90
- errors.push(`Error:Failed to parse ${file}: ${error}`);
91
- continue;
92
- }
93
- let modified = false;
94
- let usedImports = [];
95
- let { importAlias, initialImports } = (0, parseAst_1.generateImportMap)(ast, pkg);
96
- // If the file already has a T import, skip processing it
97
- if (initialImports.includes(IMPORT_MAP.T.name)) {
98
- continue;
99
- }
100
- let globalId = 0;
101
- (0, traverse_1.default)(ast, {
102
- JSXElement(path) {
103
- if (framework === 'next-pages' &&
104
- options.addGTProvider &&
105
- (baseFileName === '_app.tsx' || baseFileName === '_app.jsx')) {
106
- // Check if this is the Component element with pageProps
107
- const isComponentWithPageProps = t.isJSXElement(path.node) &&
108
- t.isJSXIdentifier(path.node.openingElement.name) &&
109
- path.node.openingElement.name.name === 'Component' &&
110
- path.node.openingElement.attributes.some((attr) => t.isJSXSpreadAttribute(attr) &&
111
- t.isIdentifier(attr.argument) &&
112
- attr.argument.name === 'pageProps');
113
- if (!isComponentWithPageProps) {
114
- return;
115
- }
116
- // Check if GTProvider already exists in the ancestors
117
- let hasGTProvider = false;
118
- let currentPath = path;
119
- while (currentPath.parentPath) {
120
- if (t.isJSXElement(currentPath.node) &&
121
- t.isJSXIdentifier(currentPath.node.openingElement.name) &&
122
- currentPath.node.openingElement.name.name === 'GTProvider') {
123
- hasGTProvider = true;
124
- break;
125
- }
126
- currentPath = currentPath.parentPath;
127
- }
128
- if (!hasGTProvider) {
129
- // Wrap the Component element with GTProvider
130
- const gtProviderJsx = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier('GTProvider'), [t.jsxSpreadAttribute(t.identifier('gtConfig'))], false), t.jsxClosingElement(t.jsxIdentifier('GTProvider')), [path.node]);
131
- path.replaceWith(gtProviderJsx);
132
- usedImports.push('GTProvider');
133
- usedImports.push({
134
- local: 'gtConfig',
135
- imported: 'default',
136
- source: normalizedConfigPath,
137
- });
138
- modified = true;
139
- path.skip();
140
- return;
141
- }
142
- }
143
- // Check if this JSX element has any JSX element ancestors
144
- let currentPath = path;
145
- if (t.isJSXElement(currentPath.parentPath?.node)) {
146
- // If we found a JSX parent, skip processing this node
147
- return;
148
- }
149
- // At this point, we're only processing top-level JSX elements
150
- const opts = {
151
- ...importAlias,
152
- idPrefix: relativePath,
153
- idCount: globalId,
154
- usedImports,
155
- modified: false,
156
- createIds: !options.disableIds,
157
- warnings,
158
- file,
159
- };
160
- const wrapped = (0, wrapJsx_1.handleJsxElement)(path.node, opts, evaluateJsx_1.isMeaningful);
161
- path.replaceWith(wrapped.node);
162
- // Update global counters
163
- modified = modified || opts.modified;
164
- globalId = opts.idCount;
165
- },
166
- });
167
- if (!modified)
168
- continue;
169
- let needsImport = usedImports.filter((imp) => typeof imp === 'string'
170
- ? !initialImports.includes(imp)
171
- : !initialImports.includes(imp.local));
172
- if (needsImport.length > 0) {
173
- (0, parseAst_1.createImports)(ast, needsImport, IMPORT_MAP);
174
- }
175
- try {
176
- const output = (0, generator_1.default)(ast, {
177
- retainLines: true,
178
- retainFunctionParens: true,
179
- comments: true,
180
- compact: 'auto',
181
- }, code);
182
- // Post-process the output to fix import spacing
183
- let processedCode = output.code;
184
- if (needsImport.length > 0) {
185
- // Add newline after the comment only
186
- 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');
187
- }
188
- // Write the modified code back to the file
189
- await node_fs_1.default.promises.writeFile(file, processedCode);
190
- filesUpdated.push(file);
191
- }
192
- catch (error) {
193
- errors.push(`Error: Failed to write ${file}: ${error}`);
194
- }
195
- }
196
- return { filesUpdated };
197
- }
@@ -1,20 +0,0 @@
1
- import { Dictionary, FlattenedDictionary, FlattenedJSONDictionary, JSONDictionary } from '../../types/data';
2
- /**
3
- * Flattens a nested dictionary by concatenating nested keys.
4
- * Throws an error if two keys result in the same flattened key.
5
- * @param {Record<string, any>} dictionary - The dictionary to flatten.
6
- * @param {string} [prefix=''] - The prefix for nested keys.
7
- * @returns {Record<string, React.ReactNode>} The flattened dictionary object.
8
- * @throws {Error} If two keys result in the same flattened key.
9
- */
10
- export default function flattenDictionary(dictionary: Dictionary, prefix?: string): FlattenedDictionary;
11
- /**
12
- * Flattens a nested dictionary containing only string values
13
- * Throws an error if two keys result in the same flattened key.
14
- * @param {JSONDictionary} dictionary - The dictionary to flatten.
15
- * @param {string} [prefix=''] - The prefix for nested keys.
16
- * @returns {FlattenedJSONDictionary} The flattened dictionary with string values.
17
- * @throws {Error} If two keys result in the same flattened key.
18
- * @throws {Error} If a value is an array.
19
- */
20
- export declare function flattenJsonDictionary(dictionary: JSONDictionary, prefix?: string): FlattenedJSONDictionary;
@@ -1,79 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = flattenDictionary;
4
- exports.flattenJsonDictionary = flattenJsonDictionary;
5
- const console_1 = require("../../console");
6
- const createDuplicateKeyError = (key) => `Duplicate key found in dictionary: "${key}"`;
7
- /**
8
- * Flattens a nested dictionary by concatenating nested keys.
9
- * Throws an error if two keys result in the same flattened key.
10
- * @param {Record<string, any>} dictionary - The dictionary to flatten.
11
- * @param {string} [prefix=''] - The prefix for nested keys.
12
- * @returns {Record<string, React.ReactNode>} The flattened dictionary object.
13
- * @throws {Error} If two keys result in the same flattened key.
14
- */
15
- function flattenDictionary(dictionary, prefix = '') {
16
- const flattened = {};
17
- for (const key in dictionary) {
18
- if (dictionary.hasOwnProperty(key)) {
19
- const newKey = prefix ? `${prefix}.${key}` : key;
20
- if (typeof dictionary[key] === 'object' &&
21
- dictionary[key] !== null &&
22
- !Array.isArray(dictionary[key])) {
23
- const nestedFlattened = flattenDictionary(dictionary[key], newKey);
24
- for (const flatKey in nestedFlattened) {
25
- if (flattened.hasOwnProperty(flatKey)) {
26
- (0, console_1.logErrorAndExit)(createDuplicateKeyError(flatKey));
27
- }
28
- flattened[flatKey] = nestedFlattened[flatKey];
29
- }
30
- }
31
- else {
32
- if (flattened.hasOwnProperty(newKey)) {
33
- (0, console_1.logErrorAndExit)(createDuplicateKeyError(newKey));
34
- }
35
- flattened[newKey] = dictionary[key];
36
- }
37
- }
38
- }
39
- return flattened;
40
- }
41
- /**
42
- * Flattens a nested dictionary containing only string values
43
- * Throws an error if two keys result in the same flattened key.
44
- * @param {JSONDictionary} dictionary - The dictionary to flatten.
45
- * @param {string} [prefix=''] - The prefix for nested keys.
46
- * @returns {FlattenedJSONDictionary} The flattened dictionary with string values.
47
- * @throws {Error} If two keys result in the same flattened key.
48
- * @throws {Error} If a value is an array.
49
- */
50
- function flattenJsonDictionary(dictionary, prefix = '') {
51
- const flattened = {};
52
- for (const key in dictionary) {
53
- if (dictionary.hasOwnProperty(key)) {
54
- const newKey = prefix ? `${prefix}.${key}` : key;
55
- const value = dictionary[key];
56
- if (Array.isArray(value)) {
57
- (0, console_1.logErrorAndExit)(`Arrays are not supported in JSON dictionary at key: "${newKey}"`);
58
- }
59
- else if (typeof value === 'object' && value !== null) {
60
- // Recursively flatten nested objects
61
- const nestedFlattened = flattenJsonDictionary(value, newKey);
62
- for (const flatKey in nestedFlattened) {
63
- if (flattened.hasOwnProperty(flatKey)) {
64
- (0, console_1.logErrorAndExit)(createDuplicateKeyError(flatKey));
65
- }
66
- flattened[flatKey] = nestedFlattened[flatKey];
67
- }
68
- }
69
- else if (typeof value === 'string') {
70
- // Handle string values
71
- if (flattened.hasOwnProperty(newKey)) {
72
- (0, console_1.logErrorAndExit)(createDuplicateKeyError(newKey));
73
- }
74
- flattened[newKey] = value;
75
- }
76
- }
77
- }
78
- return flattened;
79
- }
@@ -1,5 +0,0 @@
1
- import { DictionaryEntry, DictionaryMetadata } from '../../types/data';
2
- export default function getEntryAndMetadata(value: DictionaryEntry): {
3
- entry: string;
4
- metadata?: DictionaryMetadata;
5
- };
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = getEntryAndMetadata;
4
- function getEntryAndMetadata(value) {
5
- if (Array.isArray(value)) {
6
- if (value.length === 1) {
7
- return { entry: value[0] };
8
- }
9
- if (value.length === 2) {
10
- return { entry: value[0], metadata: value[1] };
11
- }
12
- }
13
- return { entry: value };
14
- }
@@ -1,2 +0,0 @@
1
- export declare const baseVariablePrefix = "_gt_";
2
- export declare function getVariableName(props: Record<string, any> | undefined, variableType: string): string;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.baseVariablePrefix = void 0;
4
- exports.getVariableName = getVariableName;
5
- const defaultVariableNames = {
6
- variable: 'value',
7
- number: 'n',
8
- datetime: 'date',
9
- currency: 'cost',
10
- };
11
- exports.baseVariablePrefix = '_gt_';
12
- function getVariableName(props = {}, variableType) {
13
- if (props.name)
14
- return props.name;
15
- const baseVariableName = defaultVariableNames[variableType] || 'value';
16
- return `${exports.baseVariablePrefix}${baseVariableName}_${props['data-_gt']?.id}`;
17
- }
@@ -1,4 +0,0 @@
1
- export declare function getDesiredLocales(): Promise<{
2
- defaultLocale: string;
3
- locales: string[];
4
- }>;
@@ -1,35 +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.getDesiredLocales = getDesiredLocales;
7
- const internal_1 = require("generaltranslation/internal");
8
- const console_1 = require("../console");
9
- const chalk_1 = __importDefault(require("chalk"));
10
- const generaltranslation_1 = require("generaltranslation");
11
- async function getDesiredLocales() {
12
- // Ask for the default locale
13
- const defaultLocale = await (0, console_1.promptText)({
14
- message: 'What is the default locale for your project?',
15
- defaultValue: internal_1.libraryDefaultLocale,
16
- });
17
- // Ask for the locales
18
- const locales = await (0, console_1.promptText)({
19
- message: `What locales would you like to translate your project into? ${chalk_1.default.gray('(space-separated list)')}`,
20
- defaultValue: 'es zh fr de ja',
21
- validate: (input) => {
22
- const localeList = input.split(' ');
23
- if (localeList.length === 0) {
24
- return 'Please enter at least one locale';
25
- }
26
- for (const locale of localeList) {
27
- if (!(0, generaltranslation_1.isValidLocale)(locale)) {
28
- return 'Please enter a valid locale (e.g., en, fr, es)';
29
- }
30
- }
31
- return true;
32
- },
33
- });
34
- return { defaultLocale, locales: locales.split(' ') };
35
- }
@@ -1,2 +0,0 @@
1
- import { SetupOptions } from '../types';
2
- export declare function handleSetupReactCommand(options: SetupOptions): Promise<void>;
@@ -1,171 +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.handleSetupReactCommand = handleSetupReactCommand;
7
- const postProcess_1 = require("../hooks/postProcess");
8
- const console_1 = require("../console");
9
- const console_2 = require("../console");
10
- const chalk_1 = __importDefault(require("chalk"));
11
- const console_3 = require("../console");
12
- const findFilepath_1 = __importDefault(require("../fs/findFilepath"));
13
- const postProcess_2 = require("../hooks/postProcess");
14
- const handleInitGT_1 = __importDefault(require("../next/parse/handleInitGT"));
15
- const packageJson_1 = require("../utils/packageJson");
16
- const wrapContent_1 = __importDefault(require("../react/parse/wrapContent"));
17
- const wrapContent_2 = __importDefault(require("../next/parse/wrapContent"));
18
- const packageManager_1 = require("../utils/packageManager");
19
- const installPackage_1 = require("../utils/installPackage");
20
- const setupConfig_1 = __importDefault(require("../fs/config/setupConfig"));
21
- async function handleSetupReactCommand(options) {
22
- // Ask user for confirmation using inquirer
23
- const answer = await (0, console_3.promptConfirm)({
24
- message: chalk_1.default.yellow(`This wizard will configure your React project for internationalization with GT.
25
- If your project is already using a different i18n library, this wizard may cause issues.
26
-
27
- Make sure you have committed or stashed any changes. Do you want to continue?`),
28
- defaultValue: true,
29
- cancelMessage: 'Operation cancelled. You can re-run this wizard with: npx gtx-cli setup',
30
- });
31
- if (!answer) {
32
- (0, console_2.logInfo)('Operation cancelled. You can re-run this wizard with: npx gtx-cli setup');
33
- process.exit(0);
34
- }
35
- const frameworkType = await (0, console_1.promptSelect)({
36
- message: 'What framework are you using?',
37
- options: [
38
- { value: 'next-app', label: chalk_1.default.blue('Next.js App Router') },
39
- { value: 'next-pages', label: chalk_1.default.green('Next.js Pages Router') },
40
- { value: 'vite', label: chalk_1.default.cyan('Vite + React') },
41
- { value: 'gatsby', label: chalk_1.default.magenta('Gatsby') },
42
- { value: 'react', label: chalk_1.default.yellow('React') },
43
- { value: 'redwood', label: chalk_1.default.red('RedwoodJS') },
44
- { value: 'other', label: chalk_1.default.gray('Other') },
45
- ],
46
- defaultValue: 'next-app',
47
- });
48
- if (frameworkType === 'other') {
49
- (0, console_2.logError)(`Sorry, other React frameworks are not currently supported.
50
- Please let us know what you would like to see supported at https://github.com/generaltranslation/gt/issues`);
51
- process.exit(0);
52
- }
53
- // ----- Create a starter gt.config.json file -----
54
- await (0, setupConfig_1.default)(options.config || 'gt.config.json', {
55
- framework: frameworkType,
56
- });
57
- const packageJson = await (0, packageJson_1.getPackageJson)();
58
- // Check if gt-next or gt-react is installed
59
- if (frameworkType === 'next-app' &&
60
- !(0, packageJson_1.isPackageInstalled)('gt-next', packageJson)) {
61
- const packageManager = await (0, packageManager_1.getPackageManager)();
62
- const spinner = (0, console_1.createSpinner)('timer');
63
- spinner.start(`Installing gt-next with ${packageManager.name}...`);
64
- await (0, installPackage_1.installPackage)('gt-next', packageManager);
65
- spinner.stop(chalk_1.default.green('Automatically installed gt-next.'));
66
- }
67
- else if (['next-pages', 'react', 'redwood', 'vite', 'gatsby'].includes(frameworkType) &&
68
- !(0, packageJson_1.isPackageInstalled)('gt-react', packageJson)) {
69
- const packageManager = await (0, packageManager_1.getPackageManager)();
70
- const spinner = (0, console_1.createSpinner)('timer');
71
- spinner.start(`Installing gt-react with ${packageManager.name}...`);
72
- await (0, installPackage_1.installPackage)('gt-react', packageManager);
73
- spinner.stop(chalk_1.default.green('Automatically installed gt-react.'));
74
- }
75
- let errors = [];
76
- let warnings = [];
77
- let filesUpdated = [];
78
- if (frameworkType === 'next-app') {
79
- // Check if they have a next.config.js file
80
- const nextConfigPath = (0, findFilepath_1.default)([
81
- './next.config.js',
82
- './next.config.ts',
83
- './next.config.mjs',
84
- './next.config.mts',
85
- ]);
86
- if (!nextConfigPath) {
87
- (0, console_2.logError)('No next.config.[js|ts|mjs|mts] file found.');
88
- process.exit(1);
89
- }
90
- const addGTProvider = await (0, console_3.promptConfirm)({
91
- message: 'Do you want the setup wizard to automatically add the GTProvider component?',
92
- defaultValue: true,
93
- });
94
- const addWithGTConfig = await (0, console_3.promptConfirm)({
95
- message: `Do you want to automatically add withGTConfig() to your ${nextConfigPath}?`,
96
- defaultValue: true,
97
- });
98
- const includeTId = await (0, console_3.promptConfirm)({
99
- message: 'Do you want to include an unique id for each <T> tag?',
100
- defaultValue: true,
101
- });
102
- const mergeOptions = {
103
- ...options,
104
- disableIds: !includeTId,
105
- disableFormatting: true,
106
- addGTProvider,
107
- };
108
- const spinner = (0, console_1.createSpinner)();
109
- spinner.start('Wrapping JSX content with <T> tags...');
110
- // Wrap all JSX elements in the src directory with a <T> tag, with unique ids
111
- const { filesUpdated: filesUpdatedNext } = await (0, wrapContent_2.default)(mergeOptions, 'gt-next', errors, warnings);
112
- filesUpdated = [...filesUpdated, ...filesUpdatedNext];
113
- spinner.stop(chalk_1.default.green(`Success! Added <T> tags and updated ${chalk_1.default.bold.cyan(filesUpdated.length)} files:\n`) + filesUpdated.map((file) => `${chalk_1.default.green('-')} ${file}`).join('\n'));
114
- if (addWithGTConfig) {
115
- // Add the withGTConfig() function to the next.config.js file
116
- await (0, handleInitGT_1.default)(nextConfigPath, errors, warnings, filesUpdated);
117
- (0, console_2.logStep)(chalk_1.default.green(`Added withGTConfig() to your ${nextConfigPath} file.`));
118
- }
119
- if (errors.length > 0) {
120
- (0, console_2.logError)(chalk_1.default.red('Failed to write files:\n') + errors.join('\n'));
121
- }
122
- (0, console_2.logSuccess)(chalk_1.default.green(`Success! All JSX content has been wrapped with <T> tags${includeTId ? ' and unique ids.' : '.'}`));
123
- (0, console_1.logMessage)(`To translate strings, see the docs on useGT and getGT: https://generaltranslation.com/docs/next/api/strings/getGT`);
124
- }
125
- else {
126
- let addGTProvider = false;
127
- if (frameworkType === 'next-pages') {
128
- addGTProvider = await (0, console_3.promptConfirm)({
129
- message: 'Do you want the setup wizard to automatically add the GTProvider component?',
130
- defaultValue: true,
131
- });
132
- }
133
- const includeTId = await (0, console_3.promptConfirm)({
134
- message: 'Do you want to include an unique id for each <T> tag?',
135
- defaultValue: true,
136
- });
137
- const mergeOptions = {
138
- ...options,
139
- disableIds: !includeTId,
140
- disableFormatting: true,
141
- addGTProvider,
142
- };
143
- const spinner = (0, console_1.createSpinner)();
144
- spinner.start('Wrapping JSX content with <T> tags...');
145
- // Wrap all JSX elements in the src directory with a <T> tag, with unique ids
146
- const { filesUpdated: filesUpdatedReact } = await (0, wrapContent_1.default)(mergeOptions, 'gt-react', frameworkType, errors, warnings);
147
- filesUpdated = [...filesUpdated, ...filesUpdatedReact];
148
- spinner.stop(chalk_1.default.green(`Success! Added <T> tags and updated ${chalk_1.default.bold.cyan(filesUpdated.length)} files:\n`) + filesUpdated.map((file) => `${chalk_1.default.green('-')} ${file}`).join('\n'));
149
- if (errors.length > 0) {
150
- (0, console_2.logError)(chalk_1.default.red('Failed to write files:\n') + errors.join('\n'));
151
- }
152
- (0, console_2.logSuccess)(chalk_1.default.green(`Success! All JSX content has been wrapped with <T> tags${includeTId ? ' and unique ids.' : '.'}`));
153
- (0, console_1.logMessage)(`To translate strings, see the docs on useGT: https://generaltranslation.com/docs/react/api/strings/useGT`);
154
- }
155
- if (warnings.length > 0) {
156
- (0, console_2.logWarning)(chalk_1.default.yellow('Warnings encountered:') +
157
- '\n' +
158
- warnings.map((warning) => `${chalk_1.default.yellow('-')} ${warning}`).join('\n'));
159
- }
160
- const formatter = await (0, postProcess_1.detectFormatter)();
161
- if (!formatter || filesUpdated.length === 0) {
162
- return;
163
- }
164
- const applyFormatting = await (0, console_3.promptConfirm)({
165
- message: `Would you like the wizard to auto-format the modified files? ${chalk_1.default.gray(`(${formatter})`)}`,
166
- defaultValue: true,
167
- });
168
- // Format updated files if formatters are available
169
- if (applyFormatting)
170
- await (0, postProcess_2.formatFiles)(filesUpdated, formatter);
171
- }
@@ -1,14 +0,0 @@
1
- import { Options, GenerateSourceOptions, Updates } from '../types';
2
- /**
3
- * Searches for gt-react or gt-next dictionary files and creates updates for them,
4
- * as well as inline updates for <T> tags and useGT()/getGT() calls
5
- *
6
- * @param options - The options object
7
- * @param sourceDictionary - The source dictionary file path
8
- * @param pkg - The package name
9
- * @returns An object containing the updates and errors
10
- */
11
- export declare function createUpdates(options: Options | GenerateSourceOptions, sourceDictionary: string | undefined, pkg: 'gt-react' | 'gt-next'): Promise<{
12
- updates: Updates;
13
- errors: string[];
14
- }>;
@@ -1,82 +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.createUpdates = createUpdates;
7
- const fs_1 = __importDefault(require("fs"));
8
- const logging_1 = require("../console/logging");
9
- const loadJSON_1 = __importDefault(require("../fs/loadJSON"));
10
- const createDictionaryUpdates_1 = __importDefault(require("../react/parse/createDictionaryUpdates"));
11
- const createInlineUpdates_1 = __importDefault(require("../react/parse/createInlineUpdates"));
12
- const createESBuildConfig_1 = __importDefault(require("../react/config/createESBuildConfig"));
13
- const chalk_1 = __importDefault(require("chalk"));
14
- /**
15
- * Searches for gt-react or gt-next dictionary files and creates updates for them,
16
- * as well as inline updates for <T> tags and useGT()/getGT() calls
17
- *
18
- * @param options - The options object
19
- * @param sourceDictionary - The source dictionary file path
20
- * @param pkg - The package name
21
- * @returns An object containing the updates and errors
22
- */
23
- async function createUpdates(options, sourceDictionary, pkg) {
24
- let updates = [];
25
- let errors = [];
26
- // Parse dictionary with esbuildConfig
27
- if (sourceDictionary &&
28
- fs_1.default.existsSync(sourceDictionary) &&
29
- fs_1.default.statSync(sourceDictionary).isFile()) {
30
- if (sourceDictionary.endsWith('.json')) {
31
- updates = [
32
- ...updates,
33
- ...(await (0, createDictionaryUpdates_1.default)(options, sourceDictionary)),
34
- ];
35
- }
36
- else {
37
- let esbuildConfig;
38
- if (options.jsconfig) {
39
- const jsconfig = (0, loadJSON_1.default)(options.jsconfig);
40
- if (!jsconfig) {
41
- (0, logging_1.logError)(`Failed to resolve jsconfig.json or tsconfig.json at provided filepath: "${options.jsconfig}"`);
42
- process.exit(1);
43
- }
44
- esbuildConfig = (0, createESBuildConfig_1.default)(jsconfig);
45
- }
46
- else {
47
- esbuildConfig = (0, createESBuildConfig_1.default)({});
48
- }
49
- updates = [
50
- ...updates,
51
- ...(await (0, createDictionaryUpdates_1.default)(options, sourceDictionary, esbuildConfig)),
52
- ];
53
- }
54
- }
55
- // Scan through project for <T> tags
56
- if (options.inline) {
57
- const { updates: newUpdates, errors: newErrors } = await (0, createInlineUpdates_1.default)(options, pkg);
58
- errors = [...errors, ...newErrors];
59
- updates = [...updates, ...newUpdates];
60
- }
61
- // Metadata addition and validation
62
- const idHashMap = new Map();
63
- const duplicateIds = new Set();
64
- updates = updates.map((update) => {
65
- if (!update.metadata.id)
66
- return update;
67
- const existingHash = idHashMap.get(update.metadata.id);
68
- if (existingHash) {
69
- if (existingHash !== update.metadata.hash) {
70
- errors.push(`Hashes don't match on two components with the same id: ${chalk_1.default.blue(update.metadata.id)}. Check your ${chalk_1.default.green('<T>')} tags and dictionary entries and make sure you're not accidentally duplicating IDs.`);
71
- duplicateIds.add(update.metadata.id);
72
- }
73
- }
74
- else {
75
- idHashMap.set(update.metadata.id, update.metadata.hash);
76
- }
77
- return update;
78
- });
79
- // Filter out updates with duplicate IDs
80
- updates = updates.filter((update) => !duplicateIds.has(update.metadata.id));
81
- return { updates, errors };
82
- }
@@ -1,5 +0,0 @@
1
- import { Options, Settings } from '../types';
2
- export declare function stageProject(settings: Options & Settings, pkg: 'gt-react' | 'gt-next'): Promise<{
3
- versionId: string;
4
- locales: string[];
5
- } | null>;