gt 2.18.1 → 2.20.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 +46 -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/config/generateSettings.js +7 -0
- 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 +20 -8
- package/dist/formats/files/aggregateFiles.js.map +1 -1
- package/dist/formats/files/androidLocale.d.ts +7 -0
- package/dist/formats/files/androidLocale.js +32 -0
- package/dist/formats/files/androidLocale.js.map +1 -0
- package/dist/formats/files/fileMapping.js +31 -24
- package/dist/formats/files/fileMapping.js.map +1 -1
- package/dist/formats/files/localePath.d.ts +3 -0
- package/dist/formats/files/localePath.js +18 -0
- package/dist/formats/files/localePath.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/config/parseFilesConfig.js +5 -1
- package/dist/fs/config/parseFilesConfig.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/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 +7 -7
- 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":"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;A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AAO,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,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,KACL,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,IAAI,mBAAmB,IAAI,aAAa;GAC/D,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,IAAI,mBAAmB,IAAI,aAAa;AAC/D,cAAW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ACb,GAAG,MAAM,KAAK,OAAO,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,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) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UploadSourcesStep.js","names":[],"sources":["../../../src/workflows/steps/UploadSourcesStep.ts"],"sourcesContent":["import type { FileToUpload } from 'generaltranslation/types';\nimport { logger } from '../../console/logger.js';\nimport { recordWarning } from '../../state/translateWarnings.js';\nimport type {
|
|
1
|
+
{"version":3,"file":"UploadSourcesStep.js","names":[],"sources":["../../../src/workflows/steps/UploadSourcesStep.ts"],"sourcesContent":["import type { GetFileInfoResponse } from 'generaltranslation/api';\nimport type { FileToUpload } from 'generaltranslation/types';\nimport { logger } from '../../console/logger.js';\nimport { recordWarning } from '../../state/translateWarnings.js';\nimport type { ApiClient } from '../../utils/api.js';\nimport type { Settings } from '../../types/index.js';\nimport chalk from 'chalk';\nimport { BranchData } from '../../types/branch.js';\nimport type { FileReference, OrphanedFile } from 'generaltranslation/types';\n\ntype MoveMapping = {\n oldFileId: string;\n newFileId: string;\n newFileName: string;\n};\n\ntype UploadSourcesClient = Pick<\n ApiClient,\n | 'queryFileData'\n | 'getOrphanedFiles'\n | 'processFileMoves'\n | 'uploadSourceFiles'\n>;\ntype UploadSourcesSettings = Pick<Settings, 'defaultLocale'>;\n\nexport class UploadSourcesStep {\n private spinner = logger.createSpinner('dots');\n\n constructor(\n private gt: UploadSourcesClient,\n private settings: UploadSourcesSettings\n ) {}\n\n /**\n * Detects file moves by comparing local files against orphaned files.\n * A move is detected when a local file has the same versionId (content hash)\n * as an orphaned file but a different fileId (path hash).\n */\n private detectMoves(\n localFiles: FileToUpload[],\n orphanedFiles: OrphanedFile[]\n ): MoveMapping[] {\n const moves: MoveMapping[] = [];\n\n // Build a map of versionId -> orphaned file\n const orphansByVersionId = new Map<string, OrphanedFile>();\n for (const orphan of orphanedFiles) {\n orphansByVersionId.set(orphan.versionId, orphan);\n }\n\n // Check each local file against orphaned files\n for (const local of localFiles) {\n const orphan = orphansByVersionId.get(local.versionId);\n if (orphan && orphan.fileId !== local.fileId) {\n // Same content, different path = move detected\n moves.push({\n oldFileId: orphan.fileId,\n newFileId: local.fileId,\n newFileName: local.fileName,\n });\n // Remove from map to avoid matching same orphan twice\n orphansByVersionId.delete(local.versionId);\n }\n }\n\n return moves;\n }\n\n async run({\n files,\n branchData,\n }: {\n files: FileToUpload[];\n branchData: BranchData;\n }): Promise<FileReference[]> {\n if (files.length === 0) {\n logger.info('No files to upload found... skipping upload step');\n return [];\n }\n\n const currentBranchId = branchData.currentBranch.id;\n\n this.spinner.start(\n `Syncing ${files.length} file${files.length !== 1 ? 's' : ''} with General Translation API...`\n );\n\n // Query file data and orphaned files in parallel\n const [fileData, orphanedFilesResult] = await Promise.all([\n this.gt.queryFileData({\n sourceFiles: files.map((f) => ({\n fileId: f.fileId,\n versionId: f.versionId,\n branchId: f.branchId ?? currentBranchId,\n })),\n }),\n this.gt.getOrphanedFiles(\n currentBranchId,\n files.map((f) => f.fileId)\n ),\n ]);\n\n // Detect file moves\n const moves = this.detectMoves(files, orphanedFilesResult.orphanedFiles);\n\n // Track successfully moved files\n let successfullyMovedFileIds = new Set<string>();\n\n // Process moves if any were detected\n if (moves.length > 0) {\n this.spinner.message(\n `Detected ${moves.length} moved file${moves.length !== 1 ? 's' : ''}, preserving translations...`\n );\n\n const moveResult = await this.gt.processFileMoves(moves, {\n branchId: currentBranchId,\n });\n\n // Only track files where the move actually succeeded\n successfullyMovedFileIds = new Set(\n moveResult.results.filter((r) => r.success).map((r) => r.newFileId)\n );\n\n const failed = moveResult.summary.failed;\n\n if (failed > 0) {\n logger.warn(\n `Failed to migrate ${failed} moved file${failed !== 1 ? 's' : ''}`\n );\n for (const r of moveResult.results) {\n if (!r.success) {\n const move = moves.find((m) => m.newFileId === r.newFileId);\n recordWarning(\n 'failed_move',\n move?.newFileName ?? r.newFileId,\n r.error ?? 'Unknown error'\n );\n }\n }\n }\n }\n\n // Build a map of branch:fileId:versionId to fileData\n const fileDataMap = new Map<\n string,\n GetFileInfoResponse['sourceFiles'][number]\n >();\n fileData.sourceFiles?.forEach((f) => {\n fileDataMap.set(`${f.branchId}:${f.fileId}:${f.versionId}`, f);\n });\n\n // Build a list of files that need to be uploaded\n const filesToUpload: FileToUpload[] = [];\n const filesToSkipUpload: FileToUpload[] = [];\n files.forEach((f) => {\n const key = `${f.branchId ?? currentBranchId}:${f.fileId}:${f.versionId}`;\n if (fileDataMap.has(key) || successfullyMovedFileIds.has(f.fileId)) {\n filesToSkipUpload.push(f);\n } else {\n filesToUpload.push(f);\n }\n });\n\n const response = await this.gt.uploadSourceFiles(\n filesToUpload.map((f) => ({\n source: {\n ...f,\n branchId: f.branchId ?? currentBranchId,\n locale: this.settings.defaultLocale,\n incomingBranchId: branchData.incomingBranch?.id,\n checkedOutBranchId: branchData.checkedOutBranch?.id,\n },\n })),\n { sourceLocale: this.settings.defaultLocale }\n );\n\n // The API may not echo transformFormat, so preserve it from local inputs.\n const localFileMap = new Map(\n files.map((f) => [`${f.fileId}:${f.versionId}`, f])\n );\n\n const result: FileReference[] = response.uploadedFiles.map(\n (uploadedFile) => {\n const localFile = localFileMap.get(\n `${uploadedFile.fileId}:${uploadedFile.versionId}`\n );\n return {\n branchId:\n uploadedFile.branchId ?? localFile?.branchId ?? currentBranchId,\n fileId: uploadedFile.fileId,\n versionId: uploadedFile.versionId,\n fileName: uploadedFile.fileName,\n fileFormat: uploadedFile.fileFormat,\n dataFormat: localFile?.dataFormat,\n transformFormat: localFile?.transformFormat,\n };\n }\n );\n\n // Merge files that were already uploaded into the result\n result.push(\n ...filesToSkipUpload.map((f) => ({\n fileId: f.fileId,\n versionId: f.versionId,\n branchId: f.branchId ?? currentBranchId,\n fileName: f.fileName,\n fileFormat: f.fileFormat,\n transformFormat: f.transformFormat,\n dataFormat: f.dataFormat,\n locale: f.locale,\n }))\n );\n\n const moveMsg = moves.length > 0 ? ` (${moves.length} moved)` : '';\n this.spinner.stop(chalk.green(`Files uploaded successfully${moveMsg}`));\n\n return result;\n }\n}\n"],"mappings":";;;;AAyBA,IAAa,oBAAb,MAA+B;CAC7B,UAAkB,OAAO,cAAc,OAAO;CAE9C,YACE,IACA,UACA;AAFQ,OAAA,KAAA;AACA,OAAA,WAAA;;;;;;;CAQV,YACE,YACA,eACe;EACf,MAAM,QAAuB,EAAE;EAG/B,MAAM,qCAAqB,IAAI,KAA2B;AAC1D,OAAK,MAAM,UAAU,cACnB,oBAAmB,IAAI,OAAO,WAAW,OAAO;AAIlD,OAAK,MAAM,SAAS,YAAY;GAC9B,MAAM,SAAS,mBAAmB,IAAI,MAAM,UAAU;AACtD,OAAI,UAAU,OAAO,WAAW,MAAM,QAAQ;AAE5C,UAAM,KAAK;KACT,WAAW,OAAO;KAClB,WAAW,MAAM;KACjB,aAAa,MAAM;KACpB,CAAC;AAEF,uBAAmB,OAAO,MAAM,UAAU;;;AAI9C,SAAO;;CAGT,MAAM,IAAI,EACR,OACA,cAI2B;AAC3B,MAAI,MAAM,WAAW,GAAG;AACtB,UAAO,KAAK,mDAAmD;AAC/D,UAAO,EAAE;;EAGX,MAAM,kBAAkB,WAAW,cAAc;AAEjD,OAAK,QAAQ,MACX,WAAW,MAAM,OAAO,OAAO,MAAM,WAAW,IAAI,MAAM,GAAG,kCAC9D;EAGD,MAAM,CAAC,UAAU,uBAAuB,MAAM,QAAQ,IAAI,CACxD,KAAK,GAAG,cAAc,EACpB,aAAa,MAAM,KAAK,OAAO;GAC7B,QAAQ,EAAE;GACV,WAAW,EAAE;GACb,UAAU,EAAE,YAAY;GACzB,EAAE,EACJ,CAAC,EACF,KAAK,GAAG,iBACN,iBACA,MAAM,KAAK,MAAM,EAAE,OAAO,CAC3B,CACF,CAAC;EAGF,MAAM,QAAQ,KAAK,YAAY,OAAO,oBAAoB,cAAc;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E,EACH,EAAE,cAAc,KAAK,SAAS,eAAe,CAC9C;EAGD,MAAM,eAAe,IAAI,IACvB,MAAM,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,GAAG,EAAE,aAAa,EAAE,CAAC,CACpD;EAED,MAAM,SAA0B,SAAS,cAAc,KACpD,iBAAiB;GAChB,MAAM,YAAY,aAAa,IAC7B,GAAG,aAAa,OAAO,GAAG,aAAa,YACxC;AACD,UAAO;IACL,UACE,aAAa,YAAY,WAAW,YAAY;IAClD,QAAQ,aAAa;IACrB,WAAW,aAAa;IACxB,UAAU,aAAa;IACvB,YAAY,aAAa;IACzB,YAAY,WAAW;IACvB,iBAAiB,WAAW;IAC7B;IAEJ;AAGD,SAAO,KACL,GAAG,kBAAkB,KAAK,OAAO;GAC/B,QAAQ,EAAE;GACV,WAAW,EAAE;GACb,UAAU,EAAE,YAAY;GACxB,UAAU,EAAE;GACZ,YAAY,EAAE;GACd,iBAAiB,EAAE;GACnB,YAAY,EAAE;GACd,QAAQ,EAAE;GACX,EAAE,CACJ;EAED,MAAM,UAAU,MAAM,SAAS,IAAI,KAAK,MAAM,OAAO,WAAW;AAChE,OAAK,QAAQ,KAAK,MAAM,MAAM,8BAA8B,UAAU,CAAC;AAEvE,SAAO"}
|
|
@@ -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 { type EntryMap } from '../../fs/config/downloadedVersions.js';
|
|
4
4
|
import type { FileReference, FileToUpload } from 'generaltranslation/types';
|
|
@@ -19,10 +19,10 @@ export declare function partitionTranslationsByLockfile(files: UploadTranslation
|
|
|
19
19
|
skippedCount: number;
|
|
20
20
|
};
|
|
21
21
|
export declare class UploadTranslationsStep {
|
|
22
|
-
private
|
|
22
|
+
private api;
|
|
23
23
|
private settings;
|
|
24
24
|
private spinner;
|
|
25
|
-
constructor(
|
|
25
|
+
constructor(api: Pick<ApiClient, 'uploadTranslations'>, settings: Settings);
|
|
26
26
|
run({ files }: UploadTranslationsInput): Promise<FileReference[]>;
|
|
27
27
|
/**
|
|
28
28
|
* Records the content hash of each server-confirmed upload in gt-lock.json
|
|
@@ -31,8 +31,8 @@ function partitionTranslationsByLockfile(files, entryMap) {
|
|
|
31
31
|
}
|
|
32
32
|
var UploadTranslationsStep = class {
|
|
33
33
|
spinner = logger.createSpinner("dots");
|
|
34
|
-
constructor(
|
|
35
|
-
this.
|
|
34
|
+
constructor(api, settings) {
|
|
35
|
+
this.api = api;
|
|
36
36
|
this.settings = settings;
|
|
37
37
|
}
|
|
38
38
|
async run({ files }) {
|
|
@@ -49,10 +49,28 @@ var UploadTranslationsStep = class {
|
|
|
49
49
|
}
|
|
50
50
|
const totalTranslations = filesToUpload.reduce((acc, f) => acc + f.translations.length, 0);
|
|
51
51
|
this.spinner.start(`Uploading ${totalTranslations} translation file${totalTranslations !== 1 ? "s" : ""} to the General Translation API...`);
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
const response = await this.api.uploadTranslations(filesToUpload, { sourceLocale: this.settings.defaultLocale });
|
|
53
|
+
const localFiles = /* @__PURE__ */ new Map();
|
|
54
|
+
for (const { source, translations } of filesToUpload) for (const translation of translations) localFiles.set(`${translation.fileId}:${translation.versionId}`, {
|
|
55
|
+
source,
|
|
56
|
+
translation
|
|
57
|
+
});
|
|
58
|
+
const result = response.uploadedFiles.map((uploadedFile) => {
|
|
59
|
+
const localFile = localFiles.get(`${uploadedFile.fileId}:${uploadedFile.versionId}`);
|
|
60
|
+
const branchId = uploadedFile.branchId ?? localFile?.translation.branchId ?? localFile?.source.branchId ?? lockfile.data.branchId;
|
|
61
|
+
const dataFormat = localFile?.translation.dataFormat;
|
|
62
|
+
const transformFormat = localFile?.translation.transformFormat;
|
|
63
|
+
return {
|
|
64
|
+
branchId,
|
|
65
|
+
fileId: uploadedFile.fileId,
|
|
66
|
+
versionId: uploadedFile.versionId,
|
|
67
|
+
fileName: uploadedFile.fileName,
|
|
68
|
+
fileFormat: uploadedFile.fileFormat,
|
|
69
|
+
...dataFormat && { dataFormat },
|
|
70
|
+
...transformFormat && { transformFormat },
|
|
71
|
+
locale: uploadedFile.locale
|
|
72
|
+
};
|
|
73
|
+
});
|
|
56
74
|
const uploadedCount = result.length;
|
|
57
75
|
this.spinner.stop(chalk.green(`Uploaded ${uploadedCount} translation file${uploadedCount !== 1 ? "s" : ""}${skippedCount > 0 ? `, skipped ${skippedCount} unchanged` : ""}`));
|
|
58
76
|
if (uploadedCount < totalTranslations) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UploadTranslationsStep.js","names":[],"sources":["../../../src/workflows/steps/UploadTranslationsStep.ts"],"sourcesContent":["import { logger } from '../../console/logger.js';\nimport {
|
|
1
|
+
{"version":3,"file":"UploadTranslationsStep.js","names":[],"sources":["../../../src/workflows/steps/UploadTranslationsStep.ts"],"sourcesContent":["import { logger } from '../../console/logger.js';\nimport type { ApiClient } from '../../utils/api.js';\nimport { Settings } from '../../types/index.js';\nimport chalk from 'chalk';\nimport {\n readLockfile,\n writeLockfile,\n findOrCreateEntry,\n type EntryMap,\n} from '../../fs/config/downloadedVersions.js';\nimport { hashStringSync } from '../../utils/hash.js';\nimport type { FileReference, FileToUpload } from 'generaltranslation/types';\n\ntype UploadTranslationsInput = {\n files: {\n source: FileToUpload;\n translations: FileToUpload[];\n }[];\n};\n\ntype UploadedTranslation = Awaited<\n ReturnType<ApiClient['uploadTranslations']>\n>['uploadedFiles'][number];\ntype ConfirmedTranslationReference = FileReference &\n Pick<UploadedTranslation, 'locale'>;\n\n/**\n * Splits translations into ones that need uploading and ones that can be\n * skipped because their content still matches the gt-lock.json hash recorded\n * at the last sync (download/translate/upload). Files without a lock entry —\n * or with a stale versionId — are always uploaded.\n */\nexport function partitionTranslationsByLockfile(\n files: UploadTranslationsInput['files'],\n entryMap: EntryMap\n): {\n filesToUpload: UploadTranslationsInput['files'];\n skippedCount: number;\n} {\n let skippedCount = 0;\n const filesToUpload = files\n .map((file) => {\n const translations = file.translations.filter((translation) => {\n const entry = entryMap.get(translation.fileId);\n if (!entry || entry.versionId !== translation.versionId) return true;\n const lockHash =\n entry.translations[translation.locale]?.postProcessHash;\n if (!lockHash || lockHash !== hashStringSync(translation.content)) {\n return true;\n }\n skippedCount++;\n return false;\n });\n return { source: file.source, translations };\n })\n .filter((file) => file.translations.length > 0);\n\n return { filesToUpload, skippedCount };\n}\n\nexport class UploadTranslationsStep {\n private spinner = logger.createSpinner('dots');\n\n constructor(\n private api: Pick<ApiClient, 'uploadTranslations'>,\n private settings: Settings\n ) {}\n\n async run({ files }: UploadTranslationsInput): Promise<FileReference[]> {\n // Filter to only files that have translations\n const withTranslations = files.filter((f) => f.translations.length > 0);\n\n if (withTranslations.length === 0) {\n logger.info(\n 'No translation files to upload... skipping upload translations step'\n );\n return [];\n }\n\n // Local translation files are the source of truth: everything local is\n // uploaded (the endpoint is an upsert, so existing translations are\n // overwritten). The one optimization is the lockfile: files whose content\n // hash still matches gt-lock.json are unchanged since the last sync and\n // can be skipped. Without a lockfile, everything uploads.\n const lockfile = readLockfile(this.settings);\n const { filesToUpload, skippedCount } = partitionTranslationsByLockfile(\n withTranslations,\n lockfile.entryMap\n );\n\n if (filesToUpload.length === 0) {\n logger.info(\n chalk.green(\n `All ${skippedCount} translation file${skippedCount !== 1 ? 's are' : ' is'} unchanged since the last sync... skipping upload translations step`\n )\n );\n return [];\n }\n\n const totalTranslations = filesToUpload.reduce(\n (acc, f) => acc + f.translations.length,\n 0\n );\n\n this.spinner.start(\n `Uploading ${totalTranslations} translation file${totalTranslations !== 1 ? 's' : ''} to the General Translation API...`\n );\n\n const response = await this.api.uploadTranslations(filesToUpload, {\n sourceLocale: this.settings.defaultLocale,\n });\n\n const localFiles = new Map<\n string,\n { source: FileToUpload; translation: FileToUpload }\n >();\n for (const { source, translations } of filesToUpload) {\n for (const translation of translations) {\n localFiles.set(`${translation.fileId}:${translation.versionId}`, {\n source,\n translation,\n });\n }\n }\n const result: ConfirmedTranslationReference[] = response.uploadedFiles.map(\n (uploadedFile) => {\n const localFile = localFiles.get(\n `${uploadedFile.fileId}:${uploadedFile.versionId}`\n );\n const branchId =\n uploadedFile.branchId ??\n localFile?.translation.branchId ??\n localFile?.source.branchId ??\n lockfile.data.branchId;\n const dataFormat = localFile?.translation.dataFormat;\n const transformFormat = localFile?.translation.transformFormat;\n return {\n branchId,\n fileId: uploadedFile.fileId,\n versionId: uploadedFile.versionId,\n fileName: uploadedFile.fileName,\n fileFormat: uploadedFile.fileFormat,\n ...(dataFormat && { dataFormat }),\n ...(transformFormat && { transformFormat }),\n locale: uploadedFile.locale,\n };\n }\n );\n // Report the server-confirmed count, not the attempted count — the\n // endpoint drops files it failed to persist without erroring\n const uploadedCount = result.length;\n this.spinner.stop(\n chalk.green(\n `Uploaded ${uploadedCount} translation file${uploadedCount !== 1 ? 's' : ''}${skippedCount > 0 ? `, skipped ${skippedCount} unchanged` : ''}`\n )\n );\n if (uploadedCount < totalTranslations) {\n const missingCount = totalTranslations - uploadedCount;\n logger.warn(\n chalk.yellow(\n `${missingCount} translation file${missingCount !== 1 ? 's were' : ' was'} not persisted by the server`\n )\n );\n }\n\n this.recordUploadedHashes(lockfile, filesToUpload, result);\n\n return result;\n }\n\n /**\n * Records the content hash of each server-confirmed upload in gt-lock.json\n * so unchanged files are skipped on the next run.\n */\n private recordUploadedHashes(\n lockfile: ReturnType<typeof readLockfile>,\n uploaded: UploadTranslationsInput['files'],\n confirmed: ConfirmedTranslationReference[]\n ): void {\n const confirmedKeys = new Set(\n confirmed\n .filter((file) => file.locale)\n .map((file) => `${file.fileId}:${file.locale}`)\n );\n if (confirmedKeys.size === 0) return;\n\n const updatedAt = new Date().toISOString();\n for (const file of uploaded) {\n for (const translation of file.translations) {\n if (!confirmedKeys.has(`${translation.fileId}:${translation.locale}`)) {\n continue;\n }\n const entry = findOrCreateEntry(\n lockfile.entryMap,\n lockfile.data.entries,\n translation.fileId,\n translation.versionId\n );\n entry.translations[translation.locale] = {\n ...entry.translations[translation.locale],\n updatedAt,\n postProcessHash: hashStringSync(translation.content),\n };\n }\n }\n writeLockfile(lockfile.data, lockfile.originalV1);\n }\n}\n"],"mappings":";;;;;;;;;;;AAgCA,SAAgB,gCACd,OACA,UAIA;CACA,IAAI,eAAe;AAkBnB,QAAO;EAAE,eAjBa,MACnB,KAAK,SAAS;GACb,MAAM,eAAe,KAAK,aAAa,QAAQ,gBAAgB;IAC7D,MAAM,QAAQ,SAAS,IAAI,YAAY,OAAO;AAC9C,QAAI,CAAC,SAAS,MAAM,cAAc,YAAY,UAAW,QAAO;IAChE,MAAM,WACJ,MAAM,aAAa,YAAY,SAAS;AAC1C,QAAI,CAAC,YAAY,aAAa,eAAe,YAAY,QAAQ,CAC/D,QAAO;AAET;AACA,WAAO;KACP;AACF,UAAO;IAAE,QAAQ,KAAK;IAAQ;IAAc;IAC5C,CACD,QAAQ,SAAS,KAAK,aAAa,SAAS,EAEzB;EAAE;EAAc;;AAGxC,IAAa,yBAAb,MAAoC;CAClC,UAAkB,OAAO,cAAc,OAAO;CAE9C,YACE,KACA,UACA;AAFQ,OAAA,MAAA;AACA,OAAA,WAAA;;CAGV,MAAM,IAAI,EAAE,SAA4D;EAEtE,MAAM,mBAAmB,MAAM,QAAQ,MAAM,EAAE,aAAa,SAAS,EAAE;AAEvE,MAAI,iBAAiB,WAAW,GAAG;AACjC,UAAO,KACL,sEACD;AACD,UAAO,EAAE;;EAQX,MAAM,WAAW,aAAa,KAAK,SAAS;EAC5C,MAAM,EAAE,eAAe,iBAAiB,gCACtC,kBACA,SAAS,SACV;AAED,MAAI,cAAc,WAAW,GAAG;AAC9B,UAAO,KACL,MAAM,MACJ,OAAO,aAAa,mBAAmB,iBAAiB,IAAI,UAAU,MAAM,qEAC7E,CACF;AACD,UAAO,EAAE;;EAGX,MAAM,oBAAoB,cAAc,QACrC,KAAK,MAAM,MAAM,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,KAAK,OAAO,CAC7B,KAAK,SAAS,GAAG,KAAK,OAAO,GAAG,KAAK,SAAS,CAClD;AACD,MAAI,cAAc,SAAS,EAAG;EAE9B,MAAM,6BAAY,IAAI,MAAM,EAAC,aAAa;AAC1C,OAAK,MAAM,QAAQ,SACjB,MAAK,MAAM,eAAe,KAAK,cAAc;AAC3C,OAAI,CAAC,cAAc,IAAI,GAAG,YAAY,OAAO,GAAG,YAAY,SAAS,CACnE;GAEF,MAAM,QAAQ,kBACZ,SAAS,UACT,SAAS,KAAK,SACd,YAAY,QACZ,YAAY,UACb;AACD,SAAM,aAAa,YAAY,UAAU;IACvC,GAAG,MAAM,aAAa,YAAY;IAClC;IACA,iBAAiB,eAAe,YAAY,QAAQ;IACrD;;AAGL,gBAAc,SAAS,MAAM,SAAS,WAAW"}
|
package/dist/workflows/upload.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { logger } from "../console/logger.js";
|
|
2
|
-
import { gt } from "../utils/gt.js";
|
|
3
2
|
import { logErrorAndExit } from "../console/logging.js";
|
|
4
3
|
import { branchResolutionError, withOriginalError } from "../console/index.js";
|
|
4
|
+
import { api } from "../utils/api.js";
|
|
5
5
|
import { syncFonts } from "./utils/syncFonts.js";
|
|
6
6
|
import { BranchStep } from "./steps/BranchStep.js";
|
|
7
7
|
import { UploadSourcesStep } from "./steps/UploadSourcesStep.js";
|
|
@@ -18,9 +18,9 @@ async function runUploadFilesWorkflow({ files, options }) {
|
|
|
18
18
|
try {
|
|
19
19
|
logger.message(chalk.cyan("Files to upload:") + "\n" + files.map((file) => ` - ${chalk.bold(file.source.fileName)}${file.translations.length > 0 ? ` -> ${file.translations.map((t) => t.locale).join(", ")}` : ""}`).join("\n"));
|
|
20
20
|
await syncFonts(options);
|
|
21
|
-
const branchStep = new BranchStep(
|
|
22
|
-
const uploadStep = new UploadSourcesStep(
|
|
23
|
-
const uploadTranslationsStep = new UploadTranslationsStep(
|
|
21
|
+
const branchStep = new BranchStep(api, options);
|
|
22
|
+
const uploadStep = new UploadSourcesStep(api, options);
|
|
23
|
+
const uploadTranslationsStep = new UploadTranslationsStep(api, options);
|
|
24
24
|
const branchData = await branchStep.run();
|
|
25
25
|
if (!branchData) return logErrorAndExit(branchResolutionError);
|
|
26
26
|
await uploadStep.run({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.js","names":[],"sources":["../../src/workflows/upload.ts"],"sourcesContent":["import chalk from 'chalk';\nimport { branchResolutionError, withOriginalError } from '../console/index.js';\nimport { logger } from '../console/logger.js';\nimport { logErrorAndExit } from '../console/logging.js';\nimport { Settings } from '../types/index.js';\nimport {
|
|
1
|
+
{"version":3,"file":"upload.js","names":[],"sources":["../../src/workflows/upload.ts"],"sourcesContent":["import chalk from 'chalk';\nimport { branchResolutionError, withOriginalError } from '../console/index.js';\nimport { logger } from '../console/logger.js';\nimport { logErrorAndExit } from '../console/logging.js';\nimport { Settings } from '../types/index.js';\nimport { api } from '../utils/api.js';\nimport { syncFonts } from './utils/syncFonts.js';\nimport { BranchStep } from './steps/BranchStep.js';\nimport { UploadSourcesStep } from './steps/UploadSourcesStep.js';\nimport { UploadTranslationsStep } from './steps/UploadTranslationsStep.js';\nimport type { FileToUpload } from 'generaltranslation/types';\nimport { BranchData } from '../types/branch.js';\n\n/**\n * Uploads multiple files to the API using a workflow pattern\n * @param files - Array of file objects to upload\n * @param options - The options for the API call\n * @returns The branch data resolved during the workflow\n */\nexport async function runUploadFilesWorkflow({\n files,\n options,\n}: {\n files: {\n source: FileToUpload;\n translations: FileToUpload[];\n }[];\n options: Settings;\n}): Promise<{ branchData: BranchData }> {\n try {\n logger.message(\n chalk.cyan('Files to upload:') +\n '\\n' +\n files\n .map(\n (file) =>\n ` - ${chalk.bold(file.source.fileName)}${file.translations.length > 0 ? ` -> ${file.translations.map((t) => t.locale).join(', ')}` : ''}`\n )\n .join('\\n')\n );\n\n // Sync fonts first (locale-invariant) so they're available when\n // translating formats that need them.\n await syncFonts(options);\n\n // Create workflow steps\n const branchStep = new BranchStep(api, options);\n const uploadStep = new UploadSourcesStep(api, options);\n const uploadTranslationsStep = new UploadTranslationsStep(api, options);\n\n // Step 1: Resolve branch information\n const branchData = await branchStep.run();\n\n if (!branchData) {\n return logErrorAndExit(branchResolutionError);\n }\n\n await uploadStep.run({ files: files.map((f) => f.source), branchData });\n\n // Step 3: Upload translations (if any exist)\n const filesWithTranslations = files.filter(\n (f) => f.translations.length > 0\n );\n if (filesWithTranslations.length > 0) {\n await uploadTranslationsStep.run({\n files: filesWithTranslations,\n });\n }\n\n logger.success('All files uploaded successfully');\n return { branchData };\n } catch (error) {\n return logErrorAndExit(\n withOriginalError(\n 'Files could not be uploaded. Check the files, branch configuration, and API credentials, then try again.',\n error\n )\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmBA,eAAsB,uBAAuB,EAC3C,OACA,WAOsC;AACtC,KAAI;AACF,SAAO,QACL,MAAM,KAAK,mBAAmB,GAC5B,OACA,MACG,KACE,SACC,OAAO,MAAM,KAAK,KAAK,OAAO,SAAS,GAAG,KAAK,aAAa,SAAS,IAAI,OAAO,KAAK,aAAa,KAAK,MAAM,EAAE,OAAO,CAAC,KAAK,KAAK,KAAK,KACzI,CACA,KAAK,KAAK,CAChB;AAID,QAAM,UAAU,QAAQ;EAGxB,MAAM,aAAa,IAAI,WAAW,KAAK,QAAQ;EAC/C,MAAM,aAAa,IAAI,kBAAkB,KAAK,QAAQ;EACtD,MAAM,yBAAyB,IAAI,uBAAuB,KAAK,QAAQ;EAGvE,MAAM,aAAa,MAAM,WAAW,KAAK;AAEzC,MAAI,CAAC,WACH,QAAO,gBAAgB,sBAAsB;AAG/C,QAAM,WAAW,IAAI;GAAE,OAAO,MAAM,KAAK,MAAM,EAAE,OAAO;GAAE;GAAY,CAAC;EAGvE,MAAM,wBAAwB,MAAM,QACjC,MAAM,EAAE,aAAa,SAAS,EAChC;AACD,MAAI,sBAAsB,SAAS,EACjC,OAAM,uBAAuB,IAAI,EAC/B,OAAO,uBACR,CAAC;AAGJ,SAAO,QAAQ,kCAAkC;AACjD,SAAO,EAAE,YAAY;UACd,OAAO;AACd,SAAO,gBACL,kBACE,4GACA,MACD,CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ApiClient } from '../../utils/api.js';
|
|
2
2
|
import type { FileReference } from 'generaltranslation/types';
|
|
3
|
-
type FilterFilesForEnqueueClient = Pick<
|
|
3
|
+
type FilterFilesForEnqueueClient = Pick<ApiClient, 'queryFileData'>;
|
|
4
4
|
export type EnqueueFilterResult = {
|
|
5
5
|
filesToEnqueue: FileReference[];
|
|
6
6
|
skippedFiles: FileReference[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filterFilesForEnqueue.js","names":[],"sources":["../../../src/workflows/utils/filterFilesForEnqueue.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"filterFilesForEnqueue.js","names":[],"sources":["../../../src/workflows/utils/filterFilesForEnqueue.ts"],"sourcesContent":["import type { ApiClient } from '../../utils/api.js';\nimport type { FileReference } from 'generaltranslation/types';\nimport type { FileProperties } from '../../types/files.js';\nimport {\n getFileTranslationKey,\n queryCompletedTranslationKeys,\n} from './queryCompletedTranslations.js';\n\ntype FilterFilesForEnqueueClient = Pick<ApiClient, 'queryFileData'>;\n\nexport type EnqueueFilterResult = {\n filesToEnqueue: FileReference[];\n skippedFiles: FileReference[];\n};\n\nexport async function filterFilesForEnqueue({\n gt,\n files,\n locales,\n force,\n}: {\n gt: FilterFilesForEnqueueClient;\n files: FileReference[];\n locales: string[];\n force?: boolean;\n}): Promise<EnqueueFilterResult> {\n if (force || files.length === 0 || locales.length === 0) {\n return { filesToEnqueue: files, skippedFiles: [] };\n }\n\n const fileQueryData: FileProperties[] = files.flatMap((file) =>\n locales.map((locale) => ({\n branchId: file.branchId,\n fileId: file.fileId,\n versionId: file.versionId,\n fileName: file.fileName,\n locale,\n }))\n );\n\n let completedKeys: Set<string>;\n try {\n completedKeys = await queryCompletedTranslationKeys(gt, fileQueryData);\n } catch {\n return { filesToEnqueue: files, skippedFiles: [] };\n }\n\n const filesToEnqueue: FileReference[] = [];\n const skippedFiles: FileReference[] = [];\n\n for (const file of files) {\n const hasEveryLocale = locales.every((locale) =>\n completedKeys.has(\n getFileTranslationKey({\n branchId: file.branchId,\n fileId: file.fileId,\n versionId: file.versionId,\n locale,\n })\n )\n );\n\n if (hasEveryLocale) {\n skippedFiles.push(file);\n } else {\n filesToEnqueue.push(file);\n }\n }\n\n return { filesToEnqueue, skippedFiles };\n}\n"],"mappings":";;AAeA,eAAsB,sBAAsB,EAC1C,IACA,OACA,SACA,SAM+B;AAC/B,KAAI,SAAS,MAAM,WAAW,KAAK,QAAQ,WAAW,EACpD,QAAO;EAAE,gBAAgB;EAAO,cAAc,EAAE;EAAE;CAGpD,MAAM,gBAAkC,MAAM,SAAS,SACrD,QAAQ,KAAK,YAAY;EACvB,UAAU,KAAK;EACf,QAAQ,KAAK;EACb,WAAW,KAAK;EAChB,UAAU,KAAK;EACf;EACD,EAAE,CACJ;CAED,IAAI;AACJ,KAAI;AACF,kBAAgB,MAAM,8BAA8B,IAAI,cAAc;SAChE;AACN,SAAO;GAAE,gBAAgB;GAAO,cAAc,EAAE;GAAE;;CAGpD,MAAM,iBAAkC,EAAE;CAC1C,MAAM,eAAgC,EAAE;AAExC,MAAK,MAAM,QAAQ,MAYjB,KAXuB,QAAQ,OAAO,WACpC,cAAc,IACZ,sBAAsB;EACpB,UAAU,KAAK;EACf,QAAQ,KAAK;EACb,WAAW,KAAK;EAChB;EACD,CAAC,CACH,CAGe,CAChB,cAAa,KAAK,KAAK;KAEvB,gBAAe,KAAK,KAAK;AAI7B,QAAO;EAAE;EAAgB;EAAc"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { GT } from 'generaltranslation';
|
|
2
1
|
import type { FileProperties } from '../../types/files.js';
|
|
3
|
-
|
|
2
|
+
import type { ApiClient } from '../../utils/api.js';
|
|
3
|
+
export type QueryCompletedTranslationsClient = Pick<ApiClient, 'queryFileData'>;
|
|
4
4
|
export declare function getFileTranslationKey(file: Pick<FileProperties, 'branchId' | 'fileId' | 'versionId' | 'locale'>): string;
|
|
5
|
-
export declare function queryCompletedTranslationKeys(
|
|
5
|
+
export declare function queryCompletedTranslationKeys(api: QueryCompletedTranslationsClient, fileQueryData: FileProperties[]): Promise<Set<string>>;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
function getFileTranslationKey(file) {
|
|
3
3
|
return `${file.branchId}:${file.fileId}:${file.versionId}:${file.locale}`;
|
|
4
4
|
}
|
|
5
|
-
async function queryCompletedTranslationKeys(
|
|
5
|
+
async function queryCompletedTranslationKeys(api, fileQueryData) {
|
|
6
6
|
if (fileQueryData.length === 0) return /* @__PURE__ */ new Set();
|
|
7
|
-
const fileData = await
|
|
7
|
+
const fileData = await api.queryFileData({ translatedFiles: fileQueryData.map((file) => ({
|
|
8
8
|
fileId: file.fileId,
|
|
9
9
|
versionId: file.versionId,
|
|
10
10
|
branchId: file.branchId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryCompletedTranslations.js","names":[],"sources":["../../../src/workflows/utils/queryCompletedTranslations.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"queryCompletedTranslations.js","names":[],"sources":["../../../src/workflows/utils/queryCompletedTranslations.ts"],"sourcesContent":["import type { FileProperties } from '../../types/files.js';\nimport type { ApiClient } from '../../utils/api.js';\n\nexport type QueryCompletedTranslationsClient = Pick<ApiClient, 'queryFileData'>;\n\nexport function getFileTranslationKey(\n file: Pick<FileProperties, 'branchId' | 'fileId' | 'versionId' | 'locale'>\n): string {\n return `${file.branchId}:${file.fileId}:${file.versionId}:${file.locale}`;\n}\n\nexport async function queryCompletedTranslationKeys(\n api: QueryCompletedTranslationsClient,\n fileQueryData: FileProperties[]\n): Promise<Set<string>> {\n if (fileQueryData.length === 0) {\n return new Set();\n }\n\n const fileData = await api.queryFileData({\n translatedFiles: fileQueryData.map((file) => ({\n fileId: file.fileId,\n versionId: file.versionId,\n branchId: file.branchId,\n locale: file.locale,\n })),\n });\n\n return new Set(\n (fileData.translatedFiles || [])\n .filter((file) => !!file.completedAt)\n .map(getFileTranslationKey)\n );\n}\n"],"mappings":";AAKA,SAAgB,sBACd,MACQ;AACR,QAAO,GAAG,KAAK,SAAS,GAAG,KAAK,OAAO,GAAG,KAAK,UAAU,GAAG,KAAK;;AAGnE,eAAsB,8BACpB,KACA,eACsB;AACtB,KAAI,cAAc,WAAW,EAC3B,wBAAO,IAAI,KAAK;CAGlB,MAAM,WAAW,MAAM,IAAI,cAAc,EACvC,iBAAiB,cAAc,KAAK,UAAU;EAC5C,QAAQ,KAAK;EACb,WAAW,KAAK;EAChB,UAAU,KAAK;EACf,QAAQ,KAAK;EACd,EAAE,EACJ,CAAC;AAEF,QAAO,IAAI,KACR,SAAS,mBAAmB,EAAE,EAC5B,QAAQ,SAAS,CAAC,CAAC,KAAK,YAAY,CACpC,IAAI,sBAAsB,CAC9B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gt",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"bin": "bin/main.js",
|
|
6
6
|
"files": [
|
|
@@ -117,10 +117,10 @@
|
|
|
117
117
|
"yaml": "^2.8.0",
|
|
118
118
|
"@generaltranslation/icu": "0.1.2",
|
|
119
119
|
"@generaltranslation/format": "0.1.8",
|
|
120
|
-
"@generaltranslation/python-extractor": "0.2.
|
|
121
|
-
"@generaltranslation/supported-locales": "2.1.
|
|
122
|
-
"@generaltranslation/vue-extractor": "0.1.
|
|
123
|
-
"generaltranslation": "9.
|
|
120
|
+
"@generaltranslation/python-extractor": "0.2.47",
|
|
121
|
+
"@generaltranslation/supported-locales": "2.1.27",
|
|
122
|
+
"@generaltranslation/vue-extractor": "0.1.7",
|
|
123
|
+
"generaltranslation": "9.2.0",
|
|
124
124
|
"gt-remark": "1.0.12"
|
|
125
125
|
},
|
|
126
126
|
"devDependencies": {
|