Skip to main content
Glama
file-utils.ts1.23 kB
import { readFileSync, writeFileSync, existsSync, statSync } from 'fs'; import { glob } from 'glob'; export async function searchFiles(filePattern?: string): Promise<string[]> { if (!filePattern) { return await glob('**/*', { ignore: ['node_modules/**', 'dist/**', '.git/**'], nodir: true, }); } let pattern = filePattern; if ( !pattern.includes('*') && !pattern.includes('?') && !pattern.includes('[') ) { try { if (existsSync(pattern) && statSync(pattern).isDirectory()) { pattern = pattern.endsWith('/') ? `${pattern}**` : `${pattern}/**`; } } catch { // If stat fails, use the pattern as-is } } return await glob(pattern, { ignore: ['node_modules/**', 'dist/**', '.git/**'], nodir: true, }); } export function readFileContent(filePath: string): string { try { return readFileSync(filePath, 'utf-8'); } catch (error) { throw new Error(`Failed to read file ${filePath}: ${error}`); } } export function writeFileContent(filePath: string, content: string): void { try { writeFileSync(filePath, content, 'utf-8'); } catch (error) { throw new Error(`Failed to write file ${filePath}: ${error}`); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/myuon/refactor-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server