UNPKG

@supernovaio/cli

Version:

Supernova.io Command Line Interface

50 lines (48 loc) 1.86 kB
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="efbafcda-4ef1-5d66-945d-590f1730640c")}catch(e){}}(); import * as fs from "node:fs"; import { SupernovaConfig } from "../types/config.js"; const configFileName = "supernova.config.json"; export class SupernovaConfigService { static instance; configCache = null; static getInstance() { if (!SupernovaConfigService.instance) { SupernovaConfigService.instance = new SupernovaConfigService(); } return SupernovaConfigService.instance; } get() { if (this.configCache) return this.configCache; if (!fs.existsSync(this.configPath)) return null; try { const configString = fs.readFileSync(this.configPath, "utf8"); const configJson = JSON.parse(configString); const configParseResult = SupernovaConfig.safeParse(configJson); if (configParseResult.success) { this.configCache = configParseResult.data; } return this.configCache; } catch (error) { throw new Error(`Could not read ${configFileName} file: ${error.message}`); } } update(configUpdate) { const fullConfig = { ...this.get(), ...configUpdate, }; this.write(fullConfig); } write(config) { fs.writeFileSync(this.configPath, `${JSON.stringify(config, null, 2)}\n`); this.configCache = config; } get configPath() { return configFileName; } } //# sourceMappingURL=config.service.js.map //# debugId=efbafcda-4ef1-5d66-945d-590f1730640c