gt 2.14.65 → 2.15.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 +32 -0
- package/dist/api/saveLocalEdits.js +1 -3
- package/dist/api/saveLocalEdits.js.map +1 -1
- package/dist/cli/base.js +4 -0
- package/dist/cli/base.js.map +1 -1
- package/dist/cli/inline.js +1 -3
- package/dist/cli/inline.js.map +1 -1
- package/dist/console/logger.d.ts +13 -0
- package/dist/console/logger.js +35 -8
- package/dist/console/logger.js.map +1 -1
- package/dist/console/logging.js +4 -2
- package/dist/console/logging.js.map +1 -1
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/generated/version.js.map +1 -1
- package/dist/react/jsx/evaluateJsx.js +1 -1
- package/dist/react/jsx/evaluateJsx.js.map +1 -1
- package/dist/workflows/download.js +3 -9
- package/dist/workflows/download.js.map +1 -1
- package/dist/workflows/enqueue.js +0 -2
- package/dist/workflows/enqueue.js.map +1 -1
- package/dist/workflows/publish.js +1 -3
- package/dist/workflows/publish.js.map +1 -1
- package/dist/workflows/setupProject.js +0 -3
- package/dist/workflows/setupProject.js.map +1 -1
- package/dist/workflows/stage.js +3 -13
- package/dist/workflows/stage.js.map +1 -1
- package/dist/workflows/steps/BranchStep.d.ts +1 -3
- package/dist/workflows/steps/BranchStep.js +1 -4
- package/dist/workflows/steps/BranchStep.js.map +1 -1
- package/dist/workflows/steps/DownloadStep.d.ts +1 -3
- package/dist/workflows/steps/DownloadStep.js +1 -4
- package/dist/workflows/steps/DownloadStep.js.map +1 -1
- package/dist/workflows/steps/EnqueueStep.d.ts +1 -5
- package/dist/workflows/steps/EnqueueStep.js +9 -19
- package/dist/workflows/steps/EnqueueStep.js.map +1 -1
- package/dist/workflows/steps/PollJobsStep.d.ts +1 -3
- package/dist/workflows/steps/PollJobsStep.js +1 -4
- package/dist/workflows/steps/PollJobsStep.js.map +1 -1
- package/dist/workflows/steps/PublishStep.d.ts +1 -3
- package/dist/workflows/steps/PublishStep.js +1 -4
- package/dist/workflows/steps/PublishStep.js.map +1 -1
- package/dist/workflows/steps/SetupStep.d.ts +1 -6
- package/dist/workflows/steps/SetupStep.js +14 -41
- package/dist/workflows/steps/SetupStep.js.map +1 -1
- package/dist/workflows/steps/TagStep.d.ts +1 -4
- package/dist/workflows/steps/TagStep.js +4 -9
- package/dist/workflows/steps/TagStep.js.map +1 -1
- package/dist/workflows/steps/UploadSourcesStep.d.ts +1 -7
- package/dist/workflows/steps/UploadSourcesStep.js +4 -8
- package/dist/workflows/steps/UploadSourcesStep.js.map +1 -1
- package/dist/workflows/steps/UploadTranslationsStep.d.ts +1 -4
- package/dist/workflows/steps/UploadTranslationsStep.js +6 -11
- package/dist/workflows/steps/UploadTranslationsStep.js.map +1 -1
- package/dist/workflows/steps/UserEditDiffsStep.d.ts +1 -5
- package/dist/workflows/steps/UserEditDiffsStep.js +3 -11
- package/dist/workflows/steps/UserEditDiffsStep.js.map +1 -1
- package/dist/workflows/upload.js +1 -6
- package/dist/workflows/upload.js.map +1 -1
- package/package.json +6 -6
- package/dist/workflows/steps/WorkflowStep.d.ts +0 -4
- package/dist/workflows/steps/WorkflowStep.js +0 -6
- package/dist/workflows/steps/WorkflowStep.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UploadSourcesStep.js","names":[],"sources":["../../../src/workflows/steps/UploadSourcesStep.ts"],"sourcesContent":["import type { FileToUpload } from 'generaltranslation/types';\nimport {
|
|
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 { GT } from 'generaltranslation';\nimport type { Settings } from '../../types/index.js';\nimport chalk from 'chalk';\nimport { BranchData } from '../../types/branch.js';\nimport type {\n FileDataResult,\n FileReference,\n OrphanedFile,\n} from 'generaltranslation/types';\n\ntype MoveMapping = {\n oldFileId: string;\n newFileId: string;\n newFileName: string;\n};\n\ntype UploadSourcesClient = Pick<\n GT,\n | 'queryFileData'\n | 'getOrphanedFiles'\n | 'processFileMoves'\n | 'uploadSourceFiles'\n>;\ntype UploadSourcesSettings = Pick<Settings, 'defaultLocale' | 'modelProvider'>;\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 NonNullable<FileDataResult['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 {\n sourceLocale: this.settings.defaultLocale,\n modelProvider: this.settings.modelProvider,\n }\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 = response.uploadedFiles.map((uploadedFile) => {\n const localFile = localFileMap.get(\n `${uploadedFile.fileId}:${uploadedFile.versionId}`\n );\n return {\n ...uploadedFile,\n transformFormat:\n localFile?.transformFormat ?? uploadedFile.transformFormat,\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":";;;;AA4BA,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,EA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ranslation';
|
|
3
2
|
import { Settings } from '../../types/index.js';
|
|
4
3
|
import { type EntryMap } from '../../fs/config/downloadedVersions.js';
|
|
@@ -19,11 +18,10 @@ export declare function partitionTranslationsByLockfile(files: UploadTranslation
|
|
|
19
18
|
filesToUpload: UploadTranslationsInput['files'];
|
|
20
19
|
skippedCount: number;
|
|
21
20
|
};
|
|
22
|
-
export declare class UploadTranslationsStep
|
|
21
|
+
export declare class UploadTranslationsStep {
|
|
23
22
|
private gt;
|
|
24
23
|
private settings;
|
|
25
24
|
private spinner;
|
|
26
|
-
private result;
|
|
27
25
|
constructor(gt: GT, settings: Settings);
|
|
28
26
|
run({ files }: UploadTranslationsInput): Promise<FileReference[]>;
|
|
29
27
|
/**
|
|
@@ -31,6 +29,5 @@ export declare class UploadTranslationsStep extends WorkflowStep<UploadTranslati
|
|
|
31
29
|
* so unchanged files are skipped on the next run.
|
|
32
30
|
*/
|
|
33
31
|
private recordUploadedHashes;
|
|
34
|
-
wait(): Promise<void>;
|
|
35
32
|
}
|
|
36
33
|
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { logger } from "../../console/logger.js";
|
|
2
2
|
import { hashStringSync } from "../../utils/hash.js";
|
|
3
|
-
import { WorkflowStep } from "./WorkflowStep.js";
|
|
4
3
|
import { findOrCreateEntry, readLockfile, writeLockfile } from "../../fs/config/downloadedVersions.js";
|
|
5
4
|
import chalk from "chalk";
|
|
6
5
|
//#region src/workflows/steps/UploadTranslationsStep.ts
|
|
@@ -30,11 +29,9 @@ function partitionTranslationsByLockfile(files, entryMap) {
|
|
|
30
29
|
skippedCount
|
|
31
30
|
};
|
|
32
31
|
}
|
|
33
|
-
var UploadTranslationsStep = class
|
|
32
|
+
var UploadTranslationsStep = class {
|
|
34
33
|
spinner = logger.createSpinner("dots");
|
|
35
|
-
result = [];
|
|
36
34
|
constructor(gt, settings) {
|
|
37
|
-
super();
|
|
38
35
|
this.gt = gt;
|
|
39
36
|
this.settings = settings;
|
|
40
37
|
}
|
|
@@ -52,19 +49,18 @@ var UploadTranslationsStep = class extends WorkflowStep {
|
|
|
52
49
|
}
|
|
53
50
|
const totalTranslations = filesToUpload.reduce((acc, f) => acc + f.translations.length, 0);
|
|
54
51
|
this.spinner.start(`Uploading ${totalTranslations} translation file${totalTranslations !== 1 ? "s" : ""} to the General Translation API...`);
|
|
55
|
-
const
|
|
52
|
+
const result = (await this.gt.uploadTranslations(filesToUpload, {
|
|
56
53
|
sourceLocale: this.settings.defaultLocale,
|
|
57
54
|
modelProvider: this.settings.modelProvider
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const uploadedCount = this.result.length;
|
|
55
|
+
})).uploadedFiles;
|
|
56
|
+
const uploadedCount = result.length;
|
|
61
57
|
this.spinner.stop(chalk.green(`Uploaded ${uploadedCount} translation file${uploadedCount !== 1 ? "s" : ""}${skippedCount > 0 ? `, skipped ${skippedCount} unchanged` : ""}`));
|
|
62
58
|
if (uploadedCount < totalTranslations) {
|
|
63
59
|
const missingCount = totalTranslations - uploadedCount;
|
|
64
60
|
logger.warn(chalk.yellow(`${missingCount} translation file${missingCount !== 1 ? "s were" : " was"} not persisted by the server`));
|
|
65
61
|
}
|
|
66
|
-
this.recordUploadedHashes(lockfile, filesToUpload,
|
|
67
|
-
return
|
|
62
|
+
this.recordUploadedHashes(lockfile, filesToUpload, result);
|
|
63
|
+
return result;
|
|
68
64
|
}
|
|
69
65
|
/**
|
|
70
66
|
* Records the content hash of each server-confirmed upload in gt-lock.json
|
|
@@ -85,7 +81,6 @@ var UploadTranslationsStep = class extends WorkflowStep {
|
|
|
85
81
|
}
|
|
86
82
|
writeLockfile(lockfile.data, lockfile.originalV1);
|
|
87
83
|
}
|
|
88
|
-
async wait() {}
|
|
89
84
|
};
|
|
90
85
|
//#endregion
|
|
91
86
|
export { UploadTranslationsStep, partitionTranslationsByLockfile };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UploadTranslationsStep.js","names":[],"sources":["../../../src/workflows/steps/UploadTranslationsStep.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"UploadTranslationsStep.js","names":[],"sources":["../../../src/workflows/steps/UploadTranslationsStep.ts"],"sourcesContent":["import { logger } from '../../console/logger.js';\nimport { GT } from 'generaltranslation';\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\n// The server includes the locale on each uploaded translation, but the\n// shared FileReference type does not declare it\ntype UploadedTranslationReference = FileReference & { locale?: string };\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 gt: GT,\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.gt.uploadTranslations(filesToUpload, {\n sourceLocale: this.settings.defaultLocale,\n modelProvider: this.settings.modelProvider,\n });\n\n const result = response.uploadedFiles;\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: UploadedTranslationReference[]\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":";;;;;;;;;;;AA8BA,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,IACA,UACA;AAFQ,OAAA,KAAA;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,W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aAAa,YAAY;IAClC;IACA,iBAAiB,eAAe,YAAY,QAAQ;IACrD;;AAGL,gBAAc,SAAS,MAAM,SAAS,WAAW"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import type { FileReference } from 'generaltranslation/types';
|
|
2
|
-
import { WorkflowStep } from './WorkflowStep.js';
|
|
3
2
|
import { Settings } from '../../types/index.js';
|
|
4
|
-
export declare class UserEditDiffsStep
|
|
3
|
+
export declare class UserEditDiffsStep {
|
|
5
4
|
private settings;
|
|
6
5
|
private spinner;
|
|
7
|
-
private succeeded;
|
|
8
|
-
private failed;
|
|
9
6
|
constructor(settings: Settings);
|
|
10
7
|
run(files: FileReference[]): Promise<FileReference[]>;
|
|
11
|
-
wait(): Promise<void>;
|
|
12
8
|
}
|
|
@@ -1,30 +1,22 @@
|
|
|
1
1
|
import { logger } from "../../console/logger.js";
|
|
2
|
-
import { WorkflowStep } from "./WorkflowStep.js";
|
|
3
2
|
import { collectAndSendUserEditDiffs } from "../../api/collectUserEditDiffs.js";
|
|
4
3
|
import chalk from "chalk";
|
|
5
4
|
//#region src/workflows/steps/UserEditDiffsStep.ts
|
|
6
|
-
var UserEditDiffsStep = class
|
|
5
|
+
var UserEditDiffsStep = class {
|
|
7
6
|
spinner = logger.createSpinner("dots");
|
|
8
|
-
succeeded = false;
|
|
9
|
-
failed = false;
|
|
10
7
|
constructor(settings) {
|
|
11
|
-
super();
|
|
12
8
|
this.settings = settings;
|
|
13
9
|
}
|
|
14
10
|
async run(files) {
|
|
15
11
|
this.spinner.start("Updating translations...");
|
|
16
12
|
try {
|
|
17
13
|
await collectAndSendUserEditDiffs(files, this.settings);
|
|
18
|
-
this.
|
|
14
|
+
this.spinner.stop(chalk.green("Updated translations"));
|
|
19
15
|
} catch {
|
|
20
|
-
this.
|
|
16
|
+
this.spinner.stop(chalk.yellow("Could not update translations"));
|
|
21
17
|
}
|
|
22
18
|
return files;
|
|
23
19
|
}
|
|
24
|
-
async wait() {
|
|
25
|
-
if (this.succeeded) this.spinner.stop(chalk.green("Updated translations"));
|
|
26
|
-
else if (this.failed) this.spinner.stop(chalk.yellow("Could not update translations"));
|
|
27
|
-
}
|
|
28
20
|
};
|
|
29
21
|
//#endregion
|
|
30
22
|
export { UserEditDiffsStep };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserEditDiffsStep.js","names":[],"sources":["../../../src/workflows/steps/UserEditDiffsStep.ts"],"sourcesContent":["import type { FileReference } from 'generaltranslation/types';\nimport {
|
|
1
|
+
{"version":3,"file":"UserEditDiffsStep.js","names":[],"sources":["../../../src/workflows/steps/UserEditDiffsStep.ts"],"sourcesContent":["import type { FileReference } from 'generaltranslation/types';\nimport { logger } from '../../console/logger.js';\nimport { Settings } from '../../types/index.js';\nimport chalk from 'chalk';\nimport { collectAndSendUserEditDiffs } from '../../api/collectUserEditDiffs.js';\n\nexport class UserEditDiffsStep {\n private spinner = logger.createSpinner('dots');\n\n constructor(private settings: Settings) {}\n\n async run(files: FileReference[]): Promise<FileReference[]> {\n this.spinner.start('Updating translations...');\n\n try {\n await collectAndSendUserEditDiffs(files, this.settings);\n this.spinner.stop(chalk.green('Updated translations'));\n } catch {\n // Non-fatal; keep going to enqueue\n this.spinner.stop(chalk.yellow('Could not update translations'));\n }\n\n return files;\n }\n}\n"],"mappings":";;;;AAMA,IAAa,oBAAb,MAA+B;CAC7B,UAAkB,OAAO,cAAc,OAAO;CAE9C,YAAY,UAA4B;AAApB,OAAA,WAAA;;CAEpB,MAAM,IAAI,OAAkD;AAC1D,OAAK,QAAQ,MAAM,2BAA2B;AAE9C,MAAI;AACF,SAAM,4BAA4B,OAAO,KAAK,SAAS;AACvD,QAAK,QAAQ,KAAK,MAAM,MAAM,uBAAuB,CAAC;UAChD;AAEN,QAAK,QAAQ,KAAK,MAAM,OAAO,gCAAgC,CAAC;;AAGlE,SAAO"}
|
package/dist/workflows/upload.js
CHANGED
|
@@ -20,18 +20,13 @@ async function runUploadFilesWorkflow({ files, options }) {
|
|
|
20
20
|
const uploadStep = new UploadSourcesStep(gt, options);
|
|
21
21
|
const uploadTranslationsStep = new UploadTranslationsStep(gt, options);
|
|
22
22
|
const branchData = await branchStep.run();
|
|
23
|
-
await branchStep.wait();
|
|
24
23
|
if (!branchData) return logErrorAndExit(branchResolutionError);
|
|
25
24
|
await uploadStep.run({
|
|
26
25
|
files: files.map((f) => f.source),
|
|
27
26
|
branchData
|
|
28
27
|
});
|
|
29
|
-
await uploadStep.wait();
|
|
30
28
|
const filesWithTranslations = files.filter((f) => f.translations.length > 0);
|
|
31
|
-
if (filesWithTranslations.length > 0) {
|
|
32
|
-
await uploadTranslationsStep.run({ files: filesWithTranslations });
|
|
33
|
-
await uploadTranslationsStep.wait();
|
|
34
|
-
}
|
|
29
|
+
if (filesWithTranslations.length > 0) await uploadTranslationsStep.run({ files: filesWithTranslations });
|
|
35
30
|
logger.success("All files uploaded successfully");
|
|
36
31
|
return { branchData };
|
|
37
32
|
} catch (error) {
|
|
@@ -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 { gt } from '../utils/gt.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 // Create workflow steps\n const branchStep = new BranchStep(gt, options);\n const uploadStep = new UploadSourcesStep(gt, options);\n const uploadTranslationsStep = new UploadTranslationsStep(gt, options);\n\n // Step 1: Resolve branch information\n const branchData = await branchStep.run();\n
|
|
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 { gt } from '../utils/gt.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 // Create workflow steps\n const branchStep = new BranchStep(gt, options);\n const uploadStep = new UploadSourcesStep(gt, options);\n const uploadTranslationsStep = new UploadTranslationsStep(gt, 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":";;;;;;;;;;;;;;;AAkBA,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;EAGD,MAAM,aAAa,IAAI,WAAW,IAAI,QAAQ;EAC9C,MAAM,aAAa,IAAI,kBAAkB,IAAI,QAAQ;EACrD,MAAM,yBAAyB,IAAI,uBAAuB,IAAI,QAAQ;EAGtE,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gt",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"bin": "bin/main.js",
|
|
6
6
|
"files": [
|
|
@@ -86,7 +86,6 @@
|
|
|
86
86
|
"@babel/traverse": "^7.25.7",
|
|
87
87
|
"@babel/types": "^7.25.7",
|
|
88
88
|
"@clack/prompts": "1.0.0-alpha.6",
|
|
89
|
-
"@formatjs/icu-messageformat-parser": "^2.11.4",
|
|
90
89
|
"chalk": "^5.4.1",
|
|
91
90
|
"commander": "^12.1.0",
|
|
92
91
|
"dotenv": "^16.4.5",
|
|
@@ -115,10 +114,11 @@
|
|
|
115
114
|
"unified": "^11.0.5",
|
|
116
115
|
"unist-util-visit": "^5.0.0",
|
|
117
116
|
"yaml": "^2.8.0",
|
|
118
|
-
"@generaltranslation/
|
|
119
|
-
"@generaltranslation/
|
|
120
|
-
"@generaltranslation/
|
|
121
|
-
"generaltranslation": "
|
|
117
|
+
"@generaltranslation/icu": "0.1.1",
|
|
118
|
+
"@generaltranslation/format": "0.1.4",
|
|
119
|
+
"@generaltranslation/python-extractor": "0.2.32",
|
|
120
|
+
"@generaltranslation/supported-locales": "2.1.12",
|
|
121
|
+
"generaltranslation": "9.0.5",
|
|
122
122
|
"gt-remark": "1.0.11"
|
|
123
123
|
},
|
|
124
124
|
"devDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WorkflowStep.js","names":[],"sources":["../../../src/workflows/steps/WorkflowStep.ts"],"sourcesContent":["export abstract class WorkflowStep<TInput = void, TOutput = void> {\n abstract run(input: TInput): Promise<TOutput>;\n\n abstract wait(): Promise<void>;\n}\n"],"mappings":";AAAA,IAAsB,eAAtB,MAAkE"}
|