{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAe9C,eAAO,MAAM,UAAU,cAatB,CAAC;AAEF,eAAO,MAAM,UAAU,0BAQtB,CAAC;AAEF,eAAO,MAAM,YAAY;;;QAMxB,CAAC;AAEF,eAAO,MAAM,MAAM,kCAQlB,CAAC;AAEF,eAAO,MAAM,SAAS,wBAQrB,CAAC;AAEF,eAAO,MAAM,YAAY,wBAQxB,CAAC","sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { homedir } from \"os\";\nimport { join } from \"path\";\nimport type { Config, Pod } from \"./types.js\";\n\n// Get config directory from env or use default\nconst getConfigDir = (): string => {\n\tconst configDir = process.env.PI_CONFIG_DIR || join(homedir(), \".pi\");\n\tif (!existsSync(configDir)) {\n\t\tmkdirSync(configDir, { recursive: true });\n\t}\n\treturn configDir;\n};\n\nconst getConfigPath = (): string => {\n\treturn join(getConfigDir(), \"pods.json\");\n};\n\nexport const loadConfig = (): Config => {\n\tconst configPath = getConfigPath();\n\tif (!existsSync(configPath)) {\n\t\t// Return empty config if file doesn't exist\n\t\treturn { pods: {} };\n\t}\n\ttry {\n\t\tconst data = readFileSync(configPath, \"utf-8\");\n\t\treturn JSON.parse(data);\n\t} catch (e) {\n\t\tconsole.error(`Error reading config: ${e}`);\n\t\treturn { pods: {} };\n\t}\n};\n\nexport const saveConfig = (config: Config): void => {\n\tconst configPath = getConfigPath();\n\ttry {\n\t\twriteFileSync(configPath, JSON.stringify(config, null, 2));\n\t} catch (e) {\n\t\tconsole.error(`Error saving config: ${e}`);\n\t\tprocess.exit(1);\n\t}\n};\n\nexport const getActivePod = (): { name: string; pod: Pod } | null => {\n\tconst config = loadConfig();\n\tif (!config.active || !config.pods[config.active]) {\n\t\treturn null;\n\t}\n\treturn { name: config.active, pod: config.pods[config.active] };\n};\n\nexport const addPod = (name: string, pod: Pod): void => {\n\tconst config = loadConfig();\n\tconfig.pods[name] = pod;\n\t// If no active pod, make this one active\n\tif (!config.active) {\n\t\tconfig.active = name;\n\t}\n\tsaveConfig(config);\n};\n\nexport const removePod = (name: string): void => {\n\tconst config = loadConfig();\n\tdelete config.pods[name];\n\t// If this was the active pod, clear active\n\tif (config.active === name) {\n\t\tconfig.active = undefined;\n\t}\n\tsaveConfig(config);\n};\n\nexport const setActivePod = (name: string): void => {\n\tconst config = loadConfig();\n\tif (!config.pods[name]) {\n\t\tconsole.error(`Pod '${name}' not found`);\n\t\tprocess.exit(1);\n\t}\n\tconfig.active = name;\n\tsaveConfig(config);\n};\n"]}