devbuddy
Version:
Developer-friendly runtime toolkit that intercepts JavaScript errors and provides helpful suggestions
53 lines (41 loc) ⢠1.27 kB
JavaScript
#!/usr/bin/env node
/**
* DevBuddy CLI
*
* This script provides a convenient way to run Node.js applications
* with DevBuddy preloaded. It's equivalent to:
* node --require devbuddy/preload your-app.js
*
* Usage:
* devbuddy your-app.js [args...]
*/
const { spawnSync } = require('child_process');
const path = require('path');
const preloadPath = path.resolve(__dirname, 'preload.js');
const args = process.argv.slice(2);
if (args.length === 0 || args[0] === '--help' || args[0] === '-h') {
console.log(`
š¤ DevBuddy CLI
A tool that intercepts JavaScript errors and provides helpful explanations.
Usage:
devbuddy [options] <script.js> [script-args...]
Options:
-h, --help Show this help message
Examples:
devbuddy app.js
devbuddy server.js --port 3000
You can also use DevBuddy with npm scripts by adding it to your package.json:
"scripts": {
"dev": "devbuddy app.js",
"start": "node --require devbuddy/preload app.js"
}
`);
process.exit(0);
}
// Run the user's Node.js script with DevBuddy preloaded
const result = spawnSync('node', ['--require', preloadPath, ...args], {
stdio: 'inherit',
shell: process.platform === 'win32'
});
// Exit with the same code as the child process
process.exit(result.status);