UNPKG

auto-ai-review

Version:

AI-powered code review tool

37 lines (36 loc) 1.18 kB
import fs from 'fs/promises'; import path from 'path'; import os from 'os'; import { DEFAULT_SETTINGS } from './types.js'; export class SettingsManager { settingsPath; constructor() { this.settingsPath = path.join(os.homedir(), '.aair-settings.json'); } async loadSettings() { try { if (await fs.access(this.settingsPath).then(() => true).catch(() => false)) { const settings = JSON.parse(await fs.readFile(this.settingsPath, 'utf8')); return { ...DEFAULT_SETTINGS, ...settings }; } } catch (error) { console.error('Error loading settings:', error); } return { ...DEFAULT_SETTINGS }; } async saveSettings(settings) { try { await fs.writeFile(this.settingsPath, JSON.stringify(settings, null, 2)); } catch (error) { console.error('Error saving settings:', error); } } async updateSettings(updates) { const current = await this.loadSettings(); const updated = { ...current, ...updates }; await this.saveSettings(updated); return updated; } }