gtx-cli 0.0.2 → 1.0.0-alpha.2
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/fetchTranslations.d.ts +10 -0
- package/dist/{fs/saveTranslations.js → api/fetchTranslations.js} +12 -27
- package/dist/api/sendUpdates.d.ts +18 -0
- package/dist/api/sendUpdates.js +72 -0
- package/dist/api/waitForUpdates.d.ts +10 -0
- package/dist/api/waitForUpdates.js +10 -0
- package/dist/cli/base.d.ts +7 -1
- package/dist/cli/base.js +182 -2
- package/dist/cli/next.d.ts +3 -1
- package/dist/cli/next.js +12 -8
- package/dist/cli/react.d.ts +2 -0
- package/dist/cli/react.js +70 -143
- package/dist/config/generateSettings.d.ts +7 -0
- package/dist/config/generateSettings.js +73 -0
- package/dist/console/errors.d.ts +8 -0
- package/dist/console/errors.js +9 -1
- package/dist/formats/gt/save.d.ts +9 -0
- package/dist/formats/gt/save.js +27 -0
- package/dist/formats/json/save.d.ts +9 -0
- package/dist/formats/json/save.js +60 -0
- package/dist/formats/json/translate.d.ts +15 -0
- package/dist/formats/json/translate.js +61 -0
- package/dist/fs/config/setupConfig.d.ts +6 -1
- package/dist/fs/config/setupConfig.js +11 -3
- package/dist/fs/determineFramework.d.ts +2 -0
- package/dist/fs/determineFramework.js +46 -0
- package/dist/fs/findFilepath.d.ts +14 -0
- package/dist/fs/findFilepath.js +29 -0
- package/dist/fs/saveJSON.d.ts +1 -0
- package/dist/fs/saveJSON.js +13 -0
- package/dist/fs/utils.d.ts +1 -0
- package/dist/fs/utils.js +19 -0
- package/dist/index.js +7 -67
- package/dist/react/jsx/parse/parseStringFunction.d.ts +12 -0
- package/dist/react/jsx/parse/parseStringFunction.js +120 -0
- package/dist/react/jsx/utils/parseJsx.js +1 -1
- package/dist/react/jsx/utils/parseStringFunction.js +1 -1
- package/dist/react/parse/createDictionaryUpdates.js +1 -1
- package/dist/react/updates/createDictionaryUpdates.d.ts +5 -0
- package/dist/react/updates/createDictionaryUpdates.js +76 -0
- package/dist/react/updates/createInlineUpdates.d.ts +5 -0
- package/dist/react/updates/createInlineUpdates.js +141 -0
- package/dist/react/updates/scanForContent.d.ts +13 -0
- package/dist/react/updates/scanForContent.js +200 -0
- package/dist/react/utils/flattenDictionary.d.ts +11 -1
- package/dist/react/utils/flattenDictionary.js +40 -0
- package/dist/react/utils/getEntryAndMetadata.d.ts +2 -2
- package/dist/types/api.d.ts +6 -0
- package/dist/types/data.d.ts +31 -0
- package/dist/{types.d.ts → types/index.d.ts} +21 -6
- package/dist/types/index.js +2 -0
- package/package.json +3 -3
- package/dist/fs/saveTranslations.d.ts +0 -3
- package/dist/react/types.d.ts +0 -13
- /package/dist/{react/types.js → types/api.js} +0 -0
- /package/dist/{types.js → types/data.js} +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RetrievedTranslations } from '../types/api';
|
|
2
|
+
/**
|
|
3
|
+
* Fetches translations from the API and saves them to a local directory
|
|
4
|
+
* @param baseUrl - The base URL for the API
|
|
5
|
+
* @param apiKey - The API key for the API
|
|
6
|
+
* @param versionId - The version ID of the project
|
|
7
|
+
* @param translationsDir - The directory to save the translations to
|
|
8
|
+
* @param fileType - The file type to save the translations as (file extension)
|
|
9
|
+
*/
|
|
10
|
+
export declare function fetchTranslations(baseUrl: string, apiKey: string, versionId: string): Promise<RetrievedTranslations>;
|
|
@@ -12,12 +12,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
16
|
-
exports.saveSourceFile = saveSourceFile;
|
|
15
|
+
exports.fetchTranslations = fetchTranslations;
|
|
17
16
|
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Fetches translations from the API and saves them to a local directory
|
|
19
|
+
* @param baseUrl - The base URL for the API
|
|
20
|
+
* @param apiKey - The API key for the API
|
|
21
|
+
* @param versionId - The version ID of the project
|
|
22
|
+
* @param translationsDir - The directory to save the translations to
|
|
23
|
+
* @param fileType - The file type to save the translations as (file extension)
|
|
24
|
+
*/
|
|
25
|
+
function fetchTranslations(baseUrl, apiKey, versionId) {
|
|
21
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
27
|
// First fetch the translations from the API
|
|
23
28
|
const response = yield fetch(`${baseUrl}/v1/project/translations/info/${encodeURIComponent(versionId)}`, {
|
|
@@ -27,31 +32,11 @@ function saveTranslations(baseUrl, apiKey, versionId, translationsDir) {
|
|
|
27
32
|
if (response.ok) {
|
|
28
33
|
const data = yield response.json();
|
|
29
34
|
const translations = data.translations;
|
|
30
|
-
|
|
31
|
-
const locale = translation.locale;
|
|
32
|
-
const translationData = translation.translation;
|
|
33
|
-
const filepath = path_1.default.join(translationsDir, `${locale}.json`);
|
|
34
|
-
// Ensure directory exists
|
|
35
|
-
fs_1.default.mkdirSync(path_1.default.dirname(filepath), { recursive: true });
|
|
36
|
-
fs_1.default.writeFileSync(filepath, JSON.stringify(translationData, null, 2));
|
|
37
|
-
}
|
|
38
|
-
console.log(chalk_1.default.green('Translations saved successfully!'));
|
|
35
|
+
return translations;
|
|
39
36
|
}
|
|
40
37
|
else {
|
|
41
38
|
console.error(chalk_1.default.red('Failed to fetch translations'));
|
|
42
39
|
}
|
|
40
|
+
return [];
|
|
43
41
|
});
|
|
44
42
|
}
|
|
45
|
-
function saveSourceFile(filepath, data) {
|
|
46
|
-
// Ensure directory exists
|
|
47
|
-
fs_1.default.mkdirSync(path_1.default.dirname(filepath), { recursive: true });
|
|
48
|
-
// Convert updates to the proper data format
|
|
49
|
-
const obj = {};
|
|
50
|
-
for (const update of data) {
|
|
51
|
-
const { source, metadata } = update;
|
|
52
|
-
const { hash } = metadata;
|
|
53
|
-
obj[hash] = source;
|
|
54
|
-
}
|
|
55
|
-
fs_1.default.writeFileSync(filepath, JSON.stringify(obj, null, 2));
|
|
56
|
-
console.log(chalk_1.default.green('Source file saved successfully!'));
|
|
57
|
-
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Settings, Updates } from '../types';
|
|
2
|
+
import { DataFormat } from '../types/data';
|
|
3
|
+
type ApiOptions = Settings & {
|
|
4
|
+
publish: boolean;
|
|
5
|
+
wait: boolean;
|
|
6
|
+
timeout: string;
|
|
7
|
+
dataFormat: DataFormat;
|
|
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): Promise<{
|
|
16
|
+
versionId: any;
|
|
17
|
+
} | undefined>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.sendUpdates = sendUpdates;
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
const console_1 = require("../console/console");
|
|
18
|
+
const updateConfig_1 = __importDefault(require("../fs/config/updateConfig"));
|
|
19
|
+
const waitForUpdates_1 = require("./waitForUpdates");
|
|
20
|
+
/**
|
|
21
|
+
* Sends updates to the API
|
|
22
|
+
* @param updates - The updates to send
|
|
23
|
+
* @param options - The options for the API call
|
|
24
|
+
* @returns The versionId of the updated project
|
|
25
|
+
*/
|
|
26
|
+
function sendUpdates(updates, options) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const { apiKey, projectId, defaultLocale, dataFormat } = options;
|
|
29
|
+
const globalMetadata = Object.assign(Object.assign({}, (projectId && { projectId })), (defaultLocale && { sourceLocale: defaultLocale }));
|
|
30
|
+
// If additionalLocales is provided, additionalLocales + project.current_locales will be translated
|
|
31
|
+
// If not, then options.locales will be translated
|
|
32
|
+
// If neither, then project.current_locales will be translated
|
|
33
|
+
const body = Object.assign(Object.assign(Object.assign(Object.assign({ updates }, (options.locales && { locales: options.locales })), { metadata: globalMetadata, publish: options.publish }), (dataFormat && { dataFormat })), (options.versionId && { versionId: options.versionId }));
|
|
34
|
+
const spinner = yield (0, console_1.displayLoadingAnimation)('Sending updates to General Translation API...');
|
|
35
|
+
try {
|
|
36
|
+
const startTime = Date.now();
|
|
37
|
+
const response = yield fetch(`${options.baseUrl}/v1/project/translations/update`, {
|
|
38
|
+
method: 'POST',
|
|
39
|
+
headers: Object.assign({ 'Content-Type': 'application/json' }, (apiKey && { 'x-gt-api-key': apiKey })),
|
|
40
|
+
body: JSON.stringify(body),
|
|
41
|
+
});
|
|
42
|
+
process.stdout.write('\n\n');
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
spinner.fail(yield response.text());
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
if (response.status === 204) {
|
|
48
|
+
spinner.succeed(yield response.text());
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const { versionId, message, locales } = yield response.json();
|
|
52
|
+
spinner.succeed(chalk_1.default.green(message));
|
|
53
|
+
if (options.config)
|
|
54
|
+
(0, updateConfig_1.default)({
|
|
55
|
+
configFilepath: options.config,
|
|
56
|
+
_versionId: versionId,
|
|
57
|
+
locales,
|
|
58
|
+
});
|
|
59
|
+
// Wait for translations if wait is true
|
|
60
|
+
if (options.wait && locales) {
|
|
61
|
+
// timeout was validated earlier
|
|
62
|
+
const timeout = parseInt(options.timeout) * 1000;
|
|
63
|
+
const result = yield (0, waitForUpdates_1.waitForUpdates)(apiKey, options.baseUrl, versionId, locales, startTime, timeout);
|
|
64
|
+
}
|
|
65
|
+
return { versionId };
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
spinner.fail(chalk_1.default.red('Failed to send updates'));
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
@@ -1 +1,11 @@
|
|
|
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
|
+
*/
|
|
1
11
|
export declare const waitForUpdates: (apiKey: string, baseUrl: string, versionId: string, locales: string[], startTime: number, timeoutDuration: number) => Promise<boolean>;
|
|
@@ -16,6 +16,16 @@ exports.waitForUpdates = void 0;
|
|
|
16
16
|
const chalk_1 = __importDefault(require("chalk"));
|
|
17
17
|
const console_1 = require("../console/console");
|
|
18
18
|
const generaltranslation_1 = require("generaltranslation");
|
|
19
|
+
/**
|
|
20
|
+
* Waits for translations to be deployed to the General Translation API
|
|
21
|
+
* @param apiKey - The API key for the General Translation API
|
|
22
|
+
* @param baseUrl - The base URL for the General Translation API
|
|
23
|
+
* @param versionId - The version ID of the project
|
|
24
|
+
* @param locales - The locales to wait for
|
|
25
|
+
* @param startTime - The start time of the wait
|
|
26
|
+
* @param timeoutDuration - The timeout duration for the wait
|
|
27
|
+
* @returns True if all translations are deployed, false otherwise
|
|
28
|
+
*/
|
|
19
29
|
const waitForUpdates = (apiKey, baseUrl, versionId, locales, startTime, timeoutDuration) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
30
|
const spinner = yield (0, console_1.displayLoadingAnimation)('Waiting for translation...');
|
|
21
31
|
const availableLocales = [];
|
package/dist/cli/base.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { SupportedLibraries } from '../types';
|
|
1
2
|
export declare class BaseCLI {
|
|
2
|
-
|
|
3
|
+
private library;
|
|
4
|
+
constructor(library: SupportedLibraries);
|
|
5
|
+
init(): void;
|
|
6
|
+
execute(): void;
|
|
7
|
+
protected setupGTCommand(): void;
|
|
8
|
+
protected setupInitCommand(): void;
|
|
3
9
|
}
|
package/dist/cli/base.js
CHANGED
|
@@ -1,11 +1,191 @@
|
|
|
1
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
2
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
48
|
exports.BaseCLI = void 0;
|
|
4
|
-
// packages/gt-cli-core/src/BaseCLI.ts
|
|
5
49
|
const commander_1 = require("commander");
|
|
50
|
+
const console_1 = require("../console/console");
|
|
51
|
+
const console_2 = require("../console/console");
|
|
52
|
+
const setupConfig_1 = __importDefault(require("../fs/config/setupConfig"));
|
|
53
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
54
|
+
const generaltranslation_1 = require("generaltranslation");
|
|
55
|
+
const findFilepath_1 = __importStar(require("../fs/findFilepath"));
|
|
56
|
+
const errors_1 = require("../console/errors");
|
|
57
|
+
const path_1 = __importDefault(require("path"));
|
|
58
|
+
const yaml_1 = __importDefault(require("yaml"));
|
|
59
|
+
const translate_1 = require("../formats/json/translate");
|
|
60
|
+
const utils_1 = require("../fs/utils");
|
|
61
|
+
const generateSettings_1 = require("../config/generateSettings");
|
|
62
|
+
const SUPPORTED_DATA_FORMATS = ['JSX', 'ICU', 'I18NEXT'];
|
|
6
63
|
class BaseCLI {
|
|
7
|
-
|
|
64
|
+
// Constructor is shared amongst all CLI class types
|
|
65
|
+
constructor(library) {
|
|
66
|
+
this.library = library;
|
|
67
|
+
this.setupInitCommand();
|
|
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() {
|
|
8
75
|
commander_1.program.parse();
|
|
9
76
|
}
|
|
77
|
+
setupGTCommand() {
|
|
78
|
+
commander_1.program
|
|
79
|
+
.command('translate')
|
|
80
|
+
.description('Translate your project using General Translation')
|
|
81
|
+
.option('-c, --config <path>', 'Filepath to config file, by default gt.config.json', (0, findFilepath_1.default)(['gt.config.json']))
|
|
82
|
+
.option('--api-key <key>', 'API key for General Translation cloud service')
|
|
83
|
+
.option('--project-id <id>', 'Project ID for the translation service', (0, utils_1.resolveProjectId)())
|
|
84
|
+
.option('--default-language, --default-locale <locale>', 'Default locale (e.g., en)')
|
|
85
|
+
.option('--new, --locales <locales...>', 'Space-separated list of locales (e.g., en fr es)')
|
|
86
|
+
.option('-t, --translations-dir, --translation-dir <path>', 'Directory containing your language files. Should be in the format path/to/translations/*.json or path/to/translations/*.yaml')
|
|
87
|
+
.action((options) => __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
(0, console_1.displayAsciiTitle)();
|
|
89
|
+
(0, console_2.displayInitializingText)();
|
|
90
|
+
const settings = (0, generateSettings_1.generateSettings)(options);
|
|
91
|
+
if (!settings.locales) {
|
|
92
|
+
console.error(errors_1.noLocalesError);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
if (!settings.defaultLocale) {
|
|
96
|
+
console.error(errors_1.noDefaultLocaleError);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
if (!settings.translationsDir) {
|
|
100
|
+
console.error(errors_1.noTranslationsDirError);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
if (!settings.apiKey) {
|
|
104
|
+
console.error(errors_1.noApiKeyError);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
if (!settings.projectId) {
|
|
108
|
+
console.error(errors_1.noProjectIdError);
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
// ---- CREATING UPDATES ---- //
|
|
112
|
+
// Find the source file in the translationsDir
|
|
113
|
+
const rawSource = (0, findFilepath_1.findFile)(settings.translationsDir, settings.defaultLocale);
|
|
114
|
+
if (!rawSource) {
|
|
115
|
+
console.error(errors_1.noSourceFileError);
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
118
|
+
// Get the data format from the ending of the translationsDir
|
|
119
|
+
const fileExtension = settings.translationsDir
|
|
120
|
+
.split('.')
|
|
121
|
+
.pop();
|
|
122
|
+
const dataFormat = this.library === 'next-intl'
|
|
123
|
+
? 'ICU'
|
|
124
|
+
: this.library === 'react-i18next'
|
|
125
|
+
? 'I18NEXT'
|
|
126
|
+
: this.library === 'next-i18next'
|
|
127
|
+
? 'I18NEXT'
|
|
128
|
+
: 'JSX';
|
|
129
|
+
if (!dataFormat) {
|
|
130
|
+
console.error(errors_1.noDataFormatError);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
else if (!SUPPORTED_DATA_FORMATS.includes(dataFormat)) {
|
|
134
|
+
console.error(errors_1.noSupportedDataFormatError);
|
|
135
|
+
process.exit(1);
|
|
136
|
+
}
|
|
137
|
+
const source = fileExtension === 'json'
|
|
138
|
+
? JSON.parse(rawSource)
|
|
139
|
+
: yaml_1.default.parse(rawSource);
|
|
140
|
+
const result = yield (0, translate_1.translateJson)(source, settings, dataFormat, fileExtension);
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
setupInitCommand() {
|
|
144
|
+
commander_1.program
|
|
145
|
+
.command('init')
|
|
146
|
+
.description('Initialize project for General Translation')
|
|
147
|
+
.action(() => __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
(0, console_1.displayAsciiTitle)();
|
|
149
|
+
(0, console_2.displayInitializingText)();
|
|
150
|
+
// Ask where the translations are stored
|
|
151
|
+
const translationsDir = yield (0, prompts_1.input)({
|
|
152
|
+
message: 'Where is the directory containing your language files?',
|
|
153
|
+
});
|
|
154
|
+
// Ask for the default locale
|
|
155
|
+
const defaultLocale = yield (0, prompts_1.input)({
|
|
156
|
+
message: 'What is the default locale for your project?',
|
|
157
|
+
});
|
|
158
|
+
// Ask for the locales
|
|
159
|
+
const locales = yield (0, prompts_1.input)({
|
|
160
|
+
message: 'What locales would you like to translate using General Translation? (space-separated list)',
|
|
161
|
+
validate: (input) => {
|
|
162
|
+
const locales = input.split(' ');
|
|
163
|
+
if (locales.length === 0) {
|
|
164
|
+
return 'Please enter at least one locale';
|
|
165
|
+
}
|
|
166
|
+
for (const locale of locales) {
|
|
167
|
+
if (!(0, generaltranslation_1.isValidLocale)(locale)) {
|
|
168
|
+
return 'Please enter a valid locale (e.g., en, fr, es)';
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return true;
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
const dataFormat = yield (0, prompts_1.select)({
|
|
175
|
+
message: 'What is the format of your language files?',
|
|
176
|
+
choices: ['.json', '.yaml'],
|
|
177
|
+
default: '.json',
|
|
178
|
+
});
|
|
179
|
+
// combine translationsDir and dataFormat into something like
|
|
180
|
+
// translationsDir/*[.json|.yaml]
|
|
181
|
+
const translationsDirWithFormat = path_1.default.join(translationsDir, `*${dataFormat}`);
|
|
182
|
+
// Create gt.config.json
|
|
183
|
+
(0, setupConfig_1.default)('gt.config.json', {
|
|
184
|
+
defaultLocale,
|
|
185
|
+
locales: locales.split(' '),
|
|
186
|
+
translationsDir: translationsDirWithFormat,
|
|
187
|
+
});
|
|
188
|
+
}));
|
|
189
|
+
}
|
|
10
190
|
}
|
|
11
191
|
exports.BaseCLI = BaseCLI;
|
package/dist/cli/next.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { WrapOptions, Options, Updates, SetupOptions, SupportedFrameworks } from '
|
|
1
|
+
import { WrapOptions, Options, Updates, SetupOptions, SupportedFrameworks } from '../types';
|
|
2
2
|
import { ReactCLI } from './react';
|
|
3
3
|
export declare class NextCLI extends ReactCLI {
|
|
4
4
|
constructor();
|
|
5
|
+
init(): void;
|
|
6
|
+
execute(): void;
|
|
5
7
|
protected scanForContent(options: WrapOptions, framework: SupportedFrameworks): Promise<{
|
|
6
8
|
errors: string[];
|
|
7
9
|
filesUpdated: string[];
|
package/dist/cli/next.js
CHANGED
|
@@ -13,26 +13,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.NextCLI = void 0;
|
|
16
|
-
const console_1 = require("
|
|
16
|
+
const console_1 = require("../console/console");
|
|
17
17
|
const chalk_1 = __importDefault(require("chalk"));
|
|
18
18
|
const prompts_1 = require("@inquirer/prompts");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const findFilepath_1 = __importDefault(require("gt-react-cli/fs/findFilepath"));
|
|
19
|
+
const postProcess_1 = require("../hooks/postProcess");
|
|
20
|
+
const findFilepath_1 = __importDefault(require("../fs/findFilepath"));
|
|
22
21
|
const scanForContent_1 = __importDefault(require("../next/parse/scanForContent"));
|
|
23
|
-
const createDictionaryUpdates_1 = __importDefault(require("
|
|
24
|
-
const createInlineUpdates_1 = __importDefault(require("
|
|
22
|
+
const createDictionaryUpdates_1 = __importDefault(require("../react/updates/createDictionaryUpdates"));
|
|
23
|
+
const createInlineUpdates_1 = __importDefault(require("../react/updates/createInlineUpdates"));
|
|
25
24
|
const handleInitGT_1 = __importDefault(require("../next/parse/handleInitGT"));
|
|
26
25
|
const react_1 = require("./react");
|
|
26
|
+
const generateSettings_1 = require("../config/generateSettings");
|
|
27
27
|
const pkg = 'gt-next';
|
|
28
28
|
class NextCLI extends react_1.ReactCLI {
|
|
29
29
|
constructor() {
|
|
30
30
|
super();
|
|
31
|
+
}
|
|
32
|
+
init() {
|
|
31
33
|
this.setupTranslateCommand();
|
|
32
34
|
this.setupSetupCommand();
|
|
33
35
|
this.setupScanCommand();
|
|
34
36
|
this.setupGenerateSourceCommand();
|
|
35
37
|
}
|
|
38
|
+
execute() {
|
|
39
|
+
super.execute();
|
|
40
|
+
}
|
|
36
41
|
scanForContent(options, framework) {
|
|
37
42
|
return (0, scanForContent_1.default)(options, pkg, framework);
|
|
38
43
|
}
|
|
@@ -109,8 +114,7 @@ class NextCLI extends react_1.ReactCLI {
|
|
|
109
114
|
default: true,
|
|
110
115
|
});
|
|
111
116
|
// ----- Create a starter gt.config.json file -----
|
|
112
|
-
|
|
113
|
-
(0, setupConfig_1.default)('gt.config.json', process.env.GT_PROJECT_ID, '');
|
|
117
|
+
(0, generateSettings_1.generateSettings)(options);
|
|
114
118
|
// ----- //
|
|
115
119
|
const mergeOptions = Object.assign(Object.assign({}, options), { disableIds: !includeTId, disableFormatting: true, addGTProvider });
|
|
116
120
|
// Wrap all JSX elements in the src directory with a <T> tag, with unique ids
|
package/dist/cli/react.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { Options, SetupOptions, SupportedFrameworks, Updates, WrapOptions, Gener
|
|
|
2
2
|
import { BaseCLI } from './base';
|
|
3
3
|
export declare class ReactCLI extends BaseCLI {
|
|
4
4
|
constructor();
|
|
5
|
+
init(): void;
|
|
6
|
+
execute(): void;
|
|
5
7
|
protected scanForContent(options: WrapOptions, framework: SupportedFrameworks): Promise<{
|
|
6
8
|
errors: string[];
|
|
7
9
|
filesUpdated: string[];
|