UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

83 lines 2.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.globalConfig = exports.GlobalConfigManager = void 0; const fs_1 = require("fs"); const path_1 = require("path"); const os_1 = require("os"); class GlobalConfigManager { constructor() { this.configDir = (0, path_1.join)((0, os_1.homedir)(), '.polyv-live-cli'); this.configFile = (0, path_1.join)(this.configDir, 'config.json'); } ensureConfigDir() { if (!(0, fs_1.existsSync)(this.configDir)) { (0, fs_1.mkdirSync)(this.configDir, { recursive: true }); } } load() { try { if (!(0, fs_1.existsSync)(this.configFile)) { return {}; } const content = (0, fs_1.readFileSync)(this.configFile, 'utf-8'); return JSON.parse(content); } catch (error) { console.warn('⚠️ Failed to load config file, using empty config'); return {}; } } save(config) { try { this.ensureConfigDir(); const existingConfig = this.load(); const newConfig = { ...existingConfig, ...config }; Object.keys(newConfig).forEach(key => { if (newConfig[key] === undefined) { delete newConfig[key]; } }); (0, fs_1.writeFileSync)(this.configFile, JSON.stringify(newConfig, null, 2)); console.log('✅ Configuration saved successfully'); } catch (error) { throw new Error(`Failed to save configuration: ${error instanceof Error ? error.message : 'Unknown error'}`); } } get(key) { const config = this.load(); return config[key]; } set(key, value) { const config = this.load(); config[key] = value; this.save(config); } unset(key) { const config = this.load(); delete config[key]; this.save(config); } clear() { this.save({}); console.log('✅ Configuration cleared'); } getConfigPath() { return this.configFile; } exists() { return (0, fs_1.existsSync)(this.configFile); } validate(config) { const cfg = config || this.load(); const requiredKeys = ['appId', 'appSecret']; const missingKeys = requiredKeys.filter(key => !cfg[key]); return { isValid: missingKeys.length === 0, missingKeys }; } } exports.GlobalConfigManager = GlobalConfigManager; exports.globalConfig = new GlobalConfigManager(); //# sourceMappingURL=global.js.map