UNPKG

next-intl-scanner

Version:

A tool to extract and manage translations from Next.js projects using next-intl

56 lines (55 loc) 2.52 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.runCli = void 0; const commander_1 = require("commander"); const extractTranslations_1 = __importDefault(require("./utils/extractTranslations.js")); const config_1 = require("./utils/config.js"); const logger_1 = __importDefault(require("./utils/logger.js")); const packageInfo_1 = __importDefault(require("./utils/packageInfo.js")); async function runCli(args) { const program = new commander_1.Command(); program .name("next-intl-scanner") .description("Extracts and merges translations for Next.js applications using next-intl") .version(packageInfo_1.default.version) .allowUnknownOption(false); program .command("extract") .option("--version", "Display the version number") .option("--config <path>", "Path to the configuration file") .option("--overwrite", "Overwrite existing translations", false) .option("--auto-translate", "Automatically translate strings using a translation service", false) .option("--clean", "Remove unused translation keys from output files", false) .option("--watch", "Watch for file changes and automatically re-extract translations", false) .description("Extracts translations from source files") .addHelpText("after", ` Examples: $ next-intl-scanner extract $ next-intl-scanner extract --overwrite $ next-intl-scanner extract --auto-translate $ next-intl-scanner extract --overwrite --auto-translate $ next-intl-scanner extract --watch $ next-intl-scanner extract --watch --overwrite `) .action(async (options) => { const config = options.config ? await (0, config_1.loadConfig)(options.config, true) : await (0, config_1.loadConfig)("./next-intl-scanner.config.js", false); if (!config) { logger_1.default.error("Failed to load configuration"); process.exit(1); } await (0, extractTranslations_1.default)(config, { overwrite: options.overwrite, autoTranslate: options.autoTranslate, defaultLocale: config.defaultLocale, clean: options.clean, watch: options.watch, }); }); await program.parseAsync(["node", "next-intl-scanner", ...args]); } exports.runCli = runCli;