v0-ui-reviewer
Version:
Next-gen UI/UX reviewer with multi-model AI support (OpenAI, Claude, v0), style extraction, and live preview sandbox
53 lines (52 loc) • 1.43 kB
JavaScript
import Configstore from 'configstore';
import { promises as fs } from 'fs';
import path from 'path';
import os from 'os';
export class ConfigManager {
config;
configPath;
constructor() {
this.config = new Configstore('v0-ui-reviewer', {
timeout: 60000,
defaultDevice: 'desktop',
defaultFullPage: true,
defaultShowImage: true,
logLevel: 'info',
outputDirectory: process.cwd()
});
this.configPath = path.join(os.homedir(), '.v0-ui-reviewer', 'config.json');
}
get(key) {
return this.config.get(key);
}
set(key, value) {
this.config.set(key, value);
}
getAll() {
return this.config.all;
}
setAll(config) {
Object.entries(config).forEach(([key, value]) => {
if (value !== undefined) {
this.config.set(key, value);
}
});
}
clear() {
this.config.clear();
}
getApiKey() {
return this.get('apiKey') || process.env.V0_API_KEY;
}
async ensureConfigDirectory() {
const configDir = path.dirname(this.configPath);
await fs.mkdir(configDir, { recursive: true });
}
isFirstRun() {
return !this.get('apiKey') && !process.env.V0_API_KEY;
}
getConfigPath() {
return this.config.path;
}
}
export const configManager = new ConfigManager();