mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-16 19:00:38 +09:00
19 lines
560 B
TypeScript
19 lines
560 B
TypeScript
|
|
import fs from "node:fs";
|
||
|
|
import path from "node:path";
|
||
|
|
import { paperclipConfigSchema, type PaperclipConfig } from "@paperclip/shared";
|
||
|
|
|
||
|
|
export function readConfigFile(): PaperclipConfig | null {
|
||
|
|
const configPath = process.env.PAPERCLIP_CONFIG
|
||
|
|
? path.resolve(process.env.PAPERCLIP_CONFIG)
|
||
|
|
: path.resolve(process.cwd(), ".paperclip/config.json");
|
||
|
|
|
||
|
|
if (!fs.existsSync(configPath)) return null;
|
||
|
|
|
||
|
|
try {
|
||
|
|
const raw = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
||
|
|
return paperclipConfigSchema.parse(raw);
|
||
|
|
} catch {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|