gt 2.14.60 → 2.14.61
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 +6 -0
- package/dist/api/collectUserEditDiffs.js +1 -1
- package/dist/api/downloadFileBatch.js +1 -1
- package/dist/cli/commands/download.js +1 -1
- package/dist/cli/commands/stage.js +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/workflows/steps/UploadTranslationsStep.d.ts +17 -3
- package/dist/workflows/steps/UploadTranslationsStep.js +63 -31
- package/dist/workflows/steps/UploadTranslationsStep.js.map +1 -1
- package/dist/workflows/upload.js +1 -4
- package/dist/workflows/upload.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# gtx-cli
|
|
2
2
|
|
|
3
|
+
## 2.14.61
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1876](https://github.com/generaltranslation/gt/pull/1876) [`ae59375`](https://github.com/generaltranslation/gt/commit/ae593758047e32396e8eb7eeca9b38b86a20a909) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Make `upload` command overwrite content
|
|
8
|
+
|
|
3
9
|
## 2.14.60
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { hashStringSync } from "../utils/hash.js";
|
|
2
2
|
import { gt } from "../utils/gt.js";
|
|
3
3
|
import { extractJson } from "../formats/json/extractJson.js";
|
|
4
|
-
import { createFileMapping } from "../formats/files/fileMapping.js";
|
|
5
4
|
import { readLockfile } from "../fs/config/downloadedVersions.js";
|
|
5
|
+
import { createFileMapping } from "../formats/files/fileMapping.js";
|
|
6
6
|
import { getGitUnifiedDiff } from "../utils/gitDiff.js";
|
|
7
7
|
import { extractYaml } from "../formats/yaml/extractYaml.js";
|
|
8
8
|
import { randomUUID } from "node:crypto";
|
|
@@ -6,9 +6,9 @@ import { hasNonIdentityFileFormatTransformForType } from "../formats/files/trans
|
|
|
6
6
|
import { validateJsonSchema } from "../formats/json/utils.js";
|
|
7
7
|
import { extractJson } from "../formats/json/extractJson.js";
|
|
8
8
|
import { recordWarning } from "../state/translateWarnings.js";
|
|
9
|
+
import { findOrCreateEntry, readLockfile, writeLockfile } from "../fs/config/downloadedVersions.js";
|
|
9
10
|
import { resolveMintlifyRefs, shouldResolveRefs } from "../utils/resolveMintlifyRefs.js";
|
|
10
11
|
import { validateYamlSchema } from "../formats/yaml/utils.js";
|
|
11
|
-
import { findOrCreateEntry, readLockfile, writeLockfile } from "../fs/config/downloadedVersions.js";
|
|
12
12
|
import { extractYaml } from "../formats/yaml/extractYaml.js";
|
|
13
13
|
import { mergeJson } from "../formats/json/mergeJson.js";
|
|
14
14
|
import mergeYaml from "../formats/yaml/mergeYaml.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { exitSync, logErrorAndExit } from "../../console/logging.js";
|
|
2
2
|
import { noFilesError } from "../../console/index.js";
|
|
3
|
+
import { getStagedEntriesFromLockfile } from "../../fs/config/downloadedVersions.js";
|
|
3
4
|
import { createFileMapping } from "../../formats/files/fileMapping.js";
|
|
4
5
|
import { hasValidCredentials, hasValidLocales } from "./utils/validation.js";
|
|
5
|
-
import { getStagedEntriesFromLockfile } from "../../fs/config/downloadedVersions.js";
|
|
6
6
|
import { collectFiles } from "../../formats/files/collectFiles.js";
|
|
7
7
|
import { convertToFileTranslationData } from "../../formats/files/convertToFileTranslationData.js";
|
|
8
8
|
import { runDownloadWorkflow } from "../../workflows/download.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { logger } from "../../console/logger.js";
|
|
2
2
|
import { TEMPLATE_FILE_ID } from "../../utils/constants.js";
|
|
3
3
|
import { exitSync, logCollectedFiles } from "../../console/logging.js";
|
|
4
|
-
import { hasValidCredentials, hasValidLocales } from "./utils/validation.js";
|
|
5
4
|
import { writeStagedEntries } from "../../fs/config/downloadedVersions.js";
|
|
5
|
+
import { hasValidCredentials, hasValidLocales } from "./utils/validation.js";
|
|
6
6
|
import { runStageFilesWorkflow } from "../../workflows/stage.js";
|
|
7
7
|
import updateConfig from "../../fs/config/updateConfig.js";
|
|
8
8
|
import { collectFiles } from "../../formats/files/collectFiles.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "2.14.
|
|
1
|
+
export declare const PACKAGE_VERSION = "2.14.61";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../src/generated/version.ts"],"sourcesContent":["// This file is auto-generated. Do not edit manually.\nexport const PACKAGE_VERSION = '2.14.
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/generated/version.ts"],"sourcesContent":["// This file is auto-generated. Do not edit manually.\nexport const PACKAGE_VERSION = '2.14.61';\n"],"mappings":";AACA,MAAa,kBAAkB"}
|
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import { WorkflowStep } from './WorkflowStep.js';
|
|
2
2
|
import { GT } from 'generaltranslation';
|
|
3
3
|
import { Settings } from '../../types/index.js';
|
|
4
|
-
import {
|
|
4
|
+
import { type EntryMap } from '../../fs/config/downloadedVersions.js';
|
|
5
5
|
import type { FileReference, FileToUpload } from 'generaltranslation/types';
|
|
6
6
|
type UploadTranslationsInput = {
|
|
7
7
|
files: {
|
|
8
8
|
source: FileToUpload;
|
|
9
9
|
translations: FileToUpload[];
|
|
10
10
|
}[];
|
|
11
|
-
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Splits translations into ones that need uploading and ones that can be
|
|
14
|
+
* skipped because their content still matches the gt-lock.json hash recorded
|
|
15
|
+
* at the last sync (download/translate/upload). Files without a lock entry —
|
|
16
|
+
* or with a stale versionId — are always uploaded.
|
|
17
|
+
*/
|
|
18
|
+
export declare function partitionTranslationsByLockfile(files: UploadTranslationsInput['files'], entryMap: EntryMap): {
|
|
19
|
+
filesToUpload: UploadTranslationsInput['files'];
|
|
20
|
+
skippedCount: number;
|
|
12
21
|
};
|
|
13
22
|
export declare class UploadTranslationsStep extends WorkflowStep<UploadTranslationsInput, FileReference[]> {
|
|
14
23
|
private gt;
|
|
@@ -16,7 +25,12 @@ export declare class UploadTranslationsStep extends WorkflowStep<UploadTranslati
|
|
|
16
25
|
private spinner;
|
|
17
26
|
private result;
|
|
18
27
|
constructor(gt: GT, settings: Settings);
|
|
19
|
-
run({ files
|
|
28
|
+
run({ files }: UploadTranslationsInput): Promise<FileReference[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Records the content hash of each server-confirmed upload in gt-lock.json
|
|
31
|
+
* so unchanged files are skipped on the next run.
|
|
32
|
+
*/
|
|
33
|
+
private recordUploadedHashes;
|
|
20
34
|
wait(): Promise<void>;
|
|
21
35
|
}
|
|
22
36
|
export {};
|
|
@@ -1,7 +1,35 @@
|
|
|
1
1
|
import { logger } from "../../console/logger.js";
|
|
2
|
+
import { hashStringSync } from "../../utils/hash.js";
|
|
2
3
|
import { WorkflowStep } from "./WorkflowStep.js";
|
|
4
|
+
import { findOrCreateEntry, readLockfile, writeLockfile } from "../../fs/config/downloadedVersions.js";
|
|
3
5
|
import chalk from "chalk";
|
|
4
6
|
//#region src/workflows/steps/UploadTranslationsStep.ts
|
|
7
|
+
/**
|
|
8
|
+
* Splits translations into ones that need uploading and ones that can be
|
|
9
|
+
* skipped because their content still matches the gt-lock.json hash recorded
|
|
10
|
+
* at the last sync (download/translate/upload). Files without a lock entry —
|
|
11
|
+
* or with a stale versionId — are always uploaded.
|
|
12
|
+
*/
|
|
13
|
+
function partitionTranslationsByLockfile(files, entryMap) {
|
|
14
|
+
let skippedCount = 0;
|
|
15
|
+
return {
|
|
16
|
+
filesToUpload: files.map((file) => {
|
|
17
|
+
const translations = file.translations.filter((translation) => {
|
|
18
|
+
const entry = entryMap.get(translation.fileId);
|
|
19
|
+
if (!entry || entry.versionId !== translation.versionId) return true;
|
|
20
|
+
const lockHash = entry.translations[translation.locale]?.postProcessHash;
|
|
21
|
+
if (!lockHash || lockHash !== hashStringSync(translation.content)) return true;
|
|
22
|
+
skippedCount++;
|
|
23
|
+
return false;
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
source: file.source,
|
|
27
|
+
translations
|
|
28
|
+
};
|
|
29
|
+
}).filter((file) => file.translations.length > 0),
|
|
30
|
+
skippedCount
|
|
31
|
+
};
|
|
32
|
+
}
|
|
5
33
|
var UploadTranslationsStep = class extends WorkflowStep {
|
|
6
34
|
spinner = logger.createSpinner("dots");
|
|
7
35
|
result = [];
|
|
@@ -10,52 +38,56 @@ var UploadTranslationsStep = class extends WorkflowStep {
|
|
|
10
38
|
this.gt = gt;
|
|
11
39
|
this.settings = settings;
|
|
12
40
|
}
|
|
13
|
-
async run({ files
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
41
|
+
async run({ files }) {
|
|
42
|
+
const withTranslations = files.filter((f) => f.translations.length > 0);
|
|
43
|
+
if (withTranslations.length === 0) {
|
|
16
44
|
logger.info("No translation files to upload... skipping upload translations step");
|
|
17
45
|
return [];
|
|
18
46
|
}
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const translatedFilesQuery = filesWithTranslations.flatMap((f) => f.translations.map((t) => ({
|
|
22
|
-
fileId: t.fileId,
|
|
23
|
-
versionId: t.versionId,
|
|
24
|
-
branchId: t.branchId ?? branchData.currentBranch.id,
|
|
25
|
-
locale: t.locale
|
|
26
|
-
})));
|
|
27
|
-
const fileData = await this.gt.queryFileData({ translatedFiles: translatedFilesQuery });
|
|
28
|
-
const existingTranslationsMap = /* @__PURE__ */ new Set();
|
|
29
|
-
fileData.translatedFiles?.forEach((f) => {
|
|
30
|
-
existingTranslationsMap.add(`${f.branchId}:${f.fileId}:${f.versionId}:${f.locale}`);
|
|
31
|
-
});
|
|
32
|
-
const filesToUpload = filesWithTranslations.map((f) => {
|
|
33
|
-
const newTranslations = f.translations.filter((t) => {
|
|
34
|
-
const key = `${t.branchId ?? branchData.currentBranch.id}:${t.fileId}:${t.versionId}:${t.locale}`;
|
|
35
|
-
return !existingTranslationsMap.has(key);
|
|
36
|
-
});
|
|
37
|
-
return {
|
|
38
|
-
source: f.source,
|
|
39
|
-
translations: newTranslations
|
|
40
|
-
};
|
|
41
|
-
}).filter((f) => f.translations.length > 0);
|
|
42
|
-
const skippedCount = totalTranslations - filesToUpload.reduce((acc, f) => acc + f.translations.length, 0);
|
|
47
|
+
const lockfile = readLockfile(this.settings);
|
|
48
|
+
const { filesToUpload, skippedCount } = partitionTranslationsByLockfile(withTranslations, lockfile.entryMap);
|
|
43
49
|
if (filesToUpload.length === 0) {
|
|
44
|
-
|
|
50
|
+
logger.info(chalk.green(`All ${skippedCount} translation file${skippedCount !== 1 ? "s are" : " is"} unchanged since the last sync... skipping upload translations step`));
|
|
45
51
|
return [];
|
|
46
52
|
}
|
|
47
|
-
const
|
|
53
|
+
const totalTranslations = filesToUpload.reduce((acc, f) => acc + f.translations.length, 0);
|
|
54
|
+
this.spinner.start(`Uploading ${totalTranslations} translation file${totalTranslations !== 1 ? "s" : ""} to the General Translation API...`);
|
|
48
55
|
const response = await this.gt.uploadTranslations(filesToUpload, {
|
|
49
56
|
sourceLocale: this.settings.defaultLocale,
|
|
50
57
|
modelProvider: this.settings.modelProvider
|
|
51
58
|
});
|
|
52
59
|
this.result = response.uploadedFiles;
|
|
53
|
-
this.
|
|
60
|
+
const uploadedCount = this.result.length;
|
|
61
|
+
this.spinner.stop(chalk.green(`Uploaded ${uploadedCount} translation file${uploadedCount !== 1 ? "s" : ""}${skippedCount > 0 ? `, skipped ${skippedCount} unchanged` : ""}`));
|
|
62
|
+
if (uploadedCount < totalTranslations) {
|
|
63
|
+
const missingCount = totalTranslations - uploadedCount;
|
|
64
|
+
logger.warn(chalk.yellow(`${missingCount} translation file${missingCount !== 1 ? "s were" : " was"} not persisted by the server`));
|
|
65
|
+
}
|
|
66
|
+
this.recordUploadedHashes(lockfile, filesToUpload, this.result);
|
|
54
67
|
return this.result;
|
|
55
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Records the content hash of each server-confirmed upload in gt-lock.json
|
|
71
|
+
* so unchanged files are skipped on the next run.
|
|
72
|
+
*/
|
|
73
|
+
recordUploadedHashes(lockfile, uploaded, confirmed) {
|
|
74
|
+
const confirmedKeys = new Set(confirmed.filter((file) => file.locale).map((file) => `${file.fileId}:${file.locale}`));
|
|
75
|
+
if (confirmedKeys.size === 0) return;
|
|
76
|
+
const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
77
|
+
for (const file of uploaded) for (const translation of file.translations) {
|
|
78
|
+
if (!confirmedKeys.has(`${translation.fileId}:${translation.locale}`)) continue;
|
|
79
|
+
const entry = findOrCreateEntry(lockfile.entryMap, lockfile.data.entries, translation.fileId, translation.versionId);
|
|
80
|
+
entry.translations[translation.locale] = {
|
|
81
|
+
...entry.translations[translation.locale],
|
|
82
|
+
updatedAt,
|
|
83
|
+
postProcessHash: hashStringSync(translation.content)
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
writeLockfile(lockfile.data, lockfile.originalV1);
|
|
87
|
+
}
|
|
56
88
|
async wait() {}
|
|
57
89
|
};
|
|
58
90
|
//#endregion
|
|
59
|
-
export { UploadTranslationsStep };
|
|
91
|
+
export { UploadTranslationsStep, partitionTranslationsByLockfile };
|
|
60
92
|
|
|
61
93
|
//# sourceMappingURL=UploadTranslationsStep.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UploadTranslationsStep.js","names":[],"sources":["../../../src/workflows/steps/UploadTranslationsStep.ts"],"sourcesContent":["import { WorkflowStep } from './WorkflowStep.js';\nimport { logger } from '../../console/logger.js';\nimport { GT } from 'generaltranslation';\nimport { Settings } from '../../types/index.js';\nimport chalk from 'chalk';\nimport {
|
|
1
|
+
{"version":3,"file":"UploadTranslationsStep.js","names":[],"sources":["../../../src/workflows/steps/UploadTranslationsStep.ts"],"sourcesContent":["import { WorkflowStep } from './WorkflowStep.js';\nimport { 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 extends WorkflowStep<\n UploadTranslationsInput,\n FileReference[]\n> {\n private spinner = logger.createSpinner('dots');\n private result: FileReference[] = [];\n\n constructor(\n private gt: GT,\n private settings: Settings\n ) {\n super();\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 this.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 = this.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, this.result);\n\n return this.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 async wait(): Promise<void> {\n return;\n }\n}\n"],"mappings":";;;;;;;;;;;;AA+BA,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,cAA4C,aAG1C;CACA,UAAkB,OAAO,cAAc,OAAO;CAC9C,SAAkC,EAAE;CAEpC,YACE,IACA,UACA;AACA,SAAO;AAHC,OAAA,KAAA;AACA,OAAA,WAAA;;CAKV,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,EAAE,aAAa,QACjC,EACD;AAED,OAAK,QAAQ,MACX,aAAa,kBAAkB,mBAAmB,sBAAsB,IAAI,MAAM,GAAG,oCACtF;EAED,MAAM,WAAW,MAAM,KAAK,GAAG,mBAAmB,eAAe;GAC/D,cAAc,KAAK,SAAS;GAC5B,eAAe,KAAK,SAAS;GAC9B,CAAC;AAEF,OAAK,SAAS,SAAS;EAGvB,MAAM,gBAAgB,KAAK,OAAO;AAClC,OAAK,QAAQ,KACX,MAAM,MACJ,YAAY,cAAc,mBAAmB,kBAAkB,IAAI,MAAM,KAAK,eAAe,IAAI,aAAa,aAAa,cAAc,KAC1I,CACF;AACD,MAAI,gBAAgB,mBAAmB;GACrC,MAAM,eAAe,oBAAoB;AACzC,UAAO,KACL,MAAM,OACJ,GAAG,aAAa,mBAAmB,iBAAiB,IAAI,WAAW,OAAO,8BAC3E,CACF;;AAGH,OAAK,qBAAqB,UAAU,eAAe,KAAK,OAAO;AAE/D,SAAO,KAAK;;;;;;CAOd,qBACE,UACA,UACA,WACM;EACN,MAAM,gBAAgB,IAAI,IACxB,UACG,QAAQ,SAAS,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;;CAGnD,MAAM,OAAsB"}
|
package/dist/workflows/upload.js
CHANGED
|
@@ -29,10 +29,7 @@ async function runUploadFilesWorkflow({ files, options }) {
|
|
|
29
29
|
await uploadStep.wait();
|
|
30
30
|
const filesWithTranslations = files.filter((f) => f.translations.length > 0);
|
|
31
31
|
if (filesWithTranslations.length > 0) {
|
|
32
|
-
await uploadTranslationsStep.run({
|
|
33
|
-
files: filesWithTranslations,
|
|
34
|
-
branchData
|
|
35
|
-
});
|
|
32
|
+
await uploadTranslationsStep.run({ files: filesWithTranslations });
|
|
36
33
|
await uploadTranslationsStep.wait();
|
|
37
34
|
}
|
|
38
35
|
logger.success("All files uploaded successfully");
|
|
@@ -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 await branchStep.wait();\n\n if (!branchData) {\n return logErrorAndExit(branchResolutionError);\n }\n\n await uploadStep.run({ files: files.map((f) => f.source), branchData });\n await uploadStep.wait();\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
|
|
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 await branchStep.wait();\n\n if (!branchData) {\n return logErrorAndExit(branchResolutionError);\n }\n\n await uploadStep.run({ files: files.map((f) => f.source), branchData });\n await uploadStep.wait();\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 await uploadTranslationsStep.wait();\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;AACzC,QAAM,WAAW,MAAM;AAEvB,MAAI,CAAC,WACH,QAAO,gBAAgB,sBAAsB;AAG/C,QAAM,WAAW,IAAI;GAAE,OAAO,MAAM,KAAK,MAAM,EAAE,OAAO;GAAE;GAAY,CAAC;AACvE,QAAM,WAAW,MAAM;EAGvB,MAAM,wBAAwB,MAAM,QACjC,MAAM,EAAE,aAAa,SAAS,EAChC;AACD,MAAI,sBAAsB,SAAS,GAAG;AACpC,SAAM,uBAAuB,IAAI,EAC/B,OAAO,uBACR,CAAC;AACF,SAAM,uBAAuB,MAAM;;AAGrC,SAAO,QAAQ,kCAAkC;AACjD,SAAO,EAAE,YAAY;UACd,OAAO;AACd,SAAO,gBACL,kBACE,4GACA,MACD,CACF"}
|