UNPKG

@rustling-pines/typesafe-locale-generator

Version:

A TypeScript-based tool to generate locale JSON files for i18n frameworks with type safety. It ensures missing translations are caught during development, reducing errors and streamlining localization. Fully customizable input/output paths, compatible wit

45 lines (44 loc) 2.39 kB
#!/usr/bin/env node "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = __importDefault(require("path")); const dotenv_1 = __importDefault(require("dotenv")); const processTranslations_1 = require("./processTranslations"); // Load environment variables from a .env file if it exists dotenv_1.default.config(); console.log('🚀 CLI script started'); function runAll() { return __awaiter(this, void 0, void 0, function* () { // Default paths for translation file and output JSON directory const defaultTranslationPath = 'src/translations/index.ts'; const defaultLocalesDir = 'public/locales'; // Read paths from environment variables or fallback to defaults const translationInputFile = process.env.TRANSLATIONS_INPUT_FILE || defaultTranslationPath; const localesOutputDirectory = process.env.LOCALES_OUTPUT_DIRECTORY || path_1.default.resolve(process.cwd(), defaultLocalesDir); const tempDir = path_1.default.resolve(process.cwd(), '.temp'); try { // Process translations yield (0, processTranslations_1.processTranslations)(translationInputFile, localesOutputDirectory, tempDir); } catch (error) { console.error(`❌ An error occurred during the translation process:`, error instanceof Error ? error.message : error); process.exit(1); // Exit with an error code } }); } // Entry point: run the function if this file is executed directly if (require.main === module) { runAll(); }