diff --git a/bun/soupclown/index.ts b/bun/soupclown/index.ts index e0dd8fd..e481ac8 100644 --- a/bun/soupclown/index.ts +++ b/bun/soupclown/index.ts @@ -1,6 +1,7 @@ -import { DockerSC } from "./src/interface/docker"; +import { SC_DOCKER } from "./src/interface/docker"; +import './src/interface/config' +// const containers = await DockerSC.PS(); +// containers.forEach(container => { +// console.log(`Name: ${container.Names}`) +// }); -const containers = await DockerSC.PS(); -containers.forEach(container => { - console.log(`Name: ${container.Names}`) -}); \ No newline at end of file diff --git a/bun/soupclown/src/interface/config.ts b/bun/soupclown/src/interface/config.ts new file mode 100644 index 0000000..4749537 --- /dev/null +++ b/bun/soupclown/src/interface/config.ts @@ -0,0 +1,38 @@ +import z, { config } from "zod"; + +const DEFAULT_CONFIG_PATH = "../../config.soupclown.json"; + +const hostConfigSchema = z.object({ + services: z.map(z.string(), z.unknown()), +}) + +const CONFIG_SCHEMA = z.object({ + v: z.literal('v1'), + config: z.union([ + hostConfigSchema, + ]), +}); +export type CONFIG_SCHEMA_T = z.infer + + +async function _loadConfig(path = DEFAULT_CONFIG_PATH){ + const configFile = Bun.file(path); + let fileJsonData: any = null; + + try{ + fileJsonData = await configFile.json(); + }catch(e){ + console.error('failed to parse json IG') + } + + const configParseJsonResult = CONFIG_SCHEMA.safeParse(fileJsonData); + + if(!configParseJsonResult.success){ + throw "Fuck"; + } + + return configParseJsonResult.data as CONFIG_SCHEMA_T; + +} + +export const SC_CONFIG = _loadConfig(); \ No newline at end of file diff --git a/bun/soupclown/src/interface/docker.ts b/bun/soupclown/src/interface/docker.ts index 27d22c5..72e8250 100644 --- a/bun/soupclown/src/interface/docker.ts +++ b/bun/soupclown/src/interface/docker.ts @@ -34,6 +34,6 @@ async function PS (){ return containerData; } -export const DockerSC = { +export const SC_DOCKER = { PS, } \ No newline at end of file diff --git a/config.soupclown.json b/config.soupclown.json new file mode 100644 index 0000000..301e410 --- /dev/null +++ b/config.soupclown.json @@ -0,0 +1 @@ +{ "name": "my-package" } \ No newline at end of file