gt 2.14.66 → 2.16.0
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 +36 -0
- package/dist/api/downloadFileBatch.js +28 -1
- package/dist/api/downloadFileBatch.js.map +1 -1
- package/dist/api/saveLocalEdits.js +1 -3
- package/dist/api/saveLocalEdits.js.map +1 -1
- package/dist/cli/base.js +6 -0
- package/dist/cli/base.js.map +1 -1
- package/dist/cli/commands/download.js +2 -1
- package/dist/cli/commands/download.js.map +1 -1
- package/dist/cli/commands/upload.js +5 -3
- package/dist/cli/commands/upload.js.map +1 -1
- package/dist/cli/inline.js +1 -3
- package/dist/cli/inline.js.map +1 -1
- package/dist/console/index.d.ts +3 -0
- package/dist/console/index.js +4 -1
- package/dist/console/index.js.map +1 -1
- package/dist/console/logger.d.ts +13 -0
- package/dist/console/logger.js +35 -8
- package/dist/console/logger.js.map +1 -1
- package/dist/console/logging.js +4 -2
- package/dist/console/logging.js.map +1 -1
- package/dist/formats/files/aggregateFiles.js +32 -2
- package/dist/formats/files/aggregateFiles.js.map +1 -1
- package/dist/formats/files/collectFonts.d.ts +7 -0
- package/dist/formats/files/collectFonts.js +30 -0
- package/dist/formats/files/collectFonts.js.map +1 -0
- package/dist/formats/files/detectLottieExpressions.d.ts +8 -0
- package/dist/formats/files/detectLottieExpressions.js +42 -0
- package/dist/formats/files/detectLottieExpressions.js.map +1 -0
- package/dist/formats/files/supportedFiles.d.ts +2 -1
- package/dist/formats/files/supportedFiles.js +4 -2
- package/dist/formats/files/supportedFiles.js.map +1 -1
- package/dist/formats/files/transformFormat.d.ts +2 -0
- package/dist/formats/files/transformFormat.js +6 -3
- package/dist/formats/files/transformFormat.js.map +1 -1
- package/dist/fs/findFilepath.d.ts +7 -0
- package/dist/fs/findFilepath.js +11 -1
- package/dist/fs/findFilepath.js.map +1 -1
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/generated/version.js.map +1 -1
- package/dist/types/index.d.ts +5 -0
- package/dist/workflows/download.js +3 -9
- package/dist/workflows/download.js.map +1 -1
- package/dist/workflows/enqueue.js +2 -2
- package/dist/workflows/enqueue.js.map +1 -1
- package/dist/workflows/publish.js +1 -3
- package/dist/workflows/publish.js.map +1 -1
- package/dist/workflows/setupProject.js +0 -3
- package/dist/workflows/setupProject.js.map +1 -1
- package/dist/workflows/stage.js +5 -13
- package/dist/workflows/stage.js.map +1 -1
- package/dist/workflows/steps/BranchStep.d.ts +1 -3
- package/dist/workflows/steps/BranchStep.js +1 -4
- package/dist/workflows/steps/BranchStep.js.map +1 -1
- package/dist/workflows/steps/DownloadStep.d.ts +1 -3
- package/dist/workflows/steps/DownloadStep.js +1 -4
- package/dist/workflows/steps/DownloadStep.js.map +1 -1
- package/dist/workflows/steps/EnqueueStep.d.ts +1 -5
- package/dist/workflows/steps/EnqueueStep.js +9 -19
- package/dist/workflows/steps/EnqueueStep.js.map +1 -1
- package/dist/workflows/steps/PollJobsStep.d.ts +1 -3
- package/dist/workflows/steps/PollJobsStep.js +1 -4
- package/dist/workflows/steps/PollJobsStep.js.map +1 -1
- package/dist/workflows/steps/PublishStep.d.ts +1 -3
- package/dist/workflows/steps/PublishStep.js +1 -4
- package/dist/workflows/steps/PublishStep.js.map +1 -1
- package/dist/workflows/steps/SetupStep.d.ts +1 -6
- package/dist/workflows/steps/SetupStep.js +14 -41
- package/dist/workflows/steps/SetupStep.js.map +1 -1
- package/dist/workflows/steps/TagStep.d.ts +1 -4
- package/dist/workflows/steps/TagStep.js +4 -9
- package/dist/workflows/steps/TagStep.js.map +1 -1
- package/dist/workflows/steps/UploadSourcesStep.d.ts +1 -7
- package/dist/workflows/steps/UploadSourcesStep.js +4 -8
- package/dist/workflows/steps/UploadSourcesStep.js.map +1 -1
- package/dist/workflows/steps/UploadTranslationsStep.d.ts +1 -4
- package/dist/workflows/steps/UploadTranslationsStep.js +6 -11
- package/dist/workflows/steps/UploadTranslationsStep.js.map +1 -1
- package/dist/workflows/steps/UserEditDiffsStep.d.ts +1 -5
- package/dist/workflows/steps/UserEditDiffsStep.js +3 -11
- package/dist/workflows/steps/UserEditDiffsStep.js.map +1 -1
- package/dist/workflows/upload.js +3 -6
- package/dist/workflows/upload.js.map +1 -1
- package/dist/workflows/utils/syncFonts.d.ts +9 -0
- package/dist/workflows/utils/syncFonts.js +25 -0
- package/dist/workflows/utils/syncFonts.js.map +1 -0
- package/package.json +7 -6
- package/dist/workflows/steps/WorkflowStep.d.ts +0 -4
- package/dist/workflows/steps/WorkflowStep.js +0 -6
- package/dist/workflows/steps/WorkflowStep.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish.js","names":[],"sources":["../../src/workflows/publish.ts"],"sourcesContent":["import { Settings } from '../types/index.js';\nimport { PublishStep } from './steps/PublishStep.js';\nimport { gt } from '../utils/gt.js';\nimport { hasPublishConfig } from '../utils/resolvePublish.js';\nimport { logger } from '../console/logger.js';\n\n/**\n * Publishes files to the CDN if publish config exists and the publishMap is non-empty.\n * Shared by translate, upload, and save-local commands.\n */\nexport async function runPublishWorkflow(\n files: { fileId: string; versionId: string; fileName: string }[],\n publishMap: Map<string, boolean>,\n branchId: string,\n settings: Settings\n): Promise<void> {\n if (publishMap.size === 0 || !hasPublishConfig(settings)) return;\n\n try {\n const allFileRefs = files\n .filter((file) => publishMap.has(file.fileId))\n .map((file) => ({\n fileId: file.fileId,\n versionId: file.versionId,\n branchId,\n publish: publishMap.get(file.fileId)!,\n fileName: file.fileName,\n }));\n if (allFileRefs.length === 0) return;\n const publishStep = new PublishStep(gt);\n await publishStep.run(allFileRefs);\n
|
|
1
|
+
{"version":3,"file":"publish.js","names":[],"sources":["../../src/workflows/publish.ts"],"sourcesContent":["import { Settings } from '../types/index.js';\nimport { PublishStep } from './steps/PublishStep.js';\nimport { gt } from '../utils/gt.js';\nimport { hasPublishConfig } from '../utils/resolvePublish.js';\nimport { logger } from '../console/logger.js';\n\n/**\n * Publishes files to the CDN if publish config exists and the publishMap is non-empty.\n * Shared by translate, upload, and save-local commands.\n */\nexport async function runPublishWorkflow(\n files: { fileId: string; versionId: string; fileName: string }[],\n publishMap: Map<string, boolean>,\n branchId: string,\n settings: Settings\n): Promise<void> {\n if (publishMap.size === 0 || !hasPublishConfig(settings)) return;\n\n try {\n const allFileRefs = files\n .filter((file) => publishMap.has(file.fileId))\n .map((file) => ({\n fileId: file.fileId,\n versionId: file.versionId,\n branchId,\n publish: publishMap.get(file.fileId)!,\n fileName: file.fileName,\n }));\n if (allFileRefs.length === 0) return;\n const publishStep = new PublishStep(gt);\n await publishStep.run(allFileRefs);\n } catch (error) {\n logger.warn(\n `Failed to publish files: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n}\n"],"mappings":";;;;;;;;;AAUA,eAAsB,mBACpB,OACA,YACA,UACA,UACe;AACf,KAAI,WAAW,SAAS,KAAK,CAAC,iBAAiB,SAAS,CAAE;AAE1D,KAAI;EACF,MAAM,cAAc,MACjB,QAAQ,SAAS,WAAW,IAAI,KAAK,OAAO,CAAC,CAC7C,KAAK,UAAU;GACd,QAAQ,KAAK;GACb,WAAW,KAAK;GAChB;GACA,SAAS,WAAW,IAAI,KAAK,OAAO;GACpC,UAAU,KAAK;GAChB,EAAE;AACL,MAAI,YAAY,WAAW,EAAG;AAE9B,QAAM,IADkB,YAAY,GACnB,CAAC,IAAI,YAAY;UAC3B,OAAO;AACd,SAAO,KACL,4BAA4B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,GACnF"}
|
|
@@ -21,15 +21,12 @@ async function runSetupProjectWorkflow(files, options, settings) {
|
|
|
21
21
|
const uploadStep = new UploadSourcesStep(gt, settings);
|
|
22
22
|
const setupStep = new SetupStep(gt, settings, timeoutMs);
|
|
23
23
|
const branchData = await branchStep.run();
|
|
24
|
-
await branchStep.wait();
|
|
25
24
|
if (!branchData) return logErrorAndExit(branchResolutionError);
|
|
26
25
|
const uploadedFiles = await uploadStep.run({
|
|
27
26
|
files,
|
|
28
27
|
branchData
|
|
29
28
|
});
|
|
30
|
-
await uploadStep.wait();
|
|
31
29
|
await setupStep.run(uploadedFiles, options.force ?? false);
|
|
32
|
-
await setupStep.wait();
|
|
33
30
|
return { branchData };
|
|
34
31
|
} catch (error) {
|
|
35
32
|
return logErrorAndExit(withOriginalError("Project setup could not be completed. Check the files, branch configuration, and API credentials, then try again.", error));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupProject.js","names":[],"sources":["../../src/workflows/setupProject.ts"],"sourcesContent":["import { logErrorAndExit } from '../console/logging.js';\nimport { branchResolutionError, withOriginalError } from '../console/index.js';\nimport { Settings, TranslateFlags } from '../types/index.js';\nimport { gt } from '../utils/gt.js';\nimport { FileToUpload } from 'generaltranslation/types';\nimport { UploadSourcesStep } from './steps/UploadSourcesStep.js';\nimport { SetupStep } from './steps/SetupStep.js';\nimport { BranchStep } from './steps/BranchStep.js';\nimport { BranchData } from '../types/branch.js';\nimport { logCollectedFiles } from '../console/logging.js';\nimport { calculateTimeoutMs } from '../utils/calculateTimeoutMs.js';\n\n/**\n * Sets up a project by uploading files running the setup step\n * @param files - Array of file objects to upload\n * @param options - The options for the API call\n * @param settings - Settings configuration\n * @returns The branch data\n */\nexport async function runSetupProjectWorkflow(\n files: FileToUpload[],\n options: TranslateFlags,\n settings: Settings\n): Promise<{\n branchData: BranchData;\n}> {\n try {\n // Log files to be translated\n logCollectedFiles(files);\n\n // Calculate timeout for setup step\n const timeoutMs = calculateTimeoutMs(options.timeout);\n\n // Create workflow with steps\n const branchStep = new BranchStep(gt, settings);\n const uploadStep = new UploadSourcesStep(gt, settings);\n const setupStep = new SetupStep(gt, settings, timeoutMs);\n\n // first run the branch step\n const branchData = await branchStep.run();\n
|
|
1
|
+
{"version":3,"file":"setupProject.js","names":[],"sources":["../../src/workflows/setupProject.ts"],"sourcesContent":["import { logErrorAndExit } from '../console/logging.js';\nimport { branchResolutionError, withOriginalError } from '../console/index.js';\nimport { Settings, TranslateFlags } from '../types/index.js';\nimport { gt } from '../utils/gt.js';\nimport { FileToUpload } from 'generaltranslation/types';\nimport { UploadSourcesStep } from './steps/UploadSourcesStep.js';\nimport { SetupStep } from './steps/SetupStep.js';\nimport { BranchStep } from './steps/BranchStep.js';\nimport { BranchData } from '../types/branch.js';\nimport { logCollectedFiles } from '../console/logging.js';\nimport { calculateTimeoutMs } from '../utils/calculateTimeoutMs.js';\n\n/**\n * Sets up a project by uploading files running the setup step\n * @param files - Array of file objects to upload\n * @param options - The options for the API call\n * @param settings - Settings configuration\n * @returns The branch data\n */\nexport async function runSetupProjectWorkflow(\n files: FileToUpload[],\n options: TranslateFlags,\n settings: Settings\n): Promise<{\n branchData: BranchData;\n}> {\n try {\n // Log files to be translated\n logCollectedFiles(files);\n\n // Calculate timeout for setup step\n const timeoutMs = calculateTimeoutMs(options.timeout);\n\n // Create workflow with steps\n const branchStep = new BranchStep(gt, settings);\n const uploadStep = new UploadSourcesStep(gt, settings);\n const setupStep = new SetupStep(gt, settings, timeoutMs);\n\n // first run the branch step\n const branchData = await branchStep.run();\n\n if (!branchData) {\n return logErrorAndExit(branchResolutionError);\n }\n\n // then run the upload step\n const uploadedFiles = await uploadStep.run({ files, branchData });\n\n // then run the setup step\n await setupStep.run(uploadedFiles, options.force ?? false);\n\n return { branchData };\n } catch (error) {\n return logErrorAndExit(\n withOriginalError(\n 'Project setup could not be completed. Check the files, branch configuration, and API credentials, then try again.',\n error\n )\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,eAAsB,wBACpB,OACA,SACA,UAGC;AACD,KAAI;AAEF,oBAAkB,MAAM;EAGxB,MAAM,YAAY,mBAAmB,QAAQ,QAAQ;EAGrD,MAAM,aAAa,IAAI,WAAW,IAAI,SAAS;EAC/C,MAAM,aAAa,IAAI,kBAAkB,IAAI,SAAS;EACtD,MAAM,YAAY,IAAI,UAAU,IAAI,UAAU,UAAU;EAGxD,MAAM,aAAa,MAAM,WAAW,KAAK;AAEzC,MAAI,CAAC,WACH,QAAO,gBAAgB,sBAAsB;EAI/C,MAAM,gBAAgB,MAAM,WAAW,IAAI;GAAE;GAAO;GAAY,CAAC;AAGjE,QAAM,UAAU,IAAI,eAAe,QAAQ,SAAS,MAAM;AAE1D,SAAO,EAAE,YAAY;UACd,OAAO;AACd,SAAO,gBACL,kBACE,qHACA,MACD,CACF"}
|
package/dist/workflows/stage.js
CHANGED
|
@@ -2,6 +2,7 @@ import { logger } from "../console/logger.js";
|
|
|
2
2
|
import { gt } from "../utils/gt.js";
|
|
3
3
|
import { logCollectedFiles, logErrorAndExit } from "../console/logging.js";
|
|
4
4
|
import { branchResolutionError, withOriginalError } from "../console/index.js";
|
|
5
|
+
import { syncFonts } from "./utils/syncFonts.js";
|
|
5
6
|
import { BranchStep } from "./steps/BranchStep.js";
|
|
6
7
|
import { UploadSourcesStep } from "./steps/UploadSourcesStep.js";
|
|
7
8
|
import { SetupStep } from "./steps/SetupStep.js";
|
|
@@ -21,6 +22,7 @@ import { filterFilesForEnqueue } from "./utils/filterFilesForEnqueue.js";
|
|
|
21
22
|
async function runStageFilesWorkflow({ files, options, settings }) {
|
|
22
23
|
try {
|
|
23
24
|
logCollectedFiles(files);
|
|
25
|
+
await syncFonts(settings);
|
|
24
26
|
const timeoutMs = calculateTimeoutMs(options.timeout);
|
|
25
27
|
const branchStep = new BranchStep(gt, settings);
|
|
26
28
|
const uploadStep = new UploadSourcesStep(gt, settings);
|
|
@@ -28,26 +30,18 @@ async function runStageFilesWorkflow({ files, options, settings }) {
|
|
|
28
30
|
const setupStep = new SetupStep(gt, settings, timeoutMs);
|
|
29
31
|
const enqueueStep = new EnqueueStep(gt, settings, options.force);
|
|
30
32
|
const branchData = await branchStep.run();
|
|
31
|
-
await branchStep.wait();
|
|
32
33
|
if (!branchData) return logErrorAndExit(branchResolutionError);
|
|
33
34
|
const uploadedFiles = await uploadStep.run({
|
|
34
35
|
files,
|
|
35
36
|
branchData
|
|
36
37
|
});
|
|
37
|
-
await
|
|
38
|
-
if (options?.saveLocal) {
|
|
39
|
-
await userEditDiffsStep.run(uploadedFiles);
|
|
40
|
-
await userEditDiffsStep.wait();
|
|
41
|
-
}
|
|
38
|
+
if (options?.saveLocal) await userEditDiffsStep.run(uploadedFiles);
|
|
42
39
|
if (settings.tag) try {
|
|
43
|
-
|
|
44
|
-
await tagStep.run(uploadedFiles);
|
|
45
|
-
await tagStep.wait();
|
|
40
|
+
await new TagStep(gt, settings, !!options.tag).run(uploadedFiles);
|
|
46
41
|
} catch {
|
|
47
42
|
logger.warn("Failed to create translation tag. Continuing...");
|
|
48
43
|
}
|
|
49
44
|
await setupStep.run(uploadedFiles);
|
|
50
|
-
await setupStep.wait();
|
|
51
45
|
const { filesToEnqueue, skippedFiles } = await filterFilesForEnqueue({
|
|
52
46
|
gt,
|
|
53
47
|
files: uploadedFiles,
|
|
@@ -55,11 +49,9 @@ async function runStageFilesWorkflow({ files, options, settings }) {
|
|
|
55
49
|
force: options.force
|
|
56
50
|
});
|
|
57
51
|
if (skippedFiles.length > 0) logger.info(`Skipped enqueue for ${skippedFiles.length} already translated file${skippedFiles.length === 1 ? "" : "s"}`);
|
|
58
|
-
const enqueueResult = await enqueueStep.run(filesToEnqueue);
|
|
59
|
-
await enqueueStep.wait();
|
|
60
52
|
return {
|
|
61
53
|
branchData,
|
|
62
|
-
enqueueResult
|
|
54
|
+
enqueueResult: await enqueueStep.run(filesToEnqueue)
|
|
63
55
|
};
|
|
64
56
|
} catch (error) {
|
|
65
57
|
return logErrorAndExit(withOriginalError("Files could not be sent for translation. Check the files, branch configuration, and API credentials, then try again.", error));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stage.js","names":[],"sources":["../../src/workflows/stage.ts"],"sourcesContent":["import { logCollectedFiles, logErrorAndExit } from '../console/logging.js';\nimport { branchResolutionError, withOriginalError } from '../console/index.js';\nimport { logger } from '../console/logger.js';\nimport { Settings, TranslateFlags } from '../types/index.js';\nimport { gt } from '../utils/gt.js';\nimport { EnqueueFilesResult, FileToUpload } from 'generaltranslation/types';\nimport { UploadSourcesStep } from './steps/UploadSourcesStep.js';\nimport { SetupStep } from './steps/SetupStep.js';\nimport { EnqueueStep } from './steps/EnqueueStep.js';\nimport { BranchStep } from './steps/BranchStep.js';\nimport { TagStep } from './steps/TagStep.js';\nimport { UserEditDiffsStep } from './steps/UserEditDiffsStep.js';\nimport { BranchData } from '../types/branch.js';\nimport { calculateTimeoutMs } from '../utils/calculateTimeoutMs.js';\nimport { filterFilesForEnqueue } from './utils/filterFilesForEnqueue.js';\n\n/**\n * Sends multiple files for translation to the API using a workflow pattern\n * @param files - Array of file objects to translate\n * @param options - The options for the API call\n * @param settings - Settings configuration\n * @returns The translated content or version ID\n */\nexport async function runStageFilesWorkflow({\n files,\n options,\n settings,\n}: {\n files: FileToUpload[];\n options: TranslateFlags;\n settings: Settings;\n}): Promise<{\n branchData: BranchData;\n enqueueResult: EnqueueFilesResult;\n}> {\n try {\n // Log files to be translated\n logCollectedFiles(files);\n\n // Calculate timeout for setup step\n const timeoutMs = calculateTimeoutMs(options.timeout);\n\n // Create workflow with steps\n const branchStep = new BranchStep(gt, settings);\n const uploadStep = new UploadSourcesStep(gt, settings);\n const userEditDiffsStep = new UserEditDiffsStep(settings);\n const setupStep = new SetupStep(gt, settings, timeoutMs);\n const enqueueStep = new EnqueueStep(gt, settings, options.force);\n\n // first run the branch step\n const branchData = await branchStep.run();\n
|
|
1
|
+
{"version":3,"file":"stage.js","names":[],"sources":["../../src/workflows/stage.ts"],"sourcesContent":["import { logCollectedFiles, logErrorAndExit } from '../console/logging.js';\nimport { branchResolutionError, withOriginalError } from '../console/index.js';\nimport { logger } from '../console/logger.js';\nimport { Settings, TranslateFlags } from '../types/index.js';\nimport { gt } from '../utils/gt.js';\nimport { EnqueueFilesResult, FileToUpload } from 'generaltranslation/types';\nimport { UploadSourcesStep } from './steps/UploadSourcesStep.js';\nimport { SetupStep } from './steps/SetupStep.js';\nimport { EnqueueStep } from './steps/EnqueueStep.js';\nimport { BranchStep } from './steps/BranchStep.js';\nimport { TagStep } from './steps/TagStep.js';\nimport { UserEditDiffsStep } from './steps/UserEditDiffsStep.js';\nimport { BranchData } from '../types/branch.js';\nimport { calculateTimeoutMs } from '../utils/calculateTimeoutMs.js';\nimport { filterFilesForEnqueue } from './utils/filterFilesForEnqueue.js';\nimport { syncFonts } from './utils/syncFonts.js';\n\n/**\n * Sends multiple files for translation to the API using a workflow pattern\n * @param files - Array of file objects to translate\n * @param options - The options for the API call\n * @param settings - Settings configuration\n * @returns The translated content or version ID\n */\nexport async function runStageFilesWorkflow({\n files,\n options,\n settings,\n}: {\n files: FileToUpload[];\n options: TranslateFlags;\n settings: Settings;\n}): Promise<{\n branchData: BranchData;\n enqueueResult: EnqueueFilesResult;\n}> {\n try {\n // Log files to be translated\n logCollectedFiles(files);\n\n // Sync fonts before enqueueing so the translation jobs (e.g. Lottie\n // layout refinement) can use them instead of fallback fonts.\n await syncFonts(settings);\n\n // Calculate timeout for setup step\n const timeoutMs = calculateTimeoutMs(options.timeout);\n\n // Create workflow with steps\n const branchStep = new BranchStep(gt, settings);\n const uploadStep = new UploadSourcesStep(gt, settings);\n const userEditDiffsStep = new UserEditDiffsStep(settings);\n const setupStep = new SetupStep(gt, settings, timeoutMs);\n const enqueueStep = new EnqueueStep(gt, settings, options.force);\n\n // first run the branch step\n const branchData = await branchStep.run();\n if (!branchData) {\n return logErrorAndExit(branchResolutionError);\n }\n\n // then run the upload step\n const uploadedFiles = await uploadStep.run({ files, branchData });\n\n // optionally run the user edit diffs step\n if (options?.saveLocal) {\n await userEditDiffsStep.run(uploadedFiles);\n }\n\n // then run the tag step (non-fatal — tagging failure should not block translations)\n if (settings.tag) {\n try {\n const userProvidedTag = !!options.tag;\n const tagStep = new TagStep(gt, settings, userProvidedTag);\n await tagStep.run(uploadedFiles);\n } catch {\n logger.warn('Failed to create translation tag. Continuing...');\n }\n }\n\n // then run the setup step\n await setupStep.run(uploadedFiles);\n\n // then run the enqueue step\n const { filesToEnqueue, skippedFiles } = await filterFilesForEnqueue({\n gt,\n files: uploadedFiles,\n locales: settings.locales,\n force: options.force,\n });\n if (skippedFiles.length > 0) {\n logger.info(\n `Skipped enqueue for ${skippedFiles.length} already translated file${skippedFiles.length === 1 ? '' : 's'}`\n );\n }\n\n const enqueueResult = await enqueueStep.run(filesToEnqueue);\n\n return { branchData, enqueueResult };\n } catch (error) {\n return logErrorAndExit(\n withOriginalError(\n 'Files could not be sent for translation. Check the files, branch configuration, and API credentials, then try again.',\n error\n )\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAwBA,eAAsB,sBAAsB,EAC1C,OACA,SACA,YAQC;AACD,KAAI;AAEF,oBAAkB,MAAM;AAIxB,QAAM,UAAU,SAAS;EAGzB,MAAM,YAAY,mBAAmB,QAAQ,QAAQ;EAGrD,MAAM,aAAa,IAAI,WAAW,IAAI,SAAS;EAC/C,MAAM,aAAa,IAAI,kBAAkB,IAAI,SAAS;EACtD,MAAM,oBAAoB,IAAI,kBAAkB,SAAS;EACzD,MAAM,YAAY,IAAI,UAAU,IAAI,UAAU,UAAU;EACxD,MAAM,cAAc,IAAI,YAAY,IAAI,UAAU,QAAQ,MAAM;EAGhE,MAAM,aAAa,MAAM,WAAW,KAAK;AACzC,MAAI,CAAC,WACH,QAAO,gBAAgB,sBAAsB;EAI/C,MAAM,gBAAgB,MAAM,WAAW,IAAI;GAAE;GAAO;GAAY,CAAC;AAGjE,MAAI,SAAS,UACX,OAAM,kBAAkB,IAAI,cAAc;AAI5C,MAAI,SAAS,IACX,KAAI;AAGF,SAAM,IADc,QAAQ,IAAI,UAAU,CADjB,CAAC,QAAQ,IAErB,CAAC,IAAI,cAAc;UAC1B;AACN,UAAO,KAAK,kDAAkD;;AAKlE,QAAM,UAAU,IAAI,cAAc;EAGlC,MAAM,EAAE,gBAAgB,iBAAiB,MAAM,sBAAsB;GACnE;GACA,OAAO;GACP,SAAS,SAAS;GAClB,OAAO,QAAQ;GAChB,CAAC;AACF,MAAI,aAAa,SAAS,EACxB,QAAO,KACL,uBAAuB,aAAa,OAAO,0BAA0B,aAAa,WAAW,IAAI,KAAK,MACvG;AAKH,SAAO;GAAE;GAAY,eAAA,MAFO,YAAY,IAAI,eAAe;GAEvB;UAC7B,OAAO;AACd,SAAO,gBACL,kBACE,wHACA,MACD,CACF"}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { WorkflowStep } from './WorkflowStep.js';
|
|
2
1
|
import type { GT } from 'generaltranslation';
|
|
3
2
|
import type { Settings } from '../../types/index.js';
|
|
4
3
|
import { BranchData } from '../../types/branch.js';
|
|
5
4
|
type BranchStepClient = Pick<GT, 'queryBranchData' | 'createBranch'>;
|
|
6
5
|
type BranchStepSettings = Pick<Settings, 'branchOptions'>;
|
|
7
|
-
export declare class BranchStep
|
|
6
|
+
export declare class BranchStep {
|
|
8
7
|
private spinner;
|
|
9
8
|
private branchData;
|
|
10
9
|
private settings;
|
|
11
10
|
private gt;
|
|
12
11
|
constructor(gt: BranchStepClient, settings: BranchStepSettings);
|
|
13
12
|
run(): Promise<BranchData | null>;
|
|
14
|
-
wait(): Promise<void>;
|
|
15
13
|
}
|
|
16
14
|
export {};
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { logger } from "../../console/logger.js";
|
|
2
2
|
import { logErrorAndExit } from "../../console/logging.js";
|
|
3
|
-
import { WorkflowStep } from "./WorkflowStep.js";
|
|
4
3
|
import { getCheckedOutBranches, getCurrentBranch, getIncomingBranches } from "../../git/branches.js";
|
|
5
4
|
import chalk from "chalk";
|
|
6
5
|
import { ApiError } from "generaltranslation/errors";
|
|
7
6
|
//#region src/workflows/steps/BranchStep.ts
|
|
8
|
-
var BranchStep = class
|
|
7
|
+
var BranchStep = class {
|
|
9
8
|
spinner = logger.createSpinner("dots");
|
|
10
9
|
branchData;
|
|
11
10
|
settings;
|
|
12
11
|
gt;
|
|
13
12
|
constructor(gt, settings) {
|
|
14
|
-
super();
|
|
15
13
|
this.gt = gt;
|
|
16
14
|
this.settings = settings;
|
|
17
15
|
this.branchData = {
|
|
@@ -110,7 +108,6 @@ var BranchStep = class extends WorkflowStep {
|
|
|
110
108
|
this.spinner.stop(chalk.green("Branch information resolved successfully"));
|
|
111
109
|
return this.branchData;
|
|
112
110
|
}
|
|
113
|
-
async wait() {}
|
|
114
111
|
};
|
|
115
112
|
//#endregion
|
|
116
113
|
export { BranchStep };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BranchStep.js","names":[],"sources":["../../../src/workflows/steps/BranchStep.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"BranchStep.js","names":[],"sources":["../../../src/workflows/steps/BranchStep.ts"],"sourcesContent":["import { logErrorAndExit } from '../../console/logging.js';\nimport { logger } from '../../console/logger.js';\nimport type { GT } from 'generaltranslation';\nimport type { Settings } from '../../types/index.js';\nimport chalk from 'chalk';\nimport {\n getCurrentBranch,\n getIncomingBranches,\n getCheckedOutBranches,\n} from '../../git/branches.js';\nimport { BranchData } from '../../types/branch.js';\nimport { ApiError } from 'generaltranslation/errors';\n\ntype BranchStepClient = Pick<GT, 'queryBranchData' | 'createBranch'>;\ntype BranchStepSettings = Pick<Settings, 'branchOptions'>;\n\n// Step 1: Resolve the current branch id & update API with branch information\nexport class BranchStep {\n private spinner = logger.createSpinner('dots');\n private branchData: BranchData;\n private settings: BranchStepSettings;\n private gt: BranchStepClient;\n\n constructor(gt: BranchStepClient, settings: BranchStepSettings) {\n this.gt = gt;\n this.settings = settings;\n this.branchData = {\n currentBranch: {\n id: '',\n name: '',\n },\n incomingBranch: null,\n checkedOutBranch: null,\n };\n }\n\n async run(): Promise<BranchData | null> {\n this.spinner.start(`Resolving branch information...`);\n\n // First get some info about the branches we're working with\n let current: {\n currentBranchName: string;\n defaultBranch: boolean;\n } | null = null;\n let incoming: string[] = [];\n let checkedOut: string[] = [];\n let useDefaultBranch: boolean = true;\n let detectedDefaultBranchName: string = 'main';\n let autoDetectFailed = !this.settings.branchOptions.autoDetectBranches;\n\n if (\n this.settings.branchOptions.enabled &&\n this.settings.branchOptions.autoDetectBranches\n ) {\n const [currentResult, incomingResult, checkedOutResult] =\n await Promise.all([\n getCurrentBranch(this.settings.branchOptions.remoteName),\n getIncomingBranches(this.settings.branchOptions.remoteName),\n getCheckedOutBranches(this.settings.branchOptions.remoteName),\n ]);\n current = currentResult;\n incoming = incomingResult;\n checkedOut = checkedOutResult;\n\n if (currentResult) {\n detectedDefaultBranchName = currentResult.defaultBranchName;\n }\n\n // Try env var detection if git commands failed (e.g. Vercel)\n if (!currentResult) {\n autoDetectFailed = true;\n const vercelBranch = process.env.VERCEL_GIT_COMMIT_REF;\n if (vercelBranch) {\n current = { currentBranchName: vercelBranch, defaultBranch: false };\n }\n }\n\n // If detection succeeded, use the detected branch; otherwise fall back to default\n if (current) {\n useDefaultBranch = false;\n }\n }\n if (\n this.settings.branchOptions.enabled &&\n this.settings.branchOptions.currentBranch\n ) {\n current = {\n currentBranchName: this.settings.branchOptions.currentBranch,\n defaultBranch: current?.defaultBranch ?? false, // we have no way of knowing if this is the default branch without using the auto-detection logic\n };\n useDefaultBranch = false;\n }\n\n const branchData = await this.gt.queryBranchData({\n branchNames: [\n ...(current ? [current.currentBranchName] : []),\n ...incoming,\n ...checkedOut,\n ],\n });\n\n if (useDefaultBranch) {\n if (autoDetectFailed) {\n logger.warn(\n 'Branch auto-detection failed. Falling back to the default branch. Use --branch to specify a branch manually.'\n );\n }\n if (!branchData.defaultBranch) {\n const createBranchResult = await this.gt.createBranch({\n branchName: detectedDefaultBranchName,\n defaultBranch: true,\n });\n this.branchData.currentBranch = createBranchResult.branch;\n } else {\n this.branchData.currentBranch = branchData.defaultBranch;\n }\n } else {\n if (!current) {\n return logErrorAndExit(\n 'The current git branch could not be determined. Specify a custom branch or enable automatic branch detection.'\n );\n }\n const currentBranch = branchData.branches.find(\n (b) => b.name === current.currentBranchName\n );\n if (!currentBranch) {\n try {\n const createBranchResult = await this.gt.createBranch({\n branchName: current.currentBranchName,\n defaultBranch: current.defaultBranch,\n });\n this.branchData.currentBranch = createBranchResult.branch;\n } catch (error) {\n if (error instanceof ApiError && error.code === 403) {\n logger.warn(\n 'To enable translation branching, upgrade your plan. Falling back to default branch.'\n );\n // retry with default branch\n try {\n const createBranchResult = await this.gt.createBranch({\n branchName: detectedDefaultBranchName,\n defaultBranch: true,\n });\n this.branchData.currentBranch = createBranchResult.branch;\n } catch {\n // The fallback branch may already exist.\n }\n }\n }\n } else {\n this.branchData.currentBranch = currentBranch;\n }\n }\n\n if (this.branchData.currentBranch.id === '') {\n return logErrorAndExit(\n 'Something went wrong while resolving branch information. Try again.'\n );\n }\n\n // Now set the incoming and checked out branches (first one that exists)\n this.branchData.incomingBranch =\n incoming\n .map((b) => {\n const branch = branchData.branches.find((bb) => bb.name === b);\n if (branch) {\n return branch;\n } else {\n return null;\n }\n })\n .filter((b) => b !== null)[0] ?? null;\n this.branchData.checkedOutBranch =\n checkedOut\n .map((b) => {\n const branch = branchData.branches.find((bb) => bb.name === b);\n if (branch) {\n return branch;\n } else {\n return null;\n }\n })\n .filter((b) => b !== null)[0] ?? null;\n\n // ALWAYS fallback to default branch for checked out branch (to avoid retranslation)\n if (!this.branchData.checkedOutBranch && branchData.defaultBranch) {\n this.branchData.checkedOutBranch = branchData.defaultBranch;\n }\n\n this.spinner.stop(chalk.green('Branch information resolved successfully'));\n\n return this.branchData;\n }\n}\n"],"mappings":";;;;;;AAiBA,IAAa,aAAb,MAAwB;CACtB,UAAkB,OAAO,cAAc,OAAO;CAC9C;CACA;CACA;CAEA,YAAY,IAAsB,UAA8B;AAC9D,OAAK,KAAK;AACV,OAAK,WAAW;AAChB,OAAK,aAAa;GAChB,eAAe;IACb,IAAI;IACJ,MAAM;IACP;GACD,gBAAgB;GAChB,kBAAkB;GACnB;;CAGH,MAAM,MAAkC;AACtC,OAAK,QAAQ,MAAM,kCAAkC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gB,WAAW,SAAS,MACvC,MAAM,EAAE,SAAS,QAAQ,kBAC3B;AACD,OAAI,CAAC,cACH,KAAI;IACF,MAAM,qBAAqB,MAAM,KAAK,GAAG,aAAa;KACpD,YAAY,QAAQ;KACpB,eAAe,QAAQ;KACxB,CAAC;AACF,SAAK,WAAW,gBAAgB,mBAAmB;YAC5C,OAAO;AACd,QAAI,iBAAiB,YAAY,MAAM,SAAS,KAAK;AACnD,YAAO,KACL,sFACD;AAED,SAAI;MACF,MAAM,qBAAqB,MAAM,KAAK,GAAG,aAAa;OACpD,YAAY;OACZ,eAAe;OAChB,CAAC;AACF,WAAK,WAAW,gBAAgB,mBAAmB;aAC7C;;;OAMZ,MAAK,WAAW,gBAAgB;;AAIpC,MAAI,KAAK,WAAW,cAAc,OAAO,GACvC,QAAO,gBACL,sEACD;AAIH,OAAK,WAAW,iBACd,SACG,KAAK,MAAM;GACV,MAAM,SAAS,WAAW,SAAS,MAAM,OAAO,GAAG,SAAS,EAAE;AAC9D,OAAI,OACF,QAAO;OAEP,QAAO;IAET,CACD,QAAQ,MAAM,MAAM,KAAK,CAAC,MAAM;AACrC,OAAK,WAAW,mBACd,WACG,KAAK,MAAM;GACV,MAAM,SAAS,WAAW,SAAS,MAAM,OAAO,GAAG,SAAS,EAAE;AAC9D,OAAI,OACF,QAAO;OAEP,QAAO;IAET,CACD,QAAQ,MAAM,MAAM,KAAK,CAAC,MAAM;AAGrC,MAAI,CAAC,KAAK,WAAW,oBAAoB,WAAW,cAClD,MAAK,WAAW,mBAAmB,WAAW;AAGhD,OAAK,QAAQ,KAAK,MAAM,MAAM,2CAA2C,CAAC;AAE1E,SAAO,KAAK"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { WorkflowStep } from './WorkflowStep.js';
|
|
2
1
|
import { GT } from 'generaltranslation';
|
|
3
2
|
import { Settings } from '../../types/index.js';
|
|
4
3
|
import { FileStatusTracker } from './PollJobsStep.js';
|
|
@@ -7,7 +6,7 @@ export type DownloadTranslationsInput = {
|
|
|
7
6
|
resolveOutputPath: (sourcePath: string, locale: string) => string | null;
|
|
8
7
|
forceDownload?: boolean;
|
|
9
8
|
};
|
|
10
|
-
export declare class DownloadTranslationsStep
|
|
9
|
+
export declare class DownloadTranslationsStep {
|
|
11
10
|
private gt;
|
|
12
11
|
private settings;
|
|
13
12
|
private spinner;
|
|
@@ -15,5 +14,4 @@ export declare class DownloadTranslationsStep extends WorkflowStep<DownloadTrans
|
|
|
15
14
|
run({ fileTracker, resolveOutputPath, forceDownload, }: DownloadTranslationsInput): Promise<boolean>;
|
|
16
15
|
private downloadFiles;
|
|
17
16
|
private downloadFilesWithRetry;
|
|
18
|
-
wait(): Promise<void>;
|
|
19
17
|
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { logger } from "../../console/logger.js";
|
|
2
2
|
import "../../utils/constants.js";
|
|
3
|
-
import { WorkflowStep } from "./WorkflowStep.js";
|
|
4
3
|
import { recordWarning } from "../../state/translateWarnings.js";
|
|
5
4
|
import { downloadFileBatch } from "../../api/downloadFileBatch.js";
|
|
6
5
|
import chalk from "chalk";
|
|
7
6
|
import path from "node:path";
|
|
8
7
|
//#region src/workflows/steps/DownloadStep.ts
|
|
9
|
-
var DownloadTranslationsStep = class
|
|
8
|
+
var DownloadTranslationsStep = class {
|
|
10
9
|
spinner = null;
|
|
11
10
|
constructor(gt, settings) {
|
|
12
|
-
super();
|
|
13
11
|
this.gt = gt;
|
|
14
12
|
this.settings = settings;
|
|
15
13
|
}
|
|
@@ -119,7 +117,6 @@ var DownloadTranslationsStep = class extends WorkflowStep {
|
|
|
119
117
|
skipped: allSkipped
|
|
120
118
|
};
|
|
121
119
|
}
|
|
122
|
-
async wait() {}
|
|
123
120
|
};
|
|
124
121
|
//#endregion
|
|
125
122
|
export { DownloadTranslationsStep };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DownloadStep.js","names":[],"sources":["../../../src/workflows/steps/DownloadStep.ts"],"sourcesContent":["import chalk from 'chalk';\nimport path from 'node:path';\nimport { WorkflowStep } from './WorkflowStep.js';\nimport { logger } from '../../console/logger.js';\nimport {\n BatchedFiles,\n downloadFileBatch,\n DownloadFileBatchResult,\n} from '../../api/downloadFileBatch.js';\nimport { GT } from 'generaltranslation';\nimport { Settings } from '../../types/index.js';\nimport { recordWarning } from '../../state/translateWarnings.js';\nimport { FileStatusTracker } from './PollJobsStep.js';\nimport { TEMPLATE_FILE_NAME } from '../../utils/constants.js';\n\nexport type DownloadTranslationsInput = {\n fileTracker: FileStatusTracker;\n resolveOutputPath: (sourcePath: string, locale: string) => string | null;\n forceDownload?: boolean;\n};\n\nexport class DownloadTranslationsStep extends WorkflowStep<\n DownloadTranslationsInput,\n boolean\n> {\n private spinner: ReturnType<typeof logger.createProgressBar> | null = null;\n\n constructor(\n private gt: GT,\n private settings: Settings\n ) {\n super();\n }\n\n async run({\n fileTracker,\n resolveOutputPath,\n forceDownload,\n }: DownloadTranslationsInput): Promise<boolean> {\n this.spinner = logger.createProgressBar(fileTracker.completed.size);\n this.spinner.start('Downloading files...');\n\n return this.downloadFiles(fileTracker, resolveOutputPath, forceDownload);\n }\n\n private async downloadFiles(\n fileTracker: FileStatusTracker,\n resolveOutputPath: (sourcePath: string, locale: string) => string | null,\n forceDownload?: boolean\n ): Promise<boolean> {\n try {\n // Only download files that are marked as completed\n const currentQueryData = Array.from(fileTracker.completed.values());\n\n // If no files to download, we're done\n if (currentQueryData.length === 0) {\n this.spinner?.stop(chalk.green('No files to download'));\n return true;\n }\n\n // Check for translations\n const responseData = await this.gt.queryFileData({\n translatedFiles: currentQueryData.map((item) => ({\n fileId: item.fileId,\n versionId: item.versionId,\n branchId: item.branchId,\n locale: item.locale,\n })),\n });\n const translatedFiles = responseData.translatedFiles || [];\n\n // Filter for ready translations\n const readyTranslations = translatedFiles.filter(\n (file) => file.completedAt !== null\n );\n let missingCount = 0;\n\n if (readyTranslations.length < currentQueryData.length) {\n const readyKeys = new Set(\n readyTranslations.map(\n (t) => `${t.branchId}:${t.fileId}:${t.versionId}:${t.locale}`\n )\n );\n const missing = currentQueryData.filter(\n (item) =>\n !readyKeys.has(\n `${item.branchId}:${item.fileId}:${item.versionId}:${item.locale}`\n )\n );\n missingCount = missing.length;\n logger.warn(\n `Failed to download ${missing.length} file(s):\\n${missing.map((f) => `- ${f.fileName} (${f.locale})`).join('\\n')}`\n );\n for (const f of missing) {\n recordWarning(\n 'failed_download',\n f.fileName,\n `Failed to download for locale ${f.locale}`\n );\n }\n }\n\n // Review gating: skip completed translations for normal files whose\n // effective requiresReview policy is true but that are not approved\n // yet. Skips are intentional, not failures — a review-gated file is\n // simply absent locally and falls back to source behavior.\n // GTJSON is exempt: it is always requested, and the platform filters\n // unapproved components out of the served content itself.\n const requiresReviewPaths =\n this.settings.files?.requiresReviewPaths ?? new Set<string>();\n const reviewGatedKeys = new Set<string>();\n if (requiresReviewPaths.size > 0) {\n for (const translation of readyTranslations) {\n if (translation.approvedAt !== null) continue;\n const fileKey = `${translation.branchId}:${translation.fileId}:${translation.versionId}:${translation.locale}`;\n const fileProperties = fileTracker.completed.get(fileKey);\n if (!fileProperties) continue;\n if (fileProperties.fileName === TEMPLATE_FILE_NAME) continue;\n const absolutePath = path.resolve(\n process.cwd(),\n fileProperties.fileName\n );\n if (!requiresReviewPaths.has(absolutePath)) continue;\n reviewGatedKeys.add(fileKey);\n fileTracker.completed.delete(fileKey);\n fileTracker.skipped.set(fileKey, fileProperties);\n recordWarning(\n 'pending_review',\n fileProperties.fileName,\n `Translation for locale ${translation.locale} requires review and is not approved yet`\n );\n }\n if (reviewGatedKeys.size > 0) {\n logger.info(\n `Skipped ${reviewGatedKeys.size} file(s) awaiting review approval. They will download once approved.`\n );\n }\n }\n\n // Prepare batch download data\n const batchFiles: BatchedFiles = readyTranslations\n .map((translation) => {\n const fileKey = `${translation.branchId}:${translation.fileId}:${translation.versionId}:${translation.locale}`;\n\n const fileProperties = fileTracker.completed.get(fileKey);\n if (!fileProperties) {\n return null;\n }\n const outputPath = resolveOutputPath(\n fileProperties.fileName,\n translation.locale\n );\n\n // Skip downloading GTJSON files that are not in the files configuration\n if (outputPath === null) {\n fileTracker.completed.delete(fileKey);\n fileTracker.skipped.set(fileKey, fileProperties);\n return null;\n }\n return {\n branchId: translation.branchId,\n fileId: translation.fileId,\n versionId: translation.versionId,\n locale: translation.locale,\n inputPath: fileProperties.fileName,\n outputPath,\n };\n })\n .filter((file) => file !== null) as BatchedFiles;\n\n if (batchFiles.length > 0) {\n const batchResult = await this.downloadFilesWithRetry(\n fileTracker,\n batchFiles,\n forceDownload\n );\n this.spinner?.stop(\n chalk.green(\n `Downloaded ${batchResult.successful.length} files${batchResult.skipped.length > 0 ? `, skipped ${batchResult.skipped.length} files` : ''}`\n )\n );\n if (batchResult.failed.length > 0) {\n logger.warn(\n `Failed to download ${batchResult.failed.length} files: ${batchResult.failed.map((f) => f.inputPath).join('\\n')}`\n );\n for (const f of batchResult.failed) {\n recordWarning(\n 'failed_download',\n f.inputPath,\n `Failed to download for locale ${f.locale}`\n );\n }\n }\n } else if (missingCount > 0) {\n this.spinner?.stop(\n chalk.yellow('No files downloaded - see warnings above')\n );\n } else {\n this.spinner?.stop(chalk.green('No files to download'));\n }\n\n return true;\n } catch (error) {\n this.spinner?.stop(\n chalk.red('An error occurred while downloading translations')\n );\n logger.error(chalk.red('Error: ') + error);\n return false;\n }\n }\n\n private async downloadFilesWithRetry(\n fileTracker: FileStatusTracker,\n files: BatchedFiles,\n forceDownload?: boolean,\n maxRetries: number = 3,\n initialDelay: number = 1000\n ): Promise<DownloadFileBatchResult> {\n let remainingFiles = files;\n let allSuccessful: BatchedFiles = [];\n let retryCount = 0;\n let allSkipped: BatchedFiles = [];\n while (remainingFiles.length > 0 && retryCount <= maxRetries) {\n const batchResult = await downloadFileBatch(\n fileTracker,\n remainingFiles,\n this.settings,\n forceDownload\n );\n\n allSuccessful = [...allSuccessful, ...batchResult.successful];\n allSkipped = [...allSkipped, ...batchResult.skipped];\n\n this.spinner?.advance(\n batchResult.successful.length +\n batchResult.skipped.length +\n batchResult.failed.length\n );\n\n // If no failures or we've exhausted retries, we're done\n if (batchResult.failed.length === 0 || retryCount === maxRetries) {\n return {\n successful: allSuccessful,\n failed: batchResult.failed,\n skipped: allSkipped,\n };\n }\n\n // Calculate exponential backoff delay\n const delay = initialDelay * Math.pow(2, retryCount);\n logger.error(\n chalk.yellow(\n `Retrying ${batchResult.failed.length} failed file(s) in ${delay}ms (attempt ${retryCount + 1}/${maxRetries})...`\n )\n );\n\n // Wait before retrying\n await new Promise((resolve) => setTimeout(resolve, delay));\n\n remainingFiles = batchResult.failed;\n retryCount++;\n }\n\n return {\n successful: allSuccessful,\n failed: remainingFiles,\n skipped: allSkipped,\n };\n }\n\n async wait(): Promise<void> {\n return;\n }\n}\n"],"mappings":";;;;;;;;AAqBA,IAAa,2BAAb,cAA8C,aAG5C;CACA,UAAsE;CAEtE,YACE,IACA,UACA;AACA,SAAO;AAHC,OAAA,KAAA;AACA,OAAA,WAAA;;CAKV,MAAM,IAAI,EACR,aACA,mBACA,iBAC8C;AAC9C,OAAK,UAAU,OAAO,kBAAkB,YAAY,UAAU,KAAK;AACnE,OAAK,QAAQ,MAAM,uBAAuB;AAE1C,SAAO,KAAK,cAAc,aAAa,mBAAmB,cAAc;;CAG1E,MAAc,cACZ,aACA,mBACA,eACkB;AAClB,MAAI;GAEF,MAAM,mBAAmB,MAAM,KAAK,YAAY,UAAU,QAAQ,CAAC;AAGnE,OAAI,iBAAiB,WAAW,GAAG;AACjC,SAAK,SAAS,KAAK,MAAM,MAAM,uBAAuB,CAAC;AACvD,WAAO;;GAeT,MAAM,sBAHkB,MARG,KAAK,GAAG,cAAc,EAC/C,iBAAiB,iBAAiB,KAAK,UAAU;IAC/C,QAAQ,KAAK;IACb,WAAW,KAAK;IAChB,UAAU,KAAK;IACf,QAAQ,KAAK;IACd,EAAE,EACJ,CAAC,EACmC,mBAAmB,EAAE,EAGhB,QACvC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,UAAO;;;CAIX,MAAc,uBACZ,aACA,OACA,eACA,aAAqB,GACrB,eAAuB,KACW;EAClC,IAAI,iBAAiB;EACrB,IAAI,gBAA8B,EAAE;EACpC,IAAI,aAAa;EACjB,IAAI,aAA2B,EAAE;AACjC,SAAO,eAAe,SAAS,KAAK,cAAc,YAAY;GAC5D,MAAM,cAAc,MAAM,kBACxB,aACA,gBACA,KAAK,UACL,cACD;AAED,mBAAgB,CAAC,GAAG,eAAe,GAAG,YAAY,WAAW;AAC7D,gBAAa,CAAC,GAAG,YAAY,GAAG,YAAY,QAAQ;AAEpD,QAAK,SAAS,QACZ,YAAY,WAAW,SACrB,YAAY,QAAQ,SACpB,YAAY,OAAO,OACtB;AAGD,OAAI,YAAY,OAAO,WAAW,KAAK,eAAe,WACpD,QAAO;IACL,YAAY;IACZ,QAAQ,YAAY;IACpB,SAAS;IACV;GAIH,MAAM,QAAQ,eAAe,KAAK,IAAI,GAAG,WAAW;AACpD,UAAO,MACL,MAAM,OACJ,YAAY,YAAY,OAAO,OAAO,qBAAqB,MAAM,cAAc,aAAa,EAAE,GAAG,WAAW,MAC7G,CACF;AAGD,SAAM,IAAI,SAAS,YAAY,WAAW,SAAS,MAAM,CAAC;AAE1D,oBAAiB,YAAY;AAC7B;;AAGF,SAAO;GACL,YAAY;GACZ,QAAQ;GACR,SAAS;GACV;;CAGH,MAAM,OAAsB"}
|
|
1
|
+
{"version":3,"file":"DownloadStep.js","names":[],"sources":["../../../src/workflows/steps/DownloadStep.ts"],"sourcesContent":["import chalk from 'chalk';\nimport path from 'node:path';\nimport { logger } from '../../console/logger.js';\nimport {\n BatchedFiles,\n downloadFileBatch,\n DownloadFileBatchResult,\n} from '../../api/downloadFileBatch.js';\nimport { GT } from 'generaltranslation';\nimport { Settings } from '../../types/index.js';\nimport { recordWarning } from '../../state/translateWarnings.js';\nimport { FileStatusTracker } from './PollJobsStep.js';\nimport { TEMPLATE_FILE_NAME } from '../../utils/constants.js';\n\nexport type DownloadTranslationsInput = {\n fileTracker: FileStatusTracker;\n resolveOutputPath: (sourcePath: string, locale: string) => string | null;\n forceDownload?: boolean;\n};\n\nexport class DownloadTranslationsStep {\n private spinner: ReturnType<typeof logger.createProgressBar> | null = null;\n\n constructor(\n private gt: GT,\n private settings: Settings\n ) {}\n\n async run({\n fileTracker,\n resolveOutputPath,\n forceDownload,\n }: DownloadTranslationsInput): Promise<boolean> {\n this.spinner = logger.createProgressBar(fileTracker.completed.size);\n this.spinner.start('Downloading files...');\n\n return this.downloadFiles(fileTracker, resolveOutputPath, forceDownload);\n }\n\n private async downloadFiles(\n fileTracker: FileStatusTracker,\n resolveOutputPath: (sourcePath: string, locale: string) => string | null,\n forceDownload?: boolean\n ): Promise<boolean> {\n try {\n // Only download files that are marked as completed\n const currentQueryData = Array.from(fileTracker.completed.values());\n\n // If no files to download, we're done\n if (currentQueryData.length === 0) {\n this.spinner?.stop(chalk.green('No files to download'));\n return true;\n }\n\n // Check for translations\n const responseData = await this.gt.queryFileData({\n translatedFiles: currentQueryData.map((item) => ({\n fileId: item.fileId,\n versionId: item.versionId,\n branchId: item.branchId,\n locale: item.locale,\n })),\n });\n const translatedFiles = responseData.translatedFiles || [];\n\n // Filter for ready translations\n const readyTranslations = translatedFiles.filter(\n (file) => file.completedAt !== null\n );\n let missingCount = 0;\n\n if (readyTranslations.length < currentQueryData.length) {\n const readyKeys = new Set(\n readyTranslations.map(\n (t) => `${t.branchId}:${t.fileId}:${t.versionId}:${t.locale}`\n )\n );\n const missing = currentQueryData.filter(\n (item) =>\n !readyKeys.has(\n `${item.branchId}:${item.fileId}:${item.versionId}:${item.locale}`\n )\n );\n missingCount = missing.length;\n logger.warn(\n `Failed to download ${missing.length} file(s):\\n${missing.map((f) => `- ${f.fileName} (${f.locale})`).join('\\n')}`\n );\n for (const f of missing) {\n recordWarning(\n 'failed_download',\n f.fileName,\n `Failed to download for locale ${f.locale}`\n );\n }\n }\n\n // Review gating: skip completed translations for normal files whose\n // effective requiresReview policy is true but that are not approved\n // yet. Skips are intentional, not failures — a review-gated file is\n // simply absent locally and falls back to source behavior.\n // GTJSON is exempt: it is always requested, and the platform filters\n // unapproved components out of the served content itself.\n const requiresReviewPaths =\n this.settings.files?.requiresReviewPaths ?? new Set<string>();\n const reviewGatedKeys = new Set<string>();\n if (requiresReviewPaths.size > 0) {\n for (const translation of readyTranslations) {\n if (translation.approvedAt !== null) continue;\n const fileKey = `${translation.branchId}:${translation.fileId}:${translation.versionId}:${translation.locale}`;\n const fileProperties = fileTracker.completed.get(fileKey);\n if (!fileProperties) continue;\n if (fileProperties.fileName === TEMPLATE_FILE_NAME) continue;\n const absolutePath = path.resolve(\n process.cwd(),\n fileProperties.fileName\n );\n if (!requiresReviewPaths.has(absolutePath)) continue;\n reviewGatedKeys.add(fileKey);\n fileTracker.completed.delete(fileKey);\n fileTracker.skipped.set(fileKey, fileProperties);\n recordWarning(\n 'pending_review',\n fileProperties.fileName,\n `Translation for locale ${translation.locale} requires review and is not approved yet`\n );\n }\n if (reviewGatedKeys.size > 0) {\n logger.info(\n `Skipped ${reviewGatedKeys.size} file(s) awaiting review approval. They will download once approved.`\n );\n }\n }\n\n // Prepare batch download data\n const batchFiles: BatchedFiles = readyTranslations\n .map((translation) => {\n const fileKey = `${translation.branchId}:${translation.fileId}:${translation.versionId}:${translation.locale}`;\n\n const fileProperties = fileTracker.completed.get(fileKey);\n if (!fileProperties) {\n return null;\n }\n const outputPath = resolveOutputPath(\n fileProperties.fileName,\n translation.locale\n );\n\n // Skip downloading GTJSON files that are not in the files configuration\n if (outputPath === null) {\n fileTracker.completed.delete(fileKey);\n fileTracker.skipped.set(fileKey, fileProperties);\n return null;\n }\n return {\n branchId: translation.branchId,\n fileId: translation.fileId,\n versionId: translation.versionId,\n locale: translation.locale,\n inputPath: fileProperties.fileName,\n outputPath,\n };\n })\n .filter((file) => file !== null) as BatchedFiles;\n\n if (batchFiles.length > 0) {\n const batchResult = await this.downloadFilesWithRetry(\n fileTracker,\n batchFiles,\n forceDownload\n );\n this.spinner?.stop(\n chalk.green(\n `Downloaded ${batchResult.successful.length} files${batchResult.skipped.length > 0 ? `, skipped ${batchResult.skipped.length} files` : ''}`\n )\n );\n if (batchResult.failed.length > 0) {\n logger.warn(\n `Failed to download ${batchResult.failed.length} files: ${batchResult.failed.map((f) => f.inputPath).join('\\n')}`\n );\n for (const f of batchResult.failed) {\n recordWarning(\n 'failed_download',\n f.inputPath,\n `Failed to download for locale ${f.locale}`\n );\n }\n }\n } else if (missingCount > 0) {\n this.spinner?.stop(\n chalk.yellow('No files downloaded - see warnings above')\n );\n } else {\n this.spinner?.stop(chalk.green('No files to download'));\n }\n\n return true;\n } catch (error) {\n this.spinner?.stop(\n chalk.red('An error occurred while downloading translations')\n );\n logger.error(chalk.red('Error: ') + error);\n return false;\n }\n }\n\n private async downloadFilesWithRetry(\n fileTracker: FileStatusTracker,\n files: BatchedFiles,\n forceDownload?: boolean,\n maxRetries: number = 3,\n initialDelay: number = 1000\n ): Promise<DownloadFileBatchResult> {\n let remainingFiles = files;\n let allSuccessful: BatchedFiles = [];\n let retryCount = 0;\n let allSkipped: BatchedFiles = [];\n while (remainingFiles.length > 0 && retryCount <= maxRetries) {\n const batchResult = await downloadFileBatch(\n fileTracker,\n remainingFiles,\n this.settings,\n forceDownload\n );\n\n allSuccessful = [...allSuccessful, ...batchResult.successful];\n allSkipped = [...allSkipped, ...batchResult.skipped];\n\n this.spinner?.advance(\n batchResult.successful.length +\n batchResult.skipped.length +\n batchResult.failed.length\n );\n\n // If no failures or we've exhausted retries, we're done\n if (batchResult.failed.length === 0 || retryCount === maxRetries) {\n return {\n successful: allSuccessful,\n failed: batchResult.failed,\n skipped: allSkipped,\n };\n }\n\n // Calculate exponential backoff delay\n const delay = initialDelay * Math.pow(2, retryCount);\n logger.error(\n chalk.yellow(\n `Retrying ${batchResult.failed.length} failed file(s) in ${delay}ms (attempt ${retryCount + 1}/${maxRetries})...`\n )\n );\n\n // Wait before retrying\n await new Promise((resolve) => setTimeout(resolve, delay));\n\n remainingFiles = batchResult.failed;\n retryCount++;\n }\n\n return {\n successful: allSuccessful,\n failed: remainingFiles,\n skipped: allSkipped,\n };\n }\n}\n"],"mappings":";;;;;;;AAoBA,IAAa,2BAAb,MAAsC;CACpC,UAAsE;CAEtE,YACE,IACA,UACA;AAFQ,OAAA,KAAA;AACA,OAAA,WAAA;;CAGV,MAAM,IAAI,EACR,aACA,mBACA,iBAC8C;AAC9C,OAAK,UAAU,OAAO,kBAAkB,YAAY,UAAU,KAAK;AACnE,OAAK,QAAQ,MAAM,uBAAuB;AAE1C,SAAO,KAAK,cAAc,aAAa,mBAAmB,cAAc;;CAG1E,MAAc,cACZ,aACA,mBACA,eACkB;AAClB,MAAI;GAEF,MAAM,mBAAmB,MAAM,KAAK,YAAY,UAAU,QAAQ,CAAC;AAGnE,OAAI,iBAAiB,WAAW,GAAG;AACjC,SAAK,SAAS,KAAK,MAAM,MAAM,uBAAuB,CAAC;AACvD,WAAO;;GAeT,MAAM,sBAHkB,MARG,KAAK,GAAG,cAAc,EAC/C,iBAAiB,iBAAiB,KAAK,UAAU;IAC/C,QAAQ,KAAK;IACb,WAAW,KAAK;IAChB,UAAU,KAAK;IACf,QAAQ,KAAK;IACd,EAAE,EACJ,CAAC,EACmC,mBAAmB,EAAE,EAGhB,QACvC,SAAS,KAAK,gBAAgB,KAChC;GACD,IAAI,eAAe;AAEnB,OAAI,kBAAkB,SAAS,iBAAiB,QAAQ;IACtD,MAAM,YAAY,IAAI,IACpB,kBAAkB,KACf,MAAM,GAAG,EAAE,SAAS,GAAG,EAAE,OAAO,GAAG,EAAE,UAAU,GAAG,EAAE,SACtD,CACF;IACD,MAAM,UAAU,iBAAiB,QAC9B,SACC,CAAC,UAAU,IACT,GAAG,KAAK,SAAS,GAAG,KAAK,OAAO,GAAG,KAAK,UAAU,GAAG,KAAK,SAC3D,CACJ;AACD,mBAAe,QAAQ;AACvB,WAAO,KACL,sBAAsB,QAAQ,OAAO,aAAa,QA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Q,SACpB,YAAY,OAAO,OACtB;AAGD,OAAI,YAAY,OAAO,WAAW,KAAK,eAAe,WACpD,QAAO;IACL,YAAY;IACZ,QAAQ,YAAY;IACpB,SAAS;IACV;GAIH,MAAM,QAAQ,eAAe,KAAK,IAAI,GAAG,WAAW;AACpD,UAAO,MACL,MAAM,OACJ,YAAY,YAAY,OAAO,OAAO,qBAAqB,MAAM,cAAc,aAAa,EAAE,GAAG,WAAW,MAC7G,CACF;AAGD,SAAM,IAAI,SAAS,YAAY,WAAW,SAAS,MAAM,CAAC;AAE1D,oBAAiB,YAAY;AAC7B;;AAGF,SAAO;GACL,YAAY;GACZ,QAAQ;GACR,SAAS;GACV"}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import type { EnqueueFilesResult } from 'generaltranslation/types';
|
|
2
|
-
import { WorkflowStep } from './WorkflowStep.js';
|
|
3
2
|
import { GT } from 'generaltranslation';
|
|
4
3
|
import { Settings } from '../../types/index.js';
|
|
5
4
|
import type { FileReference } from 'generaltranslation/types';
|
|
6
|
-
export declare class EnqueueStep
|
|
5
|
+
export declare class EnqueueStep {
|
|
7
6
|
private gt;
|
|
8
7
|
private settings;
|
|
9
8
|
private force?;
|
|
10
9
|
private spinner;
|
|
11
|
-
private result;
|
|
12
|
-
private spinnerStarted;
|
|
13
10
|
constructor(gt: GT, settings: Settings, force?: boolean | undefined);
|
|
14
11
|
run(files: FileReference[]): Promise<EnqueueFilesResult>;
|
|
15
|
-
wait(): Promise<void>;
|
|
16
12
|
}
|
|
@@ -1,38 +1,28 @@
|
|
|
1
1
|
import { logger } from "../../console/logger.js";
|
|
2
|
-
import { WorkflowStep } from "./WorkflowStep.js";
|
|
3
2
|
import chalk from "chalk";
|
|
4
3
|
//#region src/workflows/steps/EnqueueStep.ts
|
|
5
|
-
var EnqueueStep = class
|
|
4
|
+
var EnqueueStep = class {
|
|
6
5
|
spinner = logger.createSpinner("dots");
|
|
7
|
-
result = null;
|
|
8
|
-
spinnerStarted = false;
|
|
9
6
|
constructor(gt, settings, force) {
|
|
10
|
-
super();
|
|
11
7
|
this.gt = gt;
|
|
12
8
|
this.settings = settings;
|
|
13
9
|
this.force = force;
|
|
14
10
|
}
|
|
15
11
|
async run(files) {
|
|
16
|
-
if (files.length === 0) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
return this.result;
|
|
23
|
-
}
|
|
12
|
+
if (files.length === 0) return {
|
|
13
|
+
jobData: {},
|
|
14
|
+
locales: this.settings.locales,
|
|
15
|
+
message: "No files need to be enqueued"
|
|
16
|
+
};
|
|
24
17
|
this.spinner.start("Enqueuing translations...");
|
|
25
|
-
this.
|
|
26
|
-
this.result = await this.gt.enqueueFiles(files, {
|
|
18
|
+
const result = await this.gt.enqueueFiles(files, {
|
|
27
19
|
sourceLocale: this.settings.defaultLocale,
|
|
28
20
|
targetLocales: this.settings.locales,
|
|
29
21
|
modelProvider: this.settings.modelProvider,
|
|
30
22
|
force: this.force
|
|
31
23
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
async wait() {
|
|
35
|
-
if (this.result && this.spinnerStarted) this.spinner.stop(chalk.green("Translations enqueued successfully"));
|
|
24
|
+
this.spinner.stop(chalk.green("Translations enqueued successfully"));
|
|
25
|
+
return result;
|
|
36
26
|
}
|
|
37
27
|
};
|
|
38
28
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnqueueStep.js","names":[],"sources":["../../../src/workflows/steps/EnqueueStep.ts"],"sourcesContent":["import type { EnqueueFilesResult } from 'generaltranslation/types';\nimport {
|
|
1
|
+
{"version":3,"file":"EnqueueStep.js","names":[],"sources":["../../../src/workflows/steps/EnqueueStep.ts"],"sourcesContent":["import type { EnqueueFilesResult } from 'generaltranslation/types';\nimport { logger } from '../../console/logger.js';\nimport { GT } from 'generaltranslation';\nimport { Settings } from '../../types/index.js';\nimport type { FileReference } from 'generaltranslation/types';\nimport chalk from 'chalk';\n\nexport class EnqueueStep {\n private spinner = logger.createSpinner('dots');\n\n constructor(\n private gt: GT,\n private settings: Settings,\n private force?: boolean\n ) {}\n\n async run(files: FileReference[]): Promise<EnqueueFilesResult> {\n if (files.length === 0) {\n return {\n jobData: {},\n locales: this.settings.locales,\n message: 'No files need to be enqueued',\n };\n }\n\n this.spinner.start('Enqueuing translations...');\n\n const result = await this.gt.enqueueFiles(files, {\n sourceLocale: this.settings.defaultLocale,\n targetLocales: this.settings.locales,\n modelProvider: this.settings.modelProvider,\n force: this.force,\n });\n this.spinner.stop(chalk.green('Translations enqueued successfully'));\n return result;\n }\n}\n"],"mappings":";;;AAOA,IAAa,cAAb,MAAyB;CACvB,UAAkB,OAAO,cAAc,OAAO;CAE9C,YACE,IACA,UACA,OACA;AAHQ,OAAA,KAAA;AACA,OAAA,WAAA;AACA,OAAA,QAAA;;CAGV,MAAM,IAAI,OAAqD;AAC7D,MAAI,MAAM,WAAW,EACnB,QAAO;GACL,SAAS,EAAE;GACX,SAAS,KAAK,SAAS;GACvB,SAAS;GACV;AAGH,OAAK,QAAQ,MAAM,4BAA4B;EAE/C,MAAM,SAAS,MAAM,KAAK,GAAG,aAAa,OAAO;GAC/C,cAAc,KAAK,SAAS;GAC5B,eAAe,KAAK,SAAS;GAC7B,eAAe,KAAK,SAAS;GAC7B,OAAO,KAAK;GACb,CAAC;AACF,OAAK,QAAQ,KAAK,MAAM,MAAM,qCAAqC,CAAC;AACpE,SAAO"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { WorkflowStep } from './WorkflowStep.js';
|
|
2
1
|
import { GT } from 'generaltranslation';
|
|
3
2
|
import { EnqueueFilesResult } from 'generaltranslation/types';
|
|
4
3
|
import type { FileProperties } from '../../types/files.js';
|
|
@@ -19,7 +18,7 @@ export type PollJobsOutput = {
|
|
|
19
18
|
success: boolean;
|
|
20
19
|
fileTracker: FileStatusTracker;
|
|
21
20
|
};
|
|
22
|
-
export declare class PollTranslationJobsStep
|
|
21
|
+
export declare class PollTranslationJobsStep {
|
|
23
22
|
private gt;
|
|
24
23
|
private spinner;
|
|
25
24
|
private previousProgress;
|
|
@@ -27,5 +26,4 @@ export declare class PollTranslationJobsStep extends WorkflowStep<PollJobsInput,
|
|
|
27
26
|
run({ fileTracker, fileQueryData, jobData, timeoutDuration, forceRetranslation, }: PollJobsInput): Promise<PollJobsOutput>;
|
|
28
27
|
private updateSpinner;
|
|
29
28
|
private generateStatusSuffixText;
|
|
30
|
-
wait(): Promise<void>;
|
|
31
29
|
}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { logger } from "../../console/logger.js";
|
|
2
2
|
import "../../utils/constants.js";
|
|
3
|
-
import { WorkflowStep } from "./WorkflowStep.js";
|
|
4
3
|
import { getFileTranslationKey, queryCompletedTranslationKeys } from "../utils/queryCompletedTranslations.js";
|
|
5
4
|
import chalk from "chalk";
|
|
6
5
|
//#region src/workflows/steps/PollJobsStep.ts
|
|
7
|
-
var PollTranslationJobsStep = class
|
|
6
|
+
var PollTranslationJobsStep = class {
|
|
8
7
|
spinner = null;
|
|
9
8
|
previousProgress = 0;
|
|
10
9
|
constructor(gt) {
|
|
11
|
-
super();
|
|
12
10
|
this.gt = gt;
|
|
13
11
|
}
|
|
14
12
|
async run({ fileTracker, fileQueryData, jobData, timeoutDuration, forceRetranslation }) {
|
|
@@ -194,7 +192,6 @@ var PollTranslationJobsStep = class extends WorkflowStep {
|
|
|
194
192
|
if (filesArray.length > maxFilesToShow) newSuffixText.push(`... and ${filesArray.length - maxFilesToShow} more files`);
|
|
195
193
|
return newSuffixText.join("\n");
|
|
196
194
|
}
|
|
197
|
-
async wait() {}
|
|
198
195
|
};
|
|
199
196
|
//#endregion
|
|
200
197
|
export { PollTranslationJobsStep };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PollJobsStep.js","names":[],"sources":["../../../src/workflows/steps/PollJobsStep.ts"],"sourcesContent":["import chalk from 'chalk';\nimport { WorkflowStep } from './WorkflowStep.js';\nimport { logger } from '../../console/logger.js';\nimport { GT } from 'generaltranslation';\nimport { EnqueueFilesResult } from 'generaltranslation/types';\nimport { TEMPLATE_FILE_NAME } from '../../utils/constants.js';\nimport type { FileProperties } from '../../types/files.js';\nimport {\n getFileTranslationKey,\n queryCompletedTranslationKeys,\n} from '../utils/queryCompletedTranslations.js';\n\nexport type PollJobsInput = {\n fileTracker: FileStatusTracker;\n fileQueryData: FileProperties[];\n jobData: EnqueueFilesResult;\n timeoutDuration: number;\n forceRetranslation?: boolean;\n};\n\nexport type FileStatusTracker = {\n completed: Map<string, FileProperties>;\n inProgress: Map<string, FileProperties>;\n failed: Map<string, FileProperties>;\n skipped: Map<string, FileProperties>;\n};\n\nexport type PollJobsOutput = {\n success: boolean;\n fileTracker: FileStatusTracker;\n};\n\nexport class PollTranslationJobsStep extends WorkflowStep<\n PollJobsInput,\n PollJobsOutput\n> {\n private spinner: ReturnType<typeof logger.createProgressBar> | null = null;\n private previousProgress = 0;\n\n constructor(private gt: GT) {\n super();\n }\n\n async run({\n fileTracker,\n fileQueryData,\n jobData,\n timeoutDuration,\n forceRetranslation,\n }: PollJobsInput): Promise<PollJobsOutput> {\n const startTime = Date.now();\n this.spinner = logger.createProgressBar(fileQueryData.length);\n const spinnerMessage = forceRetranslation\n ? 'Waiting for retranslation...'\n : 'Waiting for translation...';\n this.spinner.start(spinnerMessage);\n\n // Build a map of branchId:fileId:versionId:locale -> FileProperties\n const filePropertiesMap = new Map<string, FileProperties>();\n fileQueryData.forEach((item) => {\n filePropertiesMap.set(getFileTranslationKey(item), item);\n });\n\n // Initial query to check which files already have translations\n // Skip when force retranslation is enabled, since the server\n // no longer marks force-retranslated files as incomplete\n if (!forceRetranslation) {\n const completedKeys = await queryCompletedTranslationKeys(\n this.gt,\n fileQueryData\n );\n\n completedKeys.forEach((fileKey) => {\n const fileProperties = filePropertiesMap.get(fileKey);\n if (fileProperties) {\n fileTracker.completed.set(fileKey, fileProperties);\n }\n });\n }\n\n // Build a map of jobs for quick lookup:\n // branchId:fileId:versionId:locale -> job\n const jobMap = new Map<\n string,\n (typeof jobData.jobData)[number] & { jobId: string }\n >();\n Object.entries(jobData.jobData).forEach(([jobId, job]) => {\n const jobLocale = this.gt.resolveAliasLocale(job.targetLocale);\n const key = `${job.branchId}:${job.fileId}:${job.versionId}:${jobLocale}`;\n jobMap.set(key, { ...job, jobId, targetLocale: jobLocale });\n });\n\n // Build a map of jobs for quick lookup:\n // jobId -> file data for the job\n const jobFileMap = new Map<\n string,\n {\n branchId: string;\n fileId: string;\n versionId: string;\n locale: string;\n }\n >();\n Object.entries(jobData.jobData).forEach(([jobId, job]) => {\n const jobLocale = this.gt.resolveAliasLocale(job.targetLocale);\n jobFileMap.set(jobId, {\n branchId: job.branchId,\n fileId: job.fileId,\n versionId: job.versionId,\n locale: jobLocale,\n });\n });\n\n // Categorize each file query item\n for (const item of fileQueryData) {\n const fileKey = getFileTranslationKey(item);\n\n // Check if translation already exists (completedAt is truthy)\n const existingTranslation = fileTracker.completed.get(fileKey);\n\n if (existingTranslation) {\n continue;\n }\n\n // Check if there's a job for this file\n const jobKey = `${item.branchId}:${item.fileId}:${item.versionId}:${item.locale}`;\n const job = jobMap.get(jobKey);\n\n if (job) {\n // Job exists - mark as in progress initially\n fileTracker.inProgress.set(fileKey, item);\n } else {\n // No job and no existing translation - mark as skipped\n fileTracker.skipped.set(fileKey, item);\n }\n }\n\n // Update spinner with initial status\n this.updateSpinner(fileTracker, fileQueryData);\n\n // If force retranslation, don't skip the initial check\n if (!forceRetranslation) {\n // Check if all jobs are already complete\n if (fileTracker.inProgress.size === 0) {\n this.spinner.stop(chalk.green('All translations ready'));\n return { success: true, fileTracker };\n }\n }\n\n // Calculate time until next 5-second interval since startTime\n const msUntilNextInterval = Math.max(\n 0,\n 5000 - ((Date.now() - startTime) % 5000)\n );\n\n return new Promise<PollJobsOutput>((resolve) => {\n let intervalCheck: NodeJS.Timeout;\n\n setTimeout(() => {\n intervalCheck = setInterval(async () => {\n try {\n // Query job status\n const jobIds = Array.from(jobFileMap.keys());\n const jobStatusResponse = await this.gt.checkJobStatus(jobIds);\n\n // Update status based on job completion\n for (const job of jobStatusResponse) {\n const jobFileProperties = jobFileMap.get(job.jobId);\n if (jobFileProperties) {\n const fileKey = `${jobFileProperties.branchId}:${jobFileProperties.fileId}:${jobFileProperties.versionId}:${jobFileProperties.locale}`;\n const fileProperties = filePropertiesMap.get(fileKey);\n if (!fileProperties) {\n continue;\n }\n if (job.status === 'completed') {\n fileTracker.completed.set(fileKey, fileProperties);\n fileTracker.inProgress.delete(fileKey);\n jobFileMap.delete(job.jobId);\n } else if (job.status === 'failed') {\n fileTracker.failed.set(fileKey, fileProperties);\n fileTracker.inProgress.delete(fileKey);\n jobFileMap.delete(job.jobId);\n } else if (job.status === 'unknown') {\n fileTracker.skipped.set(fileKey, fileProperties);\n fileTracker.inProgress.delete(fileKey);\n jobFileMap.delete(job.jobId);\n }\n }\n }\n\n // Update spinner\n this.updateSpinner(fileTracker, fileQueryData);\n\n const elapsed = Date.now() - startTime;\n const allJobsProcessed = fileTracker.inProgress.size === 0;\n\n if (allJobsProcessed || elapsed >= timeoutDuration * 1000) {\n clearInterval(intervalCheck);\n\n if (fileTracker.inProgress.size === 0) {\n this.spinner!.stop(chalk.green('Translation jobs finished'));\n resolve({ success: true, fileTracker });\n } else {\n this.spinner!.stop(\n chalk.red('Timed out waiting for translation jobs')\n );\n resolve({ success: false, fileTracker });\n }\n }\n } catch (error) {\n logger.error(chalk.red('Error checking job status: ') + error);\n }\n }, 5000);\n }, msUntilNextInterval);\n });\n }\n\n private updateSpinner(\n fileTracker: FileStatusTracker,\n fileQueryData: FileProperties[]\n ): void {\n if (!this.spinner) return;\n\n const statusText = this.generateStatusSuffixText(\n fileTracker,\n fileQueryData\n );\n const currentProgress =\n fileTracker.completed.size +\n fileTracker.failed.size +\n fileTracker.skipped.size;\n const progressDelta = currentProgress - this.previousProgress;\n this.spinner.advance(progressDelta, statusText);\n this.previousProgress = currentProgress;\n }\n\n private generateStatusSuffixText(\n fileTracker: FileStatusTracker,\n fileQueryData: FileProperties[]\n ): string {\n // Simple progress indicator\n const progressText = `${chalk.green(\n `[${\n fileTracker.completed.size +\n fileTracker.failed.size +\n fileTracker.skipped.size\n }/${fileQueryData.length}]`\n )} translations completed`;\n\n // Get terminal height to adapt our output\n const terminalHeight = process.stdout.rows || 24;\n\n // If terminal is very small, just show the basic progress\n if (terminalHeight < 6) {\n return progressText;\n }\n\n const newSuffixText = [progressText];\n\n // Organize data by filename : locale\n const fileStatus = new Map<\n string,\n {\n completed: Set<string>;\n pending: Set<string>;\n failed: Set<string>;\n skipped: Set<string>;\n }\n >();\n\n // Initialize with all files and locales from fileQueryData\n for (const item of fileQueryData) {\n if (!fileStatus.has(item.fileName)) {\n fileStatus.set(item.fileName, {\n completed: new Set(),\n pending: new Set([item.locale]),\n failed: new Set(),\n skipped: new Set(),\n });\n } else {\n fileStatus.get(item.fileName)?.pending.add(item.locale);\n }\n }\n\n // Mark which ones are completed, failed, or skipped\n for (const [_, fileProperties] of fileTracker.completed) {\n const { fileName, locale } = fileProperties;\n const status = fileStatus.get(fileName);\n if (status) {\n status.pending.delete(locale);\n status.completed.add(locale);\n }\n }\n\n for (const [_, fileProperties] of fileTracker.failed) {\n const { fileName, locale } = fileProperties;\n const status = fileStatus.get(fileName);\n if (status) {\n status.pending.delete(locale);\n status.failed.add(locale);\n }\n }\n\n for (const [_, fileProperties] of fileTracker.skipped) {\n const { fileName, locale } = fileProperties;\n const status = fileStatus.get(fileName);\n if (status) {\n status.pending.delete(locale);\n status.skipped.add(locale);\n }\n }\n\n // Calculate how many files we can show based on terminal height\n const filesArray = Array.from(fileStatus.entries());\n const maxFilesToShow = Math.min(\n filesArray.length,\n terminalHeight - 3 // Header + progress + buffer\n );\n\n // Display each file with its status on a single line\n for (let i = 0; i < maxFilesToShow; i++) {\n const [fileName, status] = filesArray[i];\n\n // Create condensed locale status\n const localeStatuses: { locale: string; status: string }[] = [];\n\n // Add completed locales (green)\n if (status.completed.size > 0) {\n localeStatuses.push(\n ...Array.from(status.completed).map((locale) => ({\n locale,\n status: 'completed',\n }))\n );\n }\n\n // Add skipped locales (green)\n if (status.skipped.size > 0) {\n localeStatuses.push(\n ...Array.from(status.skipped).map((locale) => ({\n locale,\n status: 'skipped',\n }))\n );\n }\n\n // Add failed locales (red)\n if (status.failed.size > 0) {\n localeStatuses.push(\n ...Array.from(status.failed).map((locale) => ({\n locale,\n status: 'failed',\n }))\n );\n }\n\n // Add pending locales (yellow)\n if (status.pending.size > 0) {\n localeStatuses.push(\n ...Array.from(status.pending).map((locale) => ({\n locale,\n status: 'pending',\n }))\n );\n }\n\n // Sort localeStatuses by locale\n localeStatuses.sort((a, b) => a.locale.localeCompare(b.locale));\n\n // Add colors\n const localeString = localeStatuses\n .map((locale) => {\n if (locale.status === 'completed') {\n return chalk.green(locale.locale);\n } else if (locale.status === 'skipped') {\n return chalk.gray(locale.locale);\n } else if (locale.status === 'failed') {\n return chalk.red(locale.locale);\n } else if (locale.status === 'pending') {\n return chalk.yellow(locale.locale);\n }\n })\n .join(', ');\n\n // Format the line\n const prettyFileName =\n fileName === TEMPLATE_FILE_NAME ? '<React Elements>' : fileName;\n newSuffixText.push(`${chalk.bold(prettyFileName)} [${localeString}]`);\n }\n\n // If we couldn't show all files, add an indicator\n if (filesArray.length > maxFilesToShow) {\n newSuffixText.push(\n `... and ${filesArray.length - maxFilesToShow} more files`\n );\n }\n\n return newSuffixText.join('\\n');\n }\n\n async wait(): Promise<void> {\n return;\n }\n}\n"],"mappings":";;;;;;AAgCA,IAAa,0BAAb,cAA6C,aAG3C;CACA,UAAsE;CACtE,mBAA2B;CAE3B,YAAY,IAAgB;AAC1B,SAAO;AADW,OAAA,KAAA;;CAIpB,MAAM,IAAI,EACR,aACA,eACA,SACA,iBACA,sBACyC;EACzC,MAAM,YAAY,KAAK,KAAK;AAC5B,OAAK,UAAU,OAAO,kBAAkB,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,GAAG,MAAM,KAAK,OAAO,QAAQ,CAAC,KAAK,YAAY;IAC7C;IACA,QAAQ;IACT,EAAE,CACJ;AAIH,kBAAe,MAAM,GAAG,MAAM,EAAE,OAAO,cAAc,EAAE,OAAO,CAAC;GAG/D,MAAM,eAAe,eAClB,KAAK,WAAW;AACf,QAAI,OAAO,WAAW,YACpB,QAAO,MAAM,MAAM,OAAO,OAAO;aACxB,OAAO,WAAW,UAC3B,QAAO,MAAM,KAAK,OAAO,OAAO;aACvB,OAAO,WAAW,SAC3B,QAAO,MAAM,IAAI,OAAO,OAAO;aACtB,OAAO,WAAW,UAC3B,QAAO,MAAM,OAAO,OAAO,OAAO;KAEpC,CACD,KAAK,KAAK;GAGb,MAAM,iBACJ,aAAA,kCAAkC,qBAAqB;AACzD,iBAAc,KAAK,GAAG,MAAM,KAAK,eAAe,CAAC,IAAI,aAAa,GAAG;;AAIvE,MAAI,WAAW,SAAS,eACtB,eAAc,KACZ,WAAW,WAAW,SAAS,eAAe,aAC/C;AAGH,SAAO,cAAc,KAAK,KAAK;;CAGjC,MAAM,OAAsB"}
|
|
1
|
+
{"version":3,"file":"PollJobsStep.js","names":[],"sources":["../../../src/workflows/steps/PollJobsStep.ts"],"sourcesContent":["import chalk from 'chalk';\nimport { logger } from '../../console/logger.js';\nimport { GT } from 'generaltranslation';\nimport { EnqueueFilesResult } from 'generaltranslation/types';\nimport { TEMPLATE_FILE_NAME } from '../../utils/constants.js';\nimport type { FileProperties } from '../../types/files.js';\nimport {\n getFileTranslationKey,\n queryCompletedTranslationKeys,\n} from '../utils/queryCompletedTranslations.js';\n\nexport type PollJobsInput = {\n fileTracker: FileStatusTracker;\n fileQueryData: FileProperties[];\n jobData: EnqueueFilesResult;\n timeoutDuration: number;\n forceRetranslation?: boolean;\n};\n\nexport type FileStatusTracker = {\n completed: Map<string, FileProperties>;\n inProgress: Map<string, FileProperties>;\n failed: Map<string, FileProperties>;\n skipped: Map<string, FileProperties>;\n};\n\nexport type PollJobsOutput = {\n success: boolean;\n fileTracker: FileStatusTracker;\n};\n\nexport class PollTranslationJobsStep {\n private spinner: ReturnType<typeof logger.createProgressBar> | null = null;\n private previousProgress = 0;\n\n constructor(private gt: GT) {}\n\n async run({\n fileTracker,\n fileQueryData,\n jobData,\n timeoutDuration,\n forceRetranslation,\n }: PollJobsInput): Promise<PollJobsOutput> {\n const startTime = Date.now();\n this.spinner = logger.createProgressBar(fileQueryData.length);\n const spinnerMessage = forceRetranslation\n ? 'Waiting for retranslation...'\n : 'Waiting for translation...';\n this.spinner.start(spinnerMessage);\n\n // Build a map of branchId:fileId:versionId:locale -> FileProperties\n const filePropertiesMap = new Map<string, FileProperties>();\n fileQueryData.forEach((item) => {\n filePropertiesMap.set(getFileTranslationKey(item), item);\n });\n\n // Initial query to check which files already have translations\n // Skip when force retranslation is enabled, since the server\n // no longer marks force-retranslated files as incomplete\n if (!forceRetranslation) {\n const completedKeys = await queryCompletedTranslationKeys(\n this.gt,\n fileQueryData\n );\n\n completedKeys.forEach((fileKey) => {\n const fileProperties = filePropertiesMap.get(fileKey);\n if (fileProperties) {\n fileTracker.completed.set(fileKey, fileProperties);\n }\n });\n }\n\n // Build a map of jobs for quick lookup:\n // branchId:fileId:versionId:locale -> job\n const jobMap = new Map<\n string,\n (typeof jobData.jobData)[number] & { jobId: string }\n >();\n Object.entries(jobData.jobData).forEach(([jobId, job]) => {\n const jobLocale = this.gt.resolveAliasLocale(job.targetLocale);\n const key = `${job.branchId}:${job.fileId}:${job.versionId}:${jobLocale}`;\n jobMap.set(key, { ...job, jobId, targetLocale: jobLocale });\n });\n\n // Build a map of jobs for quick lookup:\n // jobId -> file data for the job\n const jobFileMap = new Map<\n string,\n {\n branchId: string;\n fileId: string;\n versionId: string;\n locale: string;\n }\n >();\n Object.entries(jobData.jobData).forEach(([jobId, job]) => {\n const jobLocale = this.gt.resolveAliasLocale(job.targetLocale);\n jobFileMap.set(jobId, {\n branchId: job.branchId,\n fileId: job.fileId,\n versionId: job.versionId,\n locale: jobLocale,\n });\n });\n\n // Categorize each file query item\n for (const item of fileQueryData) {\n const fileKey = getFileTranslationKey(item);\n\n // Check if translation already exists (completedAt is truthy)\n const existingTranslation = fileTracker.completed.get(fileKey);\n\n if (existingTranslation) {\n continue;\n }\n\n // Check if there's a job for this file\n const jobKey = `${item.branchId}:${item.fileId}:${item.versionId}:${item.locale}`;\n const job = jobMap.get(jobKey);\n\n if (job) {\n // Job exists - mark as in progress initially\n fileTracker.inProgress.set(fileKey, item);\n } else {\n // No job and no existing translation - mark as skipped\n fileTracker.skipped.set(fileKey, item);\n }\n }\n\n // Update spinner with initial status\n this.updateSpinner(fileTracker, fileQueryData);\n\n // If force retranslation, don't skip the initial check\n if (!forceRetranslation) {\n // Check if all jobs are already complete\n if (fileTracker.inProgress.size === 0) {\n this.spinner.stop(chalk.green('All translations ready'));\n return { success: true, fileTracker };\n }\n }\n\n // Calculate time until next 5-second interval since startTime\n const msUntilNextInterval = Math.max(\n 0,\n 5000 - ((Date.now() - startTime) % 5000)\n );\n\n return new Promise<PollJobsOutput>((resolve) => {\n let intervalCheck: NodeJS.Timeout;\n\n setTimeout(() => {\n intervalCheck = setInterval(async () => {\n try {\n // Query job status\n const jobIds = Array.from(jobFileMap.keys());\n const jobStatusResponse = await this.gt.checkJobStatus(jobIds);\n\n // Update status based on job completion\n for (const job of jobStatusResponse) {\n const jobFileProperties = jobFileMap.get(job.jobId);\n if (jobFileProperties) {\n const fileKey = `${jobFileProperties.branchId}:${jobFileProperties.fileId}:${jobFileProperties.versionId}:${jobFileProperties.locale}`;\n const fileProperties = filePropertiesMap.get(fileKey);\n if (!fileProperties) {\n continue;\n }\n if (job.status === 'completed') {\n fileTracker.completed.set(fileKey, fileProperties);\n fileTracker.inProgress.delete(fileKey);\n jobFileMap.delete(job.jobId);\n } else if (job.status === 'failed') {\n fileTracker.failed.set(fileKey, fileProperties);\n fileTracker.inProgress.delete(fileKey);\n jobFileMap.delete(job.jobId);\n } else if (job.status === 'unknown') {\n fileTracker.skipped.set(fileKey, fileProperties);\n fileTracker.inProgress.delete(fileKey);\n jobFileMap.delete(job.jobId);\n }\n }\n }\n\n // Update spinner\n this.updateSpinner(fileTracker, fileQueryData);\n\n const elapsed = Date.now() - startTime;\n const allJobsProcessed = fileTracker.inProgress.size === 0;\n\n if (allJobsProcessed || elapsed >= timeoutDuration * 1000) {\n clearInterval(intervalCheck);\n\n if (fileTracker.inProgress.size === 0) {\n this.spinner!.stop(chalk.green('Translation jobs finished'));\n resolve({ success: true, fileTracker });\n } else {\n this.spinner!.stop(\n chalk.red('Timed out waiting for translation jobs')\n );\n resolve({ success: false, fileTracker });\n }\n }\n } catch (error) {\n logger.error(chalk.red('Error checking job status: ') + error);\n }\n }, 5000);\n }, msUntilNextInterval);\n });\n }\n\n private updateSpinner(\n fileTracker: FileStatusTracker,\n fileQueryData: FileProperties[]\n ): void {\n if (!this.spinner) return;\n\n const statusText = this.generateStatusSuffixText(\n fileTracker,\n fileQueryData\n );\n const currentProgress =\n fileTracker.completed.size +\n fileTracker.failed.size +\n fileTracker.skipped.size;\n const progressDelta = currentProgress - this.previousProgress;\n this.spinner.advance(progressDelta, statusText);\n this.previousProgress = currentProgress;\n }\n\n private generateStatusSuffixText(\n fileTracker: FileStatusTracker,\n fileQueryData: FileProperties[]\n ): string {\n // Simple progress indicator\n const progressText = `${chalk.green(\n `[${\n fileTracker.completed.size +\n fileTracker.failed.size +\n fileTracker.skipped.size\n }/${fileQueryData.length}]`\n )} translations completed`;\n\n // Get terminal height to adapt our output\n const terminalHeight = process.stdout.rows || 24;\n\n // If terminal is very small, just show the basic progress\n if (terminalHeight < 6) {\n return progressText;\n }\n\n const newSuffixText = [progressText];\n\n // Organize data by filename : locale\n const fileStatus = new Map<\n string,\n {\n completed: Set<string>;\n pending: Set<string>;\n failed: Set<string>;\n skipped: Set<string>;\n }\n >();\n\n // Initialize with all files and locales from fileQueryData\n for (const item of fileQueryData) {\n if (!fileStatus.has(item.fileName)) {\n fileStatus.set(item.fileName, {\n completed: new Set(),\n pending: new Set([item.locale]),\n failed: new Set(),\n skipped: new Set(),\n });\n } else {\n fileStatus.get(item.fileName)?.pending.add(item.locale);\n }\n }\n\n // Mark which ones are completed, failed, or skipped\n for (const [_, fileProperties] of fileTracker.completed) {\n const { fileName, locale } = fileProperties;\n const status = fileStatus.get(fileName);\n if (status) {\n status.pending.delete(locale);\n status.completed.add(locale);\n }\n }\n\n for (const [_, fileProperties] of fileTracker.failed) {\n const { fileName, locale } = fileProperties;\n const status = fileStatus.get(fileName);\n if (status) {\n status.pending.delete(locale);\n status.failed.add(locale);\n }\n }\n\n for (const [_, fileProperties] of fileTracker.skipped) {\n const { fileName, locale } = fileProperties;\n const status = fileStatus.get(fileName);\n if (status) {\n status.pending.delete(locale);\n status.skipped.add(locale);\n }\n }\n\n // Calculate how many files we can show based on terminal height\n const filesArray = Array.from(fileStatus.entries());\n const maxFilesToShow = Math.min(\n filesArray.length,\n terminalHeight - 3 // Header + progress + buffer\n );\n\n // Display each file with its status on a single line\n for (let i = 0; i < maxFilesToShow; i++) {\n const [fileName, status] = filesArray[i];\n\n // Create condensed locale status\n const localeStatuses: { locale: string; status: string }[] = [];\n\n // Add completed locales (green)\n if (status.completed.size > 0) {\n localeStatuses.push(\n ...Array.from(status.completed).map((locale) => ({\n locale,\n status: 'completed',\n }))\n );\n }\n\n // Add skipped locales (green)\n if (status.skipped.size > 0) {\n localeStatuses.push(\n ...Array.from(status.skipped).map((locale) => ({\n locale,\n status: 'skipped',\n }))\n );\n }\n\n // Add failed locales (red)\n if (status.failed.size > 0) {\n localeStatuses.push(\n ...Array.from(status.failed).map((locale) => ({\n locale,\n status: 'failed',\n }))\n );\n }\n\n // Add pending locales (yellow)\n if (status.pending.size > 0) {\n localeStatuses.push(\n ...Array.from(status.pending).map((locale) => ({\n locale,\n status: 'pending',\n }))\n );\n }\n\n // Sort localeStatuses by locale\n localeStatuses.sort((a, b) => a.locale.localeCompare(b.locale));\n\n // Add colors\n const localeString = localeStatuses\n .map((locale) => {\n if (locale.status === 'completed') {\n return chalk.green(locale.locale);\n } else if (locale.status === 'skipped') {\n return chalk.gray(locale.locale);\n } else if (locale.status === 'failed') {\n return chalk.red(locale.locale);\n } else if (locale.status === 'pending') {\n return chalk.yellow(locale.locale);\n }\n })\n .join(', ');\n\n // Format the line\n const prettyFileName =\n fileName === TEMPLATE_FILE_NAME ? '<React Elements>' : fileName;\n newSuffixText.push(`${chalk.bold(prettyFileName)} [${localeString}]`);\n }\n\n // If we couldn't show all files, add an indicator\n if (filesArray.length > maxFilesToShow) {\n newSuffixText.push(\n `... and ${filesArray.length - maxFilesToShow} more files`\n );\n }\n\n return newSuffixText.join('\\n');\n }\n}\n"],"mappings":";;;;;AA+BA,IAAa,0BAAb,MAAqC;CACnC,UAAsE;CACtE,mBAA2B;CAE3B,YAAY,IAAgB;AAAR,OAAA,KAAA;;CAEpB,MAAM,IAAI,EACR,aACA,eACA,SACA,iBACA,sBACyC;EACzC,MAAM,YAAY,KAAK,KAAK;AAC5B,OAAK,UAAU,OAAO,kBAAkB,cAAc,OAAO;EAC7D,MAAM,iBAAiB,qBACnB,iCACA;AACJ,OAAK,QAAQ,MAAM,eAAe;EAGlC,MAAM,oCAAoB,IAAI,KAA6B;AAC3D,gBAAc,SAAS,SAAS;AAC9B,qBAAkB,IAAI,sBAAsB,KAAK,EAAE,KAAK;IACxD;AAKF,MAAI,CAAC,mBAMH,EAAA,MAL4B,8BAC1B,KAAK,IACL,cACD,EAEa,SAAS,YAAY;GACjC,MAAM,iBAAiB,kBAAkB,IAAI,QAAQ;AACrD,OAAI,eACF,aAAY,UAAU,IAAI,SAAS,eAAe;IAEpD;EAKJ,MAAM,yBAAS,IAAI,KAGhB;AACH,SAAO,QAAQ,QAAQ,QAAQ,CAAC,SAAS,CAAC,OAAO,SAAS;GACxD,MAAM,YAAY,KAAK,GAAG,mBAAmB,IAAI,aAAa;GAC9D,MAAM,MAAM,GAAG,IAAI,SAAS,GAAG,IAA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WAAW,SAAS,eACtB,eAAc,KACZ,WAAW,WAAW,SAAS,eAAe,aAC/C;AAGH,SAAO,cAAc,KAAK,KAAK"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { WorkflowStep } from './WorkflowStep.js';
|
|
2
1
|
import { GT } from 'generaltranslation';
|
|
3
2
|
import type { PublishFileEntry } from 'generaltranslation/types';
|
|
4
|
-
export declare class PublishStep
|
|
3
|
+
export declare class PublishStep {
|
|
5
4
|
private gt;
|
|
6
5
|
private spinner;
|
|
7
6
|
constructor(gt: GT);
|
|
8
7
|
run(files: PublishFileEntry[]): Promise<void>;
|
|
9
|
-
wait(): Promise<void>;
|
|
10
8
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { logger } from "../../console/logger.js";
|
|
2
|
-
import { WorkflowStep } from "./WorkflowStep.js";
|
|
3
2
|
import chalk from "chalk";
|
|
4
3
|
//#region src/workflows/steps/PublishStep.ts
|
|
5
|
-
var PublishStep = class
|
|
4
|
+
var PublishStep = class {
|
|
6
5
|
spinner = logger.createSpinner("dots");
|
|
7
6
|
constructor(gt) {
|
|
8
|
-
super();
|
|
9
7
|
this.gt = gt;
|
|
10
8
|
}
|
|
11
9
|
async run(files) {
|
|
@@ -25,7 +23,6 @@ var PublishStep = class extends WorkflowStep {
|
|
|
25
23
|
logger.warn(`Publish error: ${err instanceof Error ? err.message : String(err)}`);
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
|
-
async wait() {}
|
|
29
26
|
};
|
|
30
27
|
//#endregion
|
|
31
28
|
export { PublishStep };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PublishStep.js","names":[],"sources":["../../../src/workflows/steps/PublishStep.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"PublishStep.js","names":[],"sources":["../../../src/workflows/steps/PublishStep.ts"],"sourcesContent":["import { logger } from '../../console/logger.js';\nimport { GT } from 'generaltranslation';\nimport type { PublishFileEntry } from 'generaltranslation/types';\nimport chalk from 'chalk';\n\nexport class PublishStep {\n private spinner = logger.createSpinner('dots');\n\n constructor(private gt: GT) {}\n\n async run(files: PublishFileEntry[]): Promise<void> {\n if (files.length === 0) return;\n\n this.spinner.start('Updating CDN...');\n\n try {\n const result = await this.gt.publishFiles(files);\n\n const failed = result.results.filter(\n (r: { success: boolean; error?: string }) => !r.success\n );\n if (failed.length > 0) {\n this.spinner.stop(chalk.yellow('CDN updated with errors'));\n for (const f of failed) {\n const file = files.find((p) => p.fileId === f.fileId);\n const name = file?.fileName ?? f.fileId;\n logger.warn(\n `Failed to update ${name}: ${f.error ?? 'unknown error'}`\n );\n }\n } else {\n this.spinner.stop(chalk.green('CDN updated'));\n }\n } catch (err) {\n this.spinner.stop(chalk.red('Failed to update CDN'));\n logger.warn(\n `Publish error: ${err instanceof Error ? err.message : String(err)}`\n );\n }\n }\n}\n"],"mappings":";;;AAKA,IAAa,cAAb,MAAyB;CACvB,UAAkB,OAAO,cAAc,OAAO;CAE9C,YAAY,IAAgB;AAAR,OAAA,KAAA;;CAEpB,MAAM,IAAI,OAA0C;AAClD,MAAI,MAAM,WAAW,EAAG;AAExB,OAAK,QAAQ,MAAM,kBAAkB;AAErC,MAAI;GAGF,MAAM,UAAS,MAFM,KAAK,GAAG,aAAa,MAAM,EAE1B,QAAQ,QAC3B,MAA4C,CAAC,EAAE,QACjD;AACD,OAAI,OAAO,SAAS,GAAG;AACrB,SAAK,QAAQ,KAAK,MAAM,OAAO,0BAA0B,CAAC;AAC1D,SAAK,MAAM,KAAK,QAAQ;KAEtB,MAAM,OADO,MAAM,MAAM,MAAM,EAAE,WAAW,EAAE,OAC7B,EAAE,YAAY,EAAE;AACjC,YAAO,KACL,oBAAoB,KAAK,IAAI,EAAE,SAAS,kBACzC;;SAGH,MAAK,QAAQ,KAAK,MAAM,MAAM,cAAc,CAAC;WAExC,KAAK;AACZ,QAAK,QAAQ,KAAK,MAAM,IAAI,uBAAuB,CAAC;AACpD,UAAO,KACL,kBAAkB,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI,GACnE"}
|