diff --git a/src/commands/print.js b/src/commands/print.js new file mode 100644 index 0000000..a0eb1ce --- /dev/null +++ b/src/commands/print.js @@ -0,0 +1,52 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2022-2023 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +const path = require('path'); +const {mvnw, flags} = require('../mvnw'); + +/** + * Command to convert .XMIR files into .EO files. + * @param {Hash} opts - All options + * @return {Promise} of assemble task + */ +module.exports = function(opts) { + const input = path.resolve(opts.target, '2-optimize'); + console.debug('Reading from %s', input); + const output = path.resolve(opts.target, 'print'); + console.debug('Writing into %s', output); + return mvnw( + ['eo:print'] + .concat(flags(opts)) + .concat( + [ + `-Deo.printSourcesDir=${input}`, + `-Deo.printOutputDir=${output}`, + ] + ), + opts.target, opts.batch + ).then((r) => { + console.info('XMIR files converted into EO files at %s', output); + return r; + }); +}; diff --git a/src/eoc.js b/src/eoc.js index 8fae8db..ab35d5a 100755 --- a/src/eoc.js +++ b/src/eoc.js @@ -32,6 +32,7 @@ const assemble = require('./commands/assemble'); const sodg = require('./commands/sodg'); const phi = require('./commands/phi'); const unphi = require('./commands/unphi'); +const print = require('./commands/print'); const register = require('./commands/register'); const verify = require('./commands/verify'); const transpile = require('./commands/transpile'); @@ -167,6 +168,13 @@ program.command('unphi') unphi(program.opts()); }); +program.command('print') + .description('Generate EO files from XMIR files') + .action((str, opts) => { + clear(str); + print(program.opts()); + }); + program.command('verify') .description('Verify XMIR files and fail if any issues inside') .action((str, opts) => { diff --git a/test/commands/test_print.js b/test/commands/test_print.js new file mode 100644 index 0000000..fe3fcca --- /dev/null +++ b/test/commands/test_print.js @@ -0,0 +1,54 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2022-2023 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +const fs = require('fs'); +const path = require('path'); +const {runSync, assertFilesExist} = require('../helpers'); + +describe('print', function() { + it('converts XMIR files to EO files', function(done) { + home = path.resolve('temp/test-print/simple'); + fs.rmSync(home, {recursive: true, force: true}); + fs.mkdirSync(path.resolve(home, 'target/2-optimize'), {recursive: true}); + fs.writeFileSync( + path.resolve(home, 'target/2-optimize/app.xmir'), + '' + ); + const stdout = runSync([ + 'print', + '--verbose', + '--track-optimization-steps', + '--parser=0.34.1', + '--hash=1d605bd872f27494551e9dd2341b9413d0d96d89', + '-t', path.resolve(home, 'target'), + ]); + assertFilesExist( + stdout, home, + [ + 'target/print/app.eo', + ] + ); + done(); + }); +});