can-algorithm
Version:
Cortex Algorithm Numeral - Intelligent development automation tool
100 lines (81 loc) ⢠3.66 kB
JavaScript
import { promises as fs } from 'fs';
import path from 'path';
import { exec } from 'child_process';
import { promisify } from 'util';
import chalk from 'chalk';
import ora from 'ora';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const execAsync = promisify(exec);
async function setup() {
console.log(chalk.cyan.bold('\nš Can Algorithm Installation\n'));
const spinner = ora('Checking system requirements...').start();
try {
const nodeVersion = process.version;
const majorVersion = parseInt(nodeVersion.split('.')[0].substring(1));
if (majorVersion < 16) {
spinner.fail('Node.js 16+ required');
process.exit(1);
}
spinner.succeed('System requirements met');
spinner.start('Creating directory structure...');
const dirs = [
'.can',
'services',
'core',
'lib',
'commands',
'logs'
];
for (const dir of dirs) {
await fs.mkdir(dir, { recursive: true });
}
spinner.succeed('Directory structure created');
spinner.start('Setting up local services...');
const pm2Config = {
apps: [
{
name: 'can-esp',
script: './services/esp-service.js',
env: {
ESP_PORT: 3002
}
},
{
name: 'can-cortex',
script: './services/cortex-service.js',
env: {
CORTEX_PORT: 3001
}
},
{
name: 'can-license',
script: './services/license-service.js',
env: {
LICENSE_PORT: 3003
}
}
]
};
await fs.writeFile('ecosystem.config.js', `module.exports = ${JSON.stringify(pm2Config, null, 2)}`);
spinner.succeed('Services configured');
console.log(chalk.green.bold('\nā
Installation Complete!\n'));
console.log(chalk.white('Next steps:'));
console.log(chalk.gray('1. Run ') + chalk.cyan('can genconfig') + chalk.gray(' to generate configuration'));
console.log(chalk.gray('2. Start services with ') + chalk.cyan('pm2 start ecosystem.config.js'));
console.log(chalk.gray('3. Begin using Can with ') + chalk.cyan('can <command>'));
console.log(chalk.yellow('\nš Available commands:'));
console.log(chalk.gray(' ⢠') + chalk.white('can scan') + chalk.gray(' - Analyze project structure'));
console.log(chalk.gray(' ⢠') + chalk.white('can ask <request>') + chalk.gray(' - Make simple requests'));
console.log(chalk.gray(' ⢠') + chalk.white('can proj <request>') + chalk.gray(' - Large-scale implementations'));
console.log(chalk.gray(' ⢠') + chalk.white('can crypt <file>') + chalk.gray(' - Encrypt/compile files'));
console.log(chalk.gray(' ⢠') + chalk.white('can status') + chalk.gray(' - Check system status'));
} catch (error) {
spinner.fail('Installation failed');
console.error(chalk.red(error.message));
process.exit(1);
}
}
setup();