neex
Version:
Neex - Modern Fullstack Framework Built on Express and Next.js. Fast to Start, Easy to Build, Ready to Deploy
124 lines (123 loc) • 5.83 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.addBuildCommands = addBuildCommands;
const build_manager_js_1 = require("../build-manager.js");
const logger_manager_js_1 = require("../logger-manager.js");
const chalk_1 = __importDefault(require("chalk"));
const figures_1 = __importDefault(require("figures"));
function addBuildCommands(program) {
let buildManager = null;
// Build command for TypeScript projects
program
.command('build [source]')
.description('Build TypeScript project for production (default: src)')
.option('-o, --output <dir>', 'Output directory', 'dist')
.option('-w, --watch', 'Watch mode for continuous building')
.option('-c, --clean', 'Clean output directory before build', true)
.option('-s, --sourcemap', 'Generate source maps')
.option('-t, --target <target>', 'TypeScript target (es2020, es2022, etc.)', 'es2020')
.option('-f, --format <format>', 'Output format (cjs, esm)', 'cjs')
.option('--tsconfig <file>', 'TypeScript config file', 'tsconfig.json')
.option('-v, --verbose', 'Verbose output')
.option('-q, --quiet', 'Quiet output')
.option('--no-color', 'Disable colored output')
.option('--analyze', 'Analyze bundle size')
.action(async (source, options) => {
try {
const sourceDir = source || 'src';
if (!options.quiet) {
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.green(figures_1.default.play)} Building TypeScript project from ${chalk_1.default.cyan(sourceDir)}`, 'info');
}
buildManager = new build_manager_js_1.BuildManager({
source: sourceDir,
output: options.output,
watch: options.watch,
clean: options.clean,
minify: false, // TSC doesn't handle minification
sourcemap: options.sourcemap,
target: options.target,
format: options.format,
bundle: false, // TSC doesn't bundle
external: [], // Not applicable for TSC
tsconfig: options.tsconfig,
verbose: options.verbose,
quiet: options.quiet,
color: options.color,
analyze: options.analyze
});
// --- Signal Handlers for Build ---
const cleanupAndExit = (signal) => {
if (buildManager) {
logger_manager_js_1.loggerManager.printLine(`\n${chalk_1.default.yellow('⏹')} Received ${signal}, shutting down...`, 'info');
buildManager.stop().then(() => process.exit(0));
}
else {
process.exit(0);
}
};
const sigintHandler = () => cleanupAndExit('SIGINT');
const sigtermHandler = () => cleanupAndExit('SIGTERM');
process.on('SIGINT', sigintHandler);
process.on('SIGTERM', sigtermHandler);
await buildManager.build();
// If not in watch mode, show completion message
if (!options.watch && !options.quiet) {
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.green(figures_1.default.tick)} Build completed successfully`, 'info');
}
}
catch (error) {
if (error instanceof Error) {
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.red(figures_1.default.cross)} Build failed: ${error.message}`, 'error');
}
else {
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.red(figures_1.default.cross)} An unknown build error occurred`, 'error');
}
process.exit(1);
}
});
// Add a quick build command without options
program
.command('compile [source]')
.alias('tsc')
.description('Quick TypeScript compilation (alias for build)')
.action(async (source) => {
try {
const sourceDir = source || 'src';
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.blue(figures_1.default.info)} Compiling TypeScript...`, 'info');
buildManager = new build_manager_js_1.BuildManager({
source: sourceDir,
output: 'dist',
watch: false,
clean: true,
minify: false,
sourcemap: false,
target: 'es2020',
format: 'cjs',
bundle: false,
external: [],
tsconfig: 'tsconfig.json',
verbose: false,
quiet: false,
color: true,
analyze: false
});
await buildManager.build();
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.green(figures_1.default.tick)} Compilation completed`, 'info');
}
catch (error) {
if (error instanceof Error) {
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.red(figures_1.default.cross)} Compilation failed: ${error.message}`, 'error');
}
else {
logger_manager_js_1.loggerManager.printLine(`${chalk_1.default.red(figures_1.default.cross)} An unknown compilation error occurred`, 'error');
}
process.exit(1);
}
});
// Cleanup function is no longer needed here as it's handled within the command
const cleanupBuild = async () => { };
return { cleanupBuild };
}