@masuidrive/ticket
Version:
Real-time ticket tracking viewer with Vite + Express
46 lines (39 loc) • 1.17 kB
text/typescript
import fs from 'fs/promises';
import path from 'path';
import matter from 'gray-matter';
import { TicketContent } from './types';
export class FileService {
private projectRoot: string;
constructor(projectRoot?: string) {
this.projectRoot = projectRoot || process.cwd();
}
async readTicketFile(filePath: string = 'current-ticket.md'): Promise<TicketContent | null> {
try {
const fullPath = path.join(this.projectRoot, filePath);
const fileContent = await fs.readFile(fullPath, 'utf-8');
const { data, content } = matter(fileContent);
return {
metadata: data,
content: content.trim(),
rawContent: fileContent
};
} catch (error) {
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
return null;
}
throw error;
}
}
async fileExists(filePath: string): Promise<boolean> {
try {
const fullPath = path.join(this.projectRoot, filePath);
await fs.access(fullPath);
return true;
} catch {
return false;
}
}
getFullPath(filePath: string): string {
return path.join(this.projectRoot, filePath);
}
}