cliseo
Version:
Instant AI-Powered SEO Optimization CLI for Developers
56 lines (55 loc) • 1.68 kB
JavaScript
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
}