UNPKG

bookgrabs

Version:

Interactive CLI tool for LibGen ebook searches and downloads with batch processing support

43 lines (34 loc) 1.29 kB
#!/usr/bin/env node import { spawn } from 'child_process'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); // Path to the main application file const mainFile = join(__dirname, '../index.tsx'); // Check if this is a CLI usage (has command line arguments) const args = process.argv.slice(2); const hasCliArgs = args.length > 0 && ( args.some(arg => arg.startsWith('--') || arg.startsWith('-')) || args.some(arg => !arg.startsWith('-')) // Non-flag arguments (search terms) ); // If CLI arguments are provided, use the CLI version const targetFile = hasCliArgs ? join(__dirname, '../index.js') : mainFile; // Spawn tsx to run the TypeScript file const child = spawn('npx', ['tsx', targetFile, ...args], { stdio: 'inherit', cwd: __dirname + '/..' }); // Handle process termination child.on('close', (code) => { process.exit(code); }); // Handle errors child.on('error', (error) => { console.error('Error running bookgrabs:', error.message); process.exit(1); }); // Forward signals to child process process.on('SIGINT', () => child.kill('SIGINT')); process.on('SIGTERM', () => child.kill('SIGTERM')); process.on('SIGQUIT', () => child.kill('SIGQUIT'));