gtx-cli 2.4.15 → 2.5.0-alpha.1

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 (58) hide show
  1. package/dist/api/collectUserEditDiffs.d.ts +2 -7
  2. package/dist/api/collectUserEditDiffs.js +33 -78
  3. package/dist/api/downloadFileBatch.d.ts +11 -10
  4. package/dist/api/downloadFileBatch.js +120 -127
  5. package/dist/api/saveLocalEdits.js +18 -15
  6. package/dist/cli/base.js +1 -1
  7. package/dist/cli/commands/stage.d.ts +8 -2
  8. package/dist/cli/commands/stage.js +25 -7
  9. package/dist/cli/commands/translate.d.ts +4 -2
  10. package/dist/cli/commands/translate.js +5 -6
  11. package/dist/cli/flags.js +4 -1
  12. package/dist/config/generateSettings.js +10 -0
  13. package/dist/console/logging.d.ts +1 -1
  14. package/dist/console/logging.js +3 -4
  15. package/dist/formats/files/translate.d.ts +2 -2
  16. package/dist/formats/files/translate.js +12 -7
  17. package/dist/fs/config/downloadedVersions.d.ts +10 -3
  18. package/dist/fs/config/downloadedVersions.js +8 -0
  19. package/dist/fs/config/updateVersions.d.ts +2 -1
  20. package/dist/git/branches.d.ts +7 -0
  21. package/dist/git/branches.js +88 -0
  22. package/dist/types/branch.d.ts +14 -0
  23. package/dist/types/branch.js +1 -0
  24. package/dist/types/data.d.ts +1 -1
  25. package/dist/types/files.d.ts +7 -0
  26. package/dist/types/index.d.ts +7 -0
  27. package/dist/utils/SpinnerManager.d.ts +30 -0
  28. package/dist/utils/SpinnerManager.js +73 -0
  29. package/dist/utils/gitDiff.js +18 -16
  30. package/dist/workflow/BranchStep.d.ts +13 -0
  31. package/dist/workflow/BranchStep.js +131 -0
  32. package/dist/workflow/DownloadStep.d.ts +19 -0
  33. package/dist/workflow/DownloadStep.js +127 -0
  34. package/dist/workflow/EnqueueStep.d.ts +15 -0
  35. package/dist/workflow/EnqueueStep.js +33 -0
  36. package/dist/workflow/PollJobsStep.d.ts +31 -0
  37. package/dist/workflow/PollJobsStep.js +284 -0
  38. package/dist/workflow/SetupStep.d.ts +16 -0
  39. package/dist/workflow/SetupStep.js +71 -0
  40. package/dist/workflow/UploadStep.d.ts +21 -0
  41. package/dist/workflow/UploadStep.js +72 -0
  42. package/dist/workflow/UserEditDiffsStep.d.ts +11 -0
  43. package/dist/workflow/UserEditDiffsStep.js +30 -0
  44. package/dist/workflow/Workflow.d.ts +4 -0
  45. package/dist/workflow/Workflow.js +2 -0
  46. package/dist/workflow/download.d.ts +22 -0
  47. package/dist/workflow/download.js +104 -0
  48. package/dist/workflow/stage.d.ts +14 -0
  49. package/dist/workflow/stage.js +76 -0
  50. package/package.json +4 -5
  51. package/dist/api/checkFileTranslations.d.ts +0 -23
  52. package/dist/api/checkFileTranslations.js +0 -281
  53. package/dist/api/sendFiles.d.ts +0 -17
  54. package/dist/api/sendFiles.js +0 -127
  55. package/dist/api/sendUserEdits.d.ts +0 -19
  56. package/dist/api/sendUserEdits.js +0 -15
  57. package/dist/cli/commands/edits.d.ts +0 -8
  58. package/dist/cli/commands/edits.js +0 -32
@@ -0,0 +1,131 @@
1
+ import { WorkflowStep } from './Workflow.js';
2
+ import { createSpinner, logError, logErrorAndExit, } from '../console/logging.js';
3
+ import chalk from 'chalk';
4
+ import { getCurrentBranch, getIncomingBranches, getCheckedOutBranches, } from '../git/branches.js';
5
+ import { ApiError } from 'generaltranslation/errors';
6
+ // Step 1: Resolve the current branch id & update API with branch information
7
+ export class BranchStep extends WorkflowStep {
8
+ spinner = createSpinner('dots');
9
+ branchData;
10
+ settings;
11
+ gt;
12
+ constructor(gt, settings) {
13
+ super();
14
+ this.gt = gt;
15
+ this.settings = settings;
16
+ this.branchData = {
17
+ currentBranch: {
18
+ id: '',
19
+ name: '',
20
+ },
21
+ incomingBranch: null,
22
+ checkedOutBranch: null,
23
+ };
24
+ }
25
+ async run() {
26
+ this.spinner.start(`Resolving branch information...`);
27
+ // First get some info about the branches we're working with
28
+ let current = null;
29
+ let incoming = [];
30
+ let checkedOut = [];
31
+ let useDefaultBranch = true;
32
+ if (this.settings.branchOptions.enabled &&
33
+ this.settings.branchOptions.autoDetectBranches) {
34
+ const [currentResult, incomingResult, checkedOutResult] = await Promise.all([
35
+ getCurrentBranch(this.settings.branchOptions.remoteName),
36
+ getIncomingBranches(this.settings.branchOptions.remoteName),
37
+ getCheckedOutBranches(this.settings.branchOptions.remoteName),
38
+ ]);
39
+ current = currentResult;
40
+ incoming = incomingResult;
41
+ checkedOut = checkedOutResult;
42
+ useDefaultBranch = false;
43
+ }
44
+ if (this.settings.branchOptions.enabled &&
45
+ this.settings.branchOptions.currentBranch) {
46
+ current = {
47
+ currentBranchName: this.settings.branchOptions.currentBranch,
48
+ defaultBranch: current?.defaultBranch ?? false, // we have no way of knowing if this is the default branch without using the auto-detection logic
49
+ };
50
+ useDefaultBranch = false;
51
+ }
52
+ const branchData = await this.gt.queryBranchData({
53
+ branchNames: [
54
+ ...(current ? [current.currentBranchName] : []),
55
+ ...incoming,
56
+ ...checkedOut,
57
+ ],
58
+ });
59
+ if (useDefaultBranch) {
60
+ if (!branchData.defaultBranch) {
61
+ const createBranchResult = await this.gt.createBranch({
62
+ branchName: 'main', // name doesn't matter for default branch
63
+ defaultBranch: true,
64
+ });
65
+ this.branchData.currentBranch = createBranchResult.branch;
66
+ }
67
+ else {
68
+ this.branchData.currentBranch = branchData.defaultBranch;
69
+ }
70
+ }
71
+ else {
72
+ if (!current) {
73
+ logErrorAndExit('Failed to determine the current branch. Please specify a custom branch or enable automatic branch detection.');
74
+ }
75
+ const currentBranch = branchData.branches.find((b) => b.name === current.currentBranchName);
76
+ if (!currentBranch) {
77
+ try {
78
+ const createBranchResult = await this.gt.createBranch({
79
+ branchName: current.currentBranchName,
80
+ defaultBranch: current.defaultBranch,
81
+ });
82
+ this.branchData.currentBranch = createBranchResult.branch;
83
+ }
84
+ catch (error) {
85
+ if (error instanceof ApiError && error.code === 403) {
86
+ logError('Failed to create branch. To enable branching, please upgrade your plan.');
87
+ // retry with default branch
88
+ const createBranchResult = await this.gt.createBranch({
89
+ branchName: 'main', // name doesn't matter for default branch
90
+ defaultBranch: true,
91
+ });
92
+ this.branchData.currentBranch = createBranchResult.branch;
93
+ }
94
+ }
95
+ }
96
+ else {
97
+ this.branchData.currentBranch = currentBranch;
98
+ }
99
+ }
100
+ // Now set the incoming and checked out branches (first one that exists)
101
+ this.branchData.incomingBranch =
102
+ incoming
103
+ .map((b) => {
104
+ const branch = branchData.branches.find((bb) => bb.name === b);
105
+ if (branch) {
106
+ return branch;
107
+ }
108
+ else {
109
+ return null;
110
+ }
111
+ })
112
+ .filter((b) => b !== null)[0] ?? null;
113
+ this.branchData.checkedOutBranch =
114
+ checkedOut
115
+ .map((b) => {
116
+ const branch = branchData.branches.find((bb) => bb.name === b);
117
+ if (branch) {
118
+ return branch;
119
+ }
120
+ else {
121
+ return null;
122
+ }
123
+ })
124
+ .filter((b) => b !== null)[0] ?? null;
125
+ this.spinner.stop(chalk.green('Branch information resolved successfully'));
126
+ return this.branchData;
127
+ }
128
+ async wait() {
129
+ return;
130
+ }
131
+ }
@@ -0,0 +1,19 @@
1
+ import { WorkflowStep } from './Workflow.js';
2
+ import { GT } from 'generaltranslation';
3
+ import { Settings } from '../types/index.js';
4
+ import { FileStatusTracker } from './PollJobsStep.js';
5
+ export type DownloadTranslationsInput = {
6
+ fileTracker: FileStatusTracker;
7
+ resolveOutputPath: (sourcePath: string, locale: string) => string | null;
8
+ forceDownload?: boolean;
9
+ };
10
+ export declare class DownloadTranslationsStep extends WorkflowStep<DownloadTranslationsInput, boolean> {
11
+ private gt;
12
+ private settings;
13
+ private spinner;
14
+ constructor(gt: GT, settings: Settings);
15
+ run({ fileTracker, resolveOutputPath, forceDownload, }: DownloadTranslationsInput): Promise<boolean>;
16
+ private downloadFiles;
17
+ private downloadFilesWithRetry;
18
+ wait(): Promise<void>;
19
+ }
@@ -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,284 @@
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
+ }
117
+ else if (job.status === 'failed') {
118
+ fileTracker.failed.set(fileKey, fileProperties);
119
+ fileTracker.inProgress.delete(fileKey);
120
+ }
121
+ else if (job.status === 'unknown') {
122
+ fileTracker.skipped.set(fileKey, fileProperties);
123
+ fileTracker.inProgress.delete(fileKey);
124
+ }
125
+ jobFileMap.delete(job.jobId);
126
+ }
127
+ }
128
+ // Update spinner
129
+ this.updateSpinner(fileTracker, fileQueryData);
130
+ const elapsed = Date.now() - startTime;
131
+ const allJobsProcessed = fileTracker.inProgress.size === 0;
132
+ if (allJobsProcessed || elapsed >= timeoutDuration * 1000) {
133
+ clearInterval(intervalCheck);
134
+ if (fileTracker.inProgress.size === 0) {
135
+ this.spinner.stop(chalk.green('Translation jobs finished'));
136
+ resolve({ success: true, fileTracker });
137
+ }
138
+ else {
139
+ this.spinner.stop(chalk.red('Timed out waiting for translation jobs'));
140
+ resolve({ success: false, fileTracker });
141
+ }
142
+ }
143
+ }
144
+ catch (error) {
145
+ logError(chalk.red('Error checking job status: ') + error);
146
+ }
147
+ }, 5000);
148
+ }, msUntilNextInterval);
149
+ });
150
+ }
151
+ updateSpinner(fileTracker, fileQueryData) {
152
+ if (!this.spinner)
153
+ return;
154
+ const statusText = this.generateStatusSuffixText(fileTracker, fileQueryData);
155
+ const currentProgress = fileTracker.completed.size +
156
+ fileTracker.failed.size +
157
+ fileTracker.skipped.size;
158
+ const progressDelta = currentProgress - this.previousProgress;
159
+ this.spinner.advance(progressDelta, statusText);
160
+ this.previousProgress = currentProgress;
161
+ }
162
+ generateStatusSuffixText(fileTracker, fileQueryData) {
163
+ // Simple progress indicator
164
+ const progressText = `${chalk.green(`[${fileTracker.completed.size +
165
+ fileTracker.failed.size +
166
+ fileTracker.skipped.size}/${fileQueryData.length}]`)} translations completed`;
167
+ // Get terminal height to adapt our output
168
+ const terminalHeight = process.stdout.rows || 24;
169
+ // If terminal is very small, just show the basic progress
170
+ if (terminalHeight < 6) {
171
+ return progressText;
172
+ }
173
+ const newSuffixText = [progressText];
174
+ // Organize data by filename : locale
175
+ const fileStatus = new Map();
176
+ // Initialize with all files and locales from fileQueryData
177
+ for (const item of fileQueryData) {
178
+ if (!fileStatus.has(item.fileName)) {
179
+ fileStatus.set(item.fileName, {
180
+ completed: new Set(),
181
+ pending: new Set([item.locale]),
182
+ failed: new Set(),
183
+ skipped: new Set(),
184
+ });
185
+ }
186
+ else {
187
+ fileStatus.get(item.fileName)?.pending.add(item.locale);
188
+ }
189
+ }
190
+ // Mark which ones are completed, failed, or skipped
191
+ for (const [_, fileProperties] of fileTracker.completed) {
192
+ const { fileName, locale } = fileProperties;
193
+ const status = fileStatus.get(fileName);
194
+ if (status) {
195
+ status.pending.delete(locale);
196
+ status.completed.add(locale);
197
+ }
198
+ }
199
+ for (const [_, fileProperties] of fileTracker.failed) {
200
+ const { fileName, locale } = fileProperties;
201
+ const status = fileStatus.get(fileName);
202
+ if (status) {
203
+ status.pending.delete(locale);
204
+ status.failed.add(locale);
205
+ }
206
+ }
207
+ for (const [_, fileProperties] of fileTracker.skipped) {
208
+ const { fileName, locale } = fileProperties;
209
+ const status = fileStatus.get(fileName);
210
+ if (status) {
211
+ status.pending.delete(locale);
212
+ status.skipped.add(locale);
213
+ }
214
+ }
215
+ // Calculate how many files we can show based on terminal height
216
+ const filesArray = Array.from(fileStatus.entries());
217
+ const maxFilesToShow = Math.min(filesArray.length, terminalHeight - 3 // Header + progress + buffer
218
+ );
219
+ // Display each file with its status on a single line
220
+ for (let i = 0; i < maxFilesToShow; i++) {
221
+ const [fileName, status] = filesArray[i];
222
+ // Create condensed locale status
223
+ const localeStatuses = [];
224
+ // Add completed locales (green)
225
+ if (status.completed.size > 0) {
226
+ localeStatuses.push(...Array.from(status.completed).map((locale) => ({
227
+ locale,
228
+ status: 'completed',
229
+ })));
230
+ }
231
+ // Add skipped locales (green)
232
+ if (status.skipped.size > 0) {
233
+ localeStatuses.push(...Array.from(status.skipped).map((locale) => ({
234
+ locale,
235
+ status: 'skipped',
236
+ })));
237
+ }
238
+ // Add failed locales (red)
239
+ if (status.failed.size > 0) {
240
+ localeStatuses.push(...Array.from(status.failed).map((locale) => ({
241
+ locale,
242
+ status: 'failed',
243
+ })));
244
+ }
245
+ // Add pending locales (yellow)
246
+ if (status.pending.size > 0) {
247
+ localeStatuses.push(...Array.from(status.pending).map((locale) => ({
248
+ locale,
249
+ status: 'pending',
250
+ })));
251
+ }
252
+ // Sort localeStatuses by locale
253
+ localeStatuses.sort((a, b) => a.locale.localeCompare(b.locale));
254
+ // Add colors
255
+ const localeString = localeStatuses
256
+ .map((locale) => {
257
+ if (locale.status === 'completed') {
258
+ return chalk.green(locale.locale);
259
+ }
260
+ else if (locale.status === 'skipped') {
261
+ return chalk.gray(locale.locale);
262
+ }
263
+ else if (locale.status === 'failed') {
264
+ return chalk.red(locale.locale);
265
+ }
266
+ else if (locale.status === 'pending') {
267
+ return chalk.yellow(locale.locale);
268
+ }
269
+ })
270
+ .join(', ');
271
+ // Format the line
272
+ const prettyFileName = fileName === TEMPLATE_FILE_NAME ? '<React Elements>' : fileName;
273
+ newSuffixText.push(`${chalk.bold(prettyFileName)} [${localeString}]`);
274
+ }
275
+ // If we couldn't show all files, add an indicator
276
+ if (filesArray.length > maxFilesToShow) {
277
+ newSuffixText.push(`... and ${filesArray.length - maxFilesToShow} more files`);
278
+ }
279
+ return newSuffixText.join('\n');
280
+ }
281
+ async wait() {
282
+ return;
283
+ }
284
+ }
@@ -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
+ }