@supernovaio/cli
Version:
Supernova.io Command Line Interface
57 lines (55 loc) • 2.08 kB
JavaScript
!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]="6e9ab1cf-6771-5e38-8fa2-b9cb04cdbc70")}catch(e){}}();
import * as fs from "node:fs";
import { join } from "node:path";
import { SupernovaConfig } from "../types/config.js";
const configFileName = "supernova.config.json";
export class SupernovaConfigService {
static instance;
configCache = null;
configPath;
constructor() {
this.configPath = join(process.cwd(), configFileName);
}
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) {
try {
fs.writeFileSync(this.configPath, `${JSON.stringify(config, null, 2)}\n`);
this.configCache = config;
}
catch (error) {
throw new Error(`Error saving config: ${error.message}`);
}
}
}
//# sourceMappingURL=config.service.js.map
//# debugId=6e9ab1cf-6771-5e38-8fa2-b9cb04cdbc70