import { execSync } from 'child_process';
import { existsSync } from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
console.log('π§ Setting up Slack MCP Server dependencies...\n');
// Check if node_modules exists
const nodeModulesPath = join(__dirname, 'node_modules');
if (!existsSync(nodeModulesPath)) {
console.log('π¦ Installing dependencies...');
try {
execSync('npm install', { stdio: 'inherit', cwd: __dirname });
} catch (error) {
console.error('β Failed to install dependencies');
process.exit(1);
}
}
// Verify critical dependencies
const criticalDeps = [
'@slack/web-api',
'@leanmcp/core',
'tsx',
'dotenv'
];
console.log('\nβ
Verifying dependencies...');
let allInstalled = true;
for (const dep of criticalDeps) {
const depPath = join(nodeModulesPath, dep);
if (existsSync(depPath)) {
console.log(` β ${dep}`);
} else {
console.log(` β ${dep} - MISSING`);
allInstalled = false;
}
}
if (!allInstalled) {
console.log('\nβ Some dependencies are missing. Running install again...');
try {
execSync('npm install --force', { stdio: 'inherit', cwd: __dirname });
} catch (error) {
console.error('β Failed to install dependencies');
process.exit(1);
}
} else {
console.log('\nπ All dependencies installed successfully!');
console.log('\nπ Next steps:');
console.log(' 1. Create .env file: cp .env.example .env');
console.log(' 2. Add your SLACK_BOT_TOKEN to .env');
console.log(' 3. Run: npm run dev');
}