Skip to main content
Glama

MCP Serial Port Tool

by niusulong
fix-imports-manual.js3.94 kB
const fs = require('fs'); const path = require('path'); function fixImports(dir, baseDir = dir) { const files = fs.readdirSync(dir, { withFileTypes: true }); for (const file of files) { const fullPath = path.join(dir, file.name); if (file.isDirectory()) { fixImports(fullPath, baseDir); } else if (file.name.endsWith('.js') && file.name !== 'index.js' && file.name !== 'index.new.js') { let content = fs.readFileSync(fullPath, 'utf8'); // Replace @/ imports with correct relative paths content = content.replace(/require\("(@\/[^"]+)"\)/g, (match, importPath) => { const cleanPath = importPath.replace('@/', ''); let relativePath; // Determine the correct relative path based on the import if (cleanPath.startsWith('utils/')) { relativePath = path.relative(dir, path.join(baseDir, 'utils', cleanPath.substring(6))); } else if (cleanPath.startsWith('types/')) { relativePath = path.relative(dir, path.join(baseDir, 'types', cleanPath.substring(6))); } else if (cleanPath.startsWith('core/')) { relativePath = path.relative(dir, path.join(baseDir, 'core', cleanPath.substring(5))); } else if (cleanPath.startsWith('adapters/')) { relativePath = path.relative(dir, path.join(baseDir, 'adapters', cleanPath.substring(9))); } else if (cleanPath.startsWith('services/')) { relativePath = path.relative(dir, path.join(baseDir, 'services', cleanPath.substring(9))); } else if (cleanPath.startsWith('mcp/')) { relativePath = path.relative(dir, path.join(baseDir, 'mcp', cleanPath.substring(4))); } else { relativePath = path.relative(dir, path.join(baseDir, cleanPath)); } // Replace backslashes with forward slashes and ensure .js extension relativePath = relativePath.replace(/\\/g, '/'); if (!relativePath.endsWith('.js')) { relativePath += '.js'; } return `require("${relativePath}")`; }); // Also handle require with single quotes content = content.replace(/require\('(@\/[^']+) '\)/g, (match, importPath) => { const cleanPath = importPath.replace('@/', ''); let relativePath; // Determine the correct relative path based on the import if (cleanPath.startsWith('utils/')) { relativePath = path.relative(dir, path.join(baseDir, 'utils', cleanPath.substring(6))); } else if (cleanPath.startsWith('types/')) { relativePath = path.relative(dir, path.join(baseDir, 'types', cleanPath.substring(6))); } else if (cleanPath.startsWith('core/')) { relativePath = path.relative(dir, path.join(baseDir, 'core', cleanPath.substring(5))); } else if (cleanPath.startsWith('adapters/')) { relativePath = path.relative(dir, path.join(baseDir, 'adapters', cleanPath.substring(9))); } else if (cleanPath.startsWith('services/')) { relativePath = path.relative(dir, path.join(baseDir, 'services', cleanPath.substring(9))); } else if (cleanPath.startsWith('mcp/')) { relativePath = path.relative(dir, path.join(baseDir, 'mcp', cleanPath.substring(4))); } else { relativePath = path.relative(dir, path.join(baseDir, cleanPath)); } // Replace backslashes with forward slashes and ensure .js extension relativePath = relativePath.replace(/\\/g, '/'); if (!relativePath.endsWith('.js')) { relativePath += '.js'; } return `require('${relativePath}')`; }); fs.writeFileSync(fullPath, content); console.log(`Fixed imports in: ${fullPath}`); } } } // Fix all imports in the dist directory console.log('Fixing imports...'); fixImports('./dist'); console.log('Import fixing complete!');

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/niusulong/mcp2serial'

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