work in progress :/

This commit is contained in:
2026-05-03 20:53:13 -04:00
parent e32c5ec76f
commit f13c393406
5 changed files with 33 additions and 26 deletions
+1
View File
@@ -17,6 +17,7 @@ export function RUN_CLI(){
case 'init': case 'init':
console.log('init action!') console.log('init action!')
console.log(`HOSTNAME: ${await HOST.getHostname()}`) console.log(`HOSTNAME: ${await HOST.getHostname()}`)
await HOST.initSystem()
break; break;
default: default:
+22 -15
View File
@@ -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({ const hostConfigSchema = z.object({
configurationPath: z.string(),
services: z.array(z.object({ services: z.array(z.object({
name: z.string(), name: z.string(),
desiredState: z.enum(['up', 'down']), desiredState: z.enum(['up', 'down']),
})), })),
}) })
export type HOST_CONFIG_SCHEMA_T = z.infer<typeof hostConfigSchema>;
const CONFIG_SCHEMA = z.object({ const CONFIG_SCHEMA = z.object({
v: z.literal('v1'), v: z.literal('v1'),
data: z.union([ data: z.map(z.string(), hostConfigSchema)
hostConfigSchema,
]),
}); });
export type CONFIG_SCHEMA_T = z.infer<typeof CONFIG_SCHEMA> export type CONFIG_SCHEMA_T = z.infer<typeof CONFIG_SCHEMA>
export class SC_CONFIG_C { export class SC_CONFIG_C {
constructor( constructor(
protected runningConfig = { protected runningConfig = {
v: 'v1', v: 'v1',
data: { data: new Map([
services: [ ]),
{name: 'test', desiredState: 'down'} } as CONFIG_SCHEMA_T,
]
},
} as CONFIG_SCHEMA_T
){} ){}
public static async loadConfigFile(path = DEFAULT_CONFIG_PATH){ public static async loadConfigFile(path = DEFAULT_CONFIG_PATH){
@@ -36,13 +36,11 @@ export class SC_CONFIG_C {
try{ try{
fileJsonData = await configFile.json(); fileJsonData = await configFile.json();
}catch(e){ }catch(e){
console.error('failed to parse json IG')
throw "FAILED_SCHEMA_JSON_PARSE" throw "FAILED_SCHEMA_JSON_PARSE"
} }
const configParseJsonResult = CONFIG_SCHEMA.safeParse(fileJsonData); const configParseJsonResult = CONFIG_SCHEMA.safeParse(fileJsonData);
if(!configParseJsonResult.success){ if(!configParseJsonResult.success){
console.error("Loaded config file but parsing failed")
throw "FAILED_CONFIG_SCHEMA_PARSE" throw "FAILED_CONFIG_SCHEMA_PARSE"
} }
@@ -57,7 +55,16 @@ export class SC_CONFIG_C {
} }
private async _loadConfigFile(path = DEFAULT_CONFIG_PATH){ 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){ private async _writeConfigFile(path = DEFAULT_CONFIG_PATH){
+6
View File
@@ -1,10 +1,16 @@
import { $ } from "bun"; import { $ } from "bun";
import { SC_CONFIG } from "./config";
async function getHostname(){ async function getHostname(){
const result = await $`hostname`.quiet().text(); const result = await $`hostname`.quiet().text();
return result.trim(); return result.trim();
} }
async function initSystem(){
// await $`mkdir -p ${SC_CONFIG.configurationPath}`
}
export const HOST = { export const HOST = {
getHostname, getHostname,
initSystem,
} }
-11
View File
@@ -1,11 +0,0 @@
{
"v": "v1",
"data": {
"services": [
{
"name": "doohickey",
"desiredState": "up"
}
]
}
}
+4
View File
@@ -0,0 +1,4 @@
{
"v": "v1",
"data": {}
}