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? 💀
104 lines (83 loc) • 3.43 kB
JavaScript
const { Command } = require('commander');
const ReactBrainrotCompiler = require('../src/react-compiler');
const path = require('path');
const fs = require('fs');
const program = new Command();
const compiler = new ReactBrainrotCompiler();
program
.name('brainrot-react')
.description('BrainrotScript React Development Tools - Build React apps with brainrot syntax! 🧠⚛️')
.version('1.0.0');
program
.command('compile <input>')
.description('Compile a .brainrot React component to .jsx')
.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', '.jsx');
try {
compiler.compileToReact(inputPath, outputPath);
} catch (error) {
process.exit(1);
}
});
program
.command('build <sourceDir>')
.description('Build entire React project from .brainrot files')
.option('-o, --output <dir>', 'Output directory', './build')
.action((sourceDir, options) => {
const sourcePath = path.resolve(sourceDir);
const outputPath = path.resolve(options.output);
if (!fs.existsSync(sourcePath)) {
console.error(`❌ Source directory not found: ${sourcePath}`);
process.exit(1);
}
try {
compiler.compileReactProject(sourcePath, outputPath);
} catch (error) {
process.exit(1);
}
});
program
.command('watch <sourceDir>')
.description('Watch .brainrot files and auto-compile to .jsx')
.option('-o, --output <dir>', 'Output directory', './build')
.action((sourceDir, options) => {
const sourcePath = path.resolve(sourceDir);
const outputPath = path.resolve(options.output);
if (!fs.existsSync(sourcePath)) {
console.error(`❌ Source directory not found: ${sourcePath}`);
process.exit(1);
}
try {
// Initial compilation
compiler.compileReactProject(sourcePath, outputPath);
// Start watching
compiler.watchAndCompile(sourcePath, outputPath);
console.log('Press Ctrl+C to stop watching...');
// Keep the process running
process.stdin.resume();
} catch (error) {
process.exit(1);
}
});
program
.command('create-app <name>')
.description('Create a new BrainrotScript React app')
.action((name) => {
console.log(`🧠 Creating BrainrotScript React app: ${name}`);
// TODO: Implement full app scaffolding
console.log('📦 App creation coming soon! For now, use the compile and build commands.');
console.log('💡 Check out the examples/ directory for component templates!');
});
program.parse();
module.exports = { ReactBrainrotCompiler };