gtx-cli 1.2.14 → 1.2.15
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 +7 -0
- package/package.json +1 -2
- package/.env +0 -2
- package/dist/api/checkFileTranslations.d.ts +0 -19
- package/dist/api/checkFileTranslations.js +0 -244
- package/dist/api/downloadFile.d.ts +0 -1
- package/dist/api/downloadFile.js +0 -83
- package/dist/api/downloadFileBatch.d.ts +0 -16
- package/dist/api/downloadFileBatch.js +0 -127
- package/dist/api/fetchTranslations.d.ts +0 -10
- package/dist/api/fetchTranslations.js +0 -35
- package/dist/api/sendFiles.d.ts +0 -24
- package/dist/api/sendFiles.js +0 -63
- package/dist/api/sendUpdates.d.ts +0 -19
- package/dist/api/sendUpdates.js +0 -75
- package/dist/api/waitForUpdates.d.ts +0 -11
- package/dist/api/waitForUpdates.js +0 -96
- package/dist/cli/base.d.ts +0 -28
- package/dist/cli/base.js +0 -322
- package/dist/cli/next.d.ts +0 -10
- package/dist/cli/next.js +0 -27
- package/dist/cli/react.d.ts +0 -18
- package/dist/cli/react.js +0 -305
- package/dist/config/generateSettings.d.ts +0 -7
- package/dist/config/generateSettings.js +0 -94
- package/dist/config/utils.d.ts +0 -2
- package/dist/config/utils.js +0 -7
- package/dist/config/validateSettings.d.ts +0 -2
- package/dist/config/validateSettings.js +0 -23
- package/dist/console/colors.d.ts +0 -5
- package/dist/console/colors.js +0 -26
- 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/index.d.ts +0 -19
- package/dist/console/index.js +0 -48
- package/dist/console/logging.d.ts +0 -55
- package/dist/console/logging.js +0 -207
- package/dist/console/warnings.d.ts +0 -1
- package/dist/console/warnings.js +0 -20
- package/dist/formats/files/save.d.ts +0 -5
- package/dist/formats/files/save.js +0 -23
- package/dist/formats/files/supportedFiles.d.ts +0 -8
- package/dist/formats/files/supportedFiles.js +0 -17
- package/dist/formats/files/translate.d.ts +0 -14
- package/dist/formats/files/translate.js +0 -218
- package/dist/formats/gt/save.d.ts +0 -10
- package/dist/formats/gt/save.js +0 -34
- package/dist/fs/config/loadConfig.d.ts +0 -1
- package/dist/fs/config/loadConfig.js +0 -15
- package/dist/fs/config/parseFilesConfig.d.ts +0 -23
- package/dist/fs/config/parseFilesConfig.js +0 -128
- package/dist/fs/config/setupConfig.d.ts +0 -15
- package/dist/fs/config/setupConfig.js +0 -51
- package/dist/fs/config/updateConfig.d.ts +0 -11
- package/dist/fs/config/updateConfig.js +0 -41
- package/dist/fs/determineFramework.d.ts +0 -5
- package/dist/fs/determineFramework.js +0 -52
- package/dist/fs/findFilepath.d.ts +0 -36
- package/dist/fs/findFilepath.js +0 -101
- package/dist/fs/findJsxFilepath.d.ts +0 -7
- package/dist/fs/findJsxFilepath.js +0 -36
- package/dist/fs/index.d.ts +0 -1
- package/dist/fs/index.js +0 -2
- package/dist/fs/loadJSON.d.ts +0 -6
- package/dist/fs/loadJSON.js +0 -23
- package/dist/fs/saveJSON.d.ts +0 -1
- package/dist/fs/saveJSON.js +0 -13
- package/dist/fs/utils.d.ts +0 -1
- package/dist/fs/utils.js +0 -19
- package/dist/hooks/postProcess.d.ts +0 -4
- package/dist/hooks/postProcess.js +0 -118
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -24
- package/dist/main.d.ts +0 -2
- package/dist/main.js +0 -12
- package/dist/next/config/parseNextConfig.d.ts +0 -10
- package/dist/next/config/parseNextConfig.js +0 -59
- package/dist/next/jsx/utils.d.ts +0 -7
- package/dist/next/jsx/utils.js +0 -82
- package/dist/next/parse/handleInitGT.d.ts +0 -1
- package/dist/next/parse/handleInitGT.js +0 -153
- package/dist/next/parse/wrapContent.d.ts +0 -11
- package/dist/next/parse/wrapContent.js +0 -181
- package/dist/react/config/createESBuildConfig.d.ts +0 -2
- package/dist/react/config/createESBuildConfig.js +0 -125
- package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.d.ts +0 -1
- package/dist/react/data-_gt/addGTIdentifierToSyntaxTree.js +0 -87
- package/dist/react/jsx/evaluateJsx.d.ts +0 -17
- package/dist/react/jsx/evaluateJsx.js +0 -133
- package/dist/react/jsx/parse/parseStringFunction.d.ts +0 -12
- package/dist/react/jsx/parse/parseStringFunction.js +0 -118
- package/dist/react/jsx/trimJsxStringChildren.d.ts +0 -7
- package/dist/react/jsx/trimJsxStringChildren.js +0 -100
- package/dist/react/jsx/utils/parseAst.d.ts +0 -30
- package/dist/react/jsx/utils/parseAst.js +0 -319
- package/dist/react/jsx/utils/parseJsx.d.ts +0 -13
- package/dist/react/jsx/utils/parseJsx.js +0 -250
- package/dist/react/jsx/utils/parseStringFunction.d.ts +0 -12
- package/dist/react/jsx/utils/parseStringFunction.js +0 -121
- package/dist/react/jsx/wrapJsx.d.ts +0 -51
- package/dist/react/jsx/wrapJsx.js +0 -411
- package/dist/react/parse/createDictionaryUpdates.d.ts +0 -3
- package/dist/react/parse/createDictionaryUpdates.js +0 -78
- package/dist/react/parse/createInlineUpdates.d.ts +0 -5
- package/dist/react/parse/createInlineUpdates.js +0 -135
- package/dist/react/parse/wrapContent.d.ts +0 -11
- package/dist/react/parse/wrapContent.js +0 -197
- package/dist/react/utils/flattenDictionary.d.ts +0 -20
- package/dist/react/utils/flattenDictionary.js +0 -79
- package/dist/react/utils/getEntryAndMetadata.d.ts +0 -5
- package/dist/react/utils/getEntryAndMetadata.js +0 -14
- package/dist/react/utils/getVariableName.d.ts +0 -2
- package/dist/react/utils/getVariableName.js +0 -17
- package/dist/setup/userInput.d.ts +0 -4
- package/dist/setup/userInput.js +0 -35
- package/dist/setup/wizard.d.ts +0 -2
- package/dist/setup/wizard.js +0 -171
- package/dist/translation/parse.d.ts +0 -14
- package/dist/translation/parse.js +0 -82
- package/dist/translation/stage.d.ts +0 -5
- package/dist/translation/stage.js +0 -80
- package/dist/translation/translate.d.ts +0 -2
- package/dist/translation/translate.js +0 -21
- package/dist/types/api.d.ts +0 -6
- package/dist/types/api.js +0 -2
- package/dist/types/data.d.ts +0 -31
- package/dist/types/data.js +0 -2
- package/dist/types/index.d.ts +0 -101
- package/dist/types/index.js +0 -2
- package/dist/utils/constants.d.ts +0 -1
- package/dist/utils/constants.js +0 -4
- package/dist/utils/credentials.d.ts +0 -12
- package/dist/utils/credentials.js +0 -128
- package/dist/utils/installPackage.d.ts +0 -2
- package/dist/utils/installPackage.js +0 -45
- package/dist/utils/packageJson.d.ts +0 -5
- package/dist/utils/packageJson.js +0 -78
- package/dist/utils/packageManager.d.ts +0 -23
- package/dist/utils/packageManager.js +0 -261
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Settings, SupportedLibraries, Updates } from '../types';
|
|
2
|
-
import { DataFormat } from '../types/data';
|
|
3
|
-
type ApiOptions = Settings & {
|
|
4
|
-
timeout: string;
|
|
5
|
-
dataFormat: DataFormat;
|
|
6
|
-
description?: string;
|
|
7
|
-
requireApproval?: boolean;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Sends updates to the API
|
|
11
|
-
* @param updates - The updates to send
|
|
12
|
-
* @param options - The options for the API call
|
|
13
|
-
* @returns The versionId of the updated project
|
|
14
|
-
*/
|
|
15
|
-
export declare function sendUpdates(updates: Updates, options: ApiOptions, library: SupportedLibraries): Promise<{
|
|
16
|
-
versionId: string;
|
|
17
|
-
locales: string[];
|
|
18
|
-
}>;
|
|
19
|
-
export {};
|
package/dist/api/sendUpdates.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
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");
|
|
11
|
-
/**
|
|
12
|
-
* Sends updates to the API
|
|
13
|
-
* @param updates - The updates to send
|
|
14
|
-
* @param options - The options for the API call
|
|
15
|
-
* @returns The versionId of the updated project
|
|
16
|
-
*/
|
|
17
|
-
async function sendUpdates(updates, options, library) {
|
|
18
|
-
const { apiKey, projectId, defaultLocale, dataFormat } = options;
|
|
19
|
-
const globalMetadata = {
|
|
20
|
-
...(projectId && { projectId }),
|
|
21
|
-
...(defaultLocale && { sourceLocale: defaultLocale }),
|
|
22
|
-
};
|
|
23
|
-
// If additionalLocales is provided, additionalLocales + project.current_locales will be translated
|
|
24
|
-
// If not, then options.locales will be translated
|
|
25
|
-
// If neither, then project.current_locales will be translated
|
|
26
|
-
const body = {
|
|
27
|
-
updates,
|
|
28
|
-
...(options.locales && { locales: options.locales }),
|
|
29
|
-
metadata: globalMetadata,
|
|
30
|
-
...(dataFormat && { dataFormat }),
|
|
31
|
-
...(options.version && { versionId: options.version }),
|
|
32
|
-
...(options.description && { description: options.description }),
|
|
33
|
-
...(options.requireApproval && {
|
|
34
|
-
requireApproval: options.requireApproval,
|
|
35
|
-
}),
|
|
36
|
-
};
|
|
37
|
-
const spinner = (0, console_1.createSpinner)('dots');
|
|
38
|
-
spinner.start(`Sending ${library} updates to General Translation API...`);
|
|
39
|
-
try {
|
|
40
|
-
const response = await fetch(`${options.baseUrl}/v1/project/translations/update`, {
|
|
41
|
-
method: 'POST',
|
|
42
|
-
headers: {
|
|
43
|
-
'Content-Type': 'application/json',
|
|
44
|
-
...(apiKey && { 'x-gt-api-key': apiKey }),
|
|
45
|
-
},
|
|
46
|
-
body: JSON.stringify(body),
|
|
47
|
-
});
|
|
48
|
-
if (!response.ok) {
|
|
49
|
-
spinner.stop(chalk_1.default.red(await response.text()));
|
|
50
|
-
process.exit(1);
|
|
51
|
-
}
|
|
52
|
-
const { versionId, message, locales, projectSettings } = await response.json();
|
|
53
|
-
spinner.stop(chalk_1.default.green('Sent updates'));
|
|
54
|
-
(0, console_1.logSuccess)(message);
|
|
55
|
-
if ((0, utils_1.isUsingLocalTranslations)(options) && projectSettings.cdnEnabled) {
|
|
56
|
-
(0, console_1.logWarning)(chalk_1.default.yellow('Your project is configured to use the CDN, but you are also using local translations. Please disable one or the other.'));
|
|
57
|
-
}
|
|
58
|
-
else if (!(0, utils_1.isUsingLocalTranslations)(options) &&
|
|
59
|
-
!projectSettings.cdnEnabled) {
|
|
60
|
-
(0, console_1.logWarning)(chalk_1.default.yellow('Your project is not using the CDN, nor are you using local translations. Please enable one or the other.'));
|
|
61
|
-
}
|
|
62
|
-
if (options.config) {
|
|
63
|
-
await (0, updateConfig_1.default)({
|
|
64
|
-
configFilepath: options.config,
|
|
65
|
-
_versionId: versionId,
|
|
66
|
-
locales,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
return { versionId, locales };
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
spinner.stop(chalk_1.default.red('Failed to send updates'));
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Waits for translations to be deployed to the General Translation API
|
|
3
|
-
* @param apiKey - The API key for the General Translation API
|
|
4
|
-
* @param baseUrl - The base URL for the General Translation API
|
|
5
|
-
* @param versionId - The version ID of the project
|
|
6
|
-
* @param locales - The locales to wait for
|
|
7
|
-
* @param startTime - The start time of the wait
|
|
8
|
-
* @param timeoutDuration - The timeout duration for the wait
|
|
9
|
-
* @returns True if all translations are deployed, false otherwise
|
|
10
|
-
*/
|
|
11
|
-
export declare const waitForUpdates: (apiKey: string, baseUrl: string, versionId: string, startTime: number, timeoutDuration: number) => Promise<boolean>;
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
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");
|
|
10
|
-
/**
|
|
11
|
-
* Waits for translations to be deployed to the General Translation API
|
|
12
|
-
* @param apiKey - The API key for the General Translation API
|
|
13
|
-
* @param baseUrl - The base URL for the General Translation API
|
|
14
|
-
* @param versionId - The version ID of the project
|
|
15
|
-
* @param locales - The locales to wait for
|
|
16
|
-
* @param startTime - The start time of the wait
|
|
17
|
-
* @param timeoutDuration - The timeout duration for the wait
|
|
18
|
-
* @returns True if all translations are deployed, false otherwise
|
|
19
|
-
*/
|
|
20
|
-
const waitForUpdates = async (apiKey, baseUrl, versionId, startTime, timeoutDuration) => {
|
|
21
|
-
console.log();
|
|
22
|
-
const spinner = await (0, console_1.createOraSpinner)();
|
|
23
|
-
spinner.start('Waiting for translation...');
|
|
24
|
-
const checkDeployment = async () => {
|
|
25
|
-
try {
|
|
26
|
-
const response = await fetch(`${baseUrl}/v1/project/translations/status/${encodeURIComponent(versionId)}`, {
|
|
27
|
-
method: 'GET',
|
|
28
|
-
headers: {
|
|
29
|
-
'Content-Type': 'application/json',
|
|
30
|
-
...(apiKey && { 'x-gt-api-key': apiKey }),
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
if (response.ok) {
|
|
34
|
-
const data = await response.json();
|
|
35
|
-
const { availableLocales, locales, localesWaitingForApproval } = data;
|
|
36
|
-
if (localesWaitingForApproval.length > 0) {
|
|
37
|
-
spinner.text = `Waiting for approval for ${localesWaitingForApproval.length} locales`;
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
if (availableLocales) {
|
|
41
|
-
availableLocales.forEach((locale) => {
|
|
42
|
-
if (!availableLocales.includes(locale)) {
|
|
43
|
-
availableLocales.push(locale);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
const newSuffixText = [
|
|
47
|
-
chalk_1.default.green(`[${availableLocales.length}/${locales.length}]`) +
|
|
48
|
-
` translations completed`,
|
|
49
|
-
...availableLocales.map((locale) => {
|
|
50
|
-
const localeProperties = (0, generaltranslation_1.getLocaleProperties)(locale);
|
|
51
|
-
return `Translation completed for ${chalk_1.default.green(localeProperties.name)} (${chalk_1.default.green(localeProperties.code)})`;
|
|
52
|
-
}),
|
|
53
|
-
];
|
|
54
|
-
spinner.text = newSuffixText.join('\n');
|
|
55
|
-
}
|
|
56
|
-
if (locales.every((locale) => availableLocales.includes(locale))) {
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
// Calculate time until next 5-second interval since startTime
|
|
67
|
-
const msUntilNextInterval = Math.max(0, 5000 - ((Date.now() - startTime) % 5000));
|
|
68
|
-
// Do first check immediately
|
|
69
|
-
const initialCheck = await checkDeployment();
|
|
70
|
-
if (initialCheck) {
|
|
71
|
-
spinner.succeed(chalk_1.default.green('All translations are live!'));
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
return new Promise((resolve) => {
|
|
75
|
-
let intervalCheck;
|
|
76
|
-
// Start the interval aligned with the original request time
|
|
77
|
-
setTimeout(() => {
|
|
78
|
-
intervalCheck = setInterval(async () => {
|
|
79
|
-
const isDeployed = await checkDeployment();
|
|
80
|
-
const elapsed = Date.now() - startTime;
|
|
81
|
-
if (isDeployed || elapsed >= timeoutDuration) {
|
|
82
|
-
clearInterval(intervalCheck);
|
|
83
|
-
if (isDeployed) {
|
|
84
|
-
spinner.succeed(chalk_1.default.green('All translations are live!'));
|
|
85
|
-
resolve(true);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
spinner.fail(chalk_1.default.red('Timed out waiting for translations'));
|
|
89
|
-
resolve(false);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}, 5000);
|
|
93
|
-
}, msUntilNextInterval);
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
exports.waitForUpdates = waitForUpdates;
|
package/dist/cli/base.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Settings, SupportedLibraries, SetupOptions } from '../types';
|
|
2
|
-
export type TranslateOptions = {
|
|
3
|
-
config?: string;
|
|
4
|
-
defaultLocale?: string;
|
|
5
|
-
locales?: string[];
|
|
6
|
-
apiKey?: string;
|
|
7
|
-
projectId?: string;
|
|
8
|
-
dryRun: boolean;
|
|
9
|
-
};
|
|
10
|
-
export type LoginOptions = {
|
|
11
|
-
keyType?: 'development' | 'production';
|
|
12
|
-
};
|
|
13
|
-
export declare class BaseCLI {
|
|
14
|
-
protected library: SupportedLibraries;
|
|
15
|
-
protected additionalModules: SupportedLibraries[];
|
|
16
|
-
constructor(library: SupportedLibraries, additionalModules?: SupportedLibraries[]);
|
|
17
|
-
init(): void;
|
|
18
|
-
execute(): void;
|
|
19
|
-
protected setupGTCommand(): void;
|
|
20
|
-
protected setupLoginCommand(): void;
|
|
21
|
-
protected setupInitCommand(): void;
|
|
22
|
-
protected setupConfigureCommand(): void;
|
|
23
|
-
protected setupSetupCommand(): void;
|
|
24
|
-
protected handleGenericTranslate(settings: Settings & TranslateOptions): Promise<void>;
|
|
25
|
-
protected handleSetupReactCommand(options: SetupOptions): Promise<void>;
|
|
26
|
-
protected handleInitCommand(ranReactSetup: boolean): Promise<void>;
|
|
27
|
-
protected handleLoginCommand(options: LoginOptions): Promise<void>;
|
|
28
|
-
}
|
package/dist/cli/base.js
DELETED
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.BaseCLI = void 0;
|
|
40
|
-
const commander_1 = require("commander");
|
|
41
|
-
const setupConfig_1 = __importDefault(require("../fs/config/setupConfig"));
|
|
42
|
-
const findFilepath_1 = __importStar(require("../fs/findFilepath"));
|
|
43
|
-
const console_1 = require("../console");
|
|
44
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
45
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
46
|
-
const generateSettings_1 = require("../config/generateSettings");
|
|
47
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
48
|
-
const translate_1 = require("../formats/files/translate");
|
|
49
|
-
const supportedFiles_1 = require("../formats/files/supportedFiles");
|
|
50
|
-
const wizard_1 = require("../setup/wizard");
|
|
51
|
-
const packageJson_1 = require("../utils/packageJson");
|
|
52
|
-
const userInput_1 = require("../setup/userInput");
|
|
53
|
-
const installPackage_1 = require("../utils/installPackage");
|
|
54
|
-
const packageManager_1 = require("../utils/packageManager");
|
|
55
|
-
const credentials_1 = require("../utils/credentials");
|
|
56
|
-
const credentials_2 = require("../utils/credentials");
|
|
57
|
-
class BaseCLI {
|
|
58
|
-
library;
|
|
59
|
-
additionalModules;
|
|
60
|
-
// Constructor is shared amongst all CLI class types
|
|
61
|
-
constructor(library, additionalModules) {
|
|
62
|
-
this.library = library;
|
|
63
|
-
this.additionalModules = additionalModules || [];
|
|
64
|
-
this.setupInitCommand();
|
|
65
|
-
this.setupConfigureCommand();
|
|
66
|
-
this.setupSetupCommand();
|
|
67
|
-
this.setupLoginCommand();
|
|
68
|
-
}
|
|
69
|
-
// Init is never called in a child class
|
|
70
|
-
init() {
|
|
71
|
-
this.setupGTCommand();
|
|
72
|
-
}
|
|
73
|
-
// Execute is called by the main program
|
|
74
|
-
execute() {
|
|
75
|
-
// If no command is specified, run 'init'
|
|
76
|
-
if (process.argv.length <= 2) {
|
|
77
|
-
process.argv.push('init');
|
|
78
|
-
}
|
|
79
|
-
commander_1.program.parse();
|
|
80
|
-
}
|
|
81
|
-
setupGTCommand() {
|
|
82
|
-
commander_1.program
|
|
83
|
-
.command('translate')
|
|
84
|
-
.description('Translate your project using General Translation')
|
|
85
|
-
.option('-c, --config <path>', 'Filepath to config file, by default gt.config.json', (0, findFilepath_1.default)(['gt.config.json']))
|
|
86
|
-
.option('--api-key <key>', 'API key for General Translation cloud service')
|
|
87
|
-
.option('--project-id <id>', 'Project ID for the translation service')
|
|
88
|
-
.option('--default-language, --default-locale <locale>', 'Default locale (e.g., en)')
|
|
89
|
-
.option('--new, --locales <locales...>', 'Space-separated list of locales (e.g., en fr es)')
|
|
90
|
-
.option('--dry-run', 'Dry run, does not send updates to General Translation API', false)
|
|
91
|
-
.action(async (initOptions) => {
|
|
92
|
-
(0, console_1.displayHeader)('Starting translation...');
|
|
93
|
-
const settings = await (0, generateSettings_1.generateSettings)(initOptions);
|
|
94
|
-
const options = { ...initOptions, ...settings };
|
|
95
|
-
await this.handleGenericTranslate(options);
|
|
96
|
-
(0, console_1.endCommand)('Done!');
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
setupLoginCommand() {
|
|
100
|
-
commander_1.program
|
|
101
|
-
.command('auth')
|
|
102
|
-
.description('Generate a General Translation API key and project ID')
|
|
103
|
-
.option('-c, --config <path>', 'Filepath to config file, by default gt.config.json', (0, findFilepath_1.default)(['gt.config.json']))
|
|
104
|
-
.option('-t, --key-type <type>', 'Type of key to generate, production | development')
|
|
105
|
-
.action(async (options) => {
|
|
106
|
-
(0, console_1.displayHeader)('Authenticating with General Translation...');
|
|
107
|
-
if (!options.keyType) {
|
|
108
|
-
const packageJson = await (0, packageJson_1.searchForPackageJson)();
|
|
109
|
-
const isUsingGTNext = packageJson
|
|
110
|
-
? (0, packageJson_1.isPackageInstalled)('gt-next', packageJson)
|
|
111
|
-
: false;
|
|
112
|
-
const isUsingGTReact = packageJson
|
|
113
|
-
? (0, packageJson_1.isPackageInstalled)('gt-react', packageJson)
|
|
114
|
-
: false;
|
|
115
|
-
if (isUsingGTNext || isUsingGTReact) {
|
|
116
|
-
options.keyType = 'development';
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
options.keyType = 'production';
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
if (options.keyType !== 'development' &&
|
|
124
|
-
options.keyType !== 'production') {
|
|
125
|
-
(0, console_1.logErrorAndExit)('Invalid key type, must be development or production');
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
await this.handleLoginCommand(options);
|
|
129
|
-
(0, console_1.endCommand)(`Done! A ${options.keyType} key has been generated and saved to your .env.local file.`);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
setupInitCommand() {
|
|
133
|
-
commander_1.program
|
|
134
|
-
.command('init')
|
|
135
|
-
.description('Run the setup wizard to configure your project for General Translation')
|
|
136
|
-
.option('--src <paths...>', "Filepath to directory containing the app's source code, by default ./src || ./app || ./pages || ./components", (0, findFilepath_1.findFilepaths)(['./src', './app', './pages', './components']))
|
|
137
|
-
.option('-c, --config <path>', 'Filepath to config file, by default gt.config.json', (0, findFilepath_1.default)(['gt.config.json']))
|
|
138
|
-
.action(async (options) => {
|
|
139
|
-
(0, console_1.displayHeader)('Running setup wizard...');
|
|
140
|
-
const packageJson = await (0, packageJson_1.searchForPackageJson)();
|
|
141
|
-
let ranReactSetup = false;
|
|
142
|
-
// so that people can run init in non-js projects
|
|
143
|
-
if (packageJson && (0, packageJson_1.isPackageInstalled)('react', packageJson)) {
|
|
144
|
-
const wrap = await (0, console_1.promptConfirm)({
|
|
145
|
-
message: `Detected that this project is using React. Would you like to run the React setup wizard?\nThis will install gt-react|gt-next as a dependency and internationalize your app.`,
|
|
146
|
-
defaultValue: true,
|
|
147
|
-
});
|
|
148
|
-
if (wrap) {
|
|
149
|
-
(0, console_1.logInfo)(`${chalk_1.default.yellow('[EXPERIMENTAL]')} Running React setup wizard...`);
|
|
150
|
-
await this.handleSetupReactCommand(options);
|
|
151
|
-
(0, console_1.endCommand)(`Done! Since this wizard is experimental, please review the changes and make modifications as needed.
|
|
152
|
-
Certain aspects of your app may still need manual setup.
|
|
153
|
-
See the docs for more information: https://generaltranslation.com/docs/react/tutorials/quickstart`);
|
|
154
|
-
ranReactSetup = true;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
if (ranReactSetup) {
|
|
158
|
-
(0, console_1.startCommand)('Setting up project config...');
|
|
159
|
-
}
|
|
160
|
-
// Configure gt.config.json
|
|
161
|
-
await this.handleInitCommand(ranReactSetup);
|
|
162
|
-
(0, console_1.endCommand)('Done! Check out our docs for more information on how to use General Translation: https://generaltranslation.com/docs');
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
setupConfigureCommand() {
|
|
166
|
-
commander_1.program
|
|
167
|
-
.command('configure')
|
|
168
|
-
.description('Configure your project for General Translation. This will create a gt.config.json file in your codebase.')
|
|
169
|
-
.action(async () => {
|
|
170
|
-
(0, console_1.displayHeader)('Configuring project...');
|
|
171
|
-
(0, console_1.logInfo)('Welcome! This tool will help you configure your gt.config.json file. See the docs: https://generaltranslation.com/docs/cli/reference/config for more information.');
|
|
172
|
-
// Configure gt.config.json
|
|
173
|
-
await this.handleInitCommand(false);
|
|
174
|
-
(0, console_1.endCommand)('Done! Make sure you have an API key and project ID to use General Translation. Get them on the dashboard: https://generaltranslation.com/dashboard');
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
setupSetupCommand() {
|
|
178
|
-
commander_1.program
|
|
179
|
-
.command('setup')
|
|
180
|
-
.description('Run the setup to configure your Next.js or React project for General Translation')
|
|
181
|
-
.option('--src <paths...>', "Filepath to directory containing the app's source code, by default ./src || ./app || ./pages || ./components", (0, findFilepath_1.findFilepaths)(['./src', './app', './pages', './components']))
|
|
182
|
-
.option('-c, --config <path>', 'Filepath to config file, by default gt.config.json', (0, findFilepath_1.default)(['gt.config.json']))
|
|
183
|
-
.action(async (options) => {
|
|
184
|
-
(0, console_1.displayHeader)('Running React setup wizard...');
|
|
185
|
-
await this.handleSetupReactCommand(options);
|
|
186
|
-
(0, console_1.endCommand)("Done! Take advantage of all of General Translation's features by signing up for a free account! https://generaltranslation.com/signup");
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
async handleGenericTranslate(settings) {
|
|
190
|
-
// dataFormat for JSONs
|
|
191
|
-
let dataFormat;
|
|
192
|
-
if (this.library === 'next-intl') {
|
|
193
|
-
dataFormat = 'ICU';
|
|
194
|
-
}
|
|
195
|
-
else if (this.library === 'i18next') {
|
|
196
|
-
if (this.additionalModules.includes('i18next-icu')) {
|
|
197
|
-
dataFormat = 'ICU';
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
dataFormat = 'I18NEXT';
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
dataFormat = 'JSX';
|
|
205
|
-
}
|
|
206
|
-
if (!settings.files ||
|
|
207
|
-
(Object.keys(settings.files.placeholderPaths).length === 1 &&
|
|
208
|
-
settings.files.placeholderPaths.gt)) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
const { resolvedPaths: sourceFiles, placeholderPaths, transformPaths, } = settings.files;
|
|
212
|
-
// Process all file types at once with a single call
|
|
213
|
-
await (0, translate_1.translateFiles)(sourceFiles, placeholderPaths, transformPaths, dataFormat, settings);
|
|
214
|
-
}
|
|
215
|
-
async handleSetupReactCommand(options) {
|
|
216
|
-
await (0, wizard_1.handleSetupReactCommand)(options);
|
|
217
|
-
}
|
|
218
|
-
// Wizard for configuring gt.config.json
|
|
219
|
-
async handleInitCommand(ranReactSetup) {
|
|
220
|
-
const { defaultLocale, locales } = await (0, userInput_1.getDesiredLocales)();
|
|
221
|
-
const packageJson = await (0, packageJson_1.searchForPackageJson)();
|
|
222
|
-
const isUsingGTNext = packageJson
|
|
223
|
-
? (0, packageJson_1.isPackageInstalled)('gt-next', packageJson)
|
|
224
|
-
: false;
|
|
225
|
-
const isUsingGTReact = packageJson
|
|
226
|
-
? (0, packageJson_1.isPackageInstalled)('gt-react', packageJson)
|
|
227
|
-
: false;
|
|
228
|
-
// Ask if using another i18n library
|
|
229
|
-
const isUsingGT = isUsingGTNext || isUsingGTReact || ranReactSetup;
|
|
230
|
-
// Ask where the translations are stored
|
|
231
|
-
const usingCDN = isUsingGT
|
|
232
|
-
? await (0, console_1.promptConfirm)({
|
|
233
|
-
message: `Auto-detected that you're using gt-next or gt-react. Would you like to use the General Translation CDN to store your translations?\nSee ${isUsingGTNext
|
|
234
|
-
? 'https://generaltranslation.com/docs/next/reference/local-tx'
|
|
235
|
-
: 'https://generaltranslation.com/docs/react/reference/local-tx'} for more information.\nIf you answer no, we'll configure the CLI tool to download completed translations.`,
|
|
236
|
-
defaultValue: true,
|
|
237
|
-
})
|
|
238
|
-
: false;
|
|
239
|
-
if (isUsingGT && !usingCDN) {
|
|
240
|
-
(0, console_1.logMessage)(`To prevent translations from being published, please disable the project setting on the dashboard: ${chalk_1.default.cyan('https://dash.generaltranslation.com/settings/project')}`);
|
|
241
|
-
}
|
|
242
|
-
// Ask where the translations are stored
|
|
243
|
-
const translationsDir = isUsingGT && !usingCDN
|
|
244
|
-
? await (0, console_1.promptText)({
|
|
245
|
-
message: 'What is the path to the directory where you would like to locally store your translations?',
|
|
246
|
-
defaultValue: './public/locales',
|
|
247
|
-
})
|
|
248
|
-
: null;
|
|
249
|
-
const message = !isUsingGT
|
|
250
|
-
? 'What is the format of your language resource files? Select as many as applicable.\nAdditionally, you can translate any other files you have in your project.'
|
|
251
|
-
: `${chalk_1.default.gray('(Optional)')} Do you have any separate files you would like to translate? For example, extra Markdown files for docs.`;
|
|
252
|
-
const dataFormats = await (0, console_1.promptMultiSelect)({
|
|
253
|
-
message,
|
|
254
|
-
options: [
|
|
255
|
-
{ value: 'json', label: 'JSON' },
|
|
256
|
-
{ value: 'md', label: 'Markdown' },
|
|
257
|
-
{ value: 'mdx', label: 'MDX' },
|
|
258
|
-
{ value: 'ts', label: 'TypeScript' },
|
|
259
|
-
{ value: 'js', label: 'JavaScript' },
|
|
260
|
-
],
|
|
261
|
-
required: !isUsingGT,
|
|
262
|
-
});
|
|
263
|
-
const files = {};
|
|
264
|
-
for (const dataFormat of dataFormats) {
|
|
265
|
-
const paths = await (0, console_1.promptText)({
|
|
266
|
-
message: `${chalk_1.default.cyan(supportedFiles_1.FILE_EXT_TO_FORMAT[dataFormat])}: Please enter a space-separated list of glob patterns matching the location of the ${supportedFiles_1.FILE_EXT_TO_FORMAT[dataFormat]} files you would like to translate.\nMake sure to include [locale] in the patterns.\nSee https://generaltranslation.com/docs/cli/reference/config#include for more information.`,
|
|
267
|
-
defaultValue: `./**/[locale]/*.${dataFormat}`,
|
|
268
|
-
});
|
|
269
|
-
files[dataFormat] = {
|
|
270
|
-
include: paths.split(' '),
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
// Add GT translations if using GT and storing locally
|
|
274
|
-
if (isUsingGT && !usingCDN && translationsDir) {
|
|
275
|
-
files.gt = {
|
|
276
|
-
output: node_path_1.default.join(translationsDir, `[locale].json`),
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
let configFilepath = 'gt.config.json';
|
|
280
|
-
if (node_fs_1.default.existsSync('src/gt.config.json')) {
|
|
281
|
-
configFilepath = 'src/gt.config.json';
|
|
282
|
-
}
|
|
283
|
-
// Create gt.config.json
|
|
284
|
-
await (0, setupConfig_1.default)(configFilepath, {
|
|
285
|
-
defaultLocale,
|
|
286
|
-
locales,
|
|
287
|
-
files: Object.keys(files).length > 0 ? files : undefined,
|
|
288
|
-
});
|
|
289
|
-
(0, console_1.logSuccess)(`Feel free to edit ${chalk_1.default.cyan(configFilepath)} to customize your translation setup. Docs: https://generaltranslation.com/docs/cli/reference/config`);
|
|
290
|
-
// Install gtx-cli if not installed
|
|
291
|
-
const isCLIInstalled = packageJson
|
|
292
|
-
? (0, packageJson_1.isPackageInstalled)('gtx-cli', packageJson, true, true)
|
|
293
|
-
: true; // if no package.json, we can't install it
|
|
294
|
-
if (!isCLIInstalled) {
|
|
295
|
-
const packageManager = await (0, packageManager_1.getPackageManager)();
|
|
296
|
-
const spinner = (0, console_1.createSpinner)();
|
|
297
|
-
spinner.start(`Installing gtx-cli as a dev dependency with ${packageManager.name}...`);
|
|
298
|
-
await (0, installPackage_1.installPackage)('gtx-cli', packageManager, true);
|
|
299
|
-
spinner.stop(chalk_1.default.green('Installed gtx-cli.'));
|
|
300
|
-
}
|
|
301
|
-
// Set credentials
|
|
302
|
-
if (!(0, credentials_2.areCredentialsSet)()) {
|
|
303
|
-
const loginQuestion = await (0, console_1.promptConfirm)({
|
|
304
|
-
message: `Would you like the wizard to automatically generate a ${isUsingGT ? 'development' : 'production'} API key and project ID for you?`,
|
|
305
|
-
defaultValue: true,
|
|
306
|
-
});
|
|
307
|
-
if (loginQuestion) {
|
|
308
|
-
const settings = await (0, generateSettings_1.generateSettings)({});
|
|
309
|
-
const keyType = isUsingGT ? 'development' : 'production';
|
|
310
|
-
const credentials = await (0, credentials_1.retrieveCredentials)(settings, keyType);
|
|
311
|
-
await (0, credentials_1.setCredentials)(credentials, keyType, settings.framework);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
async handleLoginCommand(options) {
|
|
316
|
-
const settings = await (0, generateSettings_1.generateSettings)({});
|
|
317
|
-
const keyType = options.keyType || 'production';
|
|
318
|
-
const credentials = await (0, credentials_1.retrieveCredentials)(settings, keyType);
|
|
319
|
-
await (0, credentials_1.setCredentials)(credentials, keyType, settings.framework);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
exports.BaseCLI = BaseCLI;
|
package/dist/cli/next.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { WrapOptions, SupportedFrameworks, SupportedLibraries } from '../types';
|
|
2
|
-
import { ReactCLI } from './react';
|
|
3
|
-
export declare class NextCLI extends ReactCLI {
|
|
4
|
-
constructor(library: 'gt-next', additionalModules?: SupportedLibraries[]);
|
|
5
|
-
init(): void;
|
|
6
|
-
execute(): void;
|
|
7
|
-
protected wrapContent(options: WrapOptions, framework: SupportedFrameworks, errors: string[], warnings: string[]): Promise<{
|
|
8
|
-
filesUpdated: string[];
|
|
9
|
-
}>;
|
|
10
|
-
}
|
package/dist/cli/next.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.NextCLI = void 0;
|
|
7
|
-
const react_1 = require("./react");
|
|
8
|
-
const wrapContent_1 = __importDefault(require("../next/parse/wrapContent"));
|
|
9
|
-
const pkg = 'gt-next';
|
|
10
|
-
class NextCLI extends react_1.ReactCLI {
|
|
11
|
-
constructor(library, additionalModules) {
|
|
12
|
-
super(library, additionalModules);
|
|
13
|
-
}
|
|
14
|
-
init() {
|
|
15
|
-
this.setupStageCommand();
|
|
16
|
-
this.setupTranslateCommand();
|
|
17
|
-
this.setupScanCommand();
|
|
18
|
-
this.setupGenerateSourceCommand();
|
|
19
|
-
}
|
|
20
|
-
execute() {
|
|
21
|
-
super.execute();
|
|
22
|
-
}
|
|
23
|
-
wrapContent(options, framework, errors, warnings) {
|
|
24
|
-
return (0, wrapContent_1.default)(options, pkg, errors, warnings);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.NextCLI = NextCLI;
|
package/dist/cli/react.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Options, SupportedFrameworks, WrapOptions, GenerateSourceOptions, SupportedLibraries } from '../types';
|
|
2
|
-
import { BaseCLI } from './base';
|
|
3
|
-
export declare class ReactCLI extends BaseCLI {
|
|
4
|
-
constructor(library: 'gt-react' | 'gt-next', additionalModules?: SupportedLibraries[]);
|
|
5
|
-
init(): void;
|
|
6
|
-
execute(): void;
|
|
7
|
-
protected wrapContent(options: WrapOptions, framework: SupportedFrameworks, errors: string[], warnings: string[]): Promise<{
|
|
8
|
-
filesUpdated: string[];
|
|
9
|
-
}>;
|
|
10
|
-
protected setupStageCommand(): void;
|
|
11
|
-
protected setupTranslateCommand(): void;
|
|
12
|
-
protected setupGenerateSourceCommand(): void;
|
|
13
|
-
protected setupScanCommand(): void;
|
|
14
|
-
protected handleGenerateSourceCommand(initOptions: GenerateSourceOptions): Promise<void>;
|
|
15
|
-
protected handleScanCommand(options: WrapOptions): Promise<void>;
|
|
16
|
-
protected handleStage(initOptions: Options): Promise<void>;
|
|
17
|
-
protected handleTranslate(initOptions: Options): Promise<void>;
|
|
18
|
-
}
|