UNPKG

@alu0101337760/constant-folding

Version:
49 lines (41 loc) 1.36 kB
#!/usr/bin/env node const { program } = require('commander'); const fs = require('fs'); const { version, description } = require('../package.json'); const constantFolding = require('../src/constant-folding'); // Your libs "use strict"; program .version(version) .name('blah') .arguments("<filename>", 'file with the original code') .option("-o, --output <filename>", "output.js") .action((filename, options) => { transpile(filename, options.output); }); program.parse(process.argv); /** * A function that takes two file names and blah, * ... * ... * @param {string} input_file The file from which to read the code * @param {string} output_file The file to which to write the code with the logs * etc. * @private */ function transpile(input_file, output_file) { fs.readFile(input_file, 'utf-8', (err, input) => { if (err) { console.log("Couldn't read the file: " + err); return; } console.log("File read succesfully"); let output = constantFolding(input); fs.writeFile(output_file, output, (err) => { if (err) { console.log("Couldn't write the output to " + output_file + ": " + err); return; } console.log("Output written succesfully in " + output_file); }); }); }