UNPKG

snapai

Version:

AI-powered icon generation CLI for mobile app developers

30 lines (29 loc) 899 B
import fs from 'fs-extra'; import path from 'path'; import os from 'os'; export class ConfigService { static configPath = path.join(os.homedir(), '.snapai', 'config.json'); static async getConfig() { try { await fs.ensureFile(this.configPath); const config = await fs.readJSON(this.configPath); return config; } catch { return {}; } } static async setConfig(updates) { const current = await this.getConfig(); const updated = { ...current, ...updates }; await fs.ensureDir(path.dirname(this.configPath)); await fs.writeJSON(this.configPath, updated, { spaces: 2 }); } static async get(key) { const config = await this.getConfig(); return config[key]; } static async set(key, value) { await this.setConfig({ [key]: value }); } }