gtx-cli 2.5.0-alpha.0 → 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.
- package/CHANGELOG.md +13 -0
- package/dist/api/collectUserEditDiffs.d.ts +2 -7
- package/dist/api/collectUserEditDiffs.js +33 -78
- package/dist/api/downloadFileBatch.d.ts +11 -10
- package/dist/api/downloadFileBatch.js +120 -127
- package/dist/api/saveLocalEdits.js +18 -15
- package/dist/cli/base.js +1 -1
- package/dist/cli/commands/stage.d.ts +8 -2
- package/dist/cli/commands/stage.js +25 -7
- package/dist/cli/commands/translate.d.ts +4 -2
- package/dist/cli/commands/translate.js +5 -6
- package/dist/cli/flags.js +4 -1
- package/dist/config/generateSettings.js +10 -0
- package/dist/console/colors.d.ts +0 -1
- package/dist/console/colors.js +0 -3
- package/dist/console/index.d.ts +0 -6
- package/dist/console/index.js +2 -13
- package/dist/console/logging.d.ts +1 -1
- package/dist/console/logging.js +3 -4
- package/dist/formats/files/translate.d.ts +2 -2
- package/dist/formats/files/translate.js +31 -5
- package/dist/fs/config/downloadedVersions.d.ts +10 -3
- package/dist/fs/config/downloadedVersions.js +8 -0
- package/dist/fs/config/updateVersions.d.ts +2 -1
- package/dist/git/branches.d.ts +7 -0
- package/dist/git/branches.js +88 -0
- package/dist/react/{jsx/utils/jsxParsing → data-_gt}/addGTIdentifierToSyntaxTree.d.ts +1 -2
- package/dist/react/{jsx/utils/jsxParsing → data-_gt}/addGTIdentifierToSyntaxTree.js +6 -30
- package/dist/react/jsx/evaluateJsx.d.ts +6 -5
- package/dist/react/jsx/evaluateJsx.js +4 -32
- package/dist/react/jsx/trimJsxStringChildren.d.ts +7 -0
- package/dist/react/jsx/trimJsxStringChildren.js +122 -0
- package/dist/react/jsx/utils/constants.d.ts +0 -2
- package/dist/react/jsx/utils/constants.js +2 -11
- package/dist/react/jsx/utils/parseJsx.d.ts +21 -0
- package/dist/react/jsx/utils/parseJsx.js +259 -0
- package/dist/react/jsx/utils/parseStringFunction.js +141 -4
- package/dist/react/parse/createInlineUpdates.js +70 -19
- package/dist/types/branch.d.ts +14 -0
- package/dist/types/branch.js +1 -0
- package/dist/types/data.d.ts +1 -1
- package/dist/types/files.d.ts +7 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/utils/SpinnerManager.d.ts +30 -0
- package/dist/utils/SpinnerManager.js +73 -0
- package/dist/utils/gitDiff.js +18 -16
- package/dist/workflow/BranchStep.d.ts +13 -0
- package/dist/workflow/BranchStep.js +131 -0
- package/dist/workflow/DownloadStep.d.ts +19 -0
- package/dist/workflow/DownloadStep.js +127 -0
- package/dist/workflow/EnqueueStep.d.ts +15 -0
- package/dist/workflow/EnqueueStep.js +33 -0
- package/dist/workflow/PollJobsStep.d.ts +31 -0
- package/dist/workflow/PollJobsStep.js +284 -0
- package/dist/workflow/SetupStep.d.ts +16 -0
- package/dist/workflow/SetupStep.js +71 -0
- package/dist/workflow/UploadStep.d.ts +21 -0
- package/dist/workflow/UploadStep.js +72 -0
- package/dist/workflow/UserEditDiffsStep.d.ts +11 -0
- package/dist/workflow/UserEditDiffsStep.js +30 -0
- package/dist/workflow/Workflow.d.ts +4 -0
- package/dist/workflow/Workflow.js +2 -0
- package/dist/workflow/download.d.ts +22 -0
- package/dist/workflow/download.js +104 -0
- package/dist/workflow/stage.d.ts +14 -0
- package/dist/workflow/stage.js +76 -0
- package/package.json +4 -5
- package/dist/api/checkFileTranslations.d.ts +0 -23
- package/dist/api/checkFileTranslations.js +0 -281
- package/dist/api/sendFiles.d.ts +0 -17
- package/dist/api/sendFiles.js +0 -127
- package/dist/api/sendUserEdits.d.ts +0 -19
- package/dist/api/sendUserEdits.js +0 -15
- package/dist/cli/commands/edits.d.ts +0 -8
- package/dist/cli/commands/edits.js +0 -32
- package/dist/react/jsx/utils/buildImportMap.d.ts +0 -9
- package/dist/react/jsx/utils/buildImportMap.js +0 -30
- package/dist/react/jsx/utils/getPathsAndAliases.d.ts +0 -17
- package/dist/react/jsx/utils/getPathsAndAliases.js +0 -89
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.d.ts +0 -6
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +0 -199
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.d.ts +0 -13
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js +0 -42
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.d.ts +0 -5
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +0 -69
- package/dist/react/jsx/utils/jsxParsing/parseJsx.d.ts +0 -60
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js +0 -949
- package/dist/react/jsx/utils/jsxParsing/parseTProps.d.ts +0 -8
- package/dist/react/jsx/utils/jsxParsing/parseTProps.js +0 -47
- package/dist/react/jsx/utils/jsxParsing/types.d.ts +0 -48
- package/dist/react/jsx/utils/jsxParsing/types.js +0 -34
- package/dist/react/jsx/utils/resolveImportPath.d.ts +0 -11
- 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,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
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
if (!status[0]) {
|
|
55
|
+
this.spinner.stop(chalk.yellow('Setup status unknown — proceeding without setup'));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (status[0].status === 'completed') {
|
|
59
|
+
this.spinner.stop(chalk.green('Setup successfully completed'));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (status[0].status === 'failed') {
|
|
63
|
+
this.spinner.stop(chalk.yellow(`Setup failed: ${status[0].error?.message || 'Unknown error'} — proceeding without setup`));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
await new Promise((r) => setTimeout(r, pollInterval));
|
|
67
|
+
}
|
|
68
|
+
// Timeout
|
|
69
|
+
this.spinner.stop(chalk.yellow('Setup timed out — proceeding without setup'));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -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
|
+
}
|