gtx-cli 2.1.5 → 2.1.6
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 +15 -0
- package/dist/api/checkFileTranslations.d.ts +1 -4
- package/dist/api/checkFileTranslations.js +32 -35
- package/dist/api/downloadFileBatch.d.ts +1 -0
- package/dist/api/sendFiles.d.ts +2 -13
- package/dist/api/sendFiles.js +15 -8
- package/dist/cli/base.d.ts +5 -17
- package/dist/cli/base.js +48 -68
- package/dist/cli/commands/stage.d.ts +5 -0
- package/dist/cli/commands/stage.js +100 -0
- package/dist/cli/commands/translate.d.ts +6 -0
- package/dist/cli/commands/translate.js +54 -0
- package/dist/cli/flags.d.ts +3 -0
- package/dist/cli/flags.js +37 -0
- package/dist/cli/next.js +0 -1
- package/dist/cli/react.d.ts +2 -5
- package/dist/cli/react.js +13 -153
- package/dist/config/generateSettings.js +11 -6
- package/dist/console/index.d.ts +1 -0
- package/dist/console/index.js +1 -0
- package/dist/console/logging.d.ts +1 -0
- package/dist/console/logging.js +3 -0
- package/dist/formats/files/fileMapping.d.ts +2 -1
- package/dist/formats/files/fileMapping.js +6 -0
- package/dist/formats/files/translate.d.ts +4 -13
- package/dist/formats/files/translate.js +30 -142
- package/dist/formats/files/upload.js +1 -75
- package/dist/formats/gt/save.d.ts +1 -2
- package/dist/formats/gt/save.js +2 -5
- package/dist/fs/config/setupConfig.d.ts +1 -0
- package/dist/fs/config/setupConfig.js +1 -0
- package/dist/fs/config/updateConfig.d.ts +1 -2
- package/dist/fs/config/updateConfig.js +1 -1
- package/dist/fs/config/updateVersions.d.ts +10 -0
- package/dist/fs/config/updateVersions.js +30 -0
- package/dist/fs/copyFile.d.ts +1 -2
- package/dist/translation/parse.d.ts +2 -2
- package/dist/translation/parse.js +4 -6
- package/dist/translation/stage.d.ts +2 -5
- package/dist/translation/stage.js +13 -55
- package/dist/types/files.d.ts +1 -0
- package/dist/types/files.js +1 -0
- package/dist/types/index.d.ts +27 -3
- package/dist/utils/flattenJsonFiles.d.ts +2 -2
- package/dist/utils/hash.d.ts +6 -0
- package/dist/utils/hash.js +11 -0
- package/dist/utils/localizeStaticImports.d.ts +2 -2
- package/dist/utils/localizeStaticUrls.d.ts +2 -2
- package/dist/utils/localizeStaticUrls.js +2 -2
- package/package.json +2 -2
- package/dist/api/downloadFile.d.ts +0 -9
- package/dist/api/downloadFile.js +0 -74
- package/dist/api/fetchTranslations.d.ts +0 -7
- package/dist/api/fetchTranslations.js +0 -18
- package/dist/api/sendUpdates.d.ts +0 -19
- package/dist/api/sendUpdates.js +0 -48
- package/dist/api/waitForUpdates.d.ts +0 -9
- package/dist/api/waitForUpdates.js +0 -89
- package/dist/translation/translate.d.ts +0 -2
- package/dist/translation/translate.js +0 -18
package/dist/api/sendUpdates.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { createSpinner, logSuccess, logWarning, } from '../console/logging.js';
|
|
3
|
-
import updateConfig from '../fs/config/updateConfig.js';
|
|
4
|
-
import { isUsingLocalTranslations } from '../config/utils.js';
|
|
5
|
-
import { gt } from '../utils/gt.js';
|
|
6
|
-
/**
|
|
7
|
-
* Sends updates to the API
|
|
8
|
-
* @param updates - The updates to send
|
|
9
|
-
* @param options - The options for the API call
|
|
10
|
-
* @returns The versionId of the updated project
|
|
11
|
-
*/
|
|
12
|
-
export async function sendUpdates(updates, options, library) {
|
|
13
|
-
const spinner = createSpinner('dots');
|
|
14
|
-
spinner.start(`Sending ${library} updates to General Translation API...`);
|
|
15
|
-
try {
|
|
16
|
-
const responseData = await gt.enqueueEntries(updates, {
|
|
17
|
-
sourceLocale: options.defaultLocale,
|
|
18
|
-
targetLocales: options.locales,
|
|
19
|
-
dataFormat: options.dataFormat,
|
|
20
|
-
version: options.version,
|
|
21
|
-
description: options.description,
|
|
22
|
-
requireApproval: options.requireApproval,
|
|
23
|
-
modelProvider: options.modelProvider,
|
|
24
|
-
});
|
|
25
|
-
const { versionId, message, locales, projectSettings } = responseData;
|
|
26
|
-
spinner.stop(chalk.green('Sent updates'));
|
|
27
|
-
logSuccess(message);
|
|
28
|
-
if (isUsingLocalTranslations(options) && projectSettings.cdnEnabled) {
|
|
29
|
-
logWarning(chalk.yellow('Your project is configured to use the CDN, but you are also using local translations. Please disable one or the other.'));
|
|
30
|
-
}
|
|
31
|
-
else if (!isUsingLocalTranslations(options) &&
|
|
32
|
-
!projectSettings.cdnEnabled) {
|
|
33
|
-
logWarning(chalk.yellow('Your project is not using the CDN, nor are you using local translations. Please enable one or the other.'));
|
|
34
|
-
}
|
|
35
|
-
if (options.config) {
|
|
36
|
-
await updateConfig({
|
|
37
|
-
configFilepath: options.config,
|
|
38
|
-
_versionId: versionId,
|
|
39
|
-
locales,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
return { versionId, locales };
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
spinner.stop(chalk.red('Failed to send updates'));
|
|
46
|
-
throw error;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Waits for translations to be deployed to the General Translation API
|
|
3
|
-
* @param versionId - The version ID of the project
|
|
4
|
-
* @param locales - The locales to wait for
|
|
5
|
-
* @param startTime - The start time of the wait
|
|
6
|
-
* @param timeoutDuration - The timeout duration for the wait
|
|
7
|
-
* @returns True if all translations are deployed, false otherwise
|
|
8
|
-
*/
|
|
9
|
-
export declare const waitForUpdates: (versionId: string, startTime: number, timeoutDuration: number) => Promise<boolean>;
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { createOraSpinner, logErrorAndExit, } from '../console/logging.js';
|
|
3
|
-
import { getLocaleProperties } from 'generaltranslation';
|
|
4
|
-
import { gt } from '../utils/gt.js';
|
|
5
|
-
/**
|
|
6
|
-
* Waits for translations to be deployed to the General Translation API
|
|
7
|
-
* @param versionId - The version ID of the project
|
|
8
|
-
* @param locales - The locales to wait for
|
|
9
|
-
* @param startTime - The start time of the wait
|
|
10
|
-
* @param timeoutDuration - The timeout duration for the wait
|
|
11
|
-
* @returns True if all translations are deployed, false otherwise
|
|
12
|
-
*/
|
|
13
|
-
export const waitForUpdates = async (versionId, startTime, timeoutDuration) => {
|
|
14
|
-
console.log();
|
|
15
|
-
const spinner = await createOraSpinner();
|
|
16
|
-
spinner.start('Waiting for translation...');
|
|
17
|
-
const checkDeployment = async () => {
|
|
18
|
-
let data;
|
|
19
|
-
try {
|
|
20
|
-
// get translation status
|
|
21
|
-
data = await gt.checkTranslationStatus(versionId);
|
|
22
|
-
}
|
|
23
|
-
catch {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
// check if any locales are waiting for approval
|
|
27
|
-
const { availableLocales, locales, localesWaitingForApproval } = data;
|
|
28
|
-
if (localesWaitingForApproval.length > 0) {
|
|
29
|
-
spinner.stop();
|
|
30
|
-
logErrorAndExit(`Error! ${localesWaitingForApproval.length} translations are waiting for approval:\n${localesWaitingForApproval
|
|
31
|
-
.map((locale) => {
|
|
32
|
-
const localeProperties = getLocaleProperties(locale);
|
|
33
|
-
return `${localeProperties.name} (${localeProperties.code})`;
|
|
34
|
-
})
|
|
35
|
-
.join('\n')}\nPlease approve these locales in the General Translation dashboard, then re-run the command.`);
|
|
36
|
-
}
|
|
37
|
-
// check if all locales are available
|
|
38
|
-
if (availableLocales) {
|
|
39
|
-
availableLocales.forEach((locale) => {
|
|
40
|
-
if (!availableLocales.includes(locale)) {
|
|
41
|
-
availableLocales.push(locale);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
const newSuffixText = [
|
|
45
|
-
chalk.green(`[${availableLocales.length}/${locales.length}]`) +
|
|
46
|
-
` translations completed`,
|
|
47
|
-
...availableLocales.map((locale) => {
|
|
48
|
-
const localeProperties = getLocaleProperties(locale);
|
|
49
|
-
return `Translation completed for ${chalk.green(localeProperties.name)} (${chalk.green(localeProperties.code)})`;
|
|
50
|
-
}),
|
|
51
|
-
];
|
|
52
|
-
spinner.text = newSuffixText.join('\n');
|
|
53
|
-
}
|
|
54
|
-
// check if all locales are available
|
|
55
|
-
if (locales.every((locale) => availableLocales.includes(locale))) {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
return false;
|
|
59
|
-
};
|
|
60
|
-
// Calculate time until next 5-second interval since startTime
|
|
61
|
-
const msUntilNextInterval = Math.max(0, 5000 - ((Date.now() - startTime) % 5000));
|
|
62
|
-
// Do first check immediately
|
|
63
|
-
const initialCheck = await checkDeployment();
|
|
64
|
-
if (initialCheck) {
|
|
65
|
-
spinner.succeed(chalk.green('All translations are live!'));
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
return new Promise((resolve) => {
|
|
69
|
-
let intervalCheck;
|
|
70
|
-
// Start the interval aligned with the original request time
|
|
71
|
-
setTimeout(() => {
|
|
72
|
-
intervalCheck = setInterval(async () => {
|
|
73
|
-
const isDeployed = await checkDeployment();
|
|
74
|
-
const elapsed = Date.now() - startTime;
|
|
75
|
-
if (isDeployed || elapsed >= timeoutDuration) {
|
|
76
|
-
clearInterval(intervalCheck);
|
|
77
|
-
if (isDeployed) {
|
|
78
|
-
spinner.succeed(chalk.green('All translations are live!'));
|
|
79
|
-
resolve(true);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
spinner.fail(chalk.red('Timed out waiting for translations'));
|
|
83
|
-
resolve(false);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}, 5000);
|
|
87
|
-
}, msUntilNextInterval);
|
|
88
|
-
});
|
|
89
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { fetchTranslations } from '../api/fetchTranslations.js';
|
|
2
|
-
import { waitForUpdates } from '../api/waitForUpdates.js';
|
|
3
|
-
import { saveTranslations } from '../formats/gt/save.js';
|
|
4
|
-
import { isUsingLocalTranslations } from '../config/utils.js';
|
|
5
|
-
export async function translate(settings, versionId) {
|
|
6
|
-
// timeout was validated earlier
|
|
7
|
-
const startTime = Date.now();
|
|
8
|
-
const timeout = parseInt(settings.timeout) * 1000;
|
|
9
|
-
const result = await waitForUpdates(versionId, startTime, timeout);
|
|
10
|
-
if (!result) {
|
|
11
|
-
process.exit(1);
|
|
12
|
-
}
|
|
13
|
-
const translations = await fetchTranslations(versionId);
|
|
14
|
-
// Save translations to local directory if files.gt.output is provided
|
|
15
|
-
if (settings.files && isUsingLocalTranslations(settings)) {
|
|
16
|
-
await saveTranslations(translations, settings.files.placeholderPaths, 'JSX');
|
|
17
|
-
}
|
|
18
|
-
}
|