config.ts•1.03 kB
import { z } from 'zod';
import { existsSync } from 'fs';
import { join } from 'path';
const ConfigSchema = z.object({
WOTB_GAME_PATH: z.string().min(1, 'WOTB_GAME_PATH environment variable is required'),
});
export function loadConfig() {
const result = ConfigSchema.safeParse(process.env);
if (!result.success) {
throw new Error(`Configuration error: ${result.error.issues.map(i => i.message).join(', ')}`);
}
const gamePath = result.data.WOTB_GAME_PATH;
const vehiclesPath = join(gamePath, 'XML', 'item_defs', 'vehicles');
if (!existsSync(vehiclesPath)) {
throw new Error(`Invalid game path: ${vehiclesPath} does not exist`);
}
return {
gamePath,
paths: {
vehicles: vehiclesPath,
common: join(vehiclesPath, 'common'),
strings: join(gamePath, 'Strings'),
maps: join(gamePath, 'maps.yaml'),
maps3d: join(gamePath, '3d', 'Maps'),
camouflages: join(vehiclesPath, 'common', 'camouflages.xml'),
},
};
}
export type Config = ReturnType<typeof loadConfig>;