UNPKG

redc

Version:

Compiles RED lang into Minecraft schematics

59 lines (58 loc) 1.74 kB
var _a, _b; import { build } from './main.js'; import yargs from 'yargs'; import * as path from 'path'; import * as fs from 'fs'; var args = yargs(process.argv.slice(2)) .help('Compile REDlang into a format usable by the RED computer.') .options({ file: { description: 'Path to input RED file', demandOption: true, alias: 'f', type: 'string' }, out: { description: 'Path to output directory. If not provided, the file will be dumped in your current directory.', alias: 'o', type: 'string' }, name: { description: 'Name of the function. Use /function <name>. If not provided, the name of <file> will be used.', alias: 'n', type: 'string' }, debug: { description: 'Enabled debugging by sending assembled machine code into STDOUT', alias: 'd', type: 'boolean' } }).parseSync(); var dir = process.cwd(); var file = args.file; if (!file.endsWith('.red')) { file += '.red'; } var out = (_a = args.out) !== null && _a !== void 0 ? _a : '.'; var name = (_b = args.name) !== null && _b !== void 0 ? _b : path.basename(file, '.red'); if (!name.endsWith('mcfunction')) { name += '.mcfunction'; } var addEmptyLine = false; var data = fs.readFileSync(path.resolve(dir, file)).toString(); build(data, { out: function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } if (addEmptyLine) { console.log(); } addEmptyLine = true; console.log.apply(console, args); }, debug: args.debug }).then(function (res) { fs.writeFileSync(path.resolve(dir, out, name), res); });