UNPKG

attranslate

Version:

Text Translator for Websites and Apps

63 lines (62 loc) 3.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.run = void 0; const tslib_1 = require("tslib"); const commander_1 = (0, tslib_1.__importDefault)(require("commander")); require("dotenv/config"); const translate_cli_1 = require("./core/translate-cli"); const file_format_definitions_1 = require("./file-formats/file-format-definitions"); const matcher_definitions_1 = require("./matchers/matcher-definitions"); const service_definitions_1 = require("./services/service-definitions"); const extract_version_1 = require("./util/extract-version"); process.on("unhandledRejection", (error) => { console.error("[fatal]", error); }); function formatOneOfOptions(options) { return `One of ${(0, translate_cli_1.formatCliOptions)(options)}`; } function run(process, cliBinDir) { var _a; commander_1.default.storeOptionsAsProperties(false); commander_1.default.addHelpCommand(false); commander_1.default .requiredOption("--srcFile <sourceFile>", "The source file to be translated") .requiredOption("--srcLng <sourceLanguage>", "The source language") .requiredOption("--targetFile <targetFile>", "The target file for the translations") .requiredOption("--targetLng <targetLanguage>", "The target language") .option("--format <format>", `Preferred format option (one format for both src and target). ${formatOneOfOptions((0, file_format_definitions_1.getTFileFormatList)())}`) .option("--srcFormat <sourceFileFormat>", `Legacy. Overrides --format for the source. ${formatOneOfOptions((0, file_format_definitions_1.getTFileFormatList)())}`) .option("--targetFormat <targetFileFormat>", `Legacy. Overrides --format for the target. ${formatOneOfOptions((0, file_format_definitions_1.getTFileFormatList)())}`) .requiredOption("--service <translationService>", formatOneOfOptions((0, service_definitions_1.getTServiceList)())) .option("--serviceConfig <serviceKey>", "supply configuration for a translation service (either a path to a key-file or an API-key)") .option("--matcher <matcher>", formatOneOfOptions((0, matcher_definitions_1.getTMatcherList)()), "none") .version((0, extract_version_1.extractVersion)({ cliBinDir }), "-v, --version") .parse(process.argv); if ((_a = commander_1.default.args) === null || _a === void 0 ? void 0 : _a.length) { // Args are not permitted, only work with options. commander_1.default.unknownCommand(); } const args = { srcFile: commander_1.default.opts().srcFile, srcLng: commander_1.default.opts().srcLng, format: commander_1.default.opts().format, srcFormat: commander_1.default.opts().srcFormat, targetFile: commander_1.default.opts().targetFile, targetLng: commander_1.default.opts().targetLng, targetFormat: commander_1.default.opts().targetFormat, service: commander_1.default.opts().service, serviceConfig: commander_1.default.opts().serviceConfig, matcher: commander_1.default.opts().matcher, }; (0, translate_cli_1.translateCli)(args) .then(() => { process.exit(0); }) .catch((e) => { console.error("An error occurred:"); console.error(e.message); console.error(e.stack); process.exit(1); }); } exports.run = run;