gtx-cli 2.5.0-alpha.0 → 2.5.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/api/collectUserEditDiffs.d.ts +2 -7
  3. package/dist/api/collectUserEditDiffs.js +33 -78
  4. package/dist/api/downloadFileBatch.d.ts +11 -10
  5. package/dist/api/downloadFileBatch.js +120 -127
  6. package/dist/api/saveLocalEdits.js +18 -15
  7. package/dist/cli/base.js +1 -1
  8. package/dist/cli/commands/stage.d.ts +8 -2
  9. package/dist/cli/commands/stage.js +25 -7
  10. package/dist/cli/commands/translate.d.ts +4 -2
  11. package/dist/cli/commands/translate.js +5 -6
  12. package/dist/cli/flags.js +4 -1
  13. package/dist/config/generateSettings.js +10 -0
  14. package/dist/console/colors.d.ts +0 -1
  15. package/dist/console/colors.js +0 -3
  16. package/dist/console/index.d.ts +0 -6
  17. package/dist/console/index.js +2 -13
  18. package/dist/console/logging.d.ts +1 -1
  19. package/dist/console/logging.js +3 -4
  20. package/dist/formats/files/translate.d.ts +2 -2
  21. package/dist/formats/files/translate.js +31 -5
  22. package/dist/fs/config/downloadedVersions.d.ts +10 -3
  23. package/dist/fs/config/downloadedVersions.js +8 -0
  24. package/dist/fs/config/updateVersions.d.ts +2 -1
  25. package/dist/git/branches.d.ts +7 -0
  26. package/dist/git/branches.js +88 -0
  27. package/dist/react/{jsx/utils/jsxParsing → data-_gt}/addGTIdentifierToSyntaxTree.d.ts +1 -2
  28. package/dist/react/{jsx/utils/jsxParsing → data-_gt}/addGTIdentifierToSyntaxTree.js +6 -30
  29. package/dist/react/jsx/evaluateJsx.d.ts +6 -5
  30. package/dist/react/jsx/evaluateJsx.js +4 -32
  31. package/dist/react/jsx/trimJsxStringChildren.d.ts +7 -0
  32. package/dist/react/jsx/trimJsxStringChildren.js +122 -0
  33. package/dist/react/jsx/utils/constants.d.ts +0 -2
  34. package/dist/react/jsx/utils/constants.js +2 -11
  35. package/dist/react/jsx/utils/parseJsx.d.ts +21 -0
  36. package/dist/react/jsx/utils/parseJsx.js +259 -0
  37. package/dist/react/jsx/utils/parseStringFunction.js +141 -4
  38. package/dist/react/parse/createInlineUpdates.js +70 -19
  39. package/dist/types/branch.d.ts +14 -0
  40. package/dist/types/branch.js +1 -0
  41. package/dist/types/data.d.ts +1 -1
  42. package/dist/types/files.d.ts +7 -0
  43. package/dist/types/index.d.ts +7 -0
  44. package/dist/utils/SpinnerManager.d.ts +30 -0
  45. package/dist/utils/SpinnerManager.js +73 -0
  46. package/dist/utils/gitDiff.js +18 -16
  47. package/dist/workflow/BranchStep.d.ts +13 -0
  48. package/dist/workflow/BranchStep.js +131 -0
  49. package/dist/workflow/DownloadStep.d.ts +19 -0
  50. package/dist/workflow/DownloadStep.js +127 -0
  51. package/dist/workflow/EnqueueStep.d.ts +15 -0
  52. package/dist/workflow/EnqueueStep.js +33 -0
  53. package/dist/workflow/PollJobsStep.d.ts +31 -0
  54. package/dist/workflow/PollJobsStep.js +286 -0
  55. package/dist/workflow/SetupStep.d.ts +16 -0
  56. package/dist/workflow/SetupStep.js +72 -0
  57. package/dist/workflow/UploadStep.d.ts +21 -0
  58. package/dist/workflow/UploadStep.js +72 -0
  59. package/dist/workflow/UserEditDiffsStep.d.ts +11 -0
  60. package/dist/workflow/UserEditDiffsStep.js +30 -0
  61. package/dist/workflow/Workflow.d.ts +4 -0
  62. package/dist/workflow/Workflow.js +2 -0
  63. package/dist/workflow/download.d.ts +22 -0
  64. package/dist/workflow/download.js +104 -0
  65. package/dist/workflow/stage.d.ts +14 -0
  66. package/dist/workflow/stage.js +76 -0
  67. package/package.json +3 -4
  68. package/dist/api/checkFileTranslations.d.ts +0 -23
  69. package/dist/api/checkFileTranslations.js +0 -281
  70. package/dist/api/sendFiles.d.ts +0 -17
  71. package/dist/api/sendFiles.js +0 -127
  72. package/dist/api/sendUserEdits.d.ts +0 -19
  73. package/dist/api/sendUserEdits.js +0 -15
  74. package/dist/cli/commands/edits.d.ts +0 -8
  75. package/dist/cli/commands/edits.js +0 -32
  76. package/dist/react/jsx/utils/buildImportMap.d.ts +0 -9
  77. package/dist/react/jsx/utils/buildImportMap.js +0 -30
  78. package/dist/react/jsx/utils/getPathsAndAliases.d.ts +0 -17
  79. package/dist/react/jsx/utils/getPathsAndAliases.js +0 -89
  80. package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.d.ts +0 -6
  81. package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +0 -199
  82. package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.d.ts +0 -13
  83. package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js +0 -42
  84. package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.d.ts +0 -5
  85. package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +0 -69
  86. package/dist/react/jsx/utils/jsxParsing/parseJsx.d.ts +0 -60
  87. package/dist/react/jsx/utils/jsxParsing/parseJsx.js +0 -949
  88. package/dist/react/jsx/utils/jsxParsing/parseTProps.d.ts +0 -8
  89. package/dist/react/jsx/utils/jsxParsing/parseTProps.js +0 -47
  90. package/dist/react/jsx/utils/jsxParsing/types.d.ts +0 -48
  91. package/dist/react/jsx/utils/jsxParsing/types.js +0 -34
  92. package/dist/react/jsx/utils/resolveImportPath.d.ts +0 -11
  93. package/dist/react/jsx/utils/resolveImportPath.js +0 -111
@@ -0,0 +1,127 @@
1
+ import chalk from 'chalk';
2
+ import { WorkflowStep } from './Workflow.js';
3
+ import { createProgressBar, logError, logWarning } from '../console/logging.js';
4
+ import { downloadFileBatch, } from '../api/downloadFileBatch.js';
5
+ export class DownloadTranslationsStep extends WorkflowStep {
6
+ gt;
7
+ settings;
8
+ spinner = null;
9
+ constructor(gt, settings) {
10
+ super();
11
+ this.gt = gt;
12
+ this.settings = settings;
13
+ }
14
+ async run({ fileTracker, resolveOutputPath, forceDownload, }) {
15
+ this.spinner = createProgressBar(fileTracker.completed.size);
16
+ this.spinner.start('Downloading files...');
17
+ // Download ready files
18
+ const success = await this.downloadFiles(fileTracker, resolveOutputPath, forceDownload);
19
+ if (success) {
20
+ this.spinner.stop(chalk.green('Downloaded files successfully'));
21
+ }
22
+ else {
23
+ this.spinner.stop(chalk.red('Failed to download files'));
24
+ }
25
+ return success;
26
+ }
27
+ async downloadFiles(fileTracker, resolveOutputPath, forceDownload) {
28
+ try {
29
+ // Only download files that are marked as completed
30
+ const currentQueryData = Array.from(fileTracker.completed.values());
31
+ // If no files to download, we're done
32
+ if (currentQueryData.length === 0) {
33
+ return true;
34
+ }
35
+ // Check for translations
36
+ const responseData = await this.gt.queryFileData({
37
+ translatedFiles: currentQueryData.map((item) => ({
38
+ fileId: item.fileId,
39
+ versionId: item.versionId,
40
+ branchId: item.branchId,
41
+ locale: item.locale,
42
+ })),
43
+ });
44
+ const translatedFiles = responseData.translatedFiles || [];
45
+ // Filter for ready translations
46
+ const readyTranslations = translatedFiles.filter((file) => file.completedAt !== null);
47
+ // Prepare batch download data
48
+ const batchFiles = readyTranslations
49
+ .map((translation) => {
50
+ const fileKey = `${translation.branchId}:${translation.fileId}:${translation.versionId}:${translation.locale}`;
51
+ const fileProperties = fileTracker.completed.get(fileKey);
52
+ if (!fileProperties) {
53
+ return null;
54
+ }
55
+ const outputPath = resolveOutputPath(fileProperties.fileName, translation.locale);
56
+ // Skip downloading GTJSON files that are not in the files configuration
57
+ if (outputPath === null) {
58
+ fileTracker.completed.delete(fileKey);
59
+ fileTracker.skipped.set(fileKey, fileProperties);
60
+ return null;
61
+ }
62
+ return {
63
+ branchId: translation.branchId,
64
+ fileId: translation.fileId,
65
+ versionId: translation.versionId,
66
+ locale: translation.locale,
67
+ inputPath: fileProperties.fileName,
68
+ outputPath,
69
+ };
70
+ })
71
+ .filter((file) => file !== null);
72
+ if (batchFiles.length > 0) {
73
+ const batchResult = await this.downloadFilesWithRetry(fileTracker, batchFiles, forceDownload);
74
+ this.spinner?.stop(chalk.green(`Downloaded ${batchResult.successful.length} files${batchResult.skipped.length > 0 ? `, skipped ${batchResult.skipped.length} files` : ''}`));
75
+ if (batchResult.failed.length > 0) {
76
+ logWarning(`Failed to download ${batchResult.failed.length} files: ${batchResult.failed.map((f) => f.inputPath).join('\n')}`);
77
+ }
78
+ }
79
+ else {
80
+ this.spinner?.stop(chalk.green('No files to download'));
81
+ }
82
+ return true;
83
+ }
84
+ catch (error) {
85
+ this.spinner?.stop(chalk.red('An error occurred while downloading translations'));
86
+ logError(chalk.red('Error: ') + error);
87
+ return false;
88
+ }
89
+ }
90
+ async downloadFilesWithRetry(fileTracker, files, forceDownload, maxRetries = 3, initialDelay = 1000) {
91
+ let remainingFiles = files;
92
+ let allSuccessful = [];
93
+ let retryCount = 0;
94
+ let allSkipped = [];
95
+ while (remainingFiles.length > 0 && retryCount <= maxRetries) {
96
+ const batchResult = await downloadFileBatch(fileTracker, remainingFiles, this.settings, forceDownload);
97
+ allSuccessful = [...allSuccessful, ...batchResult.successful];
98
+ allSkipped = [...allSkipped, ...batchResult.skipped];
99
+ this.spinner?.advance(batchResult.successful.length +
100
+ batchResult.skipped.length +
101
+ batchResult.failed.length);
102
+ // If no failures or we've exhausted retries, we're done
103
+ if (batchResult.failed.length === 0 || retryCount === maxRetries) {
104
+ return {
105
+ successful: allSuccessful,
106
+ failed: batchResult.failed,
107
+ skipped: allSkipped,
108
+ };
109
+ }
110
+ // Calculate exponential backoff delay
111
+ const delay = initialDelay * Math.pow(2, retryCount);
112
+ logError(chalk.yellow(`Retrying ${batchResult.failed.length} failed file(s) in ${delay}ms (attempt ${retryCount + 1}/${maxRetries})...`));
113
+ // Wait before retrying
114
+ await new Promise((resolve) => setTimeout(resolve, delay));
115
+ remainingFiles = batchResult.failed;
116
+ retryCount++;
117
+ }
118
+ return {
119
+ successful: allSuccessful,
120
+ failed: remainingFiles,
121
+ skipped: allSkipped,
122
+ };
123
+ }
124
+ async wait() {
125
+ return;
126
+ }
127
+ }
@@ -0,0 +1,15 @@
1
+ import type { EnqueueFilesResult } from 'generaltranslation/types';
2
+ import { WorkflowStep } from './Workflow.js';
3
+ import { GT } from 'generaltranslation';
4
+ import { Settings } from '../types/index.js';
5
+ import type { FileReference } from 'generaltranslation/types';
6
+ export declare class EnqueueStep extends WorkflowStep<FileReference[], EnqueueFilesResult> {
7
+ private gt;
8
+ private settings;
9
+ private force?;
10
+ private spinner;
11
+ private result;
12
+ constructor(gt: GT, settings: Settings, force?: boolean | undefined);
13
+ run(files: FileReference[]): Promise<EnqueueFilesResult>;
14
+ wait(): Promise<void>;
15
+ }
@@ -0,0 +1,33 @@
1
+ import { WorkflowStep } from './Workflow.js';
2
+ import { createSpinner } from '../console/logging.js';
3
+ import chalk from 'chalk';
4
+ export class EnqueueStep extends WorkflowStep {
5
+ gt;
6
+ settings;
7
+ force;
8
+ spinner = createSpinner('dots');
9
+ result = null;
10
+ constructor(gt, settings, force) {
11
+ super();
12
+ this.gt = gt;
13
+ this.settings = settings;
14
+ this.force = force;
15
+ }
16
+ async run(files) {
17
+ this.spinner.start('Enqueuing translations...');
18
+ this.result = await this.gt.enqueueFiles(files, {
19
+ sourceLocale: this.settings.defaultLocale,
20
+ targetLocales: this.settings.locales,
21
+ publish: this.settings.publish,
22
+ requireApproval: this.settings.stageTranslations,
23
+ modelProvider: this.settings.modelProvider,
24
+ force: this.force,
25
+ });
26
+ return this.result;
27
+ }
28
+ async wait() {
29
+ if (this.result) {
30
+ this.spinner.stop(chalk.green('Translations enqueued successfully'));
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,31 @@
1
+ import { WorkflowStep } from './Workflow.js';
2
+ import { GT } from 'generaltranslation';
3
+ import { EnqueueFilesResult } from 'generaltranslation/types';
4
+ import type { FileProperties } from '../types/files.js';
5
+ export type PollJobsInput = {
6
+ fileTracker: FileStatusTracker;
7
+ fileQueryData: FileProperties[];
8
+ jobData: EnqueueFilesResult;
9
+ timeoutDuration: number;
10
+ forceRetranslation?: boolean;
11
+ };
12
+ export type FileStatusTracker = {
13
+ completed: Map<string, FileProperties>;
14
+ inProgress: Map<string, FileProperties>;
15
+ failed: Map<string, FileProperties>;
16
+ skipped: Map<string, FileProperties>;
17
+ };
18
+ export type PollJobsOutput = {
19
+ success: boolean;
20
+ fileTracker: FileStatusTracker;
21
+ };
22
+ export declare class PollTranslationJobsStep extends WorkflowStep<PollJobsInput, PollJobsOutput> {
23
+ private gt;
24
+ private spinner;
25
+ private previousProgress;
26
+ constructor(gt: GT);
27
+ run({ fileTracker, fileQueryData, jobData, timeoutDuration, forceRetranslation, }: PollJobsInput): Promise<PollJobsOutput>;
28
+ private updateSpinner;
29
+ private generateStatusSuffixText;
30
+ wait(): Promise<void>;
31
+ }
@@ -0,0 +1,286 @@
1
+ import chalk from 'chalk';
2
+ import { WorkflowStep } from './Workflow.js';
3
+ import { createProgressBar, logError } from '../console/logging.js';
4
+ import { TEMPLATE_FILE_NAME } from '../cli/commands/stage.js';
5
+ export class PollTranslationJobsStep extends WorkflowStep {
6
+ gt;
7
+ spinner = null;
8
+ previousProgress = 0;
9
+ constructor(gt) {
10
+ super();
11
+ this.gt = gt;
12
+ }
13
+ async run({ fileTracker, fileQueryData, jobData, timeoutDuration, forceRetranslation, }) {
14
+ const startTime = Date.now();
15
+ this.spinner = createProgressBar(fileQueryData.length);
16
+ const spinnerMessage = forceRetranslation
17
+ ? 'Waiting for retranslation...'
18
+ : 'Waiting for translation...';
19
+ this.spinner.start(spinnerMessage);
20
+ // Build a map of branchId:fileId:versionId:locale -> FileProperties
21
+ const filePropertiesMap = new Map();
22
+ fileQueryData.forEach((item) => {
23
+ filePropertiesMap.set(`${item.branchId}:${item.fileId}:${item.versionId}:${item.locale}`, item);
24
+ });
25
+ // Initial query to check which files already have translations
26
+ const initialFileData = await this.gt.queryFileData({
27
+ translatedFiles: fileQueryData.map((item) => ({
28
+ fileId: item.fileId,
29
+ versionId: item.versionId,
30
+ branchId: item.branchId,
31
+ locale: item.locale,
32
+ })),
33
+ });
34
+ const existingTranslations = initialFileData.translatedFiles || [];
35
+ // Mark all existing translations as completed
36
+ existingTranslations.forEach((translation) => {
37
+ if (!translation.completedAt) {
38
+ return;
39
+ }
40
+ const fileKey = `${translation.branchId}:${translation.fileId}:${translation.versionId}:${translation.locale}`;
41
+ const fileProperties = filePropertiesMap.get(fileKey);
42
+ if (fileProperties) {
43
+ fileTracker.completed.set(fileKey, fileProperties);
44
+ }
45
+ });
46
+ // Build a map of jobs for quick lookup:
47
+ // branchId:fileId:versionId:locale -> job
48
+ const jobMap = new Map();
49
+ Object.entries(jobData.jobData).forEach(([jobId, job]) => {
50
+ const key = `${job.branchId}:${job.fileId}:${job.versionId}:${job.targetLocale}`;
51
+ jobMap.set(key, { ...job, jobId });
52
+ });
53
+ // Build a map of jobs for quick lookup:
54
+ // jobId -> file data for the job
55
+ const jobFileMap = new Map();
56
+ Object.entries(jobData.jobData).forEach(([jobId, job]) => {
57
+ jobFileMap.set(jobId, {
58
+ branchId: job.branchId,
59
+ fileId: job.fileId,
60
+ versionId: job.versionId,
61
+ locale: job.targetLocale,
62
+ });
63
+ });
64
+ // Categorize each file query item
65
+ for (const item of fileQueryData) {
66
+ const fileKey = `${item.branchId}:${item.fileId}:${item.versionId}:${item.locale}`;
67
+ // Check if translation already exists (completedAt is truthy)
68
+ const existingTranslation = fileTracker.completed.get(fileKey);
69
+ if (existingTranslation) {
70
+ continue;
71
+ }
72
+ // Check if there's a job for this file
73
+ const jobKey = `${item.branchId}:${item.fileId}:${item.versionId}:${item.locale}`;
74
+ const job = jobMap.get(jobKey);
75
+ if (job) {
76
+ // Job exists - mark as in progress initially
77
+ fileTracker.inProgress.set(fileKey, item);
78
+ }
79
+ else {
80
+ // No job and no existing translation - mark as skipped
81
+ fileTracker.skipped.set(fileKey, item);
82
+ }
83
+ }
84
+ // Update spinner with initial status
85
+ this.updateSpinner(fileTracker, fileQueryData);
86
+ // If force retranslation, don't skip the initial check
87
+ if (!forceRetranslation) {
88
+ // Check if all jobs are already complete
89
+ if (fileTracker.inProgress.size === 0) {
90
+ this.spinner.stop(chalk.green('All translations ready'));
91
+ return { success: true, fileTracker };
92
+ }
93
+ }
94
+ // Calculate time until next 5-second interval since startTime
95
+ const msUntilNextInterval = Math.max(0, 5000 - ((Date.now() - startTime) % 5000));
96
+ return new Promise((resolve) => {
97
+ let intervalCheck;
98
+ setTimeout(() => {
99
+ intervalCheck = setInterval(async () => {
100
+ try {
101
+ // Query job status
102
+ const jobIds = Array.from(jobFileMap.keys());
103
+ const jobStatusResponse = await this.gt.checkJobStatus(jobIds);
104
+ // Update status based on job completion
105
+ for (const job of jobStatusResponse) {
106
+ const jobFileProperties = jobFileMap.get(job.jobId);
107
+ if (jobFileProperties) {
108
+ const fileKey = `${jobFileProperties.branchId}:${jobFileProperties.fileId}:${jobFileProperties.versionId}:${jobFileProperties.locale}`;
109
+ const fileProperties = filePropertiesMap.get(fileKey);
110
+ if (!fileProperties) {
111
+ continue;
112
+ }
113
+ if (job.status === 'completed') {
114
+ fileTracker.completed.set(fileKey, fileProperties);
115
+ fileTracker.inProgress.delete(fileKey);
116
+ jobFileMap.delete(job.jobId);
117
+ }
118
+ else if (job.status === 'failed') {
119
+ fileTracker.failed.set(fileKey, fileProperties);
120
+ fileTracker.inProgress.delete(fileKey);
121
+ jobFileMap.delete(job.jobId);
122
+ }
123
+ else if (job.status === 'unknown') {
124
+ fileTracker.skipped.set(fileKey, fileProperties);
125
+ fileTracker.inProgress.delete(fileKey);
126
+ jobFileMap.delete(job.jobId);
127
+ }
128
+ }
129
+ }
130
+ // Update spinner
131
+ this.updateSpinner(fileTracker, fileQueryData);
132
+ const elapsed = Date.now() - startTime;
133
+ const allJobsProcessed = fileTracker.inProgress.size === 0;
134
+ if (allJobsProcessed || elapsed >= timeoutDuration * 1000) {
135
+ clearInterval(intervalCheck);
136
+ if (fileTracker.inProgress.size === 0) {
137
+ this.spinner.stop(chalk.green('Translation jobs finished'));
138
+ resolve({ success: true, fileTracker });
139
+ }
140
+ else {
141
+ this.spinner.stop(chalk.red('Timed out waiting for translation jobs'));
142
+ resolve({ success: false, fileTracker });
143
+ }
144
+ }
145
+ }
146
+ catch (error) {
147
+ logError(chalk.red('Error checking job status: ') + error);
148
+ }
149
+ }, 5000);
150
+ }, msUntilNextInterval);
151
+ });
152
+ }
153
+ updateSpinner(fileTracker, fileQueryData) {
154
+ if (!this.spinner)
155
+ return;
156
+ const statusText = this.generateStatusSuffixText(fileTracker, fileQueryData);
157
+ const currentProgress = fileTracker.completed.size +
158
+ fileTracker.failed.size +
159
+ fileTracker.skipped.size;
160
+ const progressDelta = currentProgress - this.previousProgress;
161
+ this.spinner.advance(progressDelta, statusText);
162
+ this.previousProgress = currentProgress;
163
+ }
164
+ generateStatusSuffixText(fileTracker, fileQueryData) {
165
+ // Simple progress indicator
166
+ const progressText = `${chalk.green(`[${fileTracker.completed.size +
167
+ fileTracker.failed.size +
168
+ fileTracker.skipped.size}/${fileQueryData.length}]`)} translations completed`;
169
+ // Get terminal height to adapt our output
170
+ const terminalHeight = process.stdout.rows || 24;
171
+ // If terminal is very small, just show the basic progress
172
+ if (terminalHeight < 6) {
173
+ return progressText;
174
+ }
175
+ const newSuffixText = [progressText];
176
+ // Organize data by filename : locale
177
+ const fileStatus = new Map();
178
+ // Initialize with all files and locales from fileQueryData
179
+ for (const item of fileQueryData) {
180
+ if (!fileStatus.has(item.fileName)) {
181
+ fileStatus.set(item.fileName, {
182
+ completed: new Set(),
183
+ pending: new Set([item.locale]),
184
+ failed: new Set(),
185
+ skipped: new Set(),
186
+ });
187
+ }
188
+ else {
189
+ fileStatus.get(item.fileName)?.pending.add(item.locale);
190
+ }
191
+ }
192
+ // Mark which ones are completed, failed, or skipped
193
+ for (const [_, fileProperties] of fileTracker.completed) {
194
+ const { fileName, locale } = fileProperties;
195
+ const status = fileStatus.get(fileName);
196
+ if (status) {
197
+ status.pending.delete(locale);
198
+ status.completed.add(locale);
199
+ }
200
+ }
201
+ for (const [_, fileProperties] of fileTracker.failed) {
202
+ const { fileName, locale } = fileProperties;
203
+ const status = fileStatus.get(fileName);
204
+ if (status) {
205
+ status.pending.delete(locale);
206
+ status.failed.add(locale);
207
+ }
208
+ }
209
+ for (const [_, fileProperties] of fileTracker.skipped) {
210
+ const { fileName, locale } = fileProperties;
211
+ const status = fileStatus.get(fileName);
212
+ if (status) {
213
+ status.pending.delete(locale);
214
+ status.skipped.add(locale);
215
+ }
216
+ }
217
+ // Calculate how many files we can show based on terminal height
218
+ const filesArray = Array.from(fileStatus.entries());
219
+ const maxFilesToShow = Math.min(filesArray.length, terminalHeight - 3 // Header + progress + buffer
220
+ );
221
+ // Display each file with its status on a single line
222
+ for (let i = 0; i < maxFilesToShow; i++) {
223
+ const [fileName, status] = filesArray[i];
224
+ // Create condensed locale status
225
+ const localeStatuses = [];
226
+ // Add completed locales (green)
227
+ if (status.completed.size > 0) {
228
+ localeStatuses.push(...Array.from(status.completed).map((locale) => ({
229
+ locale,
230
+ status: 'completed',
231
+ })));
232
+ }
233
+ // Add skipped locales (green)
234
+ if (status.skipped.size > 0) {
235
+ localeStatuses.push(...Array.from(status.skipped).map((locale) => ({
236
+ locale,
237
+ status: 'skipped',
238
+ })));
239
+ }
240
+ // Add failed locales (red)
241
+ if (status.failed.size > 0) {
242
+ localeStatuses.push(...Array.from(status.failed).map((locale) => ({
243
+ locale,
244
+ status: 'failed',
245
+ })));
246
+ }
247
+ // Add pending locales (yellow)
248
+ if (status.pending.size > 0) {
249
+ localeStatuses.push(...Array.from(status.pending).map((locale) => ({
250
+ locale,
251
+ status: 'pending',
252
+ })));
253
+ }
254
+ // Sort localeStatuses by locale
255
+ localeStatuses.sort((a, b) => a.locale.localeCompare(b.locale));
256
+ // Add colors
257
+ const localeString = localeStatuses
258
+ .map((locale) => {
259
+ if (locale.status === 'completed') {
260
+ return chalk.green(locale.locale);
261
+ }
262
+ else if (locale.status === 'skipped') {
263
+ return chalk.gray(locale.locale);
264
+ }
265
+ else if (locale.status === 'failed') {
266
+ return chalk.red(locale.locale);
267
+ }
268
+ else if (locale.status === 'pending') {
269
+ return chalk.yellow(locale.locale);
270
+ }
271
+ })
272
+ .join(', ');
273
+ // Format the line
274
+ const prettyFileName = fileName === TEMPLATE_FILE_NAME ? '<React Elements>' : fileName;
275
+ newSuffixText.push(`${chalk.bold(prettyFileName)} [${localeString}]`);
276
+ }
277
+ // If we couldn't show all files, add an indicator
278
+ if (filesArray.length > maxFilesToShow) {
279
+ newSuffixText.push(`... and ${filesArray.length - maxFilesToShow} more files`);
280
+ }
281
+ return newSuffixText.join('\n');
282
+ }
283
+ async wait() {
284
+ return;
285
+ }
286
+ }
@@ -0,0 +1,16 @@
1
+ import { FileReference } from 'generaltranslation/types';
2
+ import { WorkflowStep } from './Workflow.js';
3
+ import { GT } from 'generaltranslation';
4
+ import { Settings } from '../types/index.js';
5
+ export declare class SetupStep extends WorkflowStep<FileReference[], FileReference[]> {
6
+ private gt;
7
+ private settings;
8
+ private timeoutMs;
9
+ private spinner;
10
+ private setupJobId;
11
+ private files;
12
+ private completed;
13
+ constructor(gt: GT, settings: Settings, timeoutMs: number);
14
+ run(files: FileReference[]): Promise<FileReference[]>;
15
+ wait(): Promise<void>;
16
+ }
@@ -0,0 +1,72 @@
1
+ import { WorkflowStep } from './Workflow.js';
2
+ import { createSpinner } from '../console/logging.js';
3
+ import chalk from 'chalk';
4
+ export class SetupStep extends WorkflowStep {
5
+ gt;
6
+ settings;
7
+ timeoutMs;
8
+ spinner = createSpinner('dots');
9
+ setupJobId = null;
10
+ files = null;
11
+ completed = false;
12
+ constructor(gt, settings, timeoutMs) {
13
+ super();
14
+ this.gt = gt;
15
+ this.settings = settings;
16
+ this.timeoutMs = timeoutMs;
17
+ }
18
+ async run(files) {
19
+ this.files = files;
20
+ this.spinner.start('Setting up project...');
21
+ if (files.length === 0) {
22
+ this.completed = true;
23
+ return [];
24
+ }
25
+ const result = await this.gt.setupProject(files, {
26
+ locales: this.settings.locales,
27
+ });
28
+ if (result.status === 'completed') {
29
+ this.completed = true;
30
+ return files;
31
+ }
32
+ if (result.status === 'queued') {
33
+ this.setupJobId = result.setupJobId;
34
+ return files;
35
+ }
36
+ // Unknown status
37
+ this.completed = true;
38
+ return files;
39
+ }
40
+ async wait() {
41
+ if (this.completed) {
42
+ this.spinner.stop(chalk.green('Setup successfully completed'));
43
+ return;
44
+ }
45
+ if (!this.setupJobId) {
46
+ this.spinner.stop(chalk.yellow('Setup status unknown — proceeding without setup'));
47
+ return;
48
+ }
49
+ // Poll for completion
50
+ const start = Date.now();
51
+ const pollInterval = 5000; // 5 seconds
52
+ while (Date.now() - start < this.timeoutMs) {
53
+ const status = await this.gt.checkJobStatus([this.setupJobId]);
54
+ console.log(status);
55
+ if (!status[0]) {
56
+ this.spinner.stop(chalk.yellow('Setup status unknown — proceeding without setup'));
57
+ return;
58
+ }
59
+ if (status[0].status === 'completed') {
60
+ this.spinner.stop(chalk.green('Setup successfully completed'));
61
+ return;
62
+ }
63
+ if (status[0].status === 'failed') {
64
+ this.spinner.stop(chalk.yellow(`Setup failed: ${status[0].error?.message || 'Unknown error'} — proceeding without setup`));
65
+ return;
66
+ }
67
+ await new Promise((r) => setTimeout(r, pollInterval));
68
+ }
69
+ // Timeout
70
+ this.spinner.stop(chalk.yellow('Setup timed out — proceeding without setup'));
71
+ }
72
+ }
@@ -0,0 +1,21 @@
1
+ import type { FileToUpload } from 'generaltranslation/types';
2
+ import { WorkflowStep } from './Workflow.js';
3
+ import { GT } from 'generaltranslation';
4
+ import { Settings } from '../types/index.js';
5
+ import { BranchData } from '../types/branch.js';
6
+ import type { FileReference } from 'generaltranslation/types';
7
+ export declare class UploadStep extends WorkflowStep<{
8
+ files: FileToUpload[];
9
+ branchData: BranchData;
10
+ }, FileReference[]> {
11
+ private gt;
12
+ private settings;
13
+ private spinner;
14
+ private result;
15
+ constructor(gt: GT, settings: Settings);
16
+ run({ files, branchData, }: {
17
+ files: FileToUpload[];
18
+ branchData: BranchData;
19
+ }): Promise<FileReference[]>;
20
+ wait(): Promise<void>;
21
+ }
@@ -0,0 +1,72 @@
1
+ import { WorkflowStep } from './Workflow.js';
2
+ import { createSpinner, logInfo } from '../console/logging.js';
3
+ import chalk from 'chalk';
4
+ export class UploadStep extends WorkflowStep {
5
+ gt;
6
+ settings;
7
+ spinner = createSpinner('dots');
8
+ result = null;
9
+ constructor(gt, settings) {
10
+ super();
11
+ this.gt = gt;
12
+ this.settings = settings;
13
+ }
14
+ async run({ files, branchData, }) {
15
+ if (files.length === 0) {
16
+ logInfo('No files to upload found... skipping upload step');
17
+ return [];
18
+ }
19
+ this.spinner.start(`Syncing ${files.length} file${files.length !== 1 ? 's' : ''} with General Translation API...`);
20
+ // First, figure out which files need to be uploaded
21
+ const fileData = await this.gt.queryFileData({
22
+ sourceFiles: files.map((f) => ({
23
+ fileId: f.fileId,
24
+ versionId: f.versionId,
25
+ branchId: f.branchId ?? branchData.currentBranch.id,
26
+ })),
27
+ });
28
+ // build a map of branch:fileId:versionId to fileData
29
+ const fileDataMap = new Map();
30
+ fileData.sourceFiles?.forEach((f) => {
31
+ fileDataMap.set(`${f.branchId}:${f.fileId}:${f.versionId}`, f);
32
+ });
33
+ // Build a list of files that need to be uploaded
34
+ const filesToUpload = [];
35
+ const filesToSkipUpload = [];
36
+ files.forEach((f) => {
37
+ if (fileDataMap.has(`${f.branchId ?? branchData.currentBranch.id}:${f.fileId}:${f.versionId}`)) {
38
+ filesToSkipUpload.push(f);
39
+ }
40
+ else {
41
+ filesToUpload.push(f);
42
+ }
43
+ });
44
+ const response = await this.gt.uploadSourceFiles(filesToUpload.map((f) => ({
45
+ source: {
46
+ ...f,
47
+ branchId: f.branchId ?? branchData.currentBranch.id,
48
+ locale: this.settings.defaultLocale,
49
+ incomingBranchId: branchData.incomingBranch?.id,
50
+ checkedOutBranchId: branchData.checkedOutBranch?.id,
51
+ },
52
+ })), {
53
+ sourceLocale: this.settings.defaultLocale,
54
+ modelProvider: this.settings.modelProvider,
55
+ });
56
+ this.result = response.uploadedFiles;
57
+ // Merge files that were already uploaded into the result
58
+ this.result.push(...filesToSkipUpload.map((f) => ({
59
+ fileId: f.fileId,
60
+ versionId: f.versionId,
61
+ branchId: f.branchId ?? branchData.currentBranch.id,
62
+ fileName: f.fileName,
63
+ fileFormat: f.fileFormat,
64
+ dataFormat: f.dataFormat,
65
+ })));
66
+ this.spinner.stop(chalk.green('Files uploaded successfully'));
67
+ return this.result;
68
+ }
69
+ async wait() {
70
+ return;
71
+ }
72
+ }