UNPKG

llms-txt-generator

Version:

A powerful CLI tool and MCP server for generating standardized llms.txt and llms-full.txt documentation files to help AI models better understand project structures

67 lines 2.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.loadPrompt = loadPrompt; exports.promptExists = promptExists; exports.listPrompts = listPrompts; const node_fs_1 = require("node:fs"); const node_path_1 = require("node:path"); const node_module_1 = require("node:module"); // ES2020 compatible way to get current directory if (typeof require === 'undefined') { // 使用 __dirname 作为替代方案,避免使用 import.meta require = (0, node_module_1.createRequire)(__dirname); } const getCurrentDir = () => (0, node_path_1.dirname)(require.resolve('./utils.js')); /** * Load prompt content from markdown files * @param promptName - The name of the prompt file (without extension) * @returns Promise<string> - The content of the prompt file */ async function loadPrompt(promptName) { try { // Get the current file's directory const currentDir = getCurrentDir(); // Construct the path to the prompt file const promptPath = (0, node_path_1.join)(currentDir, 'prompts', `${promptName}.md`); // Read and return the file content const content = await node_fs_1.promises.readFile(promptPath, 'utf-8'); return content; } catch (error) { throw new Error(`Failed to load prompt '${promptName}': ${error instanceof Error ? error.message : 'Unknown error'}`); } } /** * Check if a prompt file exists * @param promptName - The name of the prompt file (without extension) * @returns Promise<boolean> - Whether the prompt file exists */ async function promptExists(promptName) { try { const currentDir = getCurrentDir(); const promptPath = (0, node_path_1.join)(currentDir, 'prompts', `${promptName}.md`); await node_fs_1.promises.access(promptPath); return true; } catch { return false; } } /** * List all available prompt files * @returns Promise<string[]> - Array of prompt names (without extensions) */ async function listPrompts() { try { const currentDir = getCurrentDir(); const promptsDir = (0, node_path_1.join)(currentDir, 'prompts'); const files = await node_fs_1.promises.readdir(promptsDir); return files .filter(file => file.endsWith('.md')) .map(file => file.replace('.md', '')); } catch (error) { throw new Error(`Failed to list prompts: ${error instanceof Error ? error.message : 'Unknown error'}`); } } //# sourceMappingURL=utils.js.map