@masuidrive/ticket
Version:
Real-time ticket tracking viewer with Vite + Express
47 lines • 1.6 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileService = void 0;
const promises_1 = __importDefault(require("fs/promises"));
const path_1 = __importDefault(require("path"));
const gray_matter_1 = __importDefault(require("gray-matter"));
class FileService {
constructor(projectRoot) {
this.projectRoot = projectRoot || process.cwd();
}
async readTicketFile(filePath = 'current-ticket.md') {
try {
const fullPath = path_1.default.join(this.projectRoot, filePath);
const fileContent = await promises_1.default.readFile(fullPath, 'utf-8');
const { data, content } = (0, gray_matter_1.default)(fileContent);
return {
metadata: data,
content: content.trim(),
rawContent: fileContent
};
}
catch (error) {
if (error.code === 'ENOENT') {
return null;
}
throw error;
}
}
async fileExists(filePath) {
try {
const fullPath = path_1.default.join(this.projectRoot, filePath);
await promises_1.default.access(fullPath);
return true;
}
catch {
return false;
}
}
getFullPath(filePath) {
return path_1.default.join(this.projectRoot, filePath);
}
}
exports.FileService = FileService;
//# sourceMappingURL=fileService.js.map