Add CLI package, config file support, and workspace setup
Add cli/ package with initial scaffolding. Add config-schema to shared package for typed configuration. Add server config-file loader for paperclip.config.ts support. Register cli in pnpm workspace. Add .paperclip/ and .pnpm-store/ to gitignore. Minor Companies page fix. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
18
server/src/config-file.ts
Normal file
18
server/src/config-file.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import { readConfigFile } from "./config-file.js";
|
||||
|
||||
export interface Config {
|
||||
port: number;
|
||||
databaseUrl: string | undefined;
|
||||
@@ -7,10 +9,20 @@ export interface Config {
|
||||
}
|
||||
|
||||
export function loadConfig(): Config {
|
||||
const fileConfig = readConfigFile();
|
||||
|
||||
const fileDbUrl =
|
||||
fileConfig?.database.mode === "postgres"
|
||||
? fileConfig.database.connectionString
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
port: Number(process.env.PORT) || 3100,
|
||||
databaseUrl: process.env.DATABASE_URL,
|
||||
serveUi: process.env.SERVE_UI === "true",
|
||||
port: Number(process.env.PORT) || fileConfig?.server.port || 3100,
|
||||
databaseUrl: process.env.DATABASE_URL ?? fileDbUrl,
|
||||
serveUi:
|
||||
process.env.SERVE_UI !== undefined
|
||||
? process.env.SERVE_UI === "true"
|
||||
: fileConfig?.server.serveUi ?? false,
|
||||
heartbeatSchedulerEnabled: process.env.HEARTBEAT_SCHEDULER_ENABLED !== "false",
|
||||
heartbeatSchedulerIntervalMs: Math.max(10000, Number(process.env.HEARTBEAT_SCHEDULER_INTERVAL_MS) || 30000),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user