|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +import { Command } from 'commander'; |
| 4 | +import { runCommand } from './commands/run.js'; |
| 5 | +import { buildCommand } from './commands/build.js'; |
| 6 | +import { replCommand } from './commands/repl.js'; |
| 7 | +import { logger } from './utils/logger.js'; |
| 8 | +import fs from 'fs-extra'; |
| 9 | +import path from 'path'; |
| 10 | +import { fileURLToPath } from 'url'; |
| 11 | + |
| 12 | +import { loadConfig, mergeOptions } from './utils/config.js'; |
| 13 | + |
| 14 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 15 | +const packageJson = fs.readJsonSync(path.join(__dirname, 'package.json')); |
| 16 | +const config = await loadConfig(); |
| 17 | + |
| 18 | +const program = new Command(); |
| 19 | + |
| 20 | +program |
| 21 | + .name('prox') |
| 22 | + .description('ProXPL CLI - Professional Command-Line Interface for ProX Programming Language') |
| 23 | + .version(packageJson.version, '-v, --version'); |
| 24 | + |
| 25 | +program |
| 26 | + .command('run') |
| 27 | + .alias('r') |
| 28 | + .description('Execute a .prox script') |
| 29 | + .argument('<file>', 'Path to the .prox script') |
| 30 | + .option('-w, --watch', 'Watch mode: automatically rerun on file changes') |
| 31 | + .option('-d, --debug', 'Show detailed debug information') |
| 32 | + .option('-v, --verbose', 'Show verbose execution info') |
| 33 | + .action((file, options) => { |
| 34 | + const merged = mergeOptions(options, config); |
| 35 | + runCommand(file, merged); |
| 36 | + }); |
| 37 | + |
| 38 | +program |
| 39 | + .command('build') |
| 40 | + .alias('b') |
| 41 | + .description('Compile a .prox script to bytecode') |
| 42 | + .argument('<file>', 'Path to the .prox script') |
| 43 | + .option('-o, --output <output>', 'Specified output file') |
| 44 | + .action((file, options) => { |
| 45 | + const merged = mergeOptions(options, config); |
| 46 | + buildCommand(file, merged); |
| 47 | + }); |
| 48 | + |
| 49 | +program |
| 50 | + .command('repl') |
| 51 | + .description('Start interactive ProXPL shell') |
| 52 | + .action(() => { |
| 53 | + replCommand(); |
| 54 | + }); |
| 55 | + |
| 56 | +// Handle unknown commands |
| 57 | +program.on('command:*', () => { |
| 58 | + logger.error('Invalid command: ' + program.args.join(' ')); |
| 59 | + logger.info('See "prox --help" for available commands.'); |
| 60 | + process.exit(1); |
| 61 | +}); |
| 62 | + |
| 63 | +// Default behavior: run repl if no args, or run file if first arg is a file |
| 64 | +if (process.argv.length === 2) { |
| 65 | + replCommand(); |
| 66 | +} else { |
| 67 | + program.parse(process.argv); |
| 68 | +} |
0 commit comments