gtx-cli 1.2.25-alpha.9 → 1.2.26
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 +18 -0
- package/LICENSE.md +1 -1
- package/dist/api/checkFileTranslations.js +21 -27
- package/dist/api/downloadFile.js +6 -42
- package/dist/api/downloadFileBatch.js +8 -44
- package/dist/api/fetchTranslations.d.ts +1 -1
- package/dist/api/fetchTranslations.js +4 -10
- package/dist/api/sendFiles.d.ts +4 -11
- package/dist/api/sendFiles.js +12 -18
- package/dist/api/sendUpdates.d.ts +3 -3
- package/dist/api/sendUpdates.js +17 -23
- package/dist/api/waitForUpdates.js +11 -18
- package/dist/cli/base.d.ts +4 -2
- package/dist/cli/base.js +97 -137
- package/dist/cli/next.d.ts +4 -3
- package/dist/cli/next.js +7 -13
- package/dist/cli/react.d.ts +6 -3
- package/dist/cli/react.js +102 -115
- package/dist/config/generateSettings.d.ts +1 -1
- package/dist/config/generateSettings.js +27 -34
- package/dist/config/utils.d.ts +1 -1
- package/dist/config/utils.js +1 -4
- package/dist/config/validateSettings.d.ts +2 -1
- package/dist/config/validateSettings.js +22 -14
- package/dist/console/colors.js +11 -21
- package/dist/console/index.d.ts +2 -2
- package/dist/console/index.js +19 -45
- package/dist/console/logging.d.ts +2 -6
- package/dist/console/logging.js +79 -111
- package/dist/formats/files/save.d.ts +2 -2
- package/dist/formats/files/save.js +9 -15
- package/dist/formats/files/supportedFiles.d.ts +1 -1
- package/dist/formats/files/supportedFiles.js +2 -5
- package/dist/formats/files/translate.d.ts +6 -5
- package/dist/formats/files/translate.js +49 -53
- package/dist/formats/gt/save.d.ts +4 -4
- package/dist/formats/gt/save.js +11 -16
- package/dist/fs/config/loadConfig.js +3 -9
- package/dist/fs/config/parseFilesConfig.d.ts +1 -1
- package/dist/fs/config/parseFilesConfig.js +17 -24
- package/dist/fs/config/setupConfig.d.ts +2 -2
- package/dist/fs/config/setupConfig.js +9 -14
- package/dist/fs/config/updateConfig.js +9 -14
- package/dist/fs/determineFramework.d.ts +1 -1
- package/dist/fs/determineFramework.js +10 -16
- package/dist/fs/findFilepath.js +23 -35
- package/dist/fs/findJsxFilepath.js +7 -13
- package/dist/fs/getPackageResource.js +5 -9
- package/dist/fs/index.js +1 -2
- package/dist/fs/loadJSON.js +4 -10
- package/dist/fs/saveJSON.js +5 -11
- package/dist/fs/utils.js +1 -4
- package/dist/hooks/postProcess.js +15 -22
- package/dist/index.d.ts +3 -2
- package/dist/index.js +10 -14
- package/dist/main.js +8 -11
- package/dist/next/config/parseNextConfig.js +8 -14
- package/dist/next/jsx/utils.js +6 -46
- package/dist/next/parse/handleInitGT.d.ts +1 -1
- package/dist/next/parse/handleInitGT.js +17 -53
- package/dist/next/parse/wrapContent.d.ts +2 -2
- package/dist/next/parse/wrapContent.js +34 -66
- package/dist/react/config/createESBuildConfig.js +11 -17
- package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.js +8 -11
- package/dist/react/jsx/evaluateJsx.js +4 -42
- package/dist/react/jsx/parse/parseStringFunction.d.ts +1 -1
- package/dist/react/jsx/parse/parseStringFunction.js +17 -52
- package/dist/react/jsx/trimJsxStringChildren.js +6 -11
- package/dist/react/jsx/utils/parseAst.js +12 -54
- package/dist/react/jsx/utils/parseJsx.d.ts +1 -1
- package/dist/react/jsx/utils/parseJsx.js +26 -64
- package/dist/react/jsx/utils/parseStringFunction.d.ts +1 -1
- package/dist/react/jsx/utils/parseStringFunction.js +34 -68
- package/dist/react/jsx/wrapJsx.d.ts +1 -1
- package/dist/react/jsx/wrapJsx.js +11 -48
- package/dist/react/parse/createDictionaryUpdates.d.ts +1 -1
- package/dist/react/parse/createDictionaryUpdates.js +25 -32
- package/dist/react/parse/createInlineUpdates.d.ts +1 -1
- package/dist/react/parse/createInlineUpdates.js +27 -31
- package/dist/react/parse/wrapContent.d.ts +2 -2
- package/dist/react/parse/wrapContent.js +27 -63
- package/dist/react/utils/flattenDictionary.d.ts +1 -1
- package/dist/react/utils/flattenDictionary.js +8 -12
- package/dist/react/utils/getEntryAndMetadata.d.ts +1 -1
- package/dist/react/utils/getEntryAndMetadata.js +1 -4
- package/dist/react/utils/getVariableName.js +3 -7
- package/dist/setup/userInput.js +10 -16
- package/dist/setup/wizard.d.ts +1 -1
- package/dist/setup/wizard.js +72 -72
- package/dist/translation/parse.d.ts +1 -1
- package/dist/translation/parse.js +18 -24
- package/dist/translation/stage.d.ts +1 -1
- package/dist/translation/stage.js +25 -30
- package/dist/translation/translate.d.ts +1 -1
- package/dist/translation/translate.js +9 -12
- package/dist/translation/validate.d.ts +2 -0
- package/dist/translation/validate.js +30 -0
- package/dist/types/api.js +1 -2
- package/dist/types/data.d.ts +2 -2
- package/dist/types/data.js +1 -2
- package/dist/types/index.d.ts +5 -4
- package/dist/types/index.js +1 -2
- package/dist/utils/constants.js +1 -4
- package/dist/utils/credentials.d.ts +2 -2
- package/dist/utils/credentials.js +22 -31
- package/dist/utils/installPackage.d.ts +3 -2
- package/dist/utils/installPackage.js +48 -16
- package/dist/utils/packageInfo.d.ts +3 -0
- package/dist/utils/packageInfo.js +17 -0
- package/dist/utils/packageJson.d.ts +3 -3
- package/dist/utils/packageJson.js +24 -40
- package/dist/utils/packageManager.d.ts +4 -3
- package/dist/utils/packageManager.js +72 -79
- package/package.json +12 -5
- package/dist/console/console.d.ts +0 -1
- package/dist/console/console.js +0 -20
- package/dist/console/errors.d.ts +0 -1
- package/dist/console/errors.js +0 -20
- package/dist/console/warnings.d.ts +0 -1
- package/dist/console/warnings.js +0 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# gtx-cli
|
|
2
2
|
|
|
3
|
+
## 1.2.26
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#391](https://github.com/generaltranslation/gt/pull/391) [`dd41343`](https://github.com/generaltranslation/gt/commit/dd413435742930d995c9fdb84368a91381da3d65) Thanks [@brian-lou](https://github.com/brian-lou)! - Improve logs for cli; Improve QOL setup for locadex
|
|
8
|
+
|
|
9
|
+
## 1.2.25
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#368](https://github.com/generaltranslation/gt/pull/368) [`86f5a18`](https://github.com/generaltranslation/gt/commit/86f5a188439864244b74d590d07bfd6a52c193f9) Thanks [@brian-lou](https://github.com/brian-lou)! - Add new 'validate' command to gtx-cli
|
|
14
|
+
|
|
15
|
+
## 1.2.24
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#358](https://github.com/generaltranslation/gt/pull/358) [`b0ea226`](https://github.com/generaltranslation/gt/commit/b0ea226310abb04ef5aa9ef1af23ee37b9e18cd1) Thanks [@brian-lou](https://github.com/brian-lou)! - Release Locadex (Beta) version
|
|
20
|
+
|
|
3
21
|
## 1.2.23
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/LICENSE.md
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.checkFileTranslations = checkFileTranslations;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const console_1 = require("../console");
|
|
9
|
-
const generaltranslation_1 = require("generaltranslation");
|
|
10
|
-
const downloadFile_1 = require("./downloadFile");
|
|
11
|
-
const downloadFileBatch_1 = require("./downloadFileBatch");
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { createOraSpinner, logError } from '../console/logging.js';
|
|
3
|
+
import { getLocaleProperties } from 'generaltranslation';
|
|
4
|
+
import { downloadFile } from './downloadFile.js';
|
|
5
|
+
import { downloadFileBatch } from './downloadFileBatch.js';
|
|
12
6
|
/**
|
|
13
7
|
* Checks the status of translations for a given version ID
|
|
14
8
|
* @param apiKey - The API key for the General Translation API
|
|
@@ -19,17 +13,17 @@ const downloadFileBatch_1 = require("./downloadFileBatch");
|
|
|
19
13
|
* @param timeoutDuration - The timeout duration for the wait in seconds
|
|
20
14
|
* @returns True if all translations are deployed, false otherwise
|
|
21
15
|
*/
|
|
22
|
-
async function checkFileTranslations(apiKey, baseUrl, data, locales, timeoutDuration, resolveOutputPath, downloadStatus) {
|
|
16
|
+
export async function checkFileTranslations(apiKey, baseUrl, data, locales, timeoutDuration, resolveOutputPath, downloadStatus) {
|
|
23
17
|
const startTime = Date.now();
|
|
24
18
|
console.log();
|
|
25
|
-
const spinner = await
|
|
19
|
+
const spinner = await createOraSpinner();
|
|
26
20
|
spinner.start('Waiting for translation...');
|
|
27
21
|
// Initialize the query data
|
|
28
22
|
const fileQueryData = prepareFileQueryData(data, locales);
|
|
29
23
|
// Do first check immediately
|
|
30
24
|
const initialCheck = await checkTranslationDeployment(baseUrl, apiKey, fileQueryData, downloadStatus, spinner, resolveOutputPath);
|
|
31
25
|
if (initialCheck) {
|
|
32
|
-
spinner.succeed(
|
|
26
|
+
spinner.succeed(chalk.green('Files translated!'));
|
|
33
27
|
return true;
|
|
34
28
|
}
|
|
35
29
|
// Calculate time until next 5-second interval since startTime
|
|
@@ -44,11 +38,11 @@ async function checkFileTranslations(apiKey, baseUrl, data, locales, timeoutDura
|
|
|
44
38
|
if (isDeployed || elapsed >= timeoutDuration * 1000) {
|
|
45
39
|
clearInterval(intervalCheck);
|
|
46
40
|
if (isDeployed) {
|
|
47
|
-
spinner.succeed(
|
|
41
|
+
spinner.succeed(chalk.green('All files translated!'));
|
|
48
42
|
resolve(true);
|
|
49
43
|
}
|
|
50
44
|
else {
|
|
51
|
-
spinner.fail(
|
|
45
|
+
spinner.fail(chalk.red('Timed out waiting for translations'));
|
|
52
46
|
resolve(false);
|
|
53
47
|
}
|
|
54
48
|
}
|
|
@@ -80,7 +74,7 @@ function prepareFileQueryData(data, locales) {
|
|
|
80
74
|
*/
|
|
81
75
|
function generateStatusSuffixText(downloadStatus, fileQueryData) {
|
|
82
76
|
// Simple progress indicator
|
|
83
|
-
const progressText =
|
|
77
|
+
const progressText = chalk.green(`[${downloadStatus.downloaded.size + downloadStatus.failed.size}/${fileQueryData.length}]`) + ` translations completed`;
|
|
84
78
|
// Get terminal height to adapt our output
|
|
85
79
|
const terminalHeight = process.stdout.rows || 24; // Default to 24 if undefined
|
|
86
80
|
// If terminal is very small, just show the basic progress
|
|
@@ -132,26 +126,26 @@ function generateStatusSuffixText(downloadStatus, fileQueryData) {
|
|
|
132
126
|
// Add completed locales
|
|
133
127
|
if (status.completed.size > 0) {
|
|
134
128
|
const completedCodes = Array.from(status.completed)
|
|
135
|
-
.map((locale) =>
|
|
129
|
+
.map((locale) => getLocaleProperties(locale).code)
|
|
136
130
|
.join(', ');
|
|
137
|
-
localeStatuses.push(
|
|
131
|
+
localeStatuses.push(chalk.green(`${completedCodes}`));
|
|
138
132
|
}
|
|
139
133
|
// Add failed locales
|
|
140
134
|
if (status.failed.size > 0) {
|
|
141
135
|
const failedCodes = Array.from(status.failed)
|
|
142
|
-
.map((locale) =>
|
|
136
|
+
.map((locale) => getLocaleProperties(locale).code)
|
|
143
137
|
.join(', ');
|
|
144
|
-
localeStatuses.push(
|
|
138
|
+
localeStatuses.push(chalk.red(`${failedCodes}`));
|
|
145
139
|
}
|
|
146
140
|
// Add pending locales
|
|
147
141
|
if (status.pending.size > 0) {
|
|
148
142
|
const pendingCodes = Array.from(status.pending)
|
|
149
|
-
.map((locale) =>
|
|
143
|
+
.map((locale) => getLocaleProperties(locale).code)
|
|
150
144
|
.join(', ');
|
|
151
|
-
localeStatuses.push(
|
|
145
|
+
localeStatuses.push(chalk.yellow(`${pendingCodes}`));
|
|
152
146
|
}
|
|
153
147
|
// Format the line
|
|
154
|
-
newSuffixText.push(`${
|
|
148
|
+
newSuffixText.push(`${chalk.bold(fileName)} [${localeStatuses.join(', ')}]`);
|
|
155
149
|
}
|
|
156
150
|
// If we couldn't show all files, add an indicator
|
|
157
151
|
if (filesArray.length > maxFilesToShow) {
|
|
@@ -199,7 +193,7 @@ async function checkTranslationDeployment(baseUrl, apiKey, fileQueryData, downlo
|
|
|
199
193
|
});
|
|
200
194
|
// Use batch download if there are multiple files
|
|
201
195
|
if (batchFiles.length > 1) {
|
|
202
|
-
const batchResult = await
|
|
196
|
+
const batchResult = await downloadFileBatch(baseUrl, apiKey, batchFiles.map(({ translationId, outputPath }) => ({
|
|
203
197
|
translationId,
|
|
204
198
|
outputPath,
|
|
205
199
|
})));
|
|
@@ -217,7 +211,7 @@ async function checkTranslationDeployment(baseUrl, apiKey, fileQueryData, downlo
|
|
|
217
211
|
else if (batchFiles.length === 1) {
|
|
218
212
|
// For a single file, use the original downloadFile method
|
|
219
213
|
const file = batchFiles[0];
|
|
220
|
-
const result = await
|
|
214
|
+
const result = await downloadFile(baseUrl, apiKey, file.translationId, file.outputPath);
|
|
221
215
|
if (result) {
|
|
222
216
|
downloadStatus.downloaded.add(file.fileLocale);
|
|
223
217
|
}
|
|
@@ -238,7 +232,7 @@ async function checkTranslationDeployment(baseUrl, apiKey, fileQueryData, downlo
|
|
|
238
232
|
return false;
|
|
239
233
|
}
|
|
240
234
|
catch (error) {
|
|
241
|
-
|
|
235
|
+
logError(chalk.red('Error checking translation status: ') + error);
|
|
242
236
|
return false;
|
|
243
237
|
}
|
|
244
238
|
}
|
package/dist/api/downloadFile.js
CHANGED
|
@@ -1,44 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.downloadFile = downloadFile;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
|
-
const path = __importStar(require("path"));
|
|
39
|
-
const console_1 = require("../console/console");
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { logError } from '../console/logging.js';
|
|
40
4
|
// Helper function to download a file
|
|
41
|
-
async function downloadFile(baseUrl, apiKey, translationId, outputPath, maxRetries = 3, retryDelay = 1000) {
|
|
5
|
+
export async function downloadFile(baseUrl, apiKey, translationId, outputPath, maxRetries = 3, retryDelay = 1000) {
|
|
42
6
|
let retries = 0;
|
|
43
7
|
while (retries <= maxRetries) {
|
|
44
8
|
try {
|
|
@@ -62,7 +26,7 @@ async function downloadFile(baseUrl, apiKey, translationId, outputPath, maxRetri
|
|
|
62
26
|
}
|
|
63
27
|
// If we get here, the response was not OK
|
|
64
28
|
if (retries >= maxRetries) {
|
|
65
|
-
|
|
29
|
+
logError(`Failed to download file ${outputPath}. Status: ${downloadResponse.status} after ${maxRetries + 1} attempts.`);
|
|
66
30
|
return false;
|
|
67
31
|
}
|
|
68
32
|
// Increment retry counter and wait before next attempt
|
|
@@ -71,7 +35,7 @@ async function downloadFile(baseUrl, apiKey, translationId, outputPath, maxRetri
|
|
|
71
35
|
}
|
|
72
36
|
catch (error) {
|
|
73
37
|
if (retries >= maxRetries) {
|
|
74
|
-
|
|
38
|
+
logError(`Error downloading file ${outputPath} after ${maxRetries + 1} attempts: ` +
|
|
75
39
|
error);
|
|
76
40
|
return false;
|
|
77
41
|
}
|
|
@@ -1,42 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.downloadFileBatch = downloadFileBatch;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
|
-
const path = __importStar(require("path"));
|
|
39
|
-
const console_1 = require("../console/console");
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { logError, logWarning } from '../console/logging.js';
|
|
40
4
|
/**
|
|
41
5
|
* Downloads multiple translation files in a single batch request
|
|
42
6
|
* @param baseUrl - The base URL for the General Translation API
|
|
@@ -46,7 +10,7 @@ const console_1 = require("../console/console");
|
|
|
46
10
|
* @param retryDelay - Delay between retries in milliseconds
|
|
47
11
|
* @returns Object containing successful and failed file IDs
|
|
48
12
|
*/
|
|
49
|
-
async function downloadFileBatch(baseUrl, apiKey, files, maxRetries = 3, retryDelay = 1000) {
|
|
13
|
+
export async function downloadFileBatch(baseUrl, apiKey, files, maxRetries = 3, retryDelay = 1000) {
|
|
50
14
|
let retries = 0;
|
|
51
15
|
const fileIds = files.map((file) => file.translationId);
|
|
52
16
|
const result = { successful: [], failed: [] };
|
|
@@ -71,7 +35,7 @@ async function downloadFileBatch(baseUrl, apiKey, files, maxRetries = 3, retryDe
|
|
|
71
35
|
const translationId = file.id;
|
|
72
36
|
const outputPath = outputPathMap.get(translationId);
|
|
73
37
|
if (!outputPath) {
|
|
74
|
-
|
|
38
|
+
logWarning(`No output path found for file: ${translationId}`);
|
|
75
39
|
result.failed.push(translationId);
|
|
76
40
|
continue;
|
|
77
41
|
}
|
|
@@ -85,7 +49,7 @@ async function downloadFileBatch(baseUrl, apiKey, files, maxRetries = 3, retryDe
|
|
|
85
49
|
result.successful.push(translationId);
|
|
86
50
|
}
|
|
87
51
|
catch (error) {
|
|
88
|
-
|
|
52
|
+
logError(`Error saving file ${file.id}: ` + error);
|
|
89
53
|
result.failed.push(file.id);
|
|
90
54
|
}
|
|
91
55
|
}
|
|
@@ -100,7 +64,7 @@ async function downloadFileBatch(baseUrl, apiKey, files, maxRetries = 3, retryDe
|
|
|
100
64
|
}
|
|
101
65
|
// If we get here, the response was not OK
|
|
102
66
|
if (retries >= maxRetries) {
|
|
103
|
-
|
|
67
|
+
logError(`Failed to download files in batch. Status: ${response.status} after ${maxRetries + 1} attempts.`);
|
|
104
68
|
// Mark all files as failed
|
|
105
69
|
result.failed = [...fileIds];
|
|
106
70
|
return result;
|
|
@@ -111,7 +75,7 @@ async function downloadFileBatch(baseUrl, apiKey, files, maxRetries = 3, retryDe
|
|
|
111
75
|
}
|
|
112
76
|
catch (error) {
|
|
113
77
|
if (retries >= maxRetries) {
|
|
114
|
-
|
|
78
|
+
logError(`Error downloading files in batch after ${maxRetries + 1} attempts: ` +
|
|
115
79
|
error);
|
|
116
80
|
// Mark all files as failed
|
|
117
81
|
result.failed = [...fileIds];
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fetchTranslations = fetchTranslations;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const errors_1 = require("../console/errors");
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { logError } from '../console/logging.js';
|
|
9
3
|
/**
|
|
10
4
|
* Fetches translations from the API and saves them to a local directory
|
|
11
5
|
* @param baseUrl - The base URL for the API
|
|
@@ -14,7 +8,7 @@ const errors_1 = require("../console/errors");
|
|
|
14
8
|
* @param translationsDir - The directory to save the translations to
|
|
15
9
|
* @param fileType - The file type to save the translations as (file extension)
|
|
16
10
|
*/
|
|
17
|
-
async function fetchTranslations(baseUrl, apiKey, versionId) {
|
|
11
|
+
export async function fetchTranslations(baseUrl, apiKey, versionId) {
|
|
18
12
|
// First fetch the translations from the API
|
|
19
13
|
const response = await fetch(`${baseUrl}/v1/project/translations/info/${encodeURIComponent(versionId)}`, {
|
|
20
14
|
method: 'GET',
|
|
@@ -29,7 +23,7 @@ async function fetchTranslations(baseUrl, apiKey, versionId) {
|
|
|
29
23
|
return translations;
|
|
30
24
|
}
|
|
31
25
|
else {
|
|
32
|
-
|
|
26
|
+
logError(chalk.red('Failed to fetch translations'));
|
|
33
27
|
}
|
|
34
28
|
return [];
|
|
35
29
|
}
|
package/dist/api/sendFiles.d.ts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import { Settings } from '../types';
|
|
2
|
-
import {
|
|
3
|
-
/**
|
|
4
|
-
* File object structure
|
|
5
|
-
* @param content - The content of the file
|
|
6
|
-
* @param fileName - The name of the file
|
|
7
|
-
* @param fileExtension - The format of the file (JSON, MDX, MD, etc.)
|
|
8
|
-
* @param format - The format of the data within the file
|
|
9
|
-
*/
|
|
1
|
+
import { Settings } from '../types/index.js';
|
|
2
|
+
import { FileFormats, DataFormat } from '../types/data.js';
|
|
10
3
|
export interface FileToTranslate {
|
|
11
4
|
content: string;
|
|
12
5
|
fileName: string;
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
fileFormat: FileFormats;
|
|
7
|
+
dataFormat: DataFormat;
|
|
15
8
|
}
|
|
16
9
|
type ApiOptions = Settings & {
|
|
17
10
|
publish: boolean;
|
package/dist/api/sendFiles.js
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.sendFiles = sendFiles;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const console_1 = require("../console");
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { createSpinner, logMessage, logSuccess } from '../console/logging.js';
|
|
9
3
|
/**
|
|
10
4
|
* Sends multiple files for translation to the API
|
|
11
5
|
* @param files - Array of file objects to translate
|
|
12
6
|
* @param options - The options for the API call
|
|
13
7
|
* @returns The translated content or version ID
|
|
14
8
|
*/
|
|
15
|
-
async function sendFiles(files, options) {
|
|
9
|
+
export async function sendFiles(files, options) {
|
|
16
10
|
const { apiKey } = options;
|
|
17
|
-
|
|
11
|
+
logMessage(chalk.cyan('Files to translate:') +
|
|
18
12
|
'\n' +
|
|
19
|
-
files.map((file) => ` - ${
|
|
20
|
-
const spinner =
|
|
13
|
+
files.map((file) => ` - ${chalk.bold(file.fileName)}`).join('\n'));
|
|
14
|
+
const spinner = createSpinner('dots');
|
|
21
15
|
spinner.start(`Sending ${files.length} file${files.length > 1 ? 's' : ''} to General Translation API...`);
|
|
22
16
|
try {
|
|
23
17
|
// Create form data
|
|
@@ -25,8 +19,8 @@ async function sendFiles(files, options) {
|
|
|
25
19
|
// Add each file to the form data
|
|
26
20
|
files.forEach((file, index) => {
|
|
27
21
|
formData.append(`file${index}`, new Blob([file.content]), file.fileName);
|
|
28
|
-
formData.append(`
|
|
29
|
-
formData.append(`
|
|
22
|
+
formData.append(`fileFormat${index}`, file.fileFormat);
|
|
23
|
+
formData.append(`fileDataFormat${index}`, file.dataFormat); // Only used when translating JSON files
|
|
30
24
|
formData.append(`fileName${index}`, file.fileName);
|
|
31
25
|
});
|
|
32
26
|
// Add number of files
|
|
@@ -46,18 +40,18 @@ async function sendFiles(files, options) {
|
|
|
46
40
|
body: formData,
|
|
47
41
|
});
|
|
48
42
|
if (!response.ok) {
|
|
49
|
-
spinner.stop(
|
|
43
|
+
spinner.stop(chalk.red(await response.text()));
|
|
50
44
|
process.exit(1);
|
|
51
45
|
}
|
|
52
46
|
const responseData = await response.json();
|
|
53
47
|
// Handle version ID response (for async processing)
|
|
54
48
|
const { data, message, locales, translations } = responseData;
|
|
55
|
-
spinner.stop(
|
|
56
|
-
|
|
49
|
+
spinner.stop(chalk.green('Files for translation uploaded successfully'));
|
|
50
|
+
logSuccess(message);
|
|
57
51
|
return { data, locales, translations };
|
|
58
52
|
}
|
|
59
53
|
catch (error) {
|
|
60
|
-
spinner.stop(
|
|
54
|
+
spinner.stop(chalk.red('Failed to send files for translation'));
|
|
61
55
|
throw error;
|
|
62
56
|
}
|
|
63
57
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Settings, SupportedLibraries, Updates } from '../types';
|
|
2
|
-
import {
|
|
1
|
+
import { Settings, SupportedLibraries, Updates } from '../types/index.js';
|
|
2
|
+
import { DataFormat } from '../types/data.js';
|
|
3
3
|
type ApiOptions = Settings & {
|
|
4
4
|
timeout: string;
|
|
5
|
-
|
|
5
|
+
dataFormat: DataFormat;
|
|
6
6
|
description?: string;
|
|
7
7
|
requireApproval?: boolean;
|
|
8
8
|
};
|
package/dist/api/sendUpdates.js
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.sendUpdates = sendUpdates;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const console_1 = require("../console");
|
|
9
|
-
const updateConfig_1 = __importDefault(require("../fs/config/updateConfig"));
|
|
10
|
-
const utils_1 = require("../config/utils");
|
|
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';
|
|
11
5
|
/**
|
|
12
6
|
* Sends updates to the API
|
|
13
7
|
* @param updates - The updates to send
|
|
14
8
|
* @param options - The options for the API call
|
|
15
9
|
* @returns The versionId of the updated project
|
|
16
10
|
*/
|
|
17
|
-
async function sendUpdates(updates, options, library) {
|
|
18
|
-
const { apiKey, projectId, defaultLocale,
|
|
11
|
+
export async function sendUpdates(updates, options, library) {
|
|
12
|
+
const { apiKey, projectId, defaultLocale, dataFormat } = options;
|
|
19
13
|
const globalMetadata = {
|
|
20
14
|
...(projectId && { projectId }),
|
|
21
15
|
...(defaultLocale && { sourceLocale: defaultLocale }),
|
|
@@ -27,14 +21,14 @@ async function sendUpdates(updates, options, library) {
|
|
|
27
21
|
updates,
|
|
28
22
|
...(options.locales && { locales: options.locales }),
|
|
29
23
|
metadata: globalMetadata,
|
|
30
|
-
...(
|
|
24
|
+
...(dataFormat && { dataFormat }),
|
|
31
25
|
...(options.version && { versionId: options.version }),
|
|
32
26
|
...(options.description && { description: options.description }),
|
|
33
27
|
...(options.requireApproval && {
|
|
34
28
|
requireApproval: options.requireApproval,
|
|
35
29
|
}),
|
|
36
30
|
};
|
|
37
|
-
const spinner =
|
|
31
|
+
const spinner = createSpinner('dots');
|
|
38
32
|
spinner.start(`Sending ${library} updates to General Translation API...`);
|
|
39
33
|
try {
|
|
40
34
|
const response = await fetch(`${options.baseUrl}/v1/project/translations/update`, {
|
|
@@ -46,21 +40,21 @@ async function sendUpdates(updates, options, library) {
|
|
|
46
40
|
body: JSON.stringify(body),
|
|
47
41
|
});
|
|
48
42
|
if (!response.ok) {
|
|
49
|
-
spinner.stop(
|
|
43
|
+
spinner.stop(chalk.red(await response.text()));
|
|
50
44
|
process.exit(1);
|
|
51
45
|
}
|
|
52
46
|
const { versionId, message, locales, projectSettings } = await response.json();
|
|
53
|
-
spinner.stop(
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
|
|
47
|
+
spinner.stop(chalk.green('Sent updates'));
|
|
48
|
+
logSuccess(message);
|
|
49
|
+
if (isUsingLocalTranslations(options) && projectSettings.cdnEnabled) {
|
|
50
|
+
logWarning(chalk.yellow('Your project is configured to use the CDN, but you are also using local translations. Please disable one or the other.'));
|
|
57
51
|
}
|
|
58
|
-
else if (!
|
|
52
|
+
else if (!isUsingLocalTranslations(options) &&
|
|
59
53
|
!projectSettings.cdnEnabled) {
|
|
60
|
-
|
|
54
|
+
logWarning(chalk.yellow('Your project is not using the CDN, nor are you using local translations. Please enable one or the other.'));
|
|
61
55
|
}
|
|
62
56
|
if (options.config) {
|
|
63
|
-
await (
|
|
57
|
+
await updateConfig({
|
|
64
58
|
configFilepath: options.config,
|
|
65
59
|
_versionId: versionId,
|
|
66
60
|
locales,
|
|
@@ -69,7 +63,7 @@ async function sendUpdates(updates, options, library) {
|
|
|
69
63
|
return { versionId, locales };
|
|
70
64
|
}
|
|
71
65
|
catch (error) {
|
|
72
|
-
spinner.stop(
|
|
66
|
+
spinner.stop(chalk.red('Failed to send updates'));
|
|
73
67
|
throw error;
|
|
74
68
|
}
|
|
75
69
|
}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.waitForUpdates = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const console_1 = require("../console");
|
|
9
|
-
const generaltranslation_1 = require("generaltranslation");
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { createOraSpinner } from '../console/logging.js';
|
|
3
|
+
import { getLocaleProperties } from 'generaltranslation';
|
|
10
4
|
/**
|
|
11
5
|
* Waits for translations to be deployed to the General Translation API
|
|
12
6
|
* @param apiKey - The API key for the General Translation API
|
|
@@ -17,9 +11,9 @@ const generaltranslation_1 = require("generaltranslation");
|
|
|
17
11
|
* @param timeoutDuration - The timeout duration for the wait
|
|
18
12
|
* @returns True if all translations are deployed, false otherwise
|
|
19
13
|
*/
|
|
20
|
-
const waitForUpdates = async (apiKey, baseUrl, versionId, startTime, timeoutDuration) => {
|
|
14
|
+
export const waitForUpdates = async (apiKey, baseUrl, versionId, startTime, timeoutDuration) => {
|
|
21
15
|
console.log();
|
|
22
|
-
const spinner = await
|
|
16
|
+
const spinner = await createOraSpinner();
|
|
23
17
|
spinner.start('Waiting for translation...');
|
|
24
18
|
const checkDeployment = async () => {
|
|
25
19
|
try {
|
|
@@ -44,11 +38,11 @@ const waitForUpdates = async (apiKey, baseUrl, versionId, startTime, timeoutDura
|
|
|
44
38
|
}
|
|
45
39
|
});
|
|
46
40
|
const newSuffixText = [
|
|
47
|
-
|
|
41
|
+
chalk.green(`[${availableLocales.length}/${locales.length}]`) +
|
|
48
42
|
` translations completed`,
|
|
49
43
|
...availableLocales.map((locale) => {
|
|
50
|
-
const localeProperties =
|
|
51
|
-
return `Translation completed for ${
|
|
44
|
+
const localeProperties = getLocaleProperties(locale);
|
|
45
|
+
return `Translation completed for ${chalk.green(localeProperties.name)} (${chalk.green(localeProperties.code)})`;
|
|
52
46
|
}),
|
|
53
47
|
];
|
|
54
48
|
spinner.text = newSuffixText.join('\n');
|
|
@@ -68,7 +62,7 @@ const waitForUpdates = async (apiKey, baseUrl, versionId, startTime, timeoutDura
|
|
|
68
62
|
// Do first check immediately
|
|
69
63
|
const initialCheck = await checkDeployment();
|
|
70
64
|
if (initialCheck) {
|
|
71
|
-
spinner.succeed(
|
|
65
|
+
spinner.succeed(chalk.green('All translations are live!'));
|
|
72
66
|
return true;
|
|
73
67
|
}
|
|
74
68
|
return new Promise((resolve) => {
|
|
@@ -81,11 +75,11 @@ const waitForUpdates = async (apiKey, baseUrl, versionId, startTime, timeoutDura
|
|
|
81
75
|
if (isDeployed || elapsed >= timeoutDuration) {
|
|
82
76
|
clearInterval(intervalCheck);
|
|
83
77
|
if (isDeployed) {
|
|
84
|
-
spinner.succeed(
|
|
78
|
+
spinner.succeed(chalk.green('All translations are live!'));
|
|
85
79
|
resolve(true);
|
|
86
80
|
}
|
|
87
81
|
else {
|
|
88
|
-
spinner.fail(
|
|
82
|
+
spinner.fail(chalk.red('Timed out waiting for translations'));
|
|
89
83
|
resolve(false);
|
|
90
84
|
}
|
|
91
85
|
}
|
|
@@ -93,4 +87,3 @@ const waitForUpdates = async (apiKey, baseUrl, versionId, startTime, timeoutDura
|
|
|
93
87
|
}, msUntilNextInterval);
|
|
94
88
|
});
|
|
95
89
|
};
|
|
96
|
-
exports.waitForUpdates = waitForUpdates;
|
package/dist/cli/base.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { Settings, SupportedLibraries, SetupOptions } from '../types/index.js';
|
|
2
3
|
export type TranslateOptions = {
|
|
3
4
|
config?: string;
|
|
4
5
|
defaultLocale?: string;
|
|
@@ -13,7 +14,8 @@ export type LoginOptions = {
|
|
|
13
14
|
export declare class BaseCLI {
|
|
14
15
|
protected library: SupportedLibraries;
|
|
15
16
|
protected additionalModules: SupportedLibraries[];
|
|
16
|
-
|
|
17
|
+
protected program: Command;
|
|
18
|
+
constructor(program: Command, library: SupportedLibraries, additionalModules?: SupportedLibraries[]);
|
|
17
19
|
init(): void;
|
|
18
20
|
execute(): void;
|
|
19
21
|
protected setupGTCommand(): void;
|