neex
Version:
Neex - Modern Fullstack Framework Built on Express and Next.js. Fast to Start, Easy to Build, Ready to Deploy
61 lines (60 loc) • 2.74 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = cli;
// src/cli.ts - Main CLI file (refactored)
const commander_1 = require("commander");
const index_js_1 = require("./commands/index.js");
const chalk_1 = __importDefault(require("chalk"));
const figures_1 = __importDefault(require("figures"));
const { version } = require('../../package.json');
function cli() {
const args = process.argv.slice(2);
// Handle the 'init' command as a special case before anything else.
// This makes 'neex' and 'neex init' act as aliases for 'npx create-neex'.
if (args.length === 0 || args[0] === 'init') {
const initArgs = args.slice(1); // Get all arguments after 'init'
(0, index_js_1.runInit)(initArgs);
return; // Exit early, do not proceed with the rest of the CLI
}
const program = new commander_1.Command();
// Initialize cleanup handlers
const cleanupHandlers = [];
program
.name('neex')
.description('Professional script runner with nodemon and PM2 functionality')
.version(version);
// Add all other command groups
(0, index_js_1.addRunCommands)(program);
(0, index_js_1.addServerCommands)(program);
const devCommands = (0, index_js_1.addDevCommands)(program);
cleanupHandlers.push(devCommands.cleanupDev);
const buildCommands = (0, index_js_1.addBuildCommands)(program);
cleanupHandlers.push(buildCommands.cleanupBuild);
const startCommands = (0, index_js_1.addStartCommands)(program);
cleanupHandlers.push(startCommands.cleanupStart);
program.parse(process.argv);
// Show help if no commands specified
if (program.args.length === 0) {
program.help();
}
// Graceful shutdown handling
const handleSignal = async (signal) => {
console.log(`\n${chalk_1.default.yellow(`${figures_1.default.warning} Received ${signal}. Cleaning up...`)}`);
// Run all cleanup handlers
for (const cleanup of cleanupHandlers) {
try {
await cleanup();
}
catch (error) {
console.error(`Cleanup error:`, error);
}
}
setTimeout(() => process.exit(0), 500);
};
process.on('SIGINT', () => handleSignal('SIGINT').catch(err => console.error('SIGINT handler error:', err)));
process.on('SIGTERM', () => handleSignal('SIGTERM').catch(err => console.error('SIGTERM handler error:', err)));
process.on('SIGQUIT', () => handleSignal('SIGQUIT').catch(err => console.error('SIGQUIT handler error:', err)));
}