tw-runner
Version:
Run and manage Tower Website projects with this utility.
24 lines (20 loc) • 778 B
JavaScript
import path from 'path';
import { fileURLToPath } from 'url';
import { spawn } from 'child_process';
import fs from 'fs';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const [, , command = 'help', ...args] = process.argv;
const commandPath = path.resolve(__dirname, 'commands', `${command}.js`);
console.log(`🚀 ${commandPath}`);
if (fs.existsSync(commandPath)) {
console.log('🔄 Running command', command, ...args)
const child = spawn('node', [commandPath, ...args], { stdio: 'inherit' });
child.on('exit', process.exit);
} else {
console.error(`❌ Unknown command: ${command}`);
const child = spawn('node', [path.resolve(__dirname, 'commands/help.js')], {
stdio: 'inherit',
});
child.on('exit', process.exit);
}