messing with more just riffin at this point
This commit is contained in:
@@ -1,7 +1,3 @@
|
||||
import { SC_DOCKER } from "./src/interface/docker";
|
||||
import './src/interface/config'
|
||||
// const containers = await DockerSC.PS();
|
||||
// containers.forEach(container => {
|
||||
// console.log(`Name: ${container.Names}`)
|
||||
// });
|
||||
import { SC_CONFIG } from "./src/interface/config";
|
||||
|
||||
console.log('config', SC_CONFIG.config)
|
||||
@@ -13,7 +13,16 @@ const CONFIG_SCHEMA = z.object({
|
||||
]),
|
||||
});
|
||||
export type CONFIG_SCHEMA_T = z.infer<typeof CONFIG_SCHEMA>
|
||||
const NEW_CONFIG: CONFIG_SCHEMA_T = {
|
||||
v: 'v1',
|
||||
config: {
|
||||
services: new Map()
|
||||
}
|
||||
};
|
||||
|
||||
async function _initConfigFile(path: string){
|
||||
await Bun.write(path, JSON.stringify(NEW_CONFIG));
|
||||
}
|
||||
|
||||
async function _loadConfig(path = DEFAULT_CONFIG_PATH){
|
||||
const configFile = Bun.file(path);
|
||||
@@ -21,18 +30,29 @@ async function _loadConfig(path = DEFAULT_CONFIG_PATH){
|
||||
|
||||
try{
|
||||
fileJsonData = await configFile.json();
|
||||
console.log('json data', fileJsonData)
|
||||
}catch(e){
|
||||
console.error('failed to parse json IG')
|
||||
throw "failed"
|
||||
}
|
||||
|
||||
const configParseJsonResult = CONFIG_SCHEMA.safeParse(fileJsonData);
|
||||
|
||||
if(!configParseJsonResult.success){
|
||||
throw "Fuck";
|
||||
console.error('parsing error, overwrting config :3', configParseJsonResult.error)
|
||||
await _initConfigFile(path);
|
||||
return NEW_CONFIG;
|
||||
}
|
||||
|
||||
return configParseJsonResult.data as CONFIG_SCHEMA_T;
|
||||
|
||||
}
|
||||
|
||||
export const SC_CONFIG = _loadConfig();
|
||||
async function methodWrapper(config: CONFIG_SCHEMA_T){
|
||||
const newConfig: CONFIG_SCHEMA_T & {
|
||||
|
||||
} = config;
|
||||
|
||||
}
|
||||
|
||||
export const SC_CONFIG = await _loadConfig();
|
||||
@@ -1 +1 @@
|
||||
{ "name": "my-package" }
|
||||
{"v":"v1","config":{"services":{}}}
|
||||
Reference in New Issue
Block a user