gtx-cli 1.2.0-alpha.3 → 1.2.0-alpha.4
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/dist/api/downloadFile.js +1 -1
- package/dist/api/downloadFileBatch.js +1 -1
- package/dist/api/sendUpdates.js +1 -1
- package/dist/cli/base.d.ts +2 -0
- package/dist/cli/base.js +42 -11
- package/dist/cli/react.js +9 -9
- package/dist/config/generateSettings.d.ts +1 -1
- package/dist/config/generateSettings.js +79 -65
- package/dist/formats/files/save.js +3 -3
- package/dist/formats/files/translate.js +4 -4
- package/dist/formats/gt/save.d.ts +1 -1
- package/dist/formats/gt/save.js +28 -17
- package/dist/fs/config/loadConfig.js +2 -2
- package/dist/fs/config/parseFilesConfig.js +10 -10
- package/dist/fs/config/setupConfig.d.ts +1 -1
- package/dist/fs/config/setupConfig.js +36 -25
- package/dist/fs/config/updateConfig.d.ts +1 -1
- package/dist/fs/config/updateConfig.js +31 -20
- package/dist/fs/determineFramework.js +5 -5
- package/dist/fs/findFilepath.js +13 -13
- package/dist/fs/findJsxFilepath.js +6 -6
- package/dist/fs/loadJSON.js +3 -3
- package/dist/fs/saveJSON.d.ts +1 -1
- package/dist/fs/saveJSON.js +16 -5
- package/dist/hooks/postProcess.js +3 -3
- package/dist/next/config/parseNextConfig.d.ts +2 -2
- package/dist/next/config/parseNextConfig.js +52 -41
- package/dist/next/parse/handleInitGT.js +3 -3
- package/dist/next/parse/scanForContent.js +3 -3
- package/dist/react/config/createESBuildConfig.js +8 -8
- package/dist/react/parse/createDictionaryUpdates.js +5 -5
- package/dist/react/parse/createInlineUpdates.js +7 -7
- package/dist/react/parse/scanForContent.js +6 -6
- package/dist/setup/wizard.js +4 -4
- package/dist/types/index.d.ts +1 -0
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.js +4 -0
- package/dist/utils/credentials.d.ts +12 -0
- package/dist/utils/credentials.js +120 -0
- package/dist/utils/packageJson.d.ts +3 -3
- package/dist/utils/packageJson.js +51 -36
- package/dist/utils/packageManager.js +12 -12
- package/package.json +2 -1
package/dist/api/downloadFile.js
CHANGED
|
@@ -65,7 +65,7 @@ function downloadFile(baseUrl_1, apiKey_1, translationId_1, outputPath_1) {
|
|
|
65
65
|
// Get the file data as an ArrayBuffer
|
|
66
66
|
const fileData = yield downloadResponse.arrayBuffer();
|
|
67
67
|
// Write the file to disk
|
|
68
|
-
fs.
|
|
68
|
+
yield fs.promises.writeFile(outputPath, Buffer.from(fileData));
|
|
69
69
|
return true;
|
|
70
70
|
}
|
|
71
71
|
// If we get here, the response was not OK
|
|
@@ -88,7 +88,7 @@ function downloadFileBatch(baseUrl_1, apiKey_1, files_1) {
|
|
|
88
88
|
fs.mkdirSync(dir, { recursive: true });
|
|
89
89
|
}
|
|
90
90
|
// Write the file to disk
|
|
91
|
-
fs.
|
|
91
|
+
yield fs.promises.writeFile(outputPath, file.data);
|
|
92
92
|
result.successful.push(translationId);
|
|
93
93
|
}
|
|
94
94
|
catch (error) {
|
package/dist/api/sendUpdates.js
CHANGED
|
@@ -53,7 +53,7 @@ function sendUpdates(updates, options, library) {
|
|
|
53
53
|
spinner.stop(chalk_1.default.green('Sent updates'));
|
|
54
54
|
(0, console_1.logSuccess)(message);
|
|
55
55
|
if (options.config)
|
|
56
|
-
(0, updateConfig_1.default)({
|
|
56
|
+
yield (0, updateConfig_1.default)({
|
|
57
57
|
configFilepath: options.config,
|
|
58
58
|
_versionId: versionId,
|
|
59
59
|
locales,
|
package/dist/cli/base.d.ts
CHANGED
|
@@ -6,10 +6,12 @@ export declare class BaseCLI {
|
|
|
6
6
|
init(): void;
|
|
7
7
|
execute(): void;
|
|
8
8
|
protected setupGTCommand(): void;
|
|
9
|
+
protected setupLoginCommand(): void;
|
|
9
10
|
protected setupInitCommand(): void;
|
|
10
11
|
protected setupConfigureCommand(): void;
|
|
11
12
|
protected setupSetupCommand(): void;
|
|
12
13
|
protected handleGenericTranslate(settings: Settings): Promise<void>;
|
|
13
14
|
protected handleSetupReactCommand(options: SetupOptions): Promise<void>;
|
|
14
15
|
protected handleInitCommand(ranReactSetup: boolean): Promise<void>;
|
|
16
|
+
protected handleLoginCommand(): Promise<void>;
|
|
15
17
|
}
|
package/dist/cli/base.js
CHANGED
|
@@ -50,8 +50,8 @@ const commander_1 = require("commander");
|
|
|
50
50
|
const setupConfig_1 = __importDefault(require("../fs/config/setupConfig"));
|
|
51
51
|
const findFilepath_1 = __importStar(require("../fs/findFilepath"));
|
|
52
52
|
const console_1 = require("../console");
|
|
53
|
-
const
|
|
54
|
-
const
|
|
53
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
54
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
55
55
|
const utils_1 = require("../fs/utils");
|
|
56
56
|
const generateSettings_1 = require("../config/generateSettings");
|
|
57
57
|
const chalk_1 = __importDefault(require("chalk"));
|
|
@@ -62,6 +62,8 @@ const packageJson_1 = require("../utils/packageJson");
|
|
|
62
62
|
const userInput_1 = require("../setup/userInput");
|
|
63
63
|
const installPackage_1 = require("../utils/installPackage");
|
|
64
64
|
const packageManager_1 = require("../utils/packageManager");
|
|
65
|
+
const credentials_1 = require("../utils/credentials");
|
|
66
|
+
const credentials_2 = require("../utils/credentials");
|
|
65
67
|
class BaseCLI {
|
|
66
68
|
// Constructor is shared amongst all CLI class types
|
|
67
69
|
constructor(library, additionalModules) {
|
|
@@ -70,6 +72,7 @@ class BaseCLI {
|
|
|
70
72
|
this.setupInitCommand();
|
|
71
73
|
this.setupConfigureCommand();
|
|
72
74
|
this.setupSetupCommand();
|
|
75
|
+
this.setupLoginCommand();
|
|
73
76
|
}
|
|
74
77
|
// Init is never called in a child class
|
|
75
78
|
init() {
|
|
@@ -90,11 +93,22 @@ class BaseCLI {
|
|
|
90
93
|
.option('--new, --locales <locales...>', 'Space-separated list of locales (e.g., en fr es)')
|
|
91
94
|
.action((options) => __awaiter(this, void 0, void 0, function* () {
|
|
92
95
|
(0, console_1.displayHeader)('Starting translation...');
|
|
93
|
-
const settings = (0, generateSettings_1.generateSettings)(options);
|
|
96
|
+
const settings = yield (0, generateSettings_1.generateSettings)(options);
|
|
94
97
|
yield this.handleGenericTranslate(settings);
|
|
95
98
|
(0, console_1.endCommand)('Done!');
|
|
96
99
|
}));
|
|
97
100
|
}
|
|
101
|
+
setupLoginCommand() {
|
|
102
|
+
commander_1.program
|
|
103
|
+
.command('auth')
|
|
104
|
+
.description('Generate a General Translation API key and project ID')
|
|
105
|
+
.option('-c, --config <path>', 'Filepath to config file, by default gt.config.json', (0, findFilepath_1.default)(['gt.config.json']))
|
|
106
|
+
.action((options) => __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
(0, console_1.displayHeader)('Authenticating with General Translation...');
|
|
108
|
+
yield this.handleLoginCommand();
|
|
109
|
+
(0, console_1.endCommand)('Done!');
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
98
112
|
setupInitCommand() {
|
|
99
113
|
commander_1.program
|
|
100
114
|
.command('init')
|
|
@@ -103,12 +117,12 @@ class BaseCLI {
|
|
|
103
117
|
.option('--config <path>', 'Filepath to config file, by default gt.config.json', (0, findFilepath_1.default)(['gt.config.json']))
|
|
104
118
|
.action((options) => __awaiter(this, void 0, void 0, function* () {
|
|
105
119
|
(0, console_1.displayHeader)('Running setup wizard...');
|
|
106
|
-
const packageJson = (0, packageJson_1.searchForPackageJson)();
|
|
120
|
+
const packageJson = yield (0, packageJson_1.searchForPackageJson)();
|
|
107
121
|
let ranReactSetup = false;
|
|
108
122
|
// so that people can run init in non-js projects
|
|
109
123
|
if (packageJson && (0, packageJson_1.isPackageInstalled)('react', packageJson)) {
|
|
110
124
|
const wrap = yield (0, console_1.promptConfirm)({
|
|
111
|
-
message: `
|
|
125
|
+
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.`,
|
|
112
126
|
defaultValue: true,
|
|
113
127
|
});
|
|
114
128
|
if (wrap) {
|
|
@@ -125,7 +139,7 @@ See the docs for more information: https://generaltranslation.com/docs/react/tut
|
|
|
125
139
|
}
|
|
126
140
|
// Configure gt.config.json
|
|
127
141
|
yield this.handleInitCommand(ranReactSetup);
|
|
128
|
-
(0, console_1.endCommand)('Done!
|
|
142
|
+
(0, console_1.endCommand)('Done! Check out our docs for more information on how to use General Translation: https://generaltranslation.com/docs');
|
|
129
143
|
}));
|
|
130
144
|
}
|
|
131
145
|
setupConfigureCommand() {
|
|
@@ -200,7 +214,7 @@ See the docs for more information: https://generaltranslation.com/docs/react/tut
|
|
|
200
214
|
handleInitCommand(ranReactSetup) {
|
|
201
215
|
return __awaiter(this, void 0, void 0, function* () {
|
|
202
216
|
const { defaultLocale, locales } = yield (0, userInput_1.getDesiredLocales)();
|
|
203
|
-
const packageJson = (0, packageJson_1.searchForPackageJson)();
|
|
217
|
+
const packageJson = yield (0, packageJson_1.searchForPackageJson)();
|
|
204
218
|
const isUsingGTNext = packageJson
|
|
205
219
|
? (0, packageJson_1.isPackageInstalled)('gt-next', packageJson)
|
|
206
220
|
: false;
|
|
@@ -212,7 +226,7 @@ See the docs for more information: https://generaltranslation.com/docs/react/tut
|
|
|
212
226
|
// Ask where the translations are stored
|
|
213
227
|
const usingCDN = isUsingGT
|
|
214
228
|
? yield (0, console_1.promptConfirm)({
|
|
215
|
-
message: `
|
|
229
|
+
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
|
|
216
230
|
? 'https://generaltranslation.com/docs/next/reference/local-tx'
|
|
217
231
|
: 'https://generaltranslation.com/docs/react/reference/local-tx'} for more information.\nIf you answer no, we'll setup your project to store translations locally.`,
|
|
218
232
|
defaultValue: true,
|
|
@@ -252,15 +266,15 @@ See the docs for more information: https://generaltranslation.com/docs/react/tut
|
|
|
252
266
|
// Add GT translations if using GT and storing locally
|
|
253
267
|
if (isUsingGT && !usingCDN && translationsDir) {
|
|
254
268
|
files.gt = {
|
|
255
|
-
output:
|
|
269
|
+
output: node_path_1.default.join(translationsDir, `[locale].json`),
|
|
256
270
|
};
|
|
257
271
|
}
|
|
258
272
|
let configFilepath = 'gt.config.json';
|
|
259
|
-
if (
|
|
273
|
+
if (node_fs_1.default.existsSync('src/gt.config.json')) {
|
|
260
274
|
configFilepath = 'src/gt.config.json';
|
|
261
275
|
}
|
|
262
276
|
// Create gt.config.json
|
|
263
|
-
(0, setupConfig_1.default)(configFilepath, {
|
|
277
|
+
yield (0, setupConfig_1.default)(configFilepath, {
|
|
264
278
|
defaultLocale,
|
|
265
279
|
locales,
|
|
266
280
|
files: Object.keys(files).length > 0 ? files : undefined,
|
|
@@ -277,6 +291,23 @@ See the docs for more information: https://generaltranslation.com/docs/react/tut
|
|
|
277
291
|
yield (0, installPackage_1.installPackage)('gtx-cli', packageManager, true);
|
|
278
292
|
spinner.stop(chalk_1.default.green('Installed gtx-cli.'));
|
|
279
293
|
}
|
|
294
|
+
// Set credentials
|
|
295
|
+
if (!(0, credentials_2.areCredentialsSet)()) {
|
|
296
|
+
const loginQuestion = yield (0, console_1.promptConfirm)({
|
|
297
|
+
message: 'Would you like the wizard to automatically generate an API key and project ID for you?',
|
|
298
|
+
defaultValue: true,
|
|
299
|
+
});
|
|
300
|
+
if (loginQuestion) {
|
|
301
|
+
yield this.handleLoginCommand();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
handleLoginCommand() {
|
|
307
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
308
|
+
const settings = yield (0, generateSettings_1.generateSettings)({});
|
|
309
|
+
const credentials = yield (0, credentials_1.retrieveCredentials)(settings);
|
|
310
|
+
yield (0, credentials_1.setCredentials)(credentials);
|
|
280
311
|
});
|
|
281
312
|
}
|
|
282
313
|
}
|
package/dist/cli/react.js
CHANGED
|
@@ -65,7 +65,7 @@ const save_1 = require("../formats/gt/save");
|
|
|
65
65
|
const generateSettings_1 = require("../config/generateSettings");
|
|
66
66
|
const saveJSON_1 = require("../fs/saveJSON");
|
|
67
67
|
const parseFilesConfig_1 = require("../fs/config/parseFilesConfig");
|
|
68
|
-
const
|
|
68
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
69
69
|
const errors_1 = require("../console/errors");
|
|
70
70
|
const DEFAULT_TIMEOUT = 600;
|
|
71
71
|
const pkg = 'gt-react';
|
|
@@ -151,7 +151,7 @@ class ReactCLI extends base_1.BaseCLI {
|
|
|
151
151
|
}
|
|
152
152
|
handleGenerateSourceCommand(initOptions) {
|
|
153
153
|
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
-
const settings = (0, generateSettings_1.generateSettings)(initOptions);
|
|
154
|
+
const settings = yield (0, generateSettings_1.generateSettings)(initOptions);
|
|
155
155
|
const options = Object.assign(Object.assign({}, initOptions), settings);
|
|
156
156
|
if (!options.dictionary) {
|
|
157
157
|
options.dictionary = (0, findFilepath_1.default)([
|
|
@@ -198,7 +198,7 @@ class ReactCLI extends base_1.BaseCLI {
|
|
|
198
198
|
(0, console_1.logError)(errors_1.noFilesError);
|
|
199
199
|
process.exit(1);
|
|
200
200
|
}
|
|
201
|
-
(0, saveJSON_1.saveJSON)(translationFiles.gt, newData);
|
|
201
|
+
yield (0, saveJSON_1.saveJSON)(translationFiles.gt, newData);
|
|
202
202
|
(0, console_1.logStep)('Source file saved successfully!');
|
|
203
203
|
// Also save translations (after merging with existing translations)
|
|
204
204
|
for (const locale of settings.locales) {
|
|
@@ -210,7 +210,7 @@ class ReactCLI extends base_1.BaseCLI {
|
|
|
210
210
|
const mergedTranslations = Object.assign(Object.assign({}, newData), existingTranslations);
|
|
211
211
|
// Filter out keys that don't exist in newData
|
|
212
212
|
const filteredTranslations = Object.fromEntries(Object.entries(mergedTranslations).filter(([key]) => newData[key]));
|
|
213
|
-
(0, saveJSON_1.saveJSON)(translationsFile.gt, filteredTranslations);
|
|
213
|
+
yield (0, saveJSON_1.saveJSON)(translationsFile.gt, filteredTranslations);
|
|
214
214
|
}
|
|
215
215
|
(0, console_1.logStep)('Merged translations successfully!');
|
|
216
216
|
}
|
|
@@ -228,7 +228,7 @@ class ReactCLI extends base_1.BaseCLI {
|
|
|
228
228
|
process.exit(0);
|
|
229
229
|
}
|
|
230
230
|
// ----- Create a starter gt.config.json file -----
|
|
231
|
-
(0, generateSettings_1.generateSettings)(options);
|
|
231
|
+
yield (0, generateSettings_1.generateSettings)(options);
|
|
232
232
|
// ----- //
|
|
233
233
|
const includeTId = yield (0, console_1.promptConfirm)({
|
|
234
234
|
message: 'Do you want to include an unique id for each <T> tag?',
|
|
@@ -265,7 +265,7 @@ class ReactCLI extends base_1.BaseCLI {
|
|
|
265
265
|
});
|
|
266
266
|
return __awaiter(this, void 0, void 0, function* () {
|
|
267
267
|
var _a, _b;
|
|
268
|
-
const settings = (0, generateSettings_1.generateSettings)(initOptions);
|
|
268
|
+
const settings = yield (0, generateSettings_1.generateSettings)(initOptions);
|
|
269
269
|
// First run the base class's handleTranslate method
|
|
270
270
|
const options = Object.assign(Object.assign({}, initOptions), settings);
|
|
271
271
|
if (!options.dryRun) {
|
|
@@ -341,7 +341,7 @@ class ReactCLI extends base_1.BaseCLI {
|
|
|
341
341
|
// Save translations to local directory if files.gt.output is provided
|
|
342
342
|
if (versionId && options.files.placeholderPaths.gt) {
|
|
343
343
|
const translations = yield (0, fetchTranslations_1.fetchTranslations)(settings.baseUrl, settings.apiKey, versionId);
|
|
344
|
-
(0, save_1.saveTranslations)(translations, options.files.placeholderPaths, 'JSX');
|
|
344
|
+
yield (0, save_1.saveTranslations)(translations, options.files.placeholderPaths, 'JSX');
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
347
|
else {
|
|
@@ -355,8 +355,8 @@ class ReactCLI extends base_1.BaseCLI {
|
|
|
355
355
|
let errors = [];
|
|
356
356
|
// Parse dictionary with esbuildConfig
|
|
357
357
|
if (sourceDictionary &&
|
|
358
|
-
|
|
359
|
-
|
|
358
|
+
node_fs_1.default.existsSync(sourceDictionary) &&
|
|
359
|
+
node_fs_1.default.statSync(sourceDictionary).isFile()) {
|
|
360
360
|
if (sourceDictionary.endsWith('.json')) {
|
|
361
361
|
updates = [
|
|
362
362
|
...updates,
|
|
@@ -4,4 +4,4 @@ import { Settings } from '../types';
|
|
|
4
4
|
* @param options - The options to generate settings from
|
|
5
5
|
* @returns The generated settings
|
|
6
6
|
*/
|
|
7
|
-
export declare function generateSettings(options: any): Settings
|
|
7
|
+
export declare function generateSettings(options: any): Promise<Settings>;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
@@ -8,79 +17,84 @@ const console_1 = require("../console/console");
|
|
|
8
17
|
const warnings_1 = require("../console/warnings");
|
|
9
18
|
const loadConfig_1 = __importDefault(require("../fs/config/loadConfig"));
|
|
10
19
|
const internal_1 = require("generaltranslation/internal");
|
|
11
|
-
const
|
|
20
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
12
21
|
const setupConfig_1 = __importDefault(require("../fs/config/setupConfig"));
|
|
13
22
|
const parseFilesConfig_1 = require("../fs/config/parseFilesConfig");
|
|
14
23
|
const findFilepath_1 = require("../fs/findFilepath");
|
|
15
24
|
const validateSettings_1 = require("./validateSettings");
|
|
25
|
+
const constants_1 = require("../utils/constants");
|
|
16
26
|
/**
|
|
17
27
|
* Generates settings from any
|
|
18
28
|
* @param options - The options to generate settings from
|
|
19
29
|
* @returns The generated settings
|
|
20
30
|
*/
|
|
21
31
|
function generateSettings(options) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
options.config
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
mergedOptions.projectId
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
mergedOptions.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
var _a;
|
|
34
|
+
// Load config file
|
|
35
|
+
let gtConfig = {};
|
|
36
|
+
if (options.config && !options.config.endsWith('.json')) {
|
|
37
|
+
options.config = `${options.config}.json`;
|
|
38
|
+
}
|
|
39
|
+
if (options.config) {
|
|
40
|
+
gtConfig = (0, loadConfig_1.default)(options.config);
|
|
41
|
+
}
|
|
42
|
+
else if (node_fs_1.default.existsSync('gt.config.json')) {
|
|
43
|
+
options.config = 'gt.config.json';
|
|
44
|
+
gtConfig = (0, loadConfig_1.default)('gt.config.json');
|
|
45
|
+
}
|
|
46
|
+
else if (node_fs_1.default.existsSync('src/gt.config.json')) {
|
|
47
|
+
options.config = 'src/gt.config.json';
|
|
48
|
+
gtConfig = (0, loadConfig_1.default)('src/gt.config.json');
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
// If neither config exists, use empty config
|
|
52
|
+
gtConfig = {};
|
|
53
|
+
}
|
|
54
|
+
// Warn if apiKey is present in gt.config.json
|
|
55
|
+
if (gtConfig.apiKey) {
|
|
56
|
+
(0, warnings_1.warnApiKeyInConfig)(options.config);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
// merge options
|
|
60
|
+
const mergedOptions = Object.assign(Object.assign({}, gtConfig), options);
|
|
61
|
+
// merge locales
|
|
62
|
+
mergedOptions.locales = Array.from(new Set([...(gtConfig.locales || []), ...(options.locales || [])]));
|
|
63
|
+
// Add apiKey if not provided
|
|
64
|
+
mergedOptions.apiKey = mergedOptions.apiKey || process.env.GT_API_KEY;
|
|
65
|
+
// Add projectId if not provided
|
|
66
|
+
mergedOptions.projectId =
|
|
67
|
+
mergedOptions.projectId || process.env.GT_PROJECT_ID;
|
|
68
|
+
// Add baseUrl if not provided
|
|
69
|
+
mergedOptions.baseUrl = mergedOptions.baseUrl || internal_1.defaultBaseUrl;
|
|
70
|
+
// Add dashboardUrl if not provided
|
|
71
|
+
mergedOptions.dashboardUrl = mergedOptions.dashboardUrl || constants_1.GT_DASHBOARD_URL;
|
|
72
|
+
// Add defaultLocale if not provided
|
|
73
|
+
mergedOptions.defaultLocale =
|
|
74
|
+
mergedOptions.defaultLocale || internal_1.libraryDefaultLocale;
|
|
75
|
+
// Add locales if not provided
|
|
76
|
+
mergedOptions.locales = mergedOptions.locales || [];
|
|
77
|
+
// Add default config file name if not provided
|
|
78
|
+
mergedOptions.config = mergedOptions.config || 'gt.config.json';
|
|
79
|
+
// Display projectId if present
|
|
80
|
+
if (mergedOptions.projectId)
|
|
81
|
+
(0, console_1.displayProjectId)(mergedOptions.projectId);
|
|
82
|
+
// Populate src if not provided
|
|
83
|
+
mergedOptions.src =
|
|
84
|
+
mergedOptions.src ||
|
|
85
|
+
(0, findFilepath_1.findFilepaths)(['./src', './app', './pages', './components']);
|
|
86
|
+
// Resolve all glob patterns in the files object
|
|
87
|
+
mergedOptions.files = (0, parseFilesConfig_1.resolveFiles)(mergedOptions.files || {}, mergedOptions.defaultLocale);
|
|
88
|
+
// if there's no existing config file, creates one
|
|
89
|
+
// does not include the API key to avoid exposing it
|
|
90
|
+
if (!node_fs_1.default.existsSync(mergedOptions.config)) {
|
|
91
|
+
yield (0, setupConfig_1.default)(mergedOptions.config, {
|
|
92
|
+
projectId: mergedOptions.projectId,
|
|
93
|
+
defaultLocale: mergedOptions.defaultLocale,
|
|
94
|
+
locales: ((_a = mergedOptions.locales) === null || _a === void 0 ? void 0 : _a.length) > 0 ? mergedOptions.locales : undefined,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
(0, validateSettings_1.validateSettings)(mergedOptions);
|
|
98
|
+
return mergedOptions;
|
|
99
|
+
});
|
|
86
100
|
}
|
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.saveTranslatedFile = saveTranslatedFile;
|
|
16
16
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
17
|
-
const
|
|
17
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
18
18
|
const console_1 = require("../../console");
|
|
19
19
|
/**
|
|
20
20
|
* Saves translated MDX/MD file content to the appropriate location
|
|
@@ -23,10 +23,10 @@ function saveTranslatedFile(translatedContent, outputDir, fileName, dataFormat,
|
|
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
24
|
// Create locale-specific directories if they don't exist
|
|
25
25
|
for (const locale of locales) {
|
|
26
|
-
const localeDir =
|
|
26
|
+
const localeDir = node_path_1.default.join(outputDir, locale);
|
|
27
27
|
yield promises_1.default.mkdir(localeDir, { recursive: true });
|
|
28
28
|
// Save the translated file with the appropriate extension
|
|
29
|
-
const outputPath =
|
|
29
|
+
const outputPath = node_path_1.default.join(localeDir, fileName);
|
|
30
30
|
yield promises_1.default.writeFile(outputPath, translatedContent);
|
|
31
31
|
(0, console_1.logSuccess)(`Saved translated ${dataFormat} file to: ${outputPath}`);
|
|
32
32
|
}
|
|
@@ -19,7 +19,7 @@ const console_1 = require("../../console");
|
|
|
19
19
|
const parseFilesConfig_1 = require("../../fs/config/parseFilesConfig");
|
|
20
20
|
const findFilepath_1 = require("../../fs/findFilepath");
|
|
21
21
|
const flattenDictionary_1 = require("../../react/utils/flattenDictionary");
|
|
22
|
-
const
|
|
22
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
23
23
|
const chalk_1 = __importDefault(require("chalk"));
|
|
24
24
|
const downloadFile_1 = require("../../api/downloadFile");
|
|
25
25
|
const downloadFileBatch_1 = require("../../api/downloadFileBatch");
|
|
@@ -116,13 +116,13 @@ function createFileMapping(filePaths, placeholderPaths, transformPaths, locales)
|
|
|
116
116
|
const transformPath = transformPaths[typeIndex];
|
|
117
117
|
if (transformPath) {
|
|
118
118
|
translatedFiles = translatedFiles.map((filePath) => {
|
|
119
|
-
const directory =
|
|
120
|
-
const fileName =
|
|
119
|
+
const directory = node_path_1.default.dirname(filePath);
|
|
120
|
+
const fileName = node_path_1.default.basename(filePath);
|
|
121
121
|
const baseName = fileName.split('.')[0];
|
|
122
122
|
const transformedFileName = transformPath
|
|
123
123
|
.replace('*', baseName)
|
|
124
124
|
.replace('[locale]', locale);
|
|
125
|
-
return
|
|
125
|
+
return node_path_1.default.join(directory, transformedFileName);
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
128
|
for (let i = 0; i < sourcePaths.length; i++) {
|
|
@@ -7,4 +7,4 @@ import { DataFormat } from '../../types/data';
|
|
|
7
7
|
* @param translationsDir - The directory to save the translations to
|
|
8
8
|
* @param fileType - The file type to save the translations as (file extension)
|
|
9
9
|
*/
|
|
10
|
-
export declare function saveTranslations(translations: RetrievedTranslations, placeholderPaths: ResolvedFiles, dataFormat: DataFormat): void
|
|
10
|
+
export declare function saveTranslations(translations: RetrievedTranslations, placeholderPaths: ResolvedFiles, dataFormat: DataFormat): Promise<void>;
|
package/dist/formats/gt/save.js
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
5
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
15
|
exports.saveTranslations = saveTranslations;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
16
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
17
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
18
|
const errors_1 = require("../../console/errors");
|
|
10
19
|
const parseFilesConfig_1 = require("../../fs/config/parseFilesConfig");
|
|
11
20
|
/**
|
|
@@ -15,20 +24,22 @@ const parseFilesConfig_1 = require("../../fs/config/parseFilesConfig");
|
|
|
15
24
|
* @param fileType - The file type to save the translations as (file extension)
|
|
16
25
|
*/
|
|
17
26
|
function saveTranslations(translations, placeholderPaths, dataFormat) {
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
for (const translation of translations) {
|
|
29
|
+
const locale = translation.locale;
|
|
30
|
+
const translationFiles = (0, parseFilesConfig_1.resolveLocaleFiles)(placeholderPaths, locale);
|
|
31
|
+
if (!translationFiles.gt) {
|
|
32
|
+
(0, errors_1.logError)(errors_1.noFilesError);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
const filepath = translationFiles.gt;
|
|
36
|
+
const translationData = translation.translation;
|
|
37
|
+
// Ensure directory exists
|
|
38
|
+
yield node_fs_1.default.promises.mkdir(node_path_1.default.dirname(filepath), { recursive: true });
|
|
39
|
+
// Handle different file types
|
|
40
|
+
if (dataFormat === 'JSX') {
|
|
41
|
+
yield node_fs_1.default.promises.writeFile(filepath, JSON.stringify(translationData, null, 2));
|
|
42
|
+
}
|
|
32
43
|
}
|
|
33
|
-
}
|
|
44
|
+
});
|
|
34
45
|
}
|
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = loadConfig;
|
|
7
|
-
const
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
8
|
function loadConfig(filepath) {
|
|
9
9
|
try {
|
|
10
|
-
return JSON.parse(
|
|
10
|
+
return JSON.parse(node_fs_1.default.readFileSync(filepath, 'utf-8'));
|
|
11
11
|
}
|
|
12
12
|
catch (error) {
|
|
13
13
|
return {};
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.resolveLocaleFiles = resolveLocaleFiles;
|
|
7
7
|
exports.resolveFiles = resolveFiles;
|
|
8
|
-
const
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
10
10
|
const supportedFiles_1 = require("../../formats/files/supportedFiles");
|
|
11
11
|
const console_1 = require("../../console");
|
|
@@ -94,9 +94,9 @@ function expandGlobPatterns(includePatterns, excludePatterns, locale, transformP
|
|
|
94
94
|
expandedPattern.includes('?') ||
|
|
95
95
|
expandedPattern.includes('{')) {
|
|
96
96
|
// Resolve the absolute pattern path
|
|
97
|
-
const absolutePattern =
|
|
97
|
+
const absolutePattern = node_path_1.default.resolve(process.cwd(), expandedPattern);
|
|
98
98
|
// Prepare exclude patterns with locale replaced
|
|
99
|
-
const expandedExcludePatterns = excludePatterns.map((p) =>
|
|
99
|
+
const expandedExcludePatterns = excludePatterns.map((p) => node_path_1.default.resolve(process.cwd(), p.replace(/\[locale\]/g, locale)));
|
|
100
100
|
// Use fast-glob to find all matching files, excluding the patterns
|
|
101
101
|
const matches = fast_glob_1.default.sync(absolutePattern, {
|
|
102
102
|
absolute: true,
|
|
@@ -106,14 +106,14 @@ function expandGlobPatterns(includePatterns, excludePatterns, locale, transformP
|
|
|
106
106
|
// For each match, create a version with [locale] in the correct positions
|
|
107
107
|
matches.forEach((match) => {
|
|
108
108
|
// Convert to relative path to make replacement easier
|
|
109
|
-
const relativePath =
|
|
109
|
+
const relativePath = node_path_1.default.relative(process.cwd(), match);
|
|
110
110
|
let originalRelativePath = relativePath;
|
|
111
111
|
// Replace locale with [locale] at each tracked position
|
|
112
112
|
if (localePositions.length > 0) {
|
|
113
113
|
// We need to account for path resolution differences
|
|
114
114
|
// This is a simplified approach - we'll replace all instances of the locale
|
|
115
115
|
// but only in path segments where we expect it based on the original pattern
|
|
116
|
-
const pathParts = relativePath.split(
|
|
116
|
+
const pathParts = relativePath.split(node_path_1.default.sep);
|
|
117
117
|
const patternParts = pattern.split(/[\/\\]/); // Handle both slash types
|
|
118
118
|
for (let i = 0; i < pathParts.length; i++) {
|
|
119
119
|
if (i < patternParts.length) {
|
|
@@ -123,18 +123,18 @@ function expandGlobPatterns(includePatterns, excludePatterns, locale, transformP
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
originalRelativePath = pathParts.join(
|
|
126
|
+
originalRelativePath = pathParts.join(node_path_1.default.sep);
|
|
127
127
|
}
|
|
128
128
|
// Convert back to absolute path
|
|
129
|
-
const originalPath =
|
|
129
|
+
const originalPath = node_path_1.default.resolve(process.cwd(), originalRelativePath);
|
|
130
130
|
placeholderPaths.push(originalPath);
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
133
|
else {
|
|
134
134
|
// If it's not a glob pattern, just add the resolved path if it's not excluded
|
|
135
|
-
const absolutePath =
|
|
135
|
+
const absolutePath = node_path_1.default.resolve(process.cwd(), expandedPattern);
|
|
136
136
|
// Check if this path should be excluded
|
|
137
|
-
const expandedExcludePatterns = excludePatterns.map((p) =>
|
|
137
|
+
const expandedExcludePatterns = excludePatterns.map((p) => node_path_1.default.resolve(process.cwd(), p.replace(/\[locale\]/g, locale)));
|
|
138
138
|
// Only include if not matched by any exclude pattern
|
|
139
139
|
const shouldExclude = expandedExcludePatterns.some((excludePattern) => {
|
|
140
140
|
if (excludePattern.includes('*') ||
|
|
@@ -150,7 +150,7 @@ function expandGlobPatterns(includePatterns, excludePatterns, locale, transformP
|
|
|
150
150
|
resolvedPaths.push(absolutePath);
|
|
151
151
|
// For non-glob patterns, we can directly replace locale with [locale]
|
|
152
152
|
// at the tracked positions in the resolved path
|
|
153
|
-
let originalPath =
|
|
153
|
+
let originalPath = node_path_1.default.resolve(process.cwd(), pattern);
|
|
154
154
|
placeholderPaths.push(originalPath);
|
|
155
155
|
}
|
|
156
156
|
}
|