/** * 读取根目录下的文本文件 */ const path = require('path') const fs = require('fs') /** 构建绝对路径:绝对路径直接返回,否则相对于 folderPath 或项目根 */ function buildFilePath(filePath, folderPath) { if (filePath.startsWith('/') || filePath.includes(':')) return filePath return folderPath ? path.join(folderPath, filePath) : filePath } /** 读取文本文件(供 ef-compiler 调用) */ function readTextFile(absoluteFilePath) { const content = fs.readFileSync(absoluteFilePath, 'utf8') return { content } } /** 执行读取文本文件 */ async function executeReadTxt({ filePath, folderPath }) { if (!filePath) return { success: false, error: 'read-txt 缺少 filePath 参数' } const absoluteFilePath = buildFilePath(filePath, folderPath) const result = readTextFile(absoluteFilePath) return { success: true, content: result.content || '' } } module.exports = { executeReadTxt, readTextFile }