UNPKG

@dmvicent3/tcli

Version:

A CLI tool for managing translations in projects using next-translate

34 lines (33 loc) 1.02 kB
import { existsSync, readFileSync, writeFileSync } from 'fs'; const CONFIG_FILE = 'tcli.config.json'; export function loadConfig() { if (!existsSync(CONFIG_FILE)) return null; return JSON.parse(readFileSync(CONFIG_FILE, 'utf-8')); } export function saveConfig(config) { const sorted = Object.keys(config) .sort() .reduce((acc, key) => { acc[key] = config[key]; return acc; }, {}); writeFileSync(CONFIG_FILE, JSON.stringify(sorted, null, 2)); } export function requireConfig() { const config = loadConfig(); if (!config) { console.error('[tcli] No config found. Run `tcli init` first.'); process.exit(1); } return config; } export function getApiKey() { const apiKey = process.env.GEMINI_API_KEY; if (!apiKey) { console.error('[tcli] GEMINI_API_KEY environment variable not found.'); console.error('[tcli] Please set it in your .env file or environment.'); process.exit(1); } return apiKey; }