#!/usr/bin/env node
/**
* Installation script for Slidev MCP PDF export dependencies
* Run this if you encounter "playwright-chromium not installed" errors
*/
import { execSync } from 'child_process';
import { existsSync } from 'fs';
import path from 'path';
console.log('๐ง Installing Slidev MCP PDF export dependencies...\n');
const dependencies = [
'@slidev/cli',
'playwright-chromium',
'@slidev/theme-apple-basic'
];
function runCommand(command, description) {
try {
console.log(`๐ฆ ${description}...`);
execSync(command, { stdio: 'inherit', timeout: 120000 });
console.log(`โ
${description} completed\n`);
return true;
} catch (error) {
console.error(`โ ${description} failed: ${error.message}\n`);
return false;
}
}
function checkDependency(dep) {
try {
execSync(`npm list ${dep}`, { stdio: 'pipe' });
return true;
} catch (error) {
return false;
}
}
async function main() {
// Check if package.json exists
if (!existsSync('package.json')) {
console.error('โ package.json not found. Please run this from the project root.');
process.exit(1);
}
console.log('๐ Checking existing dependencies...');
const missingDeps = dependencies.filter(dep => !checkDependency(dep));
if (missingDeps.length === 0) {
console.log('โ
All dependencies are already installed!');
console.log('\n๐งช Testing PDF export...');
// Test if Slidev CLI works with multiple methods
const testCommands = [
'npx slidev --version',
'node node_modules/@slidev/cli/bin/slidev.mjs --version'
];
let anyWorking = false;
for (const cmd of testCommands) {
if (runCommand(cmd, `Testing: ${cmd}`)) {
anyWorking = true;
break;
}
}
if (anyWorking) {
console.log('๐ PDF export dependencies are ready!');
} else {
console.log('โ ๏ธ Slidev CLI test failed. You may need to reinstall dependencies.');
}
return;
}
console.log(`๐ Missing dependencies: ${missingDeps.join(', ')}\n`);
// Install missing dependencies
const installCmd = `npm install -D ${missingDeps.join(' ')}`;
if (!runCommand(installCmd, 'Installing missing dependencies')) {
console.error('โ Installation failed. Please run manually:');
console.error(` ${installCmd}`);
process.exit(1);
}
// Test installation
console.log('๐งช Testing installation...');
// Test installation with multiple methods
const testCommands = [
'npx slidev --version',
'node node_modules/@slidev/cli/bin/slidev.mjs --version'
];
let installWorking = false;
for (const cmd of testCommands) {
if (runCommand(cmd, `Testing: ${cmd}`)) {
installWorking = true;
break;
}
}
if (installWorking) {
console.log('๐ PDF export dependencies installed successfully!');
console.log('\n๐ Next steps:');
console.log('1. Restart your MCP server (npm start)');
console.log('2. Try the export_to_pdf tool again');
console.log('3. Your n8n agent should now be able to export PDFs');
} else {
console.error('โ ๏ธ Installation completed but Slidev CLI test failed.');
console.error(' You may need to restart your terminal or check PATH settings.');
}
}
main().catch(error => {
console.error('๐ฅ Installation script failed:', error.message);
process.exit(1);
});