Skip to content

Commit 92dc7be

Browse files
authored
feat(config): add CYCLING_COACH_HOME env var to override data directory (#41)
Lets `npm run dev` point at a separate home (e.g. ~/.cycling-coach-dev) so it does not share config, sessions, memory, or auth profiles with the globally installed cycling-coach CLI. Supports ~/ expansion. Also wires up the `npm run setup` script, already referenced by auth/profiles.ts error messages.
1 parent 3a01612 commit 92dc7be

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ TELEGRAM_BOT_TOKEN=123456:ABC-DEF...
1919
# SESSION_IDLE_MINUTES=0
2020
# SESSION_DAILY_RESET_HOUR=4
2121
# CONTEXT_WINDOW_TOKENS=200000
22+
23+
# Data directory (optional). Overrides the default ~/.cycling-coach.
24+
# Point `npm run dev` at a separate dir so it does not share config, sessions,
25+
# memory, or auth profiles with the globally-installed `cycling-coach` CLI.
26+
# CYCLING_COACH_HOME=~/.cycling-coach-dev

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,21 @@ npm run fmt # oxfmt
172172
npm run build # tsc → dist/
173173
```
174174

175+
### Separating dev from prod
176+
177+
Set `CYCLING_COACH_HOME` to isolate `npm run dev` from the globally-installed
178+
`cycling-coach` CLI. Each dir has its own `config.yaml`, `auth-profiles.json`,
179+
`sessions/`, and `memory/`, so dev and prod never collide:
180+
181+
```bash
182+
# .env (loaded only by `npm run dev`)
183+
CYCLING_COACH_HOME=~/.cycling-coach-dev
184+
```
185+
186+
The global install keeps using `~/.cycling-coach`. For full isolation, run
187+
`npm run setup` once against the dev home to register a separate Telegram bot
188+
token and (recommended) a separate intervals.icu athlete.
189+
175190
## Project structure
176191

177192
```

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
],
1515
"scripts": {
1616
"dev": "tsx --env-file=.env src/index.ts",
17+
"setup": "tsx --env-file=.env src/index.ts setup",
1718
"build": "tsc",
1819
"prepublishOnly": "npm run build",
1920
"test": "vitest run",

src/config.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,18 @@ export interface Config {
3434
// CONFIG LOADING
3535
// ============================================================================
3636

37-
export const CONFIG_DIR = join(homedir(), ".cycling-coach");
37+
function resolveConfigDir(): string {
38+
const override = process.env.CYCLING_COACH_HOME;
39+
if (override && override.length > 0) {
40+
if (override === "~" || override.startsWith("~/")) {
41+
return join(homedir(), override.slice(1));
42+
}
43+
return override;
44+
}
45+
return join(homedir(), ".cycling-coach");
46+
}
47+
48+
export const CONFIG_DIR = resolveConfigDir();
3849
export const CONFIG_FILE = join(CONFIG_DIR, "config.yaml");
3950

4051
export function readConfigYaml(): Record<string, unknown> {

0 commit comments

Comments
 (0)