gt 2.19.0 → 2.20.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 +36 -0
- package/dist/api/collectUserEditDiffs.js +23 -23
- package/dist/api/collectUserEditDiffs.js.map +1 -1
- package/dist/api/downloadFileBatch.js +7 -4
- package/dist/api/downloadFileBatch.js.map +1 -1
- package/dist/api/saveLocalEdits.js +2 -2
- package/dist/api/saveLocalEdits.js.map +1 -1
- package/dist/cli/base.d.ts +2 -0
- package/dist/cli/base.js +45 -2
- package/dist/cli/base.js.map +1 -1
- package/dist/cli/commands/api.d.ts +17 -0
- package/dist/cli/commands/api.js +153 -0
- package/dist/cli/commands/api.js.map +1 -0
- package/dist/cli/commands/upload.js +15 -5
- package/dist/cli/commands/upload.js.map +1 -1
- package/dist/cli/commands/utils/validation.d.ts +4 -0
- package/dist/cli/commands/utils/validation.js +12 -5
- package/dist/cli/commands/utils/validation.js.map +1 -1
- package/dist/cli/flags.js +1 -1
- package/dist/cli/flags.js.map +1 -1
- package/dist/config/generateSettings.d.ts +1 -0
- package/dist/config/generateSettings.js +9 -1
- package/dist/config/generateSettings.js.map +1 -1
- package/dist/console/index.d.ts +1 -0
- package/dist/console/index.js +2 -1
- package/dist/console/index.js.map +1 -1
- package/dist/formats/files/aggregateFiles.js +14 -6
- package/dist/formats/files/aggregateFiles.js.map +1 -1
- package/dist/fs/fileContent.d.ts +65 -0
- package/dist/fs/fileContent.js +171 -0
- package/dist/fs/fileContent.js.map +1 -0
- 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/state/recentDownloads.d.ts +3 -2
- package/dist/state/recentDownloads.js.map +1 -1
- package/dist/translation/reviewSetupWarning.js +3 -3
- package/dist/translation/reviewSetupWarning.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/utils/api.d.ts +194 -0
- package/dist/utils/api.js +268 -0
- package/dist/utils/api.js.map +1 -0
- package/dist/utils/persistPostprocessHashes.d.ts +1 -7
- package/dist/utils/persistPostprocessHashes.js +15 -1
- package/dist/utils/persistPostprocessHashes.js.map +1 -1
- package/dist/workflows/download.js +4 -4
- package/dist/workflows/download.js.map +1 -1
- package/dist/workflows/enqueue.js +4 -4
- package/dist/workflows/enqueue.js.map +1 -1
- package/dist/workflows/publish.js +2 -2
- package/dist/workflows/publish.js.map +1 -1
- package/dist/workflows/setupProject.js +4 -4
- package/dist/workflows/setupProject.js.map +1 -1
- package/dist/workflows/stage.js +8 -8
- package/dist/workflows/stage.js.map +1 -1
- package/dist/workflows/steps/BranchStep.d.ts +2 -2
- package/dist/workflows/steps/BranchStep.js +9 -9
- package/dist/workflows/steps/BranchStep.js.map +1 -1
- package/dist/workflows/steps/DownloadStep.d.ts +3 -3
- package/dist/workflows/steps/DownloadStep.js +3 -3
- package/dist/workflows/steps/DownloadStep.js.map +1 -1
- package/dist/workflows/steps/EnqueueStep.d.ts +5 -3
- package/dist/workflows/steps/EnqueueStep.js.map +1 -1
- package/dist/workflows/steps/PollJobsStep.d.ts +3 -3
- package/dist/workflows/steps/PollJobsStep.js +6 -6
- package/dist/workflows/steps/PollJobsStep.js.map +1 -1
- package/dist/workflows/steps/PublishStep.d.ts +3 -3
- package/dist/workflows/steps/PublishStep.js +3 -3
- package/dist/workflows/steps/PublishStep.js.map +1 -1
- package/dist/workflows/steps/SetupStep.d.ts +6 -4
- package/dist/workflows/steps/SetupStep.js.map +1 -1
- package/dist/workflows/steps/TagStep.d.ts +3 -3
- package/dist/workflows/steps/TagStep.js +3 -3
- package/dist/workflows/steps/TagStep.js.map +1 -1
- package/dist/workflows/steps/UploadSourcesStep.d.ts +3 -3
- package/dist/workflows/steps/UploadSourcesStep.js +8 -6
- package/dist/workflows/steps/UploadSourcesStep.js.map +1 -1
- package/dist/workflows/steps/UploadTranslationsStep.d.ts +3 -3
- package/dist/workflows/steps/UploadTranslationsStep.js +24 -6
- package/dist/workflows/steps/UploadTranslationsStep.js.map +1 -1
- package/dist/workflows/upload.js +4 -4
- package/dist/workflows/upload.js.map +1 -1
- package/dist/workflows/utils/filterFilesForEnqueue.d.ts +2 -2
- package/dist/workflows/utils/filterFilesForEnqueue.js.map +1 -1
- package/dist/workflows/utils/queryCompletedTranslations.d.ts +3 -3
- package/dist/workflows/utils/queryCompletedTranslations.js +2 -2
- package/dist/workflows/utils/queryCompletedTranslations.js.map +1 -1
- package/package.json +5 -5
|
@@ -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 {
|
|
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 { api } from '../utils/api.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';\nimport type { InlineLibrary } from '../types/libraries.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 inlineLibrary,\n}: {\n files: FileToUpload[];\n options: TranslateFlags;\n settings: Settings;\n inlineLibrary?: InlineLibrary;\n}): Promise<{\n branchData: BranchData;\n enqueueResult: EnqueueFilesResult;\n}> {\n try {\n // Log files to be translated\n logCollectedFiles(files, undefined, inlineLibrary);\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(api, settings);\n const uploadStep = new UploadSourcesStep(api, settings);\n const userEditDiffsStep = new UserEditDiffsStep(settings);\n const setupStep = new SetupStep(api, settings, timeoutMs);\n const enqueueStep = new EnqueueStep(api, 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 (settings.options?.saveLocal !== false) {\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(api, 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: api,\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":";;;;;;;;;;;;;;;;;;;;;AAyBA,eAAsB,sBAAsB,EAC1C,OACA,SACA,UACA,iBASC;AACD,KAAI;AAEF,oBAAkB,OAAO,KAAA,GAAW,cAAc;AAIlD,QAAM,UAAU,SAAS;EAGzB,MAAM,YAAY,mBAAmB,QAAQ,QAAQ;EAGrD,MAAM,aAAa,IAAI,WAAW,KAAK,SAAS;EAChD,MAAM,aAAa,IAAI,kBAAkB,KAAK,SAAS;EACvD,MAAM,oBAAoB,IAAI,kBAAkB,SAAS;EACzD,MAAM,YAAY,IAAI,UAAU,KAAK,UAAU,UAAU;EACzD,MAAM,cAAc,IAAI,YAAY,KAAK,UAAU,QAAQ,MAAM;EAGjE,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,SAAS,cAAc,MAClC,OAAM,kBAAkB,IAAI,cAAc;AAI5C,MAAI,SAAS,IACX,KAAI;AAGF,SAAM,IADc,QAAQ,KAAK,UAAU,CADlB,CAAC,QAAQ,IAErB,CAAC,IAAI,cAAc;UAC1B;AACN,UAAO,KAAK,kDAAkD;;AAKlE,QAAM,UAAU,IAAI,cAAc;EAGlC,MAAM,EAAE,gBAAgB,iBAAiB,MAAM,sBAAsB;GACnE,IAAI;GACJ,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,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ApiClient } from '../../utils/api.js';
|
|
2
2
|
import type { Settings } from '../../types/index.js';
|
|
3
3
|
import { BranchData } from '../../types/branch.js';
|
|
4
|
-
type BranchStepClient = Pick<
|
|
4
|
+
type BranchStepClient = Pick<ApiClient, 'queryBranchData' | 'createBranch'>;
|
|
5
5
|
type BranchStepSettings = Pick<Settings, 'branchOptions'>;
|
|
6
6
|
export declare class BranchStep {
|
|
7
7
|
private spinner;
|
|
@@ -80,15 +80,15 @@ var BranchStep = class {
|
|
|
80
80
|
});
|
|
81
81
|
this.branchData.currentBranch = createBranchResult.branch;
|
|
82
82
|
} catch (error) {
|
|
83
|
-
if (error instanceof ApiError
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
83
|
+
if (!(error instanceof ApiError) || error.code !== 403) throw error;
|
|
84
|
+
logger.warn("To enable translation branching, upgrade your plan. Falling back to default branch.");
|
|
85
|
+
if (branchData.defaultBranch) this.branchData.currentBranch = branchData.defaultBranch;
|
|
86
|
+
else {
|
|
87
|
+
const createBranchResult = await this.gt.createBranch({
|
|
88
|
+
branchName: detectedDefaultBranchName,
|
|
89
|
+
defaultBranch: true
|
|
90
|
+
});
|
|
91
|
+
this.branchData.currentBranch = createBranchResult.branch;
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
else this.branchData.currentBranch = currentBranch;
|
|
@@ -1 +1 @@
|
|
|
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 {
|
|
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 { ApiClient } from '../../utils/api.js';\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<ApiClient, '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) throw error;\n\n logger.warn(\n 'To enable translation branching, upgrade your plan. Falling back to default branch.'\n );\n if (branchData.defaultBranch) {\n this.branchData.currentBranch = branchData.defaultBranch;\n } else {\n const createBranchResult = await this.gt.createBranch({\n branchName: detectedDefaultBranchName,\n defaultBranch: true,\n });\n this.branchData.currentBranch = createBranchResult.branch;\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;EAGrD,IAAI,UAGO;EACX,IAAI,WAAqB,EAAE;EAC3B,IAAI,aAAuB,EAAE;EAC7B,IAAI,mBAA4B;EAChC,IAAI,4BAAoC;EACxC,IAAI,mBAAmB,CAAC,KAAK,SAAS,cAAc;AAEpD,MACE,KAAK,SAAS,cAAc,WAC5B,KAAK,SAAS,cAAc,oBAC5B;GACA,MAAM,CAAC,eAAe,gBAAgB,oBACpC,MAAM,QAAQ,IAAI;IAChB,iBAAiB,KAAK,SAAS,cAAc,WAAW;IACxD,oBAAoB,KAAK,SAAS,cAAc,WAAW;IAC3D,sBAAsB,KAAK,SAAS,cAAc,WAAW;IAC9D,CAAC;AACJ,aAAU;AACV,cAAW;AACX,gBAAa;AAEb,OAAI,cACF,6BAA4B,cAAc;AAI5C,OAAI,CAAC,eAAe;AAClB,uBAAmB;IACnB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,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,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ApiClient } from '../../utils/api.js';
|
|
2
2
|
import { Settings } from '../../types/index.js';
|
|
3
3
|
import { FileStatusTracker } from './PollJobsStep.js';
|
|
4
4
|
import type { InlineLibrary } from '../../types/libraries.js';
|
|
@@ -8,11 +8,11 @@ export type DownloadTranslationsInput = {
|
|
|
8
8
|
forceDownload?: boolean;
|
|
9
9
|
};
|
|
10
10
|
export declare class DownloadTranslationsStep {
|
|
11
|
-
private
|
|
11
|
+
private api;
|
|
12
12
|
private settings;
|
|
13
13
|
private inlineLibrary?;
|
|
14
14
|
private spinner;
|
|
15
|
-
constructor(
|
|
15
|
+
constructor(api: ApiClient, settings: Settings, inlineLibrary?: InlineLibrary | undefined);
|
|
16
16
|
run({ fileTracker, resolveOutputPath, forceDownload, }: DownloadTranslationsInput): Promise<boolean>;
|
|
17
17
|
private downloadFiles;
|
|
18
18
|
private downloadFilesWithRetry;
|
|
@@ -7,8 +7,8 @@ import path from "node:path";
|
|
|
7
7
|
//#region src/workflows/steps/DownloadStep.ts
|
|
8
8
|
var DownloadTranslationsStep = class {
|
|
9
9
|
spinner = null;
|
|
10
|
-
constructor(
|
|
11
|
-
this.
|
|
10
|
+
constructor(api, settings, inlineLibrary) {
|
|
11
|
+
this.api = api;
|
|
12
12
|
this.settings = settings;
|
|
13
13
|
this.inlineLibrary = inlineLibrary;
|
|
14
14
|
}
|
|
@@ -24,7 +24,7 @@ var DownloadTranslationsStep = class {
|
|
|
24
24
|
this.spinner?.stop(chalk.green("No files to download"));
|
|
25
25
|
return true;
|
|
26
26
|
}
|
|
27
|
-
const readyTranslations = ((await this.
|
|
27
|
+
const readyTranslations = ((await this.api.queryFileData({ translatedFiles: currentQueryData.map((item) => ({
|
|
28
28
|
fileId: item.fileId,
|
|
29
29
|
versionId: item.versionId,
|
|
30
30
|
branchId: item.branchId,
|
|
@@ -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 { 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';\nimport type { InlineLibrary } from '../../types/libraries.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 private inlineLibrary?: InlineLibrary\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 this.inlineLibrary\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":";;;;;;;AAqBA,IAAa,2BAAb,MAAsC;CACpC,UAAsE;CAEtE,YACE,IACA,UACA,eACA;AAHQ,OAAA,KAAA;AACA,OAAA,WAAA;AACA,OAAA,gBAAA;;C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O,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
|
+
{"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 type { ApiClient } from '../../utils/api.js';\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';\nimport type { InlineLibrary } from '../../types/libraries.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 api: ApiClient,\n private settings: Settings,\n private inlineLibrary?: InlineLibrary\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.api.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 this.inlineLibrary\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":";;;;;;;AAqBA,IAAa,2BAAb,MAAsC;CACpC,UAAsE;CAEtE,YACE,KACA,UACA,eACA;AAHQ,OAAA,MAAA;AACA,OAAA,WAAA;AACA,OAAA,gBAAA;;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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CAAiC,EAAE,SACpC;;cAGI,eAAe,EACxB,MAAK,SAAS,KACZ,MAAM,OAAO,2CAA2C,CACzD;OAED,MAAK,SAAS,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAGzD,UAAO;WACA,OAAO;AACd,QAAK,SAAS,KACZ,MAAM,IAAI,mDAAmD,CAC9D;AACD,UAAO,MAAM,MAAM,IAAI,UAAU,GAAG,MAAM;AAC1C,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,eACA,KAAK,cACN;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"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { EnqueueFilesResult } from 'generaltranslation/types';
|
|
2
|
-
import {
|
|
3
|
-
import { Settings } from '../../types/index.js';
|
|
2
|
+
import type { ApiClient } from '../../utils/api.js';
|
|
3
|
+
import type { Settings } from '../../types/index.js';
|
|
4
4
|
import type { FileReference } from 'generaltranslation/types';
|
|
5
|
+
type EnqueueClient = Pick<ApiClient, 'enqueueFiles'>;
|
|
5
6
|
export declare class EnqueueStep {
|
|
6
7
|
private gt;
|
|
7
8
|
private settings;
|
|
8
9
|
private force?;
|
|
9
10
|
private spinner;
|
|
10
|
-
constructor(gt:
|
|
11
|
+
constructor(gt: EnqueueClient, settings: Settings, force?: boolean | undefined);
|
|
11
12
|
run(files: FileReference[]): Promise<EnqueueFilesResult>;
|
|
12
13
|
}
|
|
14
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
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 {
|
|
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 type { ApiClient } from '../../utils/api.js';\nimport type { Settings } from '../../types/index.js';\nimport type { FileReference } from 'generaltranslation/types';\nimport chalk from 'chalk';\n\ntype EnqueueClient = Pick<ApiClient, 'enqueueFiles'>;\n\nexport class EnqueueStep {\n private spinner = logger.createSpinner('dots');\n\n constructor(\n private gt: EnqueueClient,\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":";;;AASA,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,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ApiClient } from '../../utils/api.js';
|
|
2
2
|
import { EnqueueFilesResult } from 'generaltranslation/types';
|
|
3
3
|
import type { FileProperties } from '../../types/files.js';
|
|
4
4
|
import { type InlineLibrary } from '../../types/libraries.js';
|
|
@@ -20,11 +20,11 @@ export type PollJobsOutput = {
|
|
|
20
20
|
fileTracker: FileStatusTracker;
|
|
21
21
|
};
|
|
22
22
|
export declare class PollTranslationJobsStep {
|
|
23
|
-
private
|
|
23
|
+
private api;
|
|
24
24
|
private inlineLibrary?;
|
|
25
25
|
private spinner;
|
|
26
26
|
private previousProgress;
|
|
27
|
-
constructor(
|
|
27
|
+
constructor(api: ApiClient, inlineLibrary?: InlineLibrary | undefined);
|
|
28
28
|
run({ fileTracker, fileQueryData, jobData, timeoutDuration, forceRetranslation, }: PollJobsInput): Promise<PollJobsOutput>;
|
|
29
29
|
private updateSpinner;
|
|
30
30
|
private generateStatusSuffixText;
|
|
@@ -7,8 +7,8 @@ import chalk from "chalk";
|
|
|
7
7
|
var PollTranslationJobsStep = class {
|
|
8
8
|
spinner = null;
|
|
9
9
|
previousProgress = 0;
|
|
10
|
-
constructor(
|
|
11
|
-
this.
|
|
10
|
+
constructor(api, inlineLibrary) {
|
|
11
|
+
this.api = api;
|
|
12
12
|
this.inlineLibrary = inlineLibrary;
|
|
13
13
|
}
|
|
14
14
|
async run({ fileTracker, fileQueryData, jobData, timeoutDuration, forceRetranslation }) {
|
|
@@ -20,13 +20,13 @@ var PollTranslationJobsStep = class {
|
|
|
20
20
|
fileQueryData.forEach((item) => {
|
|
21
21
|
filePropertiesMap.set(getFileTranslationKey(item), item);
|
|
22
22
|
});
|
|
23
|
-
if (!forceRetranslation) (await queryCompletedTranslationKeys(this.
|
|
23
|
+
if (!forceRetranslation) (await queryCompletedTranslationKeys(this.api, fileQueryData)).forEach((fileKey) => {
|
|
24
24
|
const fileProperties = filePropertiesMap.get(fileKey);
|
|
25
25
|
if (fileProperties) fileTracker.completed.set(fileKey, fileProperties);
|
|
26
26
|
});
|
|
27
27
|
const jobMap = /* @__PURE__ */ new Map();
|
|
28
28
|
Object.entries(jobData.jobData).forEach(([jobId, job]) => {
|
|
29
|
-
const jobLocale = this.
|
|
29
|
+
const jobLocale = this.api.resolveAliasLocale(job.targetLocale);
|
|
30
30
|
const key = `${job.branchId}:${job.fileId}:${job.versionId}:${jobLocale}`;
|
|
31
31
|
jobMap.set(key, {
|
|
32
32
|
...job,
|
|
@@ -36,7 +36,7 @@ var PollTranslationJobsStep = class {
|
|
|
36
36
|
});
|
|
37
37
|
const jobFileMap = /* @__PURE__ */ new Map();
|
|
38
38
|
Object.entries(jobData.jobData).forEach(([jobId, job]) => {
|
|
39
|
-
const jobLocale = this.
|
|
39
|
+
const jobLocale = this.api.resolveAliasLocale(job.targetLocale);
|
|
40
40
|
jobFileMap.set(jobId, {
|
|
41
41
|
branchId: job.branchId,
|
|
42
42
|
fileId: job.fileId,
|
|
@@ -68,7 +68,7 @@ var PollTranslationJobsStep = class {
|
|
|
68
68
|
intervalCheck = setInterval(async () => {
|
|
69
69
|
try {
|
|
70
70
|
const jobIds = Array.from(jobFileMap.keys());
|
|
71
|
-
const jobStatusResponse = await this.
|
|
71
|
+
const jobStatusResponse = await this.api.checkJobStatus(jobIds);
|
|
72
72
|
for (const job of jobStatusResponse) {
|
|
73
73
|
const jobFileProperties = jobFileMap.get(job.jobId);
|
|
74
74
|
if (jobFileProperties) {
|
|
@@ -1 +1 @@
|
|
|
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';\nimport {\n getInlineElementsLabel,\n type InlineLibrary,\n} from '../../types/libraries.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(\n private gt: GT,\n private inlineLibrary?: InlineLibrary\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\n ? `<${getInlineElementsLabel(this.inlineLibrary)}>`\n : 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":";;;;;;AAmCA,IAAa,0BAAb,MAAqC;CACnC,UAAsE;CACtE,mBAA2B;CAE3B,YACE,IACA,eACA;AAFQ,OAAA,KAAA;AACA,OAAA,gBAAA;;CAGV,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,IAAI,OAAO,GAAG,IAAI,UAAU,GAAG;AAC9D,UAAO,IAAI,KAAK;IAAE,GAAG;IAAK;IAAO,cAAc;IAAW,CAAC;IAC3D;EAIF,MAAM,6BAAa,IAAI,KAQpB;AACH,SAAO,QAAQ,QAAQ,QAAQ,CAAC,SAAS,CAAC,OAAO,SAAS;GACxD,MAAM,YAAY,KAAK,GAAG,mBAAmB,IAAI,aAAa;AAC9D,cAAW,IAAI,OAAO;IACpB,UAA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AAO,UAAU,CAAC,KAAK,YAAY;IAC/C;IACA,QAAQ;IACT,EAAE,CACJ;AAIH,OAAI,OAAO,QAAQ,OAAO,EACxB,gBAAe,KACb,GAAG,MAAM,KAAK,OAAO,QAAQ,CAAC,KAAK,YAAY;IAC7C;IACA,QAAQ;IACT,EAAE,CACJ;AAIH,OAAI,OAAO,OAAO,OAAO,EACvB,gBAAe,KACb,GAAG,MAAM,KAAK,OAAO,OAAO,CAAC,KAAK,YAAY;IAC5C;IACA,QAAQ;IACT,EAAE,CACJ;AAIH,OAAI,OAAO,QAAQ,OAAO,EACxB,gBAAe,KACb,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,kCACI,IAAI,uBAAuB,KAAK,cAAc,CAAC,KAC/C;AACN,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"}
|
|
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 type { ApiClient } from '../../utils/api.js';\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';\nimport {\n getInlineElementsLabel,\n type InlineLibrary,\n} from '../../types/libraries.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(\n private api: ApiClient,\n private inlineLibrary?: InlineLibrary\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.api,\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.api.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.api.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.api.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\n ? `<${getInlineElementsLabel(this.inlineLibrary)}>`\n : 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":";;;;;;AAmCA,IAAa,0BAAb,MAAqC;CACnC,UAAsE;CACtE,mBAA2B;CAE3B,YACE,KACA,eACA;AAFQ,OAAA,MAAA;AACA,OAAA,gBAAA;;CAGV,MAAM,IAAI,EACR,aACA,eACA,SACA,iBACA,sBACyC;EACzC,MAAM,YAAY,KAAK,KAAK;AAC5B,OAAK,UAAU,OAAO,kBAAkB,cAAc,OAAO;EAC7D,MAAM,iBAAiB,qBACnB,iC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,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,kCACI,IAAI,uBAAuB,KAAK,cAAc,CAAC,KAC/C;AACN,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"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { GT } from 'generaltranslation';
|
|
2
1
|
import type { PublishFileEntry } from 'generaltranslation/types';
|
|
2
|
+
import type { ApiClient } from '../../utils/api.js';
|
|
3
3
|
export declare class PublishStep {
|
|
4
|
-
private
|
|
4
|
+
private api;
|
|
5
5
|
private spinner;
|
|
6
|
-
constructor(
|
|
6
|
+
constructor(api: ApiClient);
|
|
7
7
|
run(files: PublishFileEntry[]): Promise<void>;
|
|
8
8
|
}
|
|
@@ -3,14 +3,14 @@ import chalk from "chalk";
|
|
|
3
3
|
//#region src/workflows/steps/PublishStep.ts
|
|
4
4
|
var PublishStep = class {
|
|
5
5
|
spinner = logger.createSpinner("dots");
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
6
|
+
constructor(api) {
|
|
7
|
+
this.api = api;
|
|
8
8
|
}
|
|
9
9
|
async run(files) {
|
|
10
10
|
if (files.length === 0) return;
|
|
11
11
|
this.spinner.start("Updating CDN...");
|
|
12
12
|
try {
|
|
13
|
-
const failed = (await this.
|
|
13
|
+
const failed = (await this.api.publishFiles(files)).results.filter((r) => !r.success);
|
|
14
14
|
if (failed.length > 0) {
|
|
15
15
|
this.spinner.stop(chalk.yellow("CDN updated with errors"));
|
|
16
16
|
for (const f of failed) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PublishStep.js","names":[],"sources":["../../../src/workflows/steps/PublishStep.ts"],"sourcesContent":["import { logger } from '../../console/logger.js';\nimport {
|
|
1
|
+
{"version":3,"file":"PublishStep.js","names":[],"sources":["../../../src/workflows/steps/PublishStep.ts"],"sourcesContent":["import { logger } from '../../console/logger.js';\nimport type { PublishFileEntry } from 'generaltranslation/types';\nimport type { ApiClient } from '../../utils/api.js';\nimport chalk from 'chalk';\n\nexport class PublishStep {\n private spinner = logger.createSpinner('dots');\n\n constructor(private api: ApiClient) {}\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.api.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,KAAwB;AAAhB,OAAA,MAAA;;CAEpB,MAAM,IAAI,OAA0C;AAClD,MAAI,MAAM,WAAW,EAAG;AAExB,OAAK,QAAQ,MAAM,kBAAkB;AAErC,MAAI;GAGF,MAAM,UAAS,MAFM,KAAK,IAAI,aAAa,MAAM,EAE3B,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"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { FileReference } from 'generaltranslation/types';
|
|
2
|
-
import {
|
|
3
|
-
import { Settings } from '../../types/index.js';
|
|
1
|
+
import type { FileReference } from 'generaltranslation/types';
|
|
2
|
+
import type { ApiClient } from '../../utils/api.js';
|
|
3
|
+
import type { Settings } from '../../types/index.js';
|
|
4
|
+
type SetupClient = Pick<ApiClient, 'setupProject' | 'awaitJobs'>;
|
|
4
5
|
export declare class SetupStep {
|
|
5
6
|
private gt;
|
|
6
7
|
private settings;
|
|
7
8
|
private timeoutMs;
|
|
8
9
|
private spinner;
|
|
9
|
-
constructor(gt:
|
|
10
|
+
constructor(gt: SetupClient, settings: Settings, timeoutMs: number);
|
|
10
11
|
run(files: FileReference[], force?: boolean): Promise<FileReference[]>;
|
|
11
12
|
}
|
|
13
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetupStep.js","names":[],"sources":["../../../src/workflows/steps/SetupStep.ts"],"sourcesContent":["import { FileReference } from 'generaltranslation/types';\nimport { logger } from '../../console/logger.js';\nimport {
|
|
1
|
+
{"version":3,"file":"SetupStep.js","names":[],"sources":["../../../src/workflows/steps/SetupStep.ts"],"sourcesContent":["import type { FileReference } from 'generaltranslation/types';\nimport { logger } from '../../console/logger.js';\nimport type { ApiClient } from '../../utils/api.js';\nimport type { Settings } from '../../types/index.js';\nimport chalk from 'chalk';\n\ntype SetupClient = Pick<ApiClient, 'setupProject' | 'awaitJobs'>;\n\nexport class SetupStep {\n private spinner = logger.createSpinner('dots');\n\n constructor(\n private gt: SetupClient,\n private settings: Settings,\n private timeoutMs: number\n ) {}\n\n async run(\n files: FileReference[],\n force: boolean = false\n ): Promise<FileReference[]> {\n this.spinner.start('Setting up project...');\n\n if (files.length === 0) {\n this.spinner.stop(chalk.green('Setup successfully completed'));\n return [];\n }\n\n const result = await this.gt.setupProject(files, {\n locales: this.settings.locales,\n force,\n });\n\n if (result.status === 'completed') {\n this.spinner.stop(chalk.green('Setup successfully completed'));\n return files;\n }\n\n if (result.status !== 'queued' || !result.setupJobId) {\n this.spinner.stop(\n chalk.yellow('Setup status unknown — proceeding without setup')\n );\n return files;\n }\n\n const { complete, jobs } = await this.gt.awaitJobs([result.setupJobId], {\n pollingIntervalSeconds: 5,\n timeoutSeconds: this.timeoutMs / 1000,\n });\n const [job] = jobs;\n\n if (!complete) {\n this.spinner.stop(\n chalk.yellow('Setup timed out — proceeding without setup')\n );\n } else if (job?.status === 'completed') {\n this.spinner.stop(chalk.green('Setup successfully completed'));\n } else if (job?.status === 'failed') {\n this.spinner.stop(\n chalk.yellow(\n `Setup failed: ${job.error?.message || 'Unknown error'} — proceeding without setup`\n )\n );\n } else {\n this.spinner.stop(\n chalk.yellow('Setup status unknown — proceeding without setup')\n );\n }\n return files;\n }\n}\n"],"mappings":";;;AAQA,IAAa,YAAb,MAAuB;CACrB,UAAkB,OAAO,cAAc,OAAO;CAE9C,YACE,IACA,UACA,WACA;AAHQ,OAAA,KAAA;AACA,OAAA,WAAA;AACA,OAAA,YAAA;;CAGV,MAAM,IACJ,OACA,QAAiB,OACS;AAC1B,OAAK,QAAQ,MAAM,wBAAwB;AAE3C,MAAI,MAAM,WAAW,GAAG;AACtB,QAAK,QAAQ,KAAK,MAAM,MAAM,+BAA+B,CAAC;AAC9D,UAAO,EAAE;;EAGX,MAAM,SAAS,MAAM,KAAK,GAAG,aAAa,OAAO;GAC/C,SAAS,KAAK,SAAS;GACvB;GACD,CAAC;AAEF,MAAI,OAAO,WAAW,aAAa;AACjC,QAAK,QAAQ,KAAK,MAAM,MAAM,+BAA+B,CAAC;AAC9D,UAAO;;AAGT,MAAI,OAAO,WAAW,YAAY,CAAC,OAAO,YAAY;AACpD,QAAK,QAAQ,KACX,MAAM,OAAO,kDAAkD,CAChE;AACD,UAAO;;EAGT,MAAM,EAAE,UAAU,SAAS,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,WAAW,EAAE;GACtE,wBAAwB;GACxB,gBAAgB,KAAK,YAAY;GAClC,CAAC;EACF,MAAM,CAAC,OAAO;AAEd,MAAI,CAAC,SACH,MAAK,QAAQ,KACX,MAAM,OAAO,6CAA6C,CAC3D;WACQ,KAAK,WAAW,YACzB,MAAK,QAAQ,KAAK,MAAM,MAAM,+BAA+B,CAAC;WACrD,KAAK,WAAW,SACzB,MAAK,QAAQ,KACX,MAAM,OACJ,iBAAiB,IAAI,OAAO,WAAW,gBAAgB,6BACxD,CACF;MAED,MAAK,QAAQ,KACX,MAAM,OAAO,kDAAkD,CAChE;AAEH,SAAO"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { CreateTagResult } from 'generaltranslation/types';
|
|
2
|
-
import {
|
|
2
|
+
import type { ApiClient } from '../../utils/api.js';
|
|
3
3
|
import { Settings } from '../../types/index.js';
|
|
4
4
|
import type { FileReference } from 'generaltranslation/types';
|
|
5
5
|
export declare class TagStep {
|
|
6
|
-
private
|
|
6
|
+
private api;
|
|
7
7
|
private settings;
|
|
8
8
|
private userProvided;
|
|
9
9
|
private spinner;
|
|
10
|
-
constructor(
|
|
10
|
+
constructor(api: ApiClient, settings: Settings, userProvided: boolean);
|
|
11
11
|
run(files: FileReference[]): Promise<CreateTagResult>;
|
|
12
12
|
}
|
|
@@ -3,15 +3,15 @@ import chalk from "chalk";
|
|
|
3
3
|
//#region src/workflows/steps/TagStep.ts
|
|
4
4
|
var TagStep = class {
|
|
5
5
|
spinner = logger.createSpinner("dots");
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
6
|
+
constructor(api, settings, userProvided) {
|
|
7
|
+
this.api = api;
|
|
8
8
|
this.settings = settings;
|
|
9
9
|
this.userProvided = userProvided;
|
|
10
10
|
}
|
|
11
11
|
async run(files) {
|
|
12
12
|
if (this.userProvided) this.spinner.start("Creating translation tag...");
|
|
13
13
|
try {
|
|
14
|
-
const result = await this.
|
|
14
|
+
const result = await this.api.createTag({
|
|
15
15
|
tagId: this.settings.tag,
|
|
16
16
|
files: files.map((f) => ({
|
|
17
17
|
fileId: f.fileId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TagStep.js","names":[],"sources":["../../../src/workflows/steps/TagStep.ts"],"sourcesContent":["import type { CreateTagResult } from 'generaltranslation/types';\nimport { logger } from '../../console/logger.js';\nimport {
|
|
1
|
+
{"version":3,"file":"TagStep.js","names":[],"sources":["../../../src/workflows/steps/TagStep.ts"],"sourcesContent":["import type { CreateTagResult } from 'generaltranslation/types';\nimport { logger } from '../../console/logger.js';\nimport type { ApiClient } from '../../utils/api.js';\nimport { Settings } from '../../types/index.js';\nimport type { FileReference } from 'generaltranslation/types';\nimport chalk from 'chalk';\n\nexport class TagStep {\n private spinner = logger.createSpinner('dots');\n\n constructor(\n private api: ApiClient,\n private settings: Settings,\n private userProvided: boolean\n ) {}\n\n async run(files: FileReference[]): Promise<CreateTagResult> {\n if (this.userProvided) {\n this.spinner.start('Creating translation tag...');\n }\n\n try {\n const result = await this.api.createTag({\n tagId: this.settings.tag!,\n files: files.map((f) => ({\n fileId: f.fileId,\n versionId: f.versionId,\n branchId: f.branchId,\n })),\n message: this.settings.tagMessage,\n });\n if (this.userProvided) {\n this.spinner.stop(\n chalk.green(`Tagged as ${chalk.bold(result.tag.tagId)}`)\n );\n }\n return result;\n } catch (error) {\n if (this.userProvided) {\n this.spinner.stop(chalk.yellow('Failed to create translation tag'));\n }\n throw error;\n }\n }\n}\n"],"mappings":";;;AAOA,IAAa,UAAb,MAAqB;CACnB,UAAkB,OAAO,cAAc,OAAO;CAE9C,YACE,KACA,UACA,cACA;AAHQ,OAAA,MAAA;AACA,OAAA,WAAA;AACA,OAAA,eAAA;;CAGV,MAAM,IAAI,OAAkD;AAC1D,MAAI,KAAK,aACP,MAAK,QAAQ,MAAM,8BAA8B;AAGnD,MAAI;GACF,MAAM,SAAS,MAAM,KAAK,IAAI,UAAU;IACtC,OAAO,KAAK,SAAS;IACrB,OAAO,MAAM,KAAK,OAAO;KACvB,QAAQ,EAAE;KACV,WAAW,EAAE;KACb,UAAU,EAAE;KACb,EAAE;IACH,SAAS,KAAK,SAAS;IACxB,CAAC;AACF,OAAI,KAAK,aACP,MAAK,QAAQ,KACX,MAAM,MAAM,aAAa,MAAM,KAAK,OAAO,IAAI,MAAM,GAAG,CACzD;AAEH,UAAO;WACA,OAAO;AACd,OAAI,KAAK,aACP,MAAK,QAAQ,KAAK,MAAM,OAAO,mCAAmC,CAAC;AAErE,SAAM"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { FileToUpload } from 'generaltranslation/types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ApiClient } from '../../utils/api.js';
|
|
3
3
|
import type { Settings } from '../../types/index.js';
|
|
4
4
|
import { BranchData } from '../../types/branch.js';
|
|
5
5
|
import type { FileReference } from 'generaltranslation/types';
|
|
6
|
-
type UploadSourcesClient = Pick<
|
|
7
|
-
type UploadSourcesSettings = Pick<Settings, 'defaultLocale'
|
|
6
|
+
type UploadSourcesClient = Pick<ApiClient, 'queryFileData' | 'getOrphanedFiles' | 'processFileMoves' | 'uploadSourceFiles'>;
|
|
7
|
+
type UploadSourcesSettings = Pick<Settings, 'defaultLocale'>;
|
|
8
8
|
export declare class UploadSourcesStep {
|
|
9
9
|
private gt;
|
|
10
10
|
private settings;
|
|
@@ -71,16 +71,18 @@ var UploadSourcesStep = class {
|
|
|
71
71
|
locale: this.settings.defaultLocale,
|
|
72
72
|
incomingBranchId: branchData.incomingBranch?.id,
|
|
73
73
|
checkedOutBranchId: branchData.checkedOutBranch?.id
|
|
74
|
-
} })), {
|
|
75
|
-
sourceLocale: this.settings.defaultLocale,
|
|
76
|
-
modelProvider: this.settings.modelProvider
|
|
77
|
-
});
|
|
74
|
+
} })), { sourceLocale: this.settings.defaultLocale });
|
|
78
75
|
const localFileMap = new Map(files.map((f) => [`${f.fileId}:${f.versionId}`, f]));
|
|
79
76
|
const result = response.uploadedFiles.map((uploadedFile) => {
|
|
80
77
|
const localFile = localFileMap.get(`${uploadedFile.fileId}:${uploadedFile.versionId}`);
|
|
81
78
|
return {
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
branchId: uploadedFile.branchId ?? localFile?.branchId ?? currentBranchId,
|
|
80
|
+
fileId: uploadedFile.fileId,
|
|
81
|
+
versionId: uploadedFile.versionId,
|
|
82
|
+
fileName: uploadedFile.fileName,
|
|
83
|
+
fileFormat: uploadedFile.fileFormat,
|
|
84
|
+
dataFormat: localFile?.dataFormat,
|
|
85
|
+
transformFormat: localFile?.transformFormat
|
|
84
86
|
};
|
|
85
87
|
});
|
|
86
88
|
result.push(...filesToSkipUpload.map((f) => ({
|