UNPKG

cliseo

Version:

Instant AI-Powered SEO Optimization CLI for Developers

83 lines 2.5 kB
import { readFile, writeFile } from 'fs/promises'; import { join } from 'path'; import { homedir } from 'os'; const CONFIG_FILE = '.cliseorc.json'; const GLOBAL_CONFIG_FILE = join(homedir(), '.cliseorc'); const defaultConfig = { aiModel: 'gpt-4', createPRs: true, seoDirectory: true, tracking: { anonymous: true, searchConsole: false, }, }; async function readConfigFile(path) { try { const content = await readFile(path, 'utf-8'); return JSON.parse(content); } catch (error) { return {}; } } export async function loadConfig() { // Load global config first const globalConfig = await readConfigFile(GLOBAL_CONFIG_FILE); // Load local config (if exists) const localConfig = await readConfigFile(CONFIG_FILE); // Merge configs with default, giving precedence to local over global return { ...defaultConfig, ...globalConfig, ...localConfig, }; } export async function saveConfig(config, global = false) { const configPath = global ? GLOBAL_CONFIG_FILE : CONFIG_FILE; const existingConfig = await readConfigFile(configPath); const newConfig = { ...existingConfig, ...config, }; await writeFile(configPath, JSON.stringify(newConfig, null, 2)); } export async function updateConfig(updates, global = false) { await saveConfig(updates, global); return loadConfig(); } export async function getApiKey(key) { const config = await loadConfig(); return config[key]; } export async function setApiKey(key, value) { await updateConfig({ [key]: value }, true); // Always save API keys in global config } // Authentication utilities export async function getAuthToken() { const config = await loadConfig(); return config.authToken; } export async function setAuthToken(token, email, aiAccess) { await updateConfig({ authToken: token, userEmail: email, aiAccess }, true); // Always save auth token in global config } export async function clearAuthToken() { await updateConfig({ authToken: undefined, userEmail: undefined, aiAccess: undefined }, true); } export async function isAuthenticated() { const config = await loadConfig(); return !!(config.authToken && config.userEmail); } export async function hasAiAccess() { const config = await loadConfig(); return !!(config.authToken && config.aiAccess); } //# sourceMappingURL=config.js.map