tlnt
Version:
TLNT - HMS-Powered Multi-Agent Platform with Government Agency Analysis, Deep Research, and Enterprise-Ready Deployment. Self-optimizing multi-domain AI agent with continuous learning and enterprise-grade performance monitoring.
155 lines (126 loc) ⢠4.57 kB
JavaScript
#!/usr/bin/env node
/**
* Post-install script for blax package
* Handles setup for both global and local installations
*/
import { execSync } from 'child_process';
import { existsSync, readFileSync, writeFileSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// ANSI color codes
const colors = {
cyan: '\x1b[36m',
green: '\x1b[32m',
yellow: '\x1b[33m',
red: '\x1b[31m',
bold: '\x1b[1m',
reset: '\x1b[0m',
dim: '\x1b[2m'
};
function log(message, color = '') {
console.log(`${color}${message}${colors.reset}`);
}
function isGlobalInstall() {
// Check if we're in a global node_modules
const currentPath = process.cwd();
return currentPath.includes('/lib/node_modules/') ||
currentPath.includes('\\lib\\node_modules\\') ||
process.env.npm_config_global === 'true';
}
function createLocalAlias() {
const packageRoot = join(__dirname, '..');
const binPath = join(packageRoot, 'bin', 'tlnt.js');
if (!existsSync(binPath)) {
log('ā ļø Binary file not found, skipping alias creation', colors.yellow);
return;
}
// Create a wrapper script for local usage
const wrapperScript = `#!/usr/bin/env node
// Auto-generated wrapper for local blax installation
const { spawn } = require('child_process');
const path = require('path');
const binPath = path.join(__dirname, '..', 'bin', 'tlnt.js');
const child = spawn('node', [binPath, ...process.argv.slice(2)], {
stdio: 'inherit',
shell: false
});
child.on('exit', (code) => {
process.exit(code);
});
`;
const wrapperPath = join(packageRoot, 'blax.js');
writeFileSync(wrapperPath, wrapperScript);
log('ā
Created local blax wrapper', colors.green);
return wrapperPath;
}
function showInstallationGuide() {
log('\n' + '='.repeat(60), colors.cyan);
log('š BLAX INSTALLATION COMPLETE!', colors.bold + colors.cyan);
log('='.repeat(60), colors.cyan);
if (isGlobalInstall()) {
log('\nā
Global installation detected', colors.green);
log('You can now use blax from anywhere:', colors.dim);
log(' blax demo', colors.cyan);
log(' blax system start', colors.cyan);
log(' blax --help', colors.cyan);
} else {
log('\nš¦ Local installation detected', colors.yellow);
log('Use one of these methods to run blax:\n', colors.dim);
log('š Method 1 - Use npx (recommended):', colors.bold);
log(' npx blax demo', colors.cyan);
log(' npx blax system start', colors.cyan);
log(' npx blax --help', colors.cyan);
log('\nā” Method 2 - Use npm/pnpm scripts:', colors.bold);
log(' npm run blax demo', colors.cyan);
log(' pnpm blax demo', colors.cyan);
log('\nš§ Method 3 - Add to package.json scripts:', colors.bold);
log(' "scripts": { "blax": "blax" }', colors.dim);
log(' then: npm run blax demo', colors.cyan);
log('\nš” Method 4 - Global install for direct access:', colors.bold);
log(' npm install -g blax@latest', colors.cyan);
log(' then: blax demo', colors.cyan);
}
log('\nš¬ Quick Start:', colors.bold + colors.green);
if (isGlobalInstall()) {
log(' blax demo --quick', colors.cyan);
} else {
log(' npx blax demo --quick', colors.cyan);
}
log('\nš Documentation: https://docs.hms-dev.com', colors.dim);
log('š Issues: https://github.com/hms-dev/blax/issues', colors.dim);
log('\n' + '='.repeat(60), colors.cyan);
}
function updatePackageJson() {
try {
const packageJsonPath = join(process.cwd(), 'package.json');
if (existsSync(packageJsonPath)) {
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
// Add blax script if it doesn't exist
if (!packageJson.scripts) {
packageJson.scripts = {};
}
if (!packageJson.scripts.blax) {
packageJson.scripts.blax = 'blax';
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
log('ā
Added "blax" script to package.json', colors.green);
}
}
} catch (error) {
// Silent fail - not critical
}
}
// Main execution
try {
log('\nš§ Setting up blax...', colors.cyan);
if (!isGlobalInstall()) {
createLocalAlias();
updatePackageJson();
}
showInstallationGuide();
} catch (error) {
log('\nā Setup encountered an issue:', colors.red);
log(error.message, colors.dim);
log('\nYou can still use blax with: npx blax', colors.yellow);
}