brainrotscript
Version:
š§ A brainrot programming language that compiles to JavaScript - because why write normal code when you can write code that's absolutely sending you? š
89 lines (74 loc) ⢠2.68 kB
JavaScript
const { Command } = require('commander');
const BrainrotCompiler = require('../src/compiler');
const path = require('path');
const fs = require('fs');
const program = new Command();
const compiler = new BrainrotCompiler();
program
.name('brainrot')
.description('BrainrotScript - A brainrot programming language that compiles to JavaScript')
.version('1.0.0');
program
.command('compile <input>')
.description('Compile a .brainrot file to JavaScript')
.option('-o, --output <path>', 'Output file path')
.action((input, options) => {
const inputPath = path.resolve(input);
if (!fs.existsSync(inputPath)) {
console.error(`ā File not found: ${inputPath}`);
process.exit(1);
}
if (!inputPath.endsWith('.brainrot')) {
console.error('ā Input file must have .brainrot extension');
process.exit(1);
}
const outputPath = options.output || inputPath.replace('.brainrot', '.js');
try {
compiler.compile(inputPath, outputPath);
} catch (error) {
process.exit(1);
}
});
program
.command('run <input>')
.description('Compile and run a .brainrot file')
.action((input) => {
const inputPath = path.resolve(input);
if (!fs.existsSync(inputPath)) {
console.error(`ā File not found: ${inputPath}`);
process.exit(1);
}
if (!inputPath.endsWith('.brainrot')) {
console.error('ā Input file must have .brainrot extension');
process.exit(1);
}
try {
compiler.run(inputPath);
} catch (error) {
process.exit(1);
}
});
program
.command('keywords')
.description('Show all available brainrot keywords')
.action(() => {
const keywords = compiler.getKeywords();
console.log('\nš§ BrainrotScript Keywords:\n');
for (const [jsKeyword, brainrotKeyword] of Object.entries(keywords)) {
console.log(`${brainrotKeyword.padEnd(20)} ā ${jsKeyword}`);
}
console.log();
});
// Default action - if just a file is provided, run it
if (process.argv.length === 3 && process.argv[2].endsWith('.brainrot')) {
const inputPath = path.resolve(process.argv[2]);
if (fs.existsSync(inputPath)) {
compiler.run(inputPath);
} else {
console.error(`ā File not found: ${inputPath}`);
process.exit(1);
}
} else {
program.parse();
}