contextlite
Version:
Ultra-fast context engine for retrieval and AI applications
73 lines (59 loc) ⢠2.27 kB
JavaScript
/**
* ContextLite CLI Wrapper for Node.js
*
* This script provides the main entry point for the ContextLite npm package.
* It handles binary detection, download, and execution.
*/
const { spawn } = require('child_process');
const path = require('path');
const fs = require('fs');
const os = require('os');
const { BinaryManager } = require('../lib/binary-manager');
async function main() {
try {
const binaryManager = new BinaryManager();
const binaryPath = await binaryManager.getBinaryPath();
if (!binaryPath) {
console.error('ā ContextLite binary not found!');
console.error('\nš§ To install ContextLite binary:');
console.error(' Visit: https://github.com/Michael-A-Kuykendall/contextlite/releases');
console.error(' Or reinstall this package: npm install -g contextlite');
process.exit(1);
}
// Pass all arguments to the ContextLite binary
const args = process.argv.slice(2);
const child = spawn(binaryPath, args, {
stdio: 'inherit',
windowsHide: false
});
child.on('error', (error) => {
console.error(`ā Failed to execute ContextLite binary: ${error.message}`);
process.exit(1);
});
child.on('exit', (code, signal) => {
if (signal) {
console.error(`\nā¹ļø ContextLite interrupted by signal: ${signal}`);
process.exit(128 + (signal === 'SIGINT' ? 2 : 15));
} else {
process.exit(code || 0);
}
});
// Handle Ctrl+C gracefully
process.on('SIGINT', () => {
child.kill('SIGINT');
});
process.on('SIGTERM', () => {
child.kill('SIGTERM');
});
} catch (error) {
console.error(`ā ContextLite error: ${error.message}`);
process.exit(1);
}
}
if (require.main === module) {
main().catch(error => {
console.error(`ā Unexpected error: ${error.message}`);
process.exit(1);
});
}