mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-11 02:33:51 +08:00
feat(ccw): migrate backend to TypeScript
- 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>
This commit is contained in:
48
ccw/src/utils/file-utils.ts
Normal file
48
ccw/src/utils/file-utils.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user