mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-09 02:24:11 +08:00
- Convert 40 JS files to TypeScript (CLI, tools, core, MCP server) - Add Zod for runtime parameter validation - Add type definitions in src/types/ - Keep src/templates/ as JavaScript (dashboard frontend) - Update bin entries to use dist/ - Add tsconfig.json with strict mode - Add backward-compatible exports for tests - All 39 tests passing Breaking changes: None (backward compatible) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import { readFileSync, existsSync, writeFileSync } from 'fs';
|
|
import { join } from 'path';
|
|
|
|
/**
|
|
* Safely read a JSON file
|
|
* @param filePath - Path to JSON file
|
|
* @returns Parsed JSON or null on error
|
|
*/
|
|
export function readJsonFile(filePath: string): unknown | null {
|
|
if (!existsSync(filePath)) return null;
|
|
try {
|
|
return JSON.parse(readFileSync(filePath, 'utf8'));
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Safely read a text file
|
|
* @param filePath - Path to text file
|
|
* @returns File contents or null on error
|
|
*/
|
|
export function readTextFile(filePath: string): string | null {
|
|
if (!existsSync(filePath)) return null;
|
|
try {
|
|
return readFileSync(filePath, 'utf8');
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Write content to a file
|
|
* @param filePath - Path to file
|
|
* @param content - Content to write
|
|
*/
|
|
export function writeTextFile(filePath: string, content: string): void {
|
|
writeFileSync(filePath, content, 'utf8');
|
|
}
|
|
|
|
/**
|
|
* Check if a path exists
|
|
* @param filePath - Path to check
|
|
* @returns True if path exists
|
|
*/
|
|
export function pathExists(filePath: string): boolean {
|
|
return existsSync(filePath);
|
|
}
|