gtx-cli 2.6.24 → 2.6.25

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.
Files changed (63) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/api/downloadFileBatch.d.ts +1 -1
  3. package/dist/api/saveLocalEdits.js +2 -2
  4. package/dist/cli/base.d.ts +24 -0
  5. package/dist/cli/base.js +53 -3
  6. package/dist/cli/commands/download.d.ts +8 -0
  7. package/dist/cli/commands/download.js +51 -0
  8. package/dist/cli/commands/enqueue.d.ts +9 -0
  9. package/dist/cli/commands/enqueue.js +27 -0
  10. package/dist/cli/commands/setupProject.d.ts +1 -1
  11. package/dist/cli/commands/setupProject.js +9 -22
  12. package/dist/cli/commands/stage.d.ts +1 -1
  13. package/dist/cli/commands/stage.js +11 -29
  14. package/dist/cli/commands/translate.d.ts +1 -2
  15. package/dist/cli/commands/translate.js +12 -22
  16. package/dist/{formats/files → cli/commands}/upload.d.ts +3 -3
  17. package/dist/{formats/files → cli/commands}/upload.js +21 -27
  18. package/dist/cli/commands/utils/validation.d.ts +13 -0
  19. package/dist/cli/commands/utils/validation.js +38 -0
  20. package/dist/cli/inline.js +2 -0
  21. package/dist/console/index.d.ts +1 -1
  22. package/dist/console/index.js +1 -1
  23. package/dist/console/logging.d.ts +1 -1
  24. package/dist/formats/files/collectFiles.js +1 -1
  25. package/dist/formats/files/convertToFileTranslationData.d.ts +15 -0
  26. package/dist/formats/files/convertToFileTranslationData.js +21 -0
  27. package/dist/generated/version.d.ts +1 -1
  28. package/dist/generated/version.js +1 -1
  29. package/dist/utils/sharedStaticAssets.d.ts +6 -0
  30. package/dist/utils/sharedStaticAssets.js +6 -0
  31. package/dist/{workflow → workflows}/download.d.ts +11 -1
  32. package/dist/{workflow → workflows}/download.js +5 -5
  33. package/dist/workflows/enqueue.d.ts +17 -0
  34. package/dist/workflows/enqueue.js +59 -0
  35. package/dist/{workflow → workflows}/setupProject.d.ts +1 -1
  36. package/dist/{workflow → workflows}/setupProject.js +4 -4
  37. package/dist/{workflow → workflows}/stage.d.ts +5 -1
  38. package/dist/{workflow → workflows}/stage.js +6 -6
  39. package/dist/{workflow → workflows/steps}/BranchStep.d.ts +3 -3
  40. package/dist/{workflow → workflows/steps}/BranchStep.js +4 -4
  41. package/dist/{workflow → workflows/steps}/DownloadStep.d.ts +2 -2
  42. package/dist/{workflow → workflows/steps}/DownloadStep.js +4 -4
  43. package/dist/{workflow → workflows/steps}/EnqueueStep.d.ts +2 -2
  44. package/dist/{workflow → workflows/steps}/EnqueueStep.js +2 -2
  45. package/dist/{workflow → workflows/steps}/PollJobsStep.d.ts +2 -2
  46. package/dist/{workflow → workflows/steps}/PollJobsStep.js +3 -3
  47. package/dist/{workflow → workflows/steps}/SetupStep.d.ts +2 -2
  48. package/dist/{workflow → workflows/steps}/SetupStep.js +2 -2
  49. package/dist/{workflow → workflows/steps}/UploadSourcesStep.d.ts +3 -3
  50. package/dist/{workflow → workflows/steps}/UploadSourcesStep.js +3 -3
  51. package/dist/{workflow → workflows/steps}/UploadTranslationsStep.d.ts +3 -3
  52. package/dist/{workflow → workflows/steps}/UploadTranslationsStep.js +2 -2
  53. package/dist/{workflow → workflows/steps}/UserEditDiffsStep.d.ts +2 -2
  54. package/dist/{workflow → workflows/steps}/UserEditDiffsStep.js +3 -3
  55. package/dist/{workflow → workflows}/upload.d.ts +7 -4
  56. package/dist/{workflow → workflows}/upload.js +4 -4
  57. package/package.json +1 -1
  58. package/dist/formats/gt/save.d.ts +0 -9
  59. package/dist/formats/gt/save.js +0 -27
  60. /package/dist/formats/files/{translate.d.ts → aggregateFiles.d.ts} +0 -0
  61. /package/dist/formats/files/{translate.js → aggregateFiles.js} +0 -0
  62. /package/dist/{workflow/Workflow.d.ts → workflows/steps/WorkflowStep.d.ts} +0 -0
  63. /package/dist/{workflow/Workflow.js → workflows/steps/WorkflowStep.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.6.25
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1040](https://github.com/generaltranslation/gt/pull/1040) [`d7bc63f`](https://github.com/generaltranslation/gt/commit/d7bc63f497534eede92138c8836bc84169600ff1) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - chore: expose enqueue and upload commands
8
+
3
9
  ## 2.6.24
4
10
 
5
11
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  import { Settings } from '../types/index.js';
2
- import type { FileStatusTracker } from '../workflow/PollJobsStep.js';
2
+ import type { FileStatusTracker } from '../workflows/steps/PollJobsStep.js';
3
3
  export type BatchedFiles = {
4
4
  branchId: string;
5
5
  fileId: string;
@@ -1,7 +1,7 @@
1
- import { aggregateFiles } from '../formats/files/translate.js';
1
+ import { aggregateFiles } from '../formats/files/aggregateFiles.js';
2
2
  import { collectAndSendUserEditDiffs } from './collectUserEditDiffs.js';
3
3
  import { gt } from '../utils/gt.js';
4
- import { BranchStep } from '../workflow/BranchStep.js';
4
+ import { BranchStep } from '../workflows/steps/BranchStep.js';
5
5
  import { logErrorAndExit } from '../console/logging.js';
6
6
  import { logger } from '../console/logger.js';
7
7
  import chalk from 'chalk';
@@ -18,10 +18,34 @@ export declare class BaseCLI {
18
18
  execute(): void;
19
19
  protected setupSetupProjectCommand(): void;
20
20
  protected setupStageCommand(): void;
21
+ /**
22
+ * Enqueues translations for a given set of files
23
+ * @param initOptions - The options for the command
24
+ * @returns The results of the command
25
+ */
26
+ protected setupEnqueueCommand(): void;
27
+ /**
28
+ * Downloads translations that were originally staged
29
+ * @param initOptions - The options for the command
30
+ * @returns The results of the command
31
+ */
32
+ protected setupDownloadCommand(): void;
21
33
  protected setupTranslateCommand(): void;
22
34
  protected setupSendDiffsCommand(): void;
23
35
  protected handleSetupProject(initOptions: TranslateFlags): Promise<void>;
24
36
  protected handleStage(initOptions: TranslateFlags): Promise<void>;
37
+ /**
38
+ * Enqueues translations for a given set of files
39
+ * @param initOptions - The options for the command
40
+ * @returns The results of the command
41
+ */
42
+ protected handleEnqueue(initOptions: TranslateFlags): Promise<void>;
43
+ /**
44
+ * Downloads translations that were originally staged
45
+ * @param initOptions - The options for the command
46
+ * @returns The results of the command
47
+ */
48
+ protected handleDownload(initOptions: TranslateFlags): Promise<void>;
25
49
  protected handleTranslate(initOptions: TranslateFlags): Promise<void>;
26
50
  protected setupUploadCommand(): void;
27
51
  protected setupLoginCommand(): void;
package/dist/cli/base.js CHANGED
@@ -14,11 +14,12 @@ import { installPackage } from '../utils/installPackage.js';
14
14
  import { getPackageManager } from '../utils/packageManager.js';
15
15
  import { retrieveCredentials, setCredentials } from '../utils/credentials.js';
16
16
  import { areCredentialsSet } from '../utils/credentials.js';
17
- import { upload } from '../formats/files/upload.js';
17
+ import { upload } from './commands/upload.js';
18
18
  import { attachSharedFlags, attachTranslateFlags } from './flags.js';
19
19
  import { handleStage } from './commands/stage.js';
20
20
  import { handleSetupProject } from './commands/setupProject.js';
21
- import { handleDownload, handleTranslate, postProcessTranslations, } from './commands/translate.js';
21
+ import { handleDownload } from './commands/download.js';
22
+ import { handleTranslate, postProcessTranslations, } from './commands/translate.js';
22
23
  import { getDownloaded, clearDownloaded } from '../state/recentDownloads.js';
23
24
  import { clearWarnings } from '../state/translateWarnings.js';
24
25
  import { displayTranslateSummary } from '../console/displayTranslateSummary.js';
@@ -32,6 +33,7 @@ import { getFrameworkDisplayName, getReactFrameworkLibrary, } from '../setup/fra
32
33
  import { findAgentFiles, findAgentFilesWithInstructions, hasCursorRulesDir, CURSOR_GT_RULES_FILE, getAgentInstructions, appendAgentInstructions, } from '../setup/agentInstructions.js';
33
34
  import { determineLibrary } from '../fs/determineFramework.js';
34
35
  import { INLINE_LIBRARIES } from '../types/libraries.js';
36
+ import { handleEnqueue } from './commands/enqueue.js';
35
37
  export class BaseCLI {
36
38
  library;
37
39
  additionalModules;
@@ -53,6 +55,8 @@ export class BaseCLI {
53
55
  this.setupSetupProjectCommand();
54
56
  this.setupStageCommand();
55
57
  this.setupTranslateCommand();
58
+ this.setupDownloadCommand();
59
+ this.setupEnqueueCommand();
56
60
  }
57
61
  // Execute is called by the main program
58
62
  execute() {
@@ -79,6 +83,34 @@ export class BaseCLI {
79
83
  logger.endCommand('Done!');
80
84
  });
81
85
  }
86
+ /**
87
+ * Enqueues translations for a given set of files
88
+ * @param initOptions - The options for the command
89
+ * @returns The results of the command
90
+ */
91
+ setupEnqueueCommand() {
92
+ attachTranslateFlags(this.program
93
+ .command('enqueue')
94
+ .description('Enqueues translations for a given set of files')).action(async (initOptions) => {
95
+ displayHeader('Enqueuing translations...');
96
+ await this.handleEnqueue(initOptions);
97
+ logger.endCommand('Done!');
98
+ });
99
+ }
100
+ /**
101
+ * Downloads translations that were originally staged
102
+ * @param initOptions - The options for the command
103
+ * @returns The results of the command
104
+ */
105
+ setupDownloadCommand() {
106
+ attachTranslateFlags(this.program
107
+ .command('download')
108
+ .description('Download translations that were originally staged')).action(async (initOptions) => {
109
+ displayHeader('Downloading translations...');
110
+ await this.handleDownload(initOptions);
111
+ logger.endCommand('Done!');
112
+ });
113
+ }
82
114
  setupTranslateCommand() {
83
115
  attachTranslateFlags(this.program
84
116
  .command('translate')
@@ -117,6 +149,24 @@ export class BaseCLI {
117
149
  }
118
150
  await handleStage(initOptions, settings, this.library, true);
119
151
  }
152
+ /**
153
+ * Enqueues translations for a given set of files
154
+ * @param initOptions - The options for the command
155
+ * @returns The results of the command
156
+ */
157
+ async handleEnqueue(initOptions) {
158
+ const settings = await generateSettings(initOptions);
159
+ await handleEnqueue(initOptions, settings, this.library);
160
+ }
161
+ /**
162
+ * Downloads translations that were originally staged
163
+ * @param initOptions - The options for the command
164
+ * @returns The results of the command
165
+ */
166
+ async handleDownload(initOptions) {
167
+ const settings = await generateSettings(initOptions);
168
+ await handleDownload(initOptions, settings, this.library);
169
+ }
120
170
  async handleTranslate(initOptions) {
121
171
  const settings = await generateSettings(initOptions);
122
172
  // Preprocess shared static assets if configured (move + rewrite sources)
@@ -128,7 +178,7 @@ export class BaseCLI {
128
178
  }
129
179
  }
130
180
  else {
131
- await handleDownload(initOptions, settings);
181
+ await handleDownload(initOptions, settings, this.library);
132
182
  }
133
183
  // Only postprocess files downloaded in this run
134
184
  const include = getDownloaded();
@@ -0,0 +1,8 @@
1
+ import { SupportedLibraries, TranslateFlags } from '../../types/index.js';
2
+ import { Settings } from '../../types/index.js';
3
+ /**
4
+ * Downloads translations that were originally staged
5
+ * @param options - The options for the command
6
+ * @param settings - The settings for the command
7
+ */
8
+ export declare function handleDownload(options: TranslateFlags, settings: Settings, library: SupportedLibraries): Promise<undefined>;
@@ -0,0 +1,51 @@
1
+ import { noVersionIdError, noFilesError } from '../../console/index.js';
2
+ import { createFileMapping } from '../../formats/files/fileMapping.js';
3
+ import { getStagedVersions } from '../../fs/config/updateVersions.js';
4
+ import { runDownloadWorkflow, } from '../../workflows/download.js';
5
+ import { exitSync, logErrorAndExit } from '../../console/logging.js';
6
+ import { convertToFileTranslationData } from '../../formats/files/convertToFileTranslationData.js';
7
+ import { collectFiles } from '../../formats/files/collectFiles.js';
8
+ import { hasValidCredentials, hasValidLocales } from './utils/validation.js';
9
+ // Downloads translations that were originally staged
10
+ /**
11
+ * Downloads translations that were originally staged
12
+ * @param options - The options for the command
13
+ * @param settings - The settings for the command
14
+ */
15
+ export async function handleDownload(options, settings, library) {
16
+ if (!hasValidLocales(settings))
17
+ return exitSync(1);
18
+ // Validate credentials if not in dry run
19
+ if (!options.dryRun && !hasValidCredentials(settings))
20
+ return exitSync(1);
21
+ if (!settings._versionId) {
22
+ return logErrorAndExit(noVersionIdError);
23
+ }
24
+ if (!settings.files) {
25
+ return logErrorAndExit(noFilesError);
26
+ }
27
+ // Files
28
+ const { resolvedPaths, placeholderPaths, transformPaths } = settings.files;
29
+ const fileMapping = createFileMapping(resolvedPaths, placeholderPaths, transformPaths, settings.locales, settings.defaultLocale);
30
+ // Collect the hashes for all files we need to download
31
+ let fileVersionData;
32
+ if (settings.stageTranslations) {
33
+ fileVersionData = await getStagedVersions(settings.configDirectory);
34
+ }
35
+ else {
36
+ const { files } = await collectFiles(options, settings, library);
37
+ fileVersionData = convertToFileTranslationData(files);
38
+ }
39
+ // Check for remaining translations
40
+ await runDownloadWorkflow({
41
+ fileVersionData: fileVersionData,
42
+ jobData: undefined,
43
+ branchData: undefined,
44
+ locales: settings.locales,
45
+ timeoutDuration: options.timeout,
46
+ resolveOutputPath: (sourcePath, locale) => fileMapping[locale][sourcePath] ?? null,
47
+ options: settings,
48
+ forceRetranslation: false, // force is not applicable for downloading staged translations
49
+ forceDownload: options.force || options.forceDownload,
50
+ });
51
+ }
@@ -0,0 +1,9 @@
1
+ import { EnqueueFilesResult } from 'generaltranslation/types';
2
+ import { Settings, SupportedLibraries, TranslateFlags } from '../../types/index.js';
3
+ /**
4
+ * Enqueues translations for a given set of files
5
+ * @param options - The options for the enqueue operation
6
+ * @param settings - The settings for the enqueue operation
7
+ * @returns {Promise<EnqueueFilesResult>} The enqueue result
8
+ */
9
+ export declare function handleEnqueue(options: TranslateFlags, settings: Settings, library: SupportedLibraries): Promise<EnqueueFilesResult>;
@@ -0,0 +1,27 @@
1
+ import { runEnqueueWorkflow } from '../../workflows/enqueue.js';
2
+ import { collectFiles } from '../../formats/files/collectFiles.js';
3
+ import { noFilesError, noVersionIdError } from '../../console/index.js';
4
+ import { hasValidCredentials, hasValidLocales } from './utils/validation.js';
5
+ import { exitSync, logErrorAndExit } from '../../console/logging.js';
6
+ /**
7
+ * Enqueues translations for a given set of files
8
+ * @param options - The options for the enqueue operation
9
+ * @param settings - The settings for the enqueue operation
10
+ * @returns {Promise<EnqueueFilesResult>} The enqueue result
11
+ */
12
+ export async function handleEnqueue(options, settings, library) {
13
+ if (!hasValidLocales(settings))
14
+ return exitSync(1);
15
+ // Validate credentials if not in dry run
16
+ if (!options.dryRun && !hasValidCredentials(settings))
17
+ return exitSync(1);
18
+ if (!settings._versionId) {
19
+ return logErrorAndExit(noVersionIdError);
20
+ }
21
+ if (!settings.files) {
22
+ return logErrorAndExit(noFilesError);
23
+ }
24
+ // Collect the data for all files we need to enqueue
25
+ const { files } = await collectFiles(options, settings, library);
26
+ return runEnqueueWorkflow({ files, options, settings });
27
+ }
@@ -1,5 +1,5 @@
1
1
  import { Settings, SupportedLibraries, TranslateFlags } from '../../types/index.js';
2
- import { FileTranslationData } from '../../workflow/download.js';
2
+ import { FileTranslationData } from '../../workflows/download.js';
3
3
  import { BranchData } from '../../types/branch.js';
4
4
  export declare function handleSetupProject(options: TranslateFlags, settings: Settings, library: SupportedLibraries): Promise<{
5
5
  fileVersionData: FileTranslationData | undefined;
@@ -1,27 +1,14 @@
1
1
  import { logger } from '../../console/logger.js';
2
- import { logCollectedFiles, logErrorAndExit } from '../../console/logging.js';
3
- import { noLocalesError, noDefaultLocaleError, noApiKeyError, noProjectIdError, devApiKeyError, } from '../../console/index.js';
2
+ import { exitSync, logCollectedFiles } from '../../console/logging.js';
4
3
  import { collectFiles } from '../../formats/files/collectFiles.js';
5
- import { setupProject } from '../../workflow/setupProject.js';
4
+ import { runSetupProjectWorkflow } from '../../workflows/setupProject.js';
5
+ import { hasValidCredentials, hasValidLocales } from './utils/validation.js';
6
6
  export async function handleSetupProject(options, settings, library) {
7
- if (!settings.locales) {
8
- return logErrorAndExit(noLocalesError);
9
- }
10
- if (!settings.defaultLocale) {
11
- return logErrorAndExit(noDefaultLocaleError);
12
- }
13
- // Validate required settings are present if not in dry run
14
- if (!options.dryRun) {
15
- if (!settings.apiKey) {
16
- return logErrorAndExit(noApiKeyError);
17
- }
18
- if (settings.apiKey.startsWith('gtx-dev-')) {
19
- return logErrorAndExit(devApiKeyError);
20
- }
21
- if (!settings.projectId) {
22
- return logErrorAndExit(noProjectIdError);
23
- }
24
- }
7
+ if (!hasValidLocales(settings))
8
+ return exitSync(1);
9
+ // Validate credentials if not in dry run
10
+ if (!options.dryRun && !hasValidCredentials(settings))
11
+ return exitSync(1);
25
12
  const { files: allFiles, reactComponents } = await collectFiles(options, settings, library);
26
13
  // Dry run
27
14
  if (options.dryRun) {
@@ -33,7 +20,7 @@ export async function handleSetupProject(options, settings, library) {
33
20
  let fileVersionData;
34
21
  let branchData;
35
22
  if (allFiles.length > 0) {
36
- const { branchData: branchDataResult } = await setupProject(allFiles, options, settings);
23
+ const { branchData: branchDataResult } = await runSetupProjectWorkflow(allFiles, options, settings);
37
24
  branchData = branchDataResult;
38
25
  fileVersionData = Object.fromEntries(allFiles.map((file) => [
39
26
  file.fileId,
@@ -1,6 +1,6 @@
1
1
  import { Settings, SupportedLibraries, TranslateFlags } from '../../types/index.js';
2
2
  import type { EnqueueFilesResult } from 'generaltranslation/types';
3
- import { FileTranslationData } from '../../workflow/download.js';
3
+ import { FileTranslationData } from '../../workflows/download.js';
4
4
  import { BranchData } from '../../types/branch.js';
5
5
  export declare function handleStage(options: TranslateFlags, settings: Settings, library: SupportedLibraries, stage: boolean): Promise<{
6
6
  fileVersionData: FileTranslationData | undefined;
@@ -1,30 +1,18 @@
1
1
  import { logger } from '../../console/logger.js';
2
- import { logCollectedFiles, logErrorAndExit } from '../../console/logging.js';
3
- import { noLocalesError, noDefaultLocaleError, noApiKeyError, noProjectIdError, devApiKeyError, } from '../../console/index.js';
4
- import { stageFiles } from '../../workflow/stage.js';
2
+ import { exitSync, logCollectedFiles } from '../../console/logging.js';
3
+ import { runStageFilesWorkflow } from '../../workflows/stage.js';
5
4
  import { updateVersions } from '../../fs/config/updateVersions.js';
6
5
  import updateConfig from '../../fs/config/updateConfig.js';
7
6
  import { TEMPLATE_FILE_ID } from '../../utils/constants.js';
8
7
  import { collectFiles } from '../../formats/files/collectFiles.js';
8
+ import { convertToFileTranslationData } from '../../formats/files/convertToFileTranslationData.js';
9
+ import { hasValidCredentials, hasValidLocales } from './utils/validation.js';
9
10
  export async function handleStage(options, settings, library, stage) {
10
- if (!settings.locales) {
11
- return logErrorAndExit(noLocalesError);
12
- }
13
- if (!settings.defaultLocale) {
14
- return logErrorAndExit(noDefaultLocaleError);
15
- }
16
- // Validate required settings are present if not in dry run
17
- if (!options.dryRun) {
18
- if (!settings.apiKey) {
19
- return logErrorAndExit(noApiKeyError);
20
- }
21
- if (settings.apiKey.startsWith('gtx-dev-')) {
22
- return logErrorAndExit(devApiKeyError);
23
- }
24
- if (!settings.projectId) {
25
- return logErrorAndExit(noProjectIdError);
26
- }
27
- }
11
+ if (!hasValidLocales(settings))
12
+ return exitSync(1);
13
+ // Validate credentials if not in dry run
14
+ if (!options.dryRun && !hasValidCredentials(settings))
15
+ return exitSync(1);
28
16
  const { files: allFiles, reactComponents } = await collectFiles(options, settings, library);
29
17
  // Dry run
30
18
  if (options.dryRun) {
@@ -37,16 +25,10 @@ export async function handleStage(options, settings, library, stage) {
37
25
  let jobData;
38
26
  let branchData;
39
27
  if (allFiles.length > 0) {
40
- const { branchData: branchDataResult, enqueueResult } = await stageFiles(allFiles, options, settings);
28
+ const { branchData: branchDataResult, enqueueResult } = await runStageFilesWorkflow({ files: allFiles, options, settings });
41
29
  jobData = enqueueResult;
42
30
  branchData = branchDataResult;
43
- fileVersionData = Object.fromEntries(allFiles.map((file) => [
44
- file.fileId,
45
- {
46
- fileName: file.fileName,
47
- versionId: file.versionId,
48
- },
49
- ]));
31
+ fileVersionData = convertToFileTranslationData(allFiles);
50
32
  // This logic is a little scuffed because stage is async from the API
51
33
  if (stage) {
52
34
  await updateVersions({
@@ -1,8 +1,7 @@
1
1
  import { EnqueueFilesResult } from 'generaltranslation/types';
2
2
  import { TranslateFlags } from '../../types/index.js';
3
3
  import { Settings } from '../../types/index.js';
4
- import { FileTranslationData } from '../../workflow/download.js';
4
+ import { FileTranslationData } from '../../workflows/download.js';
5
5
  import { BranchData } from '../../types/branch.js';
6
6
  export declare function handleTranslate(options: TranslateFlags, settings: Settings, fileVersionData: FileTranslationData | undefined, jobData: EnqueueFilesResult | undefined, branchData: BranchData | undefined): Promise<void>;
7
- export declare function handleDownload(options: TranslateFlags, settings: Settings): Promise<void>;
8
7
  export declare function postProcessTranslations(settings: Settings, includeFiles?: Set<string>): Promise<void>;
@@ -1,15 +1,12 @@
1
- import { downloadTranslations, } from '../../workflow/download.js';
1
+ import { runDownloadWorkflow, } from '../../workflows/download.js';
2
2
  import { createFileMapping } from '../../formats/files/fileMapping.js';
3
- import { getStagedVersions } from '../../fs/config/updateVersions.js';
4
3
  import copyFile from '../../fs/copyFile.js';
5
4
  import flattenJsonFiles from '../../utils/flattenJsonFiles.js';
6
5
  import localizeStaticUrls from '../../utils/localizeStaticUrls.js';
7
6
  import localizeRelativeAssets from '../../utils/localizeRelativeAssets.js';
8
7
  import processAnchorIds from '../../utils/processAnchorIds.js';
9
8
  import processOpenApi from '../../utils/processOpenApi.js';
10
- import { noFilesError, noVersionIdError } from '../../console/index.js';
11
9
  import localizeStaticImports from '../../utils/localizeStaticImports.js';
12
- import { logErrorAndExit } from '../../console/logging.js';
13
10
  import { getDownloadedMeta } from '../../state/recentDownloads.js';
14
11
  import { persistPostProcessHashes } from '../../utils/persistPostprocessHashes.js';
15
12
  // Downloads translations that were completed
@@ -18,26 +15,19 @@ export async function handleTranslate(options, settings, fileVersionData, jobDat
18
15
  const { resolvedPaths, placeholderPaths, transformPaths } = settings.files;
19
16
  const fileMapping = createFileMapping(resolvedPaths, placeholderPaths, transformPaths, settings.locales, settings.defaultLocale);
20
17
  // Check for remaining translations
21
- await downloadTranslations(fileVersionData, jobData, branchData, settings.locales, options.timeout, (sourcePath, locale) => fileMapping[locale]?.[sourcePath] ?? null, settings, options.force, options.forceDownload || options.force // if force is true should also force download
22
- );
18
+ await runDownloadWorkflow({
19
+ fileVersionData: fileVersionData,
20
+ jobData: jobData,
21
+ branchData: branchData,
22
+ locales: settings.locales,
23
+ timeoutDuration: options.timeout,
24
+ resolveOutputPath: (sourcePath, locale) => fileMapping[locale]?.[sourcePath] ?? null,
25
+ options: settings,
26
+ forceRetranslation: options.force,
27
+ forceDownload: options.forceDownload || options.force, // if force is true should also force download
28
+ });
23
29
  }
24
30
  }
25
- // Downloads translations that were originally staged
26
- export async function handleDownload(options, settings) {
27
- if (!settings._versionId) {
28
- logErrorAndExit(noVersionIdError);
29
- }
30
- if (!settings.files) {
31
- logErrorAndExit(noFilesError);
32
- }
33
- // Files
34
- const { resolvedPaths, placeholderPaths, transformPaths } = settings.files;
35
- const fileMapping = createFileMapping(resolvedPaths, placeholderPaths, transformPaths, settings.locales, settings.defaultLocale);
36
- const stagedVersionData = await getStagedVersions(settings.configDirectory);
37
- // Check for remaining translations
38
- await downloadTranslations(stagedVersionData, undefined, undefined, settings.locales, options.timeout, (sourcePath, locale) => fileMapping[locale][sourcePath] ?? null, settings, false, // force is not applicable for downloading staged translations
39
- options.force || options.forceDownload);
40
- }
41
31
  export async function postProcessTranslations(settings, includeFiles) {
42
32
  // Mintlify OpenAPI localization (spec routing + validation)
43
33
  await processOpenApi(settings, includeFiles);
@@ -1,13 +1,13 @@
1
1
  import { ResolvedFiles, Settings, TransformFiles } from '../../types/index.js';
2
2
  import { DataFormat } from '../../types/data.js';
3
- import { UploadOptions } from '../../cli/base.js';
3
+ import { UploadOptions } from '../base.js';
4
4
  /**
5
5
  * Sends multiple files to the API for translation
6
6
  * @param filePaths - Resolved file paths for different file types
7
7
  * @param placeholderPaths - Placeholder paths for translated files
8
8
  * @param transformPaths - Transform paths for file naming
9
9
  * @param dataFormat - Format of the data within the files
10
- * @param options - Translation options including API settings
10
+ * @param settings - Translation options including API settings
11
11
  * @returns Promise that resolves when translation is complete
12
12
  */
13
- export declare function upload(filePaths: ResolvedFiles, placeholderPaths: ResolvedFiles, transformPaths: TransformFiles, dataFormat: DataFormat | undefined, options: Settings & UploadOptions): Promise<void>;
13
+ export declare function upload(filePaths: ResolvedFiles, placeholderPaths: ResolvedFiles, transformPaths: TransformFiles, dataFormat: DataFormat | undefined, settings: Settings & UploadOptions): Promise<void>;
@@ -1,15 +1,16 @@
1
- import { noSupportedFormatError, noDefaultLocaleError, noApiKeyError, noProjectIdError, devApiKeyError, } from '../../console/index.js';
2
- import { logErrorAndExit } from '../../console/logging.js';
1
+ import { noSupportedFormatError, noDefaultLocaleError, } from '../../console/index.js';
2
+ import { exitSync, logErrorAndExit } from '../../console/logging.js';
3
3
  import { logger } from '../../console/logger.js';
4
4
  import { getRelative, readFile } from '../../fs/findFilepath.js';
5
- import { SUPPORTED_FILE_EXTENSIONS } from './supportedFiles.js';
5
+ import { SUPPORTED_FILE_EXTENSIONS } from '../../formats/files/supportedFiles.js';
6
6
  import sanitizeFileContent from '../../utils/sanitizeFileContent.js';
7
- import { parseJson } from '../json/parseJson.js';
8
- import { uploadFiles } from '../../workflow/upload.js';
7
+ import { parseJson } from '../../formats/json/parseJson.js';
8
+ import { runUploadFilesWorkflow } from '../../workflows/upload.js';
9
9
  import { existsSync, readFileSync } from 'node:fs';
10
- import { createFileMapping } from './fileMapping.js';
11
- import parseYaml from '../yaml/parseYaml.js';
10
+ import { createFileMapping } from '../../formats/files/fileMapping.js';
11
+ import parseYaml from '../../formats/yaml/parseYaml.js';
12
12
  import { hashStringSync } from '../../utils/hash.js';
13
+ import { hasValidCredentials } from './utils/validation.js';
13
14
  const SUPPORTED_DATA_FORMATS = ['JSX', 'ICU', 'I18NEXT'];
14
15
  /**
15
16
  * Sends multiple files to the API for translation
@@ -17,13 +18,13 @@ const SUPPORTED_DATA_FORMATS = ['JSX', 'ICU', 'I18NEXT'];
17
18
  * @param placeholderPaths - Placeholder paths for translated files
18
19
  * @param transformPaths - Transform paths for file naming
19
20
  * @param dataFormat - Format of the data within the files
20
- * @param options - Translation options including API settings
21
+ * @param settings - Translation options including API settings
21
22
  * @returns Promise that resolves when translation is complete
22
23
  */
23
- export async function upload(filePaths, placeholderPaths, transformPaths, dataFormat = 'JSX', options) {
24
+ export async function upload(filePaths, placeholderPaths, transformPaths, dataFormat = 'JSX', settings) {
24
25
  // Collect all files to translate
25
26
  const allFiles = [];
26
- const additionalOptions = options.options || {};
27
+ const additionalOptions = settings.options || {};
27
28
  // Process JSON files
28
29
  if (filePaths.json) {
29
30
  if (!SUPPORTED_DATA_FORMATS.includes(dataFormat)) {
@@ -31,14 +32,14 @@ export async function upload(filePaths, placeholderPaths, transformPaths, dataFo
31
32
  }
32
33
  const jsonFiles = filePaths.json.map((filePath) => {
33
34
  const content = readFile(filePath);
34
- const parsedJson = parseJson(content, filePath, additionalOptions, options.defaultLocale);
35
+ const parsedJson = parseJson(content, filePath, additionalOptions, settings.defaultLocale);
35
36
  const relativePath = getRelative(filePath);
36
37
  return {
37
38
  content: parsedJson,
38
39
  fileName: relativePath,
39
40
  fileFormat: 'JSON',
40
41
  dataFormat,
41
- locale: options.defaultLocale,
42
+ locale: settings.defaultLocale,
42
43
  fileId: hashStringSync(relativePath),
43
44
  versionId: hashStringSync(parsedJson),
44
45
  };
@@ -59,7 +60,7 @@ export async function upload(filePaths, placeholderPaths, transformPaths, dataFo
59
60
  fileName: relativePath,
60
61
  fileFormat,
61
62
  dataFormat,
62
- locale: options.defaultLocale,
63
+ locale: settings.defaultLocale,
63
64
  fileId: hashStringSync(relativePath),
64
65
  versionId: hashStringSync(parsedYaml),
65
66
  };
@@ -79,7 +80,7 @@ export async function upload(filePaths, placeholderPaths, transformPaths, dataFo
79
80
  fileName: relativePath,
80
81
  fileFormat: fileType.toUpperCase(),
81
82
  dataFormat,
82
- locale: options.defaultLocale,
83
+ locale: settings.defaultLocale,
83
84
  fileId: hashStringSync(relativePath),
84
85
  versionId: hashStringSync(sanitizedContent),
85
86
  };
@@ -91,21 +92,14 @@ export async function upload(filePaths, placeholderPaths, transformPaths, dataFo
91
92
  logger.error('No files to upload were found. Please check your configuration and try again.');
92
93
  return;
93
94
  }
94
- if (!options.defaultLocale) {
95
+ if (!settings.defaultLocale) {
95
96
  return logErrorAndExit(noDefaultLocaleError);
96
97
  }
97
- if (!options.apiKey) {
98
- return logErrorAndExit(noApiKeyError);
99
- }
100
- if (options.apiKey.startsWith('gtx-dev-')) {
101
- return logErrorAndExit(devApiKeyError);
102
- }
103
- if (!options.projectId) {
104
- return logErrorAndExit(noProjectIdError);
105
- }
106
- const locales = options.locales || [];
98
+ if (!hasValidCredentials(settings))
99
+ return exitSync(1);
100
+ const locales = settings.locales || [];
107
101
  // Create file mapping for all file types
108
- const fileMapping = createFileMapping(filePaths, placeholderPaths, transformPaths, locales, options.defaultLocale);
102
+ const fileMapping = createFileMapping(filePaths, placeholderPaths, transformPaths, locales, settings.defaultLocale);
109
103
  // construct object
110
104
  const uploadData = allFiles.map((file) => {
111
105
  const sourceFile = {
@@ -140,7 +134,7 @@ export async function upload(filePaths, placeholderPaths, transformPaths, dataFo
140
134
  });
141
135
  try {
142
136
  // Send all files in a single API call
143
- await uploadFiles(uploadData, options);
137
+ await runUploadFilesWorkflow({ files: uploadData, options: settings });
144
138
  }
145
139
  catch (error) {
146
140
  logErrorAndExit(`Error uploading files: ${error}`);
@@ -0,0 +1,13 @@
1
+ import { Settings } from '../../../types/index.js';
2
+ /**
3
+ * Validate locales
4
+ * @param settings - The settings to validate
5
+ * @returns True if has locales and default locale
6
+ */
7
+ export declare function hasValidLocales(settings: Settings): boolean;
8
+ /**
9
+ * Validate credentials
10
+ * @param settings - The settings to validate
11
+ * @returns True if has API key, project ID, and does not have a development API key
12
+ */
13
+ export declare function hasValidCredentials(settings: Settings): boolean;
@@ -0,0 +1,38 @@
1
+ import { noDefaultLocaleError, noLocalesError, noApiKeyError, devApiKeyError, noProjectIdError, } from '../../../console/index.js';
2
+ import { logger } from '../../../console/logger.js';
3
+ /**
4
+ * Validate locales
5
+ * @param settings - The settings to validate
6
+ * @returns True if has locales and default locale
7
+ */
8
+ export function hasValidLocales(settings) {
9
+ if (!settings.locales) {
10
+ logger.error(noLocalesError);
11
+ return false;
12
+ }
13
+ if (!settings.defaultLocale) {
14
+ logger.error(noDefaultLocaleError);
15
+ return false;
16
+ }
17
+ return true;
18
+ }
19
+ /**
20
+ * Validate credentials
21
+ * @param settings - The settings to validate
22
+ * @returns True if has API key, project ID, and does not have a development API key
23
+ */
24
+ export function hasValidCredentials(settings) {
25
+ if (!settings.apiKey) {
26
+ logger.error(noApiKeyError);
27
+ return false;
28
+ }
29
+ if (settings.apiKey.startsWith('gtx-dev-')) {
30
+ logger.error(devApiKeyError);
31
+ return false;
32
+ }
33
+ if (!settings.projectId) {
34
+ logger.error(noProjectIdError);
35
+ return false;
36
+ }
37
+ return true;
38
+ }