workin on config stuff and interface things
This commit is contained in:
@@ -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}`)
|
||||
});
|
||||
@@ -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<typeof CONFIG_SCHEMA>
|
||||
|
||||
|
||||
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();
|
||||
@@ -34,6 +34,6 @@ async function PS (){
|
||||
return containerData;
|
||||
}
|
||||
|
||||
export const DockerSC = {
|
||||
export const SC_DOCKER = {
|
||||
PS,
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "name": "my-package" }
|
||||
Reference in New Issue
Block a user