Skip to content

Commit

Permalink
#235: demand
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Feb 14, 2024
1 parent 2778225 commit 25e2878
Show file tree
Hide file tree
Showing 19 changed files with 90 additions and 15 deletions.
31 changes: 31 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"fast-xml-parser": "4.3.4",
"node": "21.6.1",
"relative": "3.0.2",
"semver": "7.6.0",
"sync-request": "6.1.0",
"xmlhttprequest": "1.8.0"
},
Expand Down
6 changes: 4 additions & 2 deletions src/commands/phi.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

const rel = require('relative');
const path = require('path');
const {gte} = require('../demand')
const {mvnw, flags} = require('../mvnw');

/**
Expand All @@ -32,6 +33,7 @@ const {mvnw, flags} = require('../mvnw');
* @return {Promise} of assemble task
*/
module.exports = function(opts) {
gte('EO parser', opts.parser, '0.35.2');
const target = path.resolve(opts.target);
const input = path.resolve(opts.target, '2-optimize');
console.debug('Reading .XMIR files from %s', rel(input));
Expand All @@ -42,8 +44,8 @@ module.exports = function(opts) {
.concat(flags(opts))
.concat(
[
`-DphiInputDir=${input}`,
`-DphiOutputDir=${output}`,
`-Deo.phiInputDir=${input}`,
`-Deo.phiOutputDir=${output}`,
]
),
opts.target, opts.batch
Expand Down
6 changes: 4 additions & 2 deletions src/commands/unphi.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
const rel = require('relative');
const path = require('path');
const {mvnw, flags} = require('../mvnw');
const {gte} = require('../demand')

/**
* Command to convert .PHI files into .XMIR files.
* @param {Hash} opts - All options
* @return {Promise} of assemble task
*/
module.exports = function(opts) {
gte('EO parser', opts.parser, '0.35.2');
const input = path.resolve(opts.target, 'phi');
console.debug('Reading .PHI files from %s', rel(input));
const output = path.resolve(opts.target, 'unphi');
Expand All @@ -41,8 +43,8 @@ module.exports = function(opts) {
.concat(flags(opts))
.concat(
[
`-DunphiInputDir=${input}`,
`-DunphiOutputDir=${output}`,
`-Deo.unphiInputDir=${input}`,
`-Deo.unphiOutputDir=${output}`,
]
),
opts.target, opts.batch
Expand Down
35 changes: 35 additions & 0 deletions src/demand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 semver = require('semver');

/**
* Only if provided version is the required one or younger.
*/
module.exports.gte = function(subject, current, min) {
if (semver.lt(current, min)) {
console.error('%s is required to have version %s or higher, while you use %s', subject, min, current);
process.exit(1);
}
}
2 changes: 1 addition & 1 deletion test/commands/test_assemble.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('assemble', function() {
home = path.resolve('temp/test-assemble/simple');
fs.rmSync(home, {recursive: true, force: true});
fs.mkdirSync(path.resolve(home, 'src'), {recursive: true});
fs.writeFileSync(path.resolve(home, 'src/assemble.eo'), '[] > assemble\n');
fs.writeFileSync(path.resolve(home, 'src/assemble.eo'), '# sample\n[] > assemble\n');
const stdout = runSync([
'assemble',
'--verbose',
Expand Down
2 changes: 1 addition & 1 deletion test/commands/test_clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('clean', function() {
fs.rmSync(eo, {recursive: true, force: true});
fs.mkdirSync(path.resolve(home, 'src'), {recursive: true});
fs.mkdirSync(eo, {recursive: true});
fs.writeFileSync(path.resolve(home, 'src/clean.eo'), '[] > clean\n');
fs.writeFileSync(path.resolve(home, 'src/clean.eo'), '# sample\n[] > clean\n');
const stdout = runSync([
'clean', '-s', path.resolve(home, 'src'), '-t', path.resolve(home, 'target'), '--global',
]);
Expand Down
3 changes: 2 additions & 1 deletion test/commands/test_compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ describe('compile', function() {
'+package foo.bar',
'+junit',
'',
'# This is a sample object',
'[] > simple-test-compile',
' TRUE > @',
'',
].join('\n')
);
const stdout = runSync([
Expand Down Expand Up @@ -116,6 +116,7 @@ function simple(name) {
'+package foo.bar',
'+alias org.eolang.io.stdout',
'',
'# This is a simple object',
`[args] > ${name}`,
' stdout "Hello, world!" > @',
].join('\n');
Expand Down
1 change: 1 addition & 0 deletions test/commands/test_dataize.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ versions.forEach(function(hash, version) {
'+package foo.bar',
'+alias org.eolang.io.stdout',
'',
'# sample',
'[args] > simple',
' stdout "Hello, world!\\n" > @',
].join('\n')
Expand Down
1 change: 1 addition & 0 deletions test/commands/test_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('link', function() {
'+package foo.bar',
'+alias org.eolang.io.stdout',
'',
'# sample object'
'[args] > link',
' stdout "Hello, world!" > @',
].join('\n')
Expand Down
2 changes: 1 addition & 1 deletion test/commands/test_parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('parse', function() {
home = path.resolve('temp/test-parse/simple');
fs.rmSync(home, {recursive: true, force: true});
fs.mkdirSync(path.resolve(home, 'src'), {recursive: true});
fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '[] > simple\n');
fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '# sample\n[] > simple\n');
const stdout = runSync([
'parse',
'--verbose',
Expand Down
2 changes: 1 addition & 1 deletion test/commands/test_phi.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('phi', function() {
home = path.resolve('temp/test-phi/simple');
fs.rmSync(home, {recursive: true, force: true});
fs.mkdirSync(path.resolve(home, 'src'), {recursive: true});
fs.writeFileSync(path.resolve(home, 'src/phi.eo'), '[] > phi\n');
fs.writeFileSync(path.resolve(home, 'src/phi.eo'), '# sample\n[] > phi\n');
const stdout = runSync([
'phi',
'--verbose',
Expand Down
2 changes: 1 addition & 1 deletion test/commands/test_register.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('register', function() {
home = path.resolve('temp/test-register/simple');
fs.rmSync(home, {recursive: true, force: true});
fs.mkdirSync(path.resolve(home, 'src'), {recursive: true});
fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '[] > simple\n');
fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '# sample\n[] > simple\n');
const stdout = runSync([
'register',
'--verbose',
Expand Down
2 changes: 1 addition & 1 deletion test/commands/test_sodg.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('sodg', function() {
home = path.resolve('temp/test-sodg/simple');
fs.rmSync(home, {recursive: true, force: true});
fs.mkdirSync(path.resolve(home, 'src'), {recursive: true});
fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '[] > simple\n');
fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '# sample\n[] > simple\n');
const stdout = runSync([
'sodg',
'--verbose',
Expand Down
1 change: 1 addition & 0 deletions test/commands/test_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('test', function() {
[
'+junit',
'',
'# sample',
'[] > simple-comparison-works',
' gt. > @',
' 10',
Expand Down
2 changes: 1 addition & 1 deletion test/commands/test_transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('transpile', function() {
home = path.resolve('temp/test-transpile/transpile');
fs.rmSync(home, {recursive: true, force: true});
fs.mkdirSync(path.resolve(home, 'src'), {recursive: true});
fs.writeFileSync(path.resolve(home, 'src/transpile.eo'), '[] > transpile\n');
fs.writeFileSync(path.resolve(home, 'src/transpile.eo'), '# sample\n[] > transpile\n');
const stdout = runSync([
'transpile',
'--verbose',
Expand Down
2 changes: 1 addition & 1 deletion test/commands/test_unphi.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('unphi', function() {
home = path.resolve('temp/test-unphi/simple');
fs.rmSync(home, {recursive: true, force: true});
fs.mkdirSync(path.resolve(home, 'target/phi'), {recursive: true});
fs.writeFileSync(path.resolve(home, 'target/phi/app.phi'), '{ app ↦ ⟦ ⟧ }');
fs.writeFileSync(path.resolve(home, 'target/phi/app.phi'), '{ app ↦ ⟦ ⟧ }');
const stdout = runSync([
'unphi',
'--verbose',
Expand Down
2 changes: 1 addition & 1 deletion test/commands/test_verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('verify', function() {
home = path.resolve('temp/test-verify/simple');
fs.rmSync(home, {recursive: true, force: true});
fs.mkdirSync(path.resolve(home, 'src'), {recursive: true});
fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '[] > simple\n');
fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '# sample\n[] > simple\n');
const stdout = runSync([
'verify',
'--verbose',
Expand Down
2 changes: 1 addition & 1 deletion test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// When you upgrade them, don't forget to place old values to the
// "test_dataize.js" table of versions, in order to make sure we
// do test dataization with all possible old versions.
module.exports.parserVersion = '0.35.1';
module.exports.parserVersion = '0.35.2';
module.exports.homeHash = '130afdd1456a0cbafd52aee8d7bc612e1faac547';

/**
Expand Down

0 comments on commit 25e2878

Please sign in to comment.