diff options
| author | ivar <i@oiee.no> | 2026-03-09 23:05:38 +0100 |
|---|---|---|
| committer | ivar <i@oiee.no> | 2026-03-09 23:05:38 +0100 |
| commit | 69448e29a85cad3a94b3be3ad33efbc52764528f (patch) | |
| tree | c32b8c817322fdf26edbbb3fa75b9505a7020ae8 /cli/src/config.ts | |
| parent | b35302fa020ec82a9d67a6cb34379d42983d3cfc (diff) | |
| download | sparebank1-actualbudget-master.tar.xz sparebank1-actualbudget-master.zip | |
Diffstat (limited to 'cli/src/config.ts')
| -rw-r--r-- | cli/src/config.ts | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/cli/src/config.ts b/cli/src/config.ts new file mode 100644 index 0000000..a4c68a4 --- /dev/null +++ b/cli/src/config.ts @@ -0,0 +1,53 @@ +import { join } from "node:path" +import { homedir } from "node:os" +import { mkdirSync, existsSync, readFileSync, writeFileSync } from "node:fs" + +export const CONFIG_DIR = join(homedir(), ".config", "sb1-actual") +export const CONFIG_PATH = join(CONFIG_DIR, "config.json") +export const TOKENS_PATH = join(CONFIG_DIR, "tokens.json") + +export type AccountMapping = { + sb1Id: string + actualId: string + label?: string +} + +export type Config = { + sb1: { + clientId: string + clientSecret: string + finInst: string + } + actual: { + host: string + password: string + fileId: string + } + mappings: AccountMapping[] +} + +export function loadConfig(): Config { + if (!existsSync(CONFIG_PATH)) { + throw new Error(`No config found at ${CONFIG_PATH}\n\nRun \`sb1-actual init\` to create it.`) + } + return JSON.parse(readFileSync(CONFIG_PATH, "utf8")) +} + +export function saveConfig(config: Config): void { + mkdirSync(CONFIG_DIR, { recursive: true }) + writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2)) +} + +const exampleConfig: Config = { + sb1: { + clientId: "YOUR_CLIENT_ID", + clientSecret: "YOUR_CLIENT_SECRET", + finInst: "YOUR_FIN_INST" + }, + actual: { + host: "http://localhost:5006", + password: "your-password", + fileId: "your-budget-file-id" + }, + mappings: [] +} |
