From 69448e29a85cad3a94b3be3ad33efbc52764528f Mon Sep 17 00:00:00 2001 From: ivar Date: Mon, 9 Mar 2026 23:05:38 +0100 Subject: Add wip cli --- cli/src/config.ts | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 cli/src/config.ts (limited to 'cli/src/config.ts') 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: [] +} -- cgit v1.3