Files
writing-agent/src/config/user-data-dir.ts
2026-07-10 08:31:27 +08:00

26 lines
764 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { mkdirSync } from "node:fs";
import os from "node:os";
import path from "node:path";
/** 本地用户数据目录(不进 git、不同步 */
export function getUserDataDir(): string {
if (process.env.WRITING_AGENT_DATA_DIR) {
return path.resolve(process.env.WRITING_AGENT_DATA_DIR);
}
return path.join(os.homedir(), ".writing-agent");
}
export function getPresetsDir(): string {
return path.join(getUserDataDir(), "presets");
}
export function getBooksDir(): string {
return path.join(getUserDataDir(), "books");
}
export function ensureUserDataDirs(): void {
mkdirSync(getPresetsDir(), { recursive: true });
mkdirSync(getBooksDir(), { recursive: true });
mkdirSync(path.join(getUserDataDir(), "stats"), { recursive: true });
}