mirror of
https://github.com/JimLiu/baoyu-skills.git
synced 2026-07-17 16:09:47 +08:00
23fac03691
Move the codex-imagegen wrapper out of scripts/ into its own workspace package alongside baoyu-md, baoyu-chrome-cdp, and baoyu-fetch. Drop the bash shim — src/main.ts now carries a `#\!/usr/bin/env bun` shebang and serves as the sole entrypoint. Add scripts/sync-codex-imagegen.sh so skills/baoyu-image-gen/scripts/codex-imagegen/ can be regenerated from packages/baoyu-codex-imagegen/src/ for skill self-containment. Update CLAUDE.md, docs/codex-imagegen-backend.md, and the CI workflow paths accordingly.
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { appendFile, mkdir } from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
export interface LogEntry {
|
|
ts: string;
|
|
level: "info" | "warn" | "error";
|
|
event: string;
|
|
[k: string]: unknown;
|
|
}
|
|
|
|
export class JsonLogger {
|
|
constructor(private logFile: string | null, public verbose: boolean) {}
|
|
|
|
async log(level: LogEntry["level"], event: string, extra: Record<string, unknown> = {}): Promise<void> {
|
|
const entry: LogEntry = { ts: new Date().toISOString(), level, event, ...extra };
|
|
const line = JSON.stringify(entry);
|
|
if (this.verbose) process.stderr.write(`[${level}] ${event} ${jsonExtras(extra)}\n`);
|
|
if (this.logFile) {
|
|
await mkdir(path.dirname(this.logFile), { recursive: true });
|
|
await appendFile(this.logFile, line + "\n", "utf-8");
|
|
}
|
|
}
|
|
|
|
info(event: string, extra?: Record<string, unknown>) {
|
|
return this.log("info", event, extra);
|
|
}
|
|
warn(event: string, extra?: Record<string, unknown>) {
|
|
return this.log("warn", event, extra);
|
|
}
|
|
error(event: string, extra?: Record<string, unknown>) {
|
|
return this.log("error", event, extra);
|
|
}
|
|
}
|
|
|
|
function jsonExtras(extra: Record<string, unknown>): string {
|
|
const entries = Object.entries(extra);
|
|
if (entries.length === 0) return "";
|
|
return entries.map(([k, v]) => `${k}=${typeof v === "string" ? v : JSON.stringify(v)}`).join(" ");
|
|
}
|