UNPKG

sql-talk

Version:

SQL Talk - 自然言語をSQLに変換するMCPサーバー(安全性保護・SSHトンネル対応) / SQL Talk - MCP Server for Natural Language to SQL conversion with safety guards and SSH tunnel support

59 lines (47 loc) 1.9 kB
#!/usr/bin/env node import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); // パスエイリアスを相対パスに変換する関数 function convertPathAliases(filePath) { const content = fs.readFileSync(filePath, 'utf-8'); // @/ を相対パスに変換 let newContent = content.replace(/from ['"]@\/([^'"]+)['"]/g, (match, modulePath) => { const relativePath = getRelativePath(filePath, modulePath); return `from '${relativePath}'`; }); // 動的インポートも変換 newContent = newContent.replace(/import\(['"]@\/([^'"]+)['"]\)/g, (match, modulePath) => { const relativePath = getRelativePath(filePath, modulePath); return `import('${relativePath}')`; }); if (newContent !== content) { fs.writeFileSync(filePath, newContent, 'utf-8'); console.log(`✅ Fixed paths in: ${path.relative(process.cwd(), filePath)}`); } } // ファイルパスから相対パスを計算 function getRelativePath(fromFile, modulePath) { const fromDir = path.dirname(fromFile); const toFile = path.join(__dirname, '../dist', modulePath); const relativePath = path.relative(fromDir, toFile); return relativePath.startsWith('.') ? relativePath : './' + relativePath; } // distディレクトリ内の全JSファイルを処理 function processDistFiles(dir) { const files = fs.readdirSync(dir); for (const file of files) { const filePath = path.join(dir, file); const stat = fs.statSync(filePath); if (stat.isDirectory()) { processDistFiles(filePath); } else if (file.endsWith('.js')) { convertPathAliases(filePath); } } } // メイン実行 console.log('🔧 Converting path aliases to relative paths...'); processDistFiles(path.join(__dirname, '../dist')); console.log('✅ Path conversion complete!');