lua_to_cpls
Version:
A tool capable of compiling a subset of Lua to Please lang compiled files
45 lines (38 loc) • 1.21 kB
JavaScript
// @ts-check
/**
* @description An executable to convert Lua to compiled please
*/
;
const {convertToCompiledPlease} = require('./parser.js');
const fs = require('fs');
const {program} = require('commander');
const {version} = require('../package.json');
const path = require('path');
program
.version(version)
.arguments('<origin>')
.option(
'-o, --out <destination>', 'Path for output file. If it isn\'t ' +
'specified the path of the origin file will be used,' +
'changing the extension to .cpls',
)
.description(
'Convert a lua file to compiled please',
{
origin: 'The path of the file to convert',
},
)
.action((origin, options) => {
try {
const code = fs.readFileSync(origin, 'utf-8');
let translation = convertToCompiledPlease(code);
if (options.out == undefined) {
options.out = origin.match(/^[^\.]*/)[0] + '.cpls';
}
fs.writeFileSync(options.out, JSON.stringify(translation, undefined, 2));
} catch (err) {
console.log('There was an error: ' + err.message);
}
});
program.parse(process.argv);