diff --git a/bun/soupclown/src/interface/cli.ts b/bun/soupclown/src/interface/cli.ts index 85bfbbd..11bc417 100644 --- a/bun/soupclown/src/interface/cli.ts +++ b/bun/soupclown/src/interface/cli.ts @@ -17,6 +17,7 @@ export function RUN_CLI(){ case 'init': console.log('init action!') console.log(`HOSTNAME: ${await HOST.getHostname()}`) + await HOST.initSystem() break; default: diff --git a/bun/soupclown/src/interface/config.ts b/bun/soupclown/src/interface/config.ts index fe8a257..1b58418 100644 --- a/bun/soupclown/src/interface/config.ts +++ b/bun/soupclown/src/interface/config.ts @@ -1,32 +1,32 @@ -import z, { config } from "zod"; +import z from "zod"; +import { HOST } from "./host"; -const DEFAULT_CONFIG_PATH = "../../config.soupclown.json"; +const DEFAULT_CONFIG_PATH = "../../state.soupclown.json"; const hostConfigSchema = z.object({ + configurationPath: z.string(), services: z.array(z.object({ name: z.string(), desiredState: z.enum(['up', 'down']), })), }) +export type HOST_CONFIG_SCHEMA_T = z.infer; const CONFIG_SCHEMA = z.object({ v: z.literal('v1'), - data: z.union([ - hostConfigSchema, - ]), + data: z.map(z.string(), hostConfigSchema) }); export type CONFIG_SCHEMA_T = z.infer -export class SC_CONFIG_C { +export class SC_CONFIG_C { + + constructor( protected runningConfig = { v: 'v1', - data: { - services: [ - {name: 'test', desiredState: 'down'} - ] - }, - } as CONFIG_SCHEMA_T + data: new Map([ + ]), + } as CONFIG_SCHEMA_T, ){} public static async loadConfigFile(path = DEFAULT_CONFIG_PATH){ @@ -36,13 +36,11 @@ export class SC_CONFIG_C { try{ fileJsonData = await configFile.json(); }catch(e){ - console.error('failed to parse json IG') throw "FAILED_SCHEMA_JSON_PARSE" } const configParseJsonResult = CONFIG_SCHEMA.safeParse(fileJsonData); if(!configParseJsonResult.success){ - console.error("Loaded config file but parsing failed") throw "FAILED_CONFIG_SCHEMA_PARSE" } @@ -57,7 +55,16 @@ export class SC_CONFIG_C { } private async _loadConfigFile(path = DEFAULT_CONFIG_PATH){ - this.runningConfig = await SC_CONFIG_C.loadConfigFile(path); + try{ + this.runningConfig = await SC_CONFIG_C.loadConfigFile(path); + const hostconfig = this.runningConfig.data.get(await HOST.getHostname()); + if(hostconfig){ + this.configurationPath = hostconfig.configurationPath; + this.services = hostconfig.services; + } + }catch{ + console.error('Failed to load config, assuming you know what you\'re doing'); + } } private async _writeConfigFile(path = DEFAULT_CONFIG_PATH){ diff --git a/bun/soupclown/src/interface/host.ts b/bun/soupclown/src/interface/host.ts index cb68d44..a21cf71 100644 --- a/bun/soupclown/src/interface/host.ts +++ b/bun/soupclown/src/interface/host.ts @@ -1,10 +1,16 @@ import { $ } from "bun"; +import { SC_CONFIG } from "./config"; async function getHostname(){ const result = await $`hostname`.quiet().text(); return result.trim(); } +async function initSystem(){ + // await $`mkdir -p ${SC_CONFIG.configurationPath}` +} + export const HOST = { getHostname, + initSystem, } \ No newline at end of file diff --git a/config.soupclown.json b/config.soupclown.json deleted file mode 100644 index 3d484a4..0000000 --- a/config.soupclown.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "v": "v1", - "data": { - "services": [ - { - "name": "doohickey", - "desiredState": "up" - } - ] - } -} \ No newline at end of file diff --git a/state.soupclown.json b/state.soupclown.json new file mode 100644 index 0000000..34260cb --- /dev/null +++ b/state.soupclown.json @@ -0,0 +1,4 @@ +{ + "v": "v1", + "data": {} +} \ No newline at end of file