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.
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 -84
  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 -245
  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
package/dist/cli/react.js DELETED
@@ -1,305 +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.ReactCLI = void 0;
40
- // packages/gt-cli-core/src/BaseCLI.ts
41
- const commander_1 = require("commander");
42
- const console_1 = require("../console/console");
43
- const loadJSON_1 = __importDefault(require("../fs/loadJSON"));
44
- const findFilepath_1 = __importStar(require("../fs/findFilepath"));
45
- const chalk_1 = __importDefault(require("chalk"));
46
- const postProcess_1 = require("../hooks/postProcess");
47
- const base_1 = require("./base");
48
- const wrapContent_1 = __importDefault(require("../react/parse/wrapContent"));
49
- const generateSettings_1 = require("../config/generateSettings");
50
- const saveJSON_1 = require("../fs/saveJSON");
51
- const parseFilesConfig_1 = require("../fs/config/parseFilesConfig");
52
- const errors_1 = require("../console/errors");
53
- const stage_1 = require("../translation/stage");
54
- const parse_1 = require("../translation/parse");
55
- const translate_1 = require("../translation/translate");
56
- const updateConfig_1 = __importDefault(require("../fs/config/updateConfig"));
57
- const DEFAULT_TIMEOUT = 600;
58
- const pkg = 'gt-react';
59
- class ReactCLI extends base_1.BaseCLI {
60
- constructor(library, additionalModules) {
61
- super(library, additionalModules);
62
- }
63
- init() {
64
- this.setupStageCommand();
65
- this.setupTranslateCommand();
66
- this.setupScanCommand();
67
- this.setupGenerateSourceCommand();
68
- }
69
- execute() {
70
- super.execute();
71
- }
72
- wrapContent(options, framework, errors, warnings) {
73
- return (0, wrapContent_1.default)(options, pkg, framework, errors, warnings);
74
- }
75
- setupStageCommand() {
76
- commander_1.program
77
- .command('stage')
78
- .description('Submits the project to the General Translation API for translation. Translations created using this command will require human approval.')
79
- .option('-c, --config <path>', 'Filepath to config file, by default gt.config.json', (0, findFilepath_1.default)(['gt.config.json']))
80
- .option('--api-key <key>', 'API key for General Translation cloud service')
81
- .option('--project-id <id>', 'Project ID for the translation service')
82
- .option('--version-id <id>', 'Version ID for the translation service')
83
- .option('--tsconfig, --jsconfig <path>', 'Path to jsconfig or tsconfig file', (0, findFilepath_1.default)(['./tsconfig.json', './jsconfig.json']))
84
- .option('--dictionary <path>', 'Path to dictionary file')
85
- .option('--src <paths...>', "Filepath to directory containing the app's source code, by default ./src || ./app || ./pages || ./components")
86
- .option('--default-language, --default-locale <locale>', 'Default locale (e.g., en)')
87
- .option('--new, --locales <locales...>', 'Space-separated list of locales (e.g., en fr es)')
88
- .option('--inline', 'Include inline <T> tags in addition to dictionary file', true)
89
- .option('--ignore-errors', 'Ignore errors encountered while scanning for <T> tags', false)
90
- .option('--dry-run', 'Dry run, does not send updates to General Translation API', false)
91
- .option('--timeout <seconds>', 'Timeout in seconds for waiting for updates to be deployed to the CDN', DEFAULT_TIMEOUT.toString())
92
- .action(async (options) => {
93
- (0, console_1.displayHeader)('Staging project for translation with approval...');
94
- await this.handleStage(options);
95
- (0, console_1.endCommand)('Done!');
96
- });
97
- }
98
- setupTranslateCommand() {
99
- commander_1.program
100
- .command('translate')
101
- .description('Scans the project for a dictionary and/or <T> tags, and sends the updates to the General Translation API for translation.')
102
- .option('-c, --config <path>', 'Filepath to config file, by default gt.config.json', (0, findFilepath_1.default)(['gt.config.json']))
103
- .option('--api-key <key>', 'API key for General Translation cloud service')
104
- .option('--project-id <id>', 'Project ID for the translation service')
105
- .option('--version-id <id>', 'Version ID for the translation service')
106
- .option('--tsconfig, --jsconfig <path>', 'Path to jsconfig or tsconfig file', (0, findFilepath_1.default)(['./tsconfig.json', './jsconfig.json']))
107
- .option('--dictionary <path>', 'Path to dictionary file')
108
- .option('--src <paths...>', "Filepath to directory containing the app's source code, by default ./src || ./app || ./pages || ./components")
109
- .option('--default-language, --default-locale <locale>', 'Default locale (e.g., en)')
110
- .option('--new, --locales <locales...>', 'Space-separated list of locales (e.g., en fr es)')
111
- .option('--inline', 'Include inline <T> tags in addition to dictionary file', true)
112
- .option('--ignore-errors', 'Ignore errors encountered while scanning for <T> tags', false)
113
- .option('--dry-run', 'Dry run, does not send updates to General Translation API', false)
114
- .option('--timeout <seconds>', 'Timeout in seconds for waiting for updates to be deployed to the CDN', DEFAULT_TIMEOUT.toString())
115
- .action(async (options) => {
116
- (0, console_1.displayHeader)('Translating project...');
117
- await this.handleTranslate(options);
118
- (0, console_1.endCommand)('Done!');
119
- });
120
- }
121
- setupGenerateSourceCommand() {
122
- commander_1.program
123
- .command('generate')
124
- .description('Generate a translation file for the source locale. The -t flag must be provided. This command should be used if you are handling your own translations.')
125
- .option('--src <paths...>', "Filepath to directory containing the app's source code, by default ./src || ./app || ./pages || ./components")
126
- .option('--tsconfig, --jsconfig <path>', 'Path to jsconfig or tsconfig file', (0, findFilepath_1.default)(['./tsconfig.json', './jsconfig.json']))
127
- .option('--dictionary <path>', 'Path to dictionary file')
128
- .option('--default-language, --default-locale <locale>', 'Source locale (e.g., en)')
129
- .option('--inline', 'Include inline <T> tags in addition to dictionary file', true)
130
- .option('--ignore-errors', 'Ignore errors encountered while scanning for <T> tags', false)
131
- .option('-t, --translations-dir, --translation-dir <path>', 'Path to directory where translations will be saved. If this flag is not provided, translations will not be saved locally.')
132
- .action(async (options) => {
133
- (0, console_1.displayHeader)('Generating source templates...');
134
- await this.handleGenerateSourceCommand(options);
135
- (0, console_1.endCommand)('Done!');
136
- });
137
- }
138
- setupScanCommand() {
139
- commander_1.program
140
- .command('scan')
141
- .description('Scans the project and wraps all JSX elements in the src directory with a <T> tag, with unique ids')
142
- .option('--src <paths...>', "Filepath to directory containing the app's source code, by default ./src || ./app || ./pages || ./components", (0, findFilepath_1.findFilepaths)(['./src', './app', './pages', './components']))
143
- .option('-c, --config <path>', 'Filepath to config file, by default gt.config.json', (0, findFilepath_1.default)(['gt.config.json']))
144
- .option('--disable-ids', 'Disable id generation for the <T> tags', false)
145
- .option('--disable-formatting', 'Disable formatting of edited files', false)
146
- .action(async (options) => {
147
- (0, console_1.displayHeader)('Scanning project...');
148
- await this.handleScanCommand(options);
149
- (0, console_1.endCommand)('Done!');
150
- });
151
- }
152
- async handleGenerateSourceCommand(initOptions) {
153
- const settings = await (0, generateSettings_1.generateSettings)(initOptions);
154
- const options = { ...initOptions, ...settings };
155
- if (!options.dictionary) {
156
- options.dictionary = (0, findFilepath_1.default)([
157
- './dictionary.js',
158
- './src/dictionary.js',
159
- './dictionary.json',
160
- './src/dictionary.json',
161
- './dictionary.ts',
162
- './src/dictionary.ts',
163
- ]);
164
- }
165
- // User has to provide a dictionary file
166
- // will not read from settings.files.resolvedPaths.json
167
- const { updates, errors } = await (0, parse_1.createUpdates)(options, options.dictionary, this.library === 'gt-next' ? 'gt-next' : 'gt-react');
168
- if (errors.length > 0) {
169
- if (options.ignoreErrors) {
170
- (0, console_1.logWarning)(chalk_1.default.yellow(`CLI tool encountered errors while scanning for translatable content. These components will not be translated.\n` +
171
- errors
172
- .map((error) => chalk_1.default.yellow('• Warning: ') + chalk_1.default.white(error))
173
- .join('\n')));
174
- }
175
- else {
176
- (0, console_1.logErrorAndExit)(chalk_1.default.red(`CLI tool encountered errors while scanning for translatable content. ${chalk_1.default.gray('To ignore these errors, re-run with --ignore-errors')}\n` +
177
- errors
178
- .map((error) => chalk_1.default.red('• Error: ') + chalk_1.default.white(error))
179
- .join('\n')));
180
- }
181
- }
182
- // Convert updates to the proper data format
183
- const newData = {};
184
- for (const update of updates) {
185
- const { source, metadata } = update;
186
- const { hash, id } = metadata;
187
- if (id) {
188
- newData[id] = source;
189
- }
190
- else {
191
- newData[hash] = source;
192
- }
193
- }
194
- // Save source file if files.json is provided
195
- if (settings.files && settings.files.placeholderPaths.gt) {
196
- const translationFiles = (0, parseFilesConfig_1.resolveLocaleFiles)(settings.files.placeholderPaths, settings.defaultLocale);
197
- if (!translationFiles.gt) {
198
- (0, console_1.logError)(errors_1.noFilesError);
199
- process.exit(1);
200
- }
201
- await (0, saveJSON_1.saveJSON)(translationFiles.gt, newData);
202
- (0, console_1.logStep)('Source file saved successfully!');
203
- // Also save translations (after merging with existing translations)
204
- for (const locale of settings.locales) {
205
- const translationsFile = (0, parseFilesConfig_1.resolveLocaleFiles)(settings.files.placeholderPaths, locale);
206
- if (!translationsFile.gt) {
207
- continue;
208
- }
209
- const existingTranslations = (0, loadJSON_1.default)(translationsFile.gt);
210
- const mergedTranslations = {
211
- ...newData,
212
- ...existingTranslations,
213
- };
214
- // Filter out keys that don't exist in newData
215
- const filteredTranslations = Object.fromEntries(Object.entries(mergedTranslations).filter(([key]) => newData[key]));
216
- await (0, saveJSON_1.saveJSON)(translationsFile.gt, filteredTranslations);
217
- }
218
- (0, console_1.logStep)('Merged translations successfully!');
219
- }
220
- }
221
- async handleScanCommand(options) {
222
- // Ask user for confirmation using inquirer
223
- const answer = await (0, console_1.promptConfirm)({
224
- message: chalk_1.default.yellow('Warning: This operation will modify your source files! Make sure you have committed or stashed your current changes. Do you want to continue?'),
225
- defaultValue: true,
226
- });
227
- if (!answer) {
228
- (0, console_1.logError)('Operation cancelled.');
229
- process.exit(0);
230
- }
231
- // ----- Create a starter gt.config.json file -----
232
- await (0, generateSettings_1.generateSettings)(options);
233
- // ----- //
234
- const includeTId = await (0, console_1.promptConfirm)({
235
- message: 'Do you want to include an unique id for each <T> tag?',
236
- defaultValue: true,
237
- });
238
- options.disableIds = !includeTId;
239
- let errors = [];
240
- let warnings = [];
241
- // Wrap all JSX elements in the src directory with a <T> tag, with unique ids
242
- const { filesUpdated } = await this.wrapContent(options, 'react', errors, warnings);
243
- if (errors.length > 0) {
244
- (0, console_1.logError)(chalk_1.default.red('Failed to write files:\n') + errors.join('\n'));
245
- }
246
- // Format updated files if formatters are available
247
- if (!options.disableFormatting)
248
- await (0, postProcess_1.formatFiles)(filesUpdated);
249
- (0, console_1.logSuccess)(`Success! Added <T> tags and updated ${chalk_1.default.bold.cyan(filesUpdated.length)} files:\n` +
250
- filesUpdated.map((file) => `${chalk_1.default.green('-')} ${file}`).join('\n'));
251
- if (filesUpdated.length > 0) {
252
- (0, console_1.logStep)(chalk_1.default.green('Please verify the changes before committing.'));
253
- }
254
- if (warnings.length > 0) {
255
- (0, console_1.logWarning)(chalk_1.default.yellow('Warnings encountered:') +
256
- '\n' +
257
- warnings
258
- .map((warning) => `${chalk_1.default.yellow('-')} ${warning}`)
259
- .join('\n'));
260
- }
261
- }
262
- async handleStage(initOptions) {
263
- const settings = await (0, generateSettings_1.generateSettings)(initOptions);
264
- // First run the base class's handleTranslate method
265
- const options = { ...initOptions, ...settings };
266
- if (!settings.stageTranslations) {
267
- // Update settings.stageTranslations to true
268
- settings.stageTranslations = true;
269
- await (0, updateConfig_1.default)({
270
- configFilepath: options.config,
271
- stageTranslations: true,
272
- });
273
- }
274
- const pkg = this.library === 'gt-next' ? 'gt-next' : 'gt-react';
275
- await (0, stage_1.stageProject)(options, pkg);
276
- }
277
- async handleTranslate(initOptions) {
278
- const settings = await (0, generateSettings_1.generateSettings)(initOptions);
279
- // First run the base class's handleTranslate method
280
- const options = { ...initOptions, ...settings };
281
- try {
282
- await super.handleGenericTranslate(options);
283
- // If the base class's handleTranslate completes successfully, continue with ReactCLI-specific code
284
- }
285
- catch (error) {
286
- // Continue with ReactCLI-specific code even if base handleTranslate failed
287
- }
288
- if (!settings.stageTranslations) {
289
- // If stageTranslations is false, stage the project
290
- const pkg = this.library === 'gt-next' ? 'gt-next' : 'gt-react';
291
- const results = await (0, stage_1.stageProject)(options, pkg);
292
- if (results) {
293
- await (0, translate_1.translate)(options, results.versionId);
294
- }
295
- }
296
- else {
297
- if (!settings._versionId) {
298
- (0, console_1.logError)(errors_1.noVersionIdError);
299
- process.exit(1);
300
- }
301
- await (0, translate_1.translate)(options, settings._versionId);
302
- }
303
- }
304
- }
305
- exports.ReactCLI = ReactCLI;
@@ -1,7 +0,0 @@
1
- import { Settings } from '../types';
2
- /**
3
- * Generates settings from any
4
- * @param options - The options to generate settings from
5
- * @returns The generated settings
6
- */
7
- export declare function generateSettings(options: any): Promise<Settings>;
@@ -1,94 +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.generateSettings = generateSettings;
7
- const console_1 = require("../console/console");
8
- const warnings_1 = require("../console/warnings");
9
- const loadConfig_1 = __importDefault(require("../fs/config/loadConfig"));
10
- const internal_1 = require("generaltranslation/internal");
11
- const node_fs_1 = __importDefault(require("node:fs"));
12
- const setupConfig_1 = __importDefault(require("../fs/config/setupConfig"));
13
- const parseFilesConfig_1 = require("../fs/config/parseFilesConfig");
14
- const findFilepath_1 = require("../fs/findFilepath");
15
- const validateSettings_1 = require("./validateSettings");
16
- const constants_1 = require("../utils/constants");
17
- const utils_1 = require("../fs/utils");
18
- /**
19
- * Generates settings from any
20
- * @param options - The options to generate settings from
21
- * @returns The generated settings
22
- */
23
- async function generateSettings(options) {
24
- // Load config file
25
- let gtConfig = {};
26
- if (options.config && !options.config.endsWith('.json')) {
27
- options.config = `${options.config}.json`;
28
- }
29
- if (options.config) {
30
- gtConfig = (0, loadConfig_1.default)(options.config);
31
- }
32
- else if (node_fs_1.default.existsSync('gt.config.json')) {
33
- options.config = 'gt.config.json';
34
- gtConfig = (0, loadConfig_1.default)('gt.config.json');
35
- }
36
- else if (node_fs_1.default.existsSync('src/gt.config.json')) {
37
- options.config = 'src/gt.config.json';
38
- gtConfig = (0, loadConfig_1.default)('src/gt.config.json');
39
- }
40
- else {
41
- // If neither config exists, use empty config
42
- gtConfig = {};
43
- }
44
- // Warn if apiKey is present in gt.config.json
45
- if (gtConfig.apiKey) {
46
- (0, warnings_1.warnApiKeyInConfig)(options.config);
47
- process.exit(1);
48
- }
49
- // merge options
50
- const mergedOptions = { ...gtConfig, ...options };
51
- // merge locales
52
- mergedOptions.locales = Array.from(new Set([...(gtConfig.locales || []), ...(options.locales || [])]));
53
- // Add apiKey if not provided
54
- mergedOptions.apiKey = mergedOptions.apiKey || process.env.GT_API_KEY;
55
- // Add projectId if not provided
56
- mergedOptions.projectId = mergedOptions.projectId || (0, utils_1.resolveProjectId)();
57
- // Add baseUrl if not provided
58
- mergedOptions.baseUrl = mergedOptions.baseUrl || internal_1.defaultBaseUrl;
59
- // Add dashboardUrl if not provided
60
- mergedOptions.dashboardUrl = mergedOptions.dashboardUrl || constants_1.GT_DASHBOARD_URL;
61
- // Add defaultLocale if not provided
62
- mergedOptions.defaultLocale =
63
- mergedOptions.defaultLocale || internal_1.libraryDefaultLocale;
64
- // Add locales if not provided
65
- mergedOptions.locales = mergedOptions.locales || [];
66
- // Add default config file name if not provided
67
- mergedOptions.config = mergedOptions.config || 'gt.config.json';
68
- // Display projectId if present
69
- if (mergedOptions.projectId)
70
- (0, console_1.displayProjectId)(mergedOptions.projectId);
71
- // Add stageTranslations if not provided
72
- // For human review, always stage the project
73
- mergedOptions.stageTranslations = mergedOptions.stageTranslations ?? false;
74
- // Populate src if not provided
75
- mergedOptions.src =
76
- mergedOptions.src ||
77
- (0, findFilepath_1.findFilepaths)(['./src', './app', './pages', './components']);
78
- // Resolve all glob patterns in the files object
79
- mergedOptions.files = mergedOptions.files
80
- ? (0, parseFilesConfig_1.resolveFiles)(mergedOptions.files, mergedOptions.defaultLocale)
81
- : undefined;
82
- // if there's no existing config file, creates one
83
- // does not include the API key to avoid exposing it
84
- if (!node_fs_1.default.existsSync(mergedOptions.config)) {
85
- await (0, setupConfig_1.default)(mergedOptions.config, {
86
- projectId: mergedOptions.projectId,
87
- defaultLocale: mergedOptions.defaultLocale,
88
- locales: mergedOptions.locales?.length > 0 ? mergedOptions.locales : undefined,
89
- framework: mergedOptions.framework,
90
- });
91
- }
92
- (0, validateSettings_1.validateSettings)(mergedOptions);
93
- return mergedOptions;
94
- }
@@ -1,2 +0,0 @@
1
- import { Settings } from '../types';
2
- export declare function isUsingLocalTranslations(settings: Settings): string | undefined;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isUsingLocalTranslations = isUsingLocalTranslations;
4
- // returns true if the project is configured to use local translations
5
- function isUsingLocalTranslations(settings) {
6
- return settings.files && settings.files.placeholderPaths.gt;
7
- }
@@ -1,2 +0,0 @@
1
- import { Settings } from '../types';
2
- export declare function validateSettings(settings: Settings): void;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateSettings = validateSettings;
4
- const generaltranslation_1 = require("generaltranslation");
5
- const console_1 = require("../console");
6
- function validateSettings(settings) {
7
- // Validate locales
8
- for (const locale of settings.locales) {
9
- if (!(0, generaltranslation_1.isValidLocale)(locale)) {
10
- (0, console_1.logErrorAndExit)(`Provided locales: "${settings?.locales?.join()}", ${locale} is not a valid locale!`);
11
- }
12
- }
13
- if (settings.defaultLocale && !(0, generaltranslation_1.isValidLocale)(settings.defaultLocale)) {
14
- (0, console_1.logErrorAndExit)(`defaultLocale: ${settings.defaultLocale} is not a valid locale!`);
15
- }
16
- // defaultLocale cannot be a superset of any other locale
17
- if (settings.defaultLocale &&
18
- settings.locales.some((locale) => (0, generaltranslation_1.isSupersetLocale)(settings.defaultLocale, locale) &&
19
- !(0, generaltranslation_1.isSupersetLocale)(locale, settings.defaultLocale))) {
20
- const locale = settings.locales.find((locale) => (0, generaltranslation_1.isSupersetLocale)(settings.defaultLocale, locale));
21
- (0, console_1.logErrorAndExit)(`defaultLocale: ${settings.defaultLocale} is a superset of another locale (${locale})! Please change the defaultLocale to a more specific locale.`);
22
- }
23
- }
@@ -1,5 +0,0 @@
1
- export declare function colorizeFilepath(filepath: string): string;
2
- export declare function colorizeComponent(component: string): string;
3
- export declare function colorizeIdString(id: string): string;
4
- export declare function colorizeContent(content: string): string;
5
- export declare function colorizeLine(line: string): string;
@@ -1,26 +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.colorizeFilepath = colorizeFilepath;
7
- exports.colorizeComponent = colorizeComponent;
8
- exports.colorizeIdString = colorizeIdString;
9
- exports.colorizeContent = colorizeContent;
10
- exports.colorizeLine = colorizeLine;
11
- const chalk_1 = __importDefault(require("chalk"));
12
- function colorizeFilepath(filepath) {
13
- return chalk_1.default.cyan(filepath);
14
- }
15
- function colorizeComponent(component) {
16
- return chalk_1.default.yellow(component);
17
- }
18
- function colorizeIdString(id) {
19
- return chalk_1.default.yellow(id);
20
- }
21
- function colorizeContent(content) {
22
- return chalk_1.default.yellow(content);
23
- }
24
- function colorizeLine(line) {
25
- return chalk_1.default.gray(line);
26
- }
@@ -1 +0,0 @@
1
- export * from './logging';
@@ -1,20 +0,0 @@
1
- "use strict";
2
- // This file is kept for backwards compatibility.
3
- // All functionality has been moved to logging.ts
4
- // Please use the functions exported from src/console/index.ts instead
5
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = { enumerable: true, get: function() { return m[k]; } };
10
- }
11
- Object.defineProperty(o, k2, desc);
12
- }) : (function(o, m, k, k2) {
13
- if (k2 === undefined) k2 = k;
14
- o[k2] = m[k];
15
- }));
16
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- __exportStar(require("./logging"), exports);
@@ -1 +0,0 @@
1
- export * from './index';
@@ -1,20 +0,0 @@
1
- "use strict";
2
- // This file is kept for backwards compatibility.
3
- // All error messages have been moved to index.ts
4
- // Please use the error constants exported from src/console/index.ts instead
5
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = { enumerable: true, get: function() { return m[k]; } };
10
- }
11
- Object.defineProperty(o, k2, desc);
12
- }) : (function(o, m, k, k2) {
13
- if (k2 === undefined) k2 = k;
14
- o[k2] = m[k];
15
- }));
16
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- __exportStar(require("./index"), exports);
@@ -1,19 +0,0 @@
1
- export * from './logging';
2
- export declare const warnApiKeyInConfigSync: (optionsFilepath: string) => string;
3
- export declare const warnVariablePropSync: (file: string, attrName: string, value: string, location?: string) => string;
4
- export declare const warnHasUnwrappedExpressionSync: (file: string, unwrappedExpressions: string[], id?: string, location?: string) => string;
5
- export declare const warnNonStaticExpressionSync: (file: string, attrName: string, value: string, location?: string) => string;
6
- export declare const warnTemplateLiteralSync: (file: string, value: string, location?: string) => string;
7
- export declare const warnNonStringSync: (file: string, value: string, location?: string) => string;
8
- export declare const warnTernarySync: (file: string, location?: string) => string;
9
- export declare const withLocation: (file: string, message: string, location?: string) => string;
10
- export declare const noLocalesError = "No locales found! Please provide a list of locales to translate to, or specify them in your gt.config.json file.";
11
- export declare const noDefaultLocaleError = "No default locale found! Please provide a default locale, or specify it in your gt.config.json file.";
12
- export declare const noFilesError = "Incorrect or missing files configuration! Please make sure your files are configured correctly in your gt.config.json file.";
13
- export declare const noSourceFileError = "No source file found! Please double check your translations directory and default locale.";
14
- export declare const noDataFormatError = "No data format found! Please make sure your translationsDir parameter ends with a supported file extension.";
15
- export declare const noSupportedDataFormatError = "Unsupported data format! Please make sure your translationsDir parameter ends with a supported file extension.";
16
- export declare const noApiKeyError = "No API key found! Please provide an API key using the --api-key flag or set the GT_API_KEY environment variable.";
17
- export declare const devApiKeyError = "You are using a development API key. Please use a production API key to use the General Translation API.\nYou can generate a production API key with the command: npx gtx-cli auth -t production";
18
- export declare const noProjectIdError = "No project ID found! Please provide a project ID using the --project-id flag, specify it in your gt.config.json file, or set the GT_PROJECT_ID environment variable.";
19
- export declare const noVersionIdError = "No version ID found! Please provide a version ID using the --version-id flag or specify it in your gt.config.json file as the _versionId property.";
@@ -1,48 +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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.noVersionIdError = exports.noProjectIdError = exports.devApiKeyError = exports.noApiKeyError = exports.noSupportedDataFormatError = exports.noDataFormatError = exports.noSourceFileError = exports.noFilesError = exports.noDefaultLocaleError = exports.noLocalesError = exports.withLocation = exports.warnTernarySync = exports.warnNonStringSync = exports.warnTemplateLiteralSync = exports.warnNonStaticExpressionSync = exports.warnHasUnwrappedExpressionSync = exports.warnVariablePropSync = exports.warnApiKeyInConfigSync = void 0;
18
- // Export all logging functions
19
- __exportStar(require("./logging"), exports);
20
- const colors_1 = require("./colors");
21
- // Synchronous wrappers for backward compatibility
22
- const warnApiKeyInConfigSync = (optionsFilepath) => `${(0, colors_1.colorizeFilepath)(optionsFilepath)}: Your API key is exposed! Please remove it from the file and include it as an environment variable.`;
23
- exports.warnApiKeyInConfigSync = warnApiKeyInConfigSync;
24
- const warnVariablePropSync = (file, attrName, value, location) => (0, exports.withLocation)(file, `${(0, colors_1.colorizeComponent)('<T>')} component has dynamic attribute ${(0, colors_1.colorizeIdString)(attrName)} with value: ${(0, colors_1.colorizeContent)(value)}. Change ${(0, colors_1.colorizeIdString)(attrName)} to ensure this content is translated.`, location);
25
- exports.warnVariablePropSync = warnVariablePropSync;
26
- const warnHasUnwrappedExpressionSync = (file, unwrappedExpressions, id, location) => (0, exports.withLocation)(file, `${(0, colors_1.colorizeComponent)('<T>')} component${id ? ` with id ${(0, colors_1.colorizeIdString)(id)}` : ''} has children that could change at runtime. Use a variable component like ${(0, colors_1.colorizeComponent)('<Var>')} to ensure this content is translated.\n${(0, colors_1.colorizeContent)(unwrappedExpressions.join('\n'))}`, location);
27
- exports.warnHasUnwrappedExpressionSync = warnHasUnwrappedExpressionSync;
28
- const warnNonStaticExpressionSync = (file, attrName, value, location) => (0, exports.withLocation)(file, `Found non-static expression for attribute ${(0, colors_1.colorizeIdString)(attrName)}: ${(0, colors_1.colorizeContent)(value)}. Change "${(0, colors_1.colorizeIdString)(attrName)}" to ensure this content is translated.`, location);
29
- exports.warnNonStaticExpressionSync = warnNonStaticExpressionSync;
30
- const warnTemplateLiteralSync = (file, value, location) => (0, exports.withLocation)(file, `Found template literal with quasis (${(0, colors_1.colorizeContent)(value)}). Change the template literal to a string to ensure this content is translated.`, location);
31
- exports.warnTemplateLiteralSync = warnTemplateLiteralSync;
32
- const warnNonStringSync = (file, value, location) => (0, exports.withLocation)(file, `Found non-string literal (${(0, colors_1.colorizeContent)(value)}). Change the value to a string literal to ensure this content is translated.`, location);
33
- exports.warnNonStringSync = warnNonStringSync;
34
- const warnTernarySync = (file, location) => (0, exports.withLocation)(file, 'Found ternary expression. A Branch component may be more appropriate here.', location);
35
- exports.warnTernarySync = warnTernarySync;
36
- const withLocation = (file, message, location) => `${(0, colors_1.colorizeFilepath)(file)}${location ? ` (${(0, colors_1.colorizeLine)(location)})` : ''}: ${message}`;
37
- exports.withLocation = withLocation;
38
- // Re-export error messages
39
- exports.noLocalesError = `No locales found! Please provide a list of locales to translate to, or specify them in your gt.config.json file.`;
40
- exports.noDefaultLocaleError = `No default locale found! Please provide a default locale, or specify it in your gt.config.json file.`;
41
- exports.noFilesError = `Incorrect or missing files configuration! Please make sure your files are configured correctly in your gt.config.json file.`;
42
- exports.noSourceFileError = `No source file found! Please double check your translations directory and default locale.`;
43
- exports.noDataFormatError = `No data format found! Please make sure your translationsDir parameter ends with a supported file extension.`;
44
- exports.noSupportedDataFormatError = `Unsupported data format! Please make sure your translationsDir parameter ends with a supported file extension.`;
45
- exports.noApiKeyError = `No API key found! Please provide an API key using the --api-key flag or set the GT_API_KEY environment variable.`;
46
- exports.devApiKeyError = `You are using a development API key. Please use a production API key to use the General Translation API.\nYou can generate a production API key with the command: npx gtx-cli auth -t production`;
47
- exports.noProjectIdError = `No project ID found! Please provide a project ID using the --project-id flag, specify it in your gt.config.json file, or set the GT_PROJECT_ID environment variable.`;
48
- exports.noVersionIdError = `No version ID found! Please provide a version ID using the --version-id flag or specify it in your gt.config.json file as the _versionId property.`;