Skip to content

Commit

Permalink
feat(#93): fix all eslint complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Nov 30, 2022
1 parent e36ecc1 commit 7a5fa4c
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 62 deletions.
3 changes: 2 additions & 1 deletion src/commands/assemble.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const parserVersion = require('../parser-version');
/**
* Command to assemble .XMIR files.
* @param {Hash} opts - All options
* @return {Promise} of assemble task
*/
module.exports = function(opts) {
return mvnwSync([
Expand All @@ -41,7 +42,7 @@ module.exports = function(opts) {
`-Deo.outputDir=${path.resolve(opts.target, 'classes')}`,
`-Deo.placed=${path.resolve(opts.target, 'eo-placed.csv')}`,
`-Deo.placedFormat=csv`,
]).then(r => {
]).then((r) => {
console.info('EO program assembled in %s', path.resolve(opts.target));
return r;
});
Expand Down
3 changes: 2 additions & 1 deletion src/commands/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const parserVersion = require('../parser-version');
/**
* Command to compile target language into binaries.
* @param {Hash} opts - All options
* @return {Promise} of compile task
*/
module.exports = function(opts) {
const target = path.resolve(opts.target);
Expand All @@ -40,7 +41,7 @@ module.exports = function(opts) {
`-Deo.targetDir=${target}`,
`-Deo.generatedDir=${path.resolve(opts.target, 'generated-sources')}`,
'-Deo.version=' + (opts.parser ? opts.parser : parserVersion()),
]).then(r => {
]).then((r) => {
console.info('Java .class files compiled into %s', target);
return r;
});
Expand Down
3 changes: 2 additions & 1 deletion src/commands/gmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const parserVersion = require('../parser-version');
/**
* Generate GMI files from XMIR.
* @param {Hash} opts - All options
* @return {Promise} of gmi task
*/
module.exports = function(opts) {
const argv = [
Expand Down Expand Up @@ -59,7 +60,7 @@ module.exports = function(opts) {
argv.push('-Deo.generateGraphFiles');
argv.push('-Deo.generateDotFiles');
}
return mvnwSync(argv).then(r => {
return mvnwSync(argv).then((r) => {
console.info('GMI files generated in %s', path.resolve(opts.target));
return r;
});
Expand Down
5 changes: 3 additions & 2 deletions src/commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ const parserVersion = require('../parser-version');
/**
* Command to link binaries into a single executable binary.
* @param {Hash} opts - All options
* @return {Promise} of link task
*/
module.exports = function(opts) {
return mvnwSync([
'jar:jar',
opts.verbose ? '' : '--quiet',
`-Deo.targetDir=${path.resolve(opts.target)}`,
'-Deo.version=' + (opts.parser ? opts.parser : parserVersion()),
]).then(r => {
]).then((r) => {
console.info('Executable JAR created at %s', path.resolve(opts.target, 'eoc.jar'));
return r;
})
});
};
3 changes: 2 additions & 1 deletion src/commands/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const parserVersion = require('../parser-version');
/**
* Command to register .EO sources.
* @param {Hash} opts - All options
* @return {Promise} of register task
*/
module.exports = function(opts) {
const foreign = path.resolve(opts.target, 'eo-foreign.json');
Expand All @@ -38,7 +39,7 @@ module.exports = function(opts) {
opts.verbose ? '' : '--quiet',
`-Deo.targetDir=${path.resolve(opts.target)}`,
`-Deo.sourcesDir=${path.resolve(opts.sources)}`,
]).then(r => {
]).then((r) => {
console.info('EO objects registered in %s', foreign);
return r;
});
Expand Down
1 change: 1 addition & 0 deletions src/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const path = require('path');
/**
* Command to run all available unit tests.
* @param {Hash} opts - All options
* @return {Promise} of compile task
*/
module.exports = function(opts) {
return mvnwSync([
Expand Down
3 changes: 2 additions & 1 deletion src/commands/transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const parserVersion = require('../parser-version');
/**
* Command to transpile XMIR files into target language.
* @param {Hash} opts - All options
* @return {Promise} of transpile task
*/
module.exports = function(opts) {
const sources = path.resolve(opts.target, 'generated-sources');
Expand All @@ -38,7 +39,7 @@ module.exports = function(opts) {
opts.verbose ? '' : '--quiet',
`-Deo.targetDir=${path.resolve(opts.target)}`,
`-Deo.generatedDir=${sources}`,
]).then(r => {
]).then((r) => {
console.info('Java sources generated in %s', sources);
return r;
});
Expand Down
46 changes: 23 additions & 23 deletions src/eoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ program.command('assemble')
.action((str, opts) => {
if (program.opts().alone == undefined) {
register(program.opts())
.then(r => assemble(program.opts()));
.then((r) => assemble(program.opts()));
} else {
assemble(program.opts());
}
Expand All @@ -106,8 +106,8 @@ program.command('gmi')
.action((str, opts) => {
if (program.opts().alone == undefined) {
register(program.opts())
.then(r => assemble(program.opts()))
.then(r => gmi({...program.opts(), ...str}));
.then((r) => assemble(program.opts()))
.then((r) => gmi({...program.opts(), ...str}));
} else {
gmi({...program.opts(), ...str});
}
Expand All @@ -118,10 +118,10 @@ program.command('transpile')
.action((str, opts) => {
if (program.opts().alone == undefined) {
register(program.opts())
.then(r => assemble(program.opts()))
.then(r => transpile(program.opts()));
.then((r) => assemble(program.opts()))
.then((r) => transpile(program.opts()));
} else {
transpile(program.opts())
transpile(program.opts());
}
});

Expand All @@ -130,9 +130,9 @@ program.command('compile')
.action((str, opts) => {
if (program.opts().alone == undefined) {
register(program.opts())
.then(r => assemble(program.opts()))
.then(r => transpile(program.opts()))
.then(r => compile(program.opts()))
.then((r) => assemble(program.opts()))
.then((r) => transpile(program.opts()))
.then((r) => compile(program.opts()));
} else {
compile(program.opts());
}
Expand All @@ -143,10 +143,10 @@ program.command('link')
.action((str, opts) => {
if (program.opts().alone == undefined) {
register(program.opts())
.then(r => assemble(program.opts()))
.then(r => transpile(program.opts()))
.then(r => compile(program.opts()))
.then(r => link(program.opts()))
.then((r) => assemble(program.opts()))
.then((r) => transpile(program.opts()))
.then((r) => compile(program.opts()))
.then((r) => link(program.opts()));
} else {
link(program.opts());
}
Expand All @@ -158,11 +158,11 @@ program.command('dataize')
.action((str, opts) => {
if (program.opts().alone == undefined) {
register(program.opts())
.then(r => assemble(program.opts()))
.then(r => transpile(program.opts()))
.then(r => compile(program.opts()))
.then(r => link(program.opts()))
.then(r => dataize(program.args[1], program.args.slice(2), {...program.opts(), ...str}));
.then((r) => assemble(program.opts()))
.then((r) => transpile(program.opts()))
.then((r) => compile(program.opts()))
.then((r) => link(program.opts()))
.then((r) => dataize(program.args[1], program.args.slice(2), {...program.opts(), ...str}));
} else {
dataize(program.args[1], program.args.slice(2), {...program.opts(), ...str});
}
Expand All @@ -173,11 +173,11 @@ program.command('test')
.action((str, opts) => {
if (program.opts().alone == undefined) {
register(program.opts())
.then(r => assemble(program.opts()))
.then(r => transpile(program.opts()))
.then(r => compile(program.opts()))
.then(r => link(program.opts()))
.then(r => test(program.opts()))
.then((r) => assemble(program.opts()))
.then((r) => transpile(program.opts()))
.then((r) => compile(program.opts()))
.then((r) => link(program.opts()))
.then((r) => test(program.opts()));
} else {
test(program.opts());
}
Expand Down
11 changes: 6 additions & 5 deletions src/mvnw.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function shell() {
/**
* Run mvnw with provided commands.
* @param {Hash} args - All arguments to pass to it
* @return {Promise} of maven execution task
*/
module.exports = function(args) {
return new Promise((resolve, reject) => {
Expand All @@ -63,16 +64,16 @@ module.exports = function(args) {
shell: shell(),
}
);
let target = params.find(element => element.includes("targetDir"));
if(target != undefined){
status.start(args[0], target.split("=")[1]);
const target = params.find((element) => element.includes('targetDir'));
if (target != undefined) {
status.start(args[0], target.split('=')[1]);
}
result.on('close', code => {
result.on('close', (code) => {
if (code !== 0) {
throw new Error('The command "' + cmd + '" exited with #' + code + ' code');
}
status.stop();
resolve(args);
});
});
};
};
72 changes: 45 additions & 27 deletions src/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,47 +31,65 @@ module.exports = {
stop: stop,
};

var running = false;
var phase = "unknown";
var beginning;
var target;
let running = false;
let phase = 'unknown';
let beginning;
let target;

function start(stage, dir){
/**
* Starts mvnw execution status detection.
* @param {String} stage - A maven stage like assemble, compile, transpile, etc.
* @param {String} dir - Directory where to check progress - ./.eoc
*/
function start(stage, dir) {
running = true;
phase = stage;
target = dir;
beginning = Date.now();
var check = function(){
if(running){
const check = function() {
if (running) {
print();
setTimeout(check, 200);
}
}
};
check();
}

function stop(){
/**
* Stops mvnw execution status detection.
*/
function stop() {
running = false;
process.stdout.write("\n");
process.stdout.write('\n');
}

function print(){
readline.clearLine(process.stdout);
readline.cursorTo(process.stdout, 0);
let duration = Date.now() - beginning;
function count(dir, curr){
if(fs.existsSync(dir)) {
for (const f of fs.readdirSync(dir)) {
next = path.join(dir, f);
if(fs.statSync(next).isDirectory()){
curr = count(next, curr);
} else {
curr++;
}
}
/**
* Prints mvnw execution status.
*/
function print() {
readline.clearLine(process.stdout);
readline.cursorTo(process.stdout, 0);
const duration = Date.now() - beginning;
/**
* Recursively calculates number of files under a directory.
* @param {String} dir - Directory where to count.
* @param {Integer} curr - Current counter.
* @return {Integer} Total number files.
*/
function count(dir, curr) {
if (fs.existsSync(dir)) {
for (const f of fs.readdirSync(dir)) {
next = path.join(dir, f);
if (fs.statSync(next).isDirectory()) {
curr = count(next, curr);
} else {
curr++;
}
return curr;
}
}
process.stdout.write(`\x1b[33m[${phase}] ${duration} ms. Total number of compiled files ${count(target, 0)}\x1b[0m`);
return curr;
}
process.stdout.write(
`\x1b[33m[${phase}] ${duration} ms. Total number of compiled files ${count(target, 0)}\x1b[0m`
);
}

0 comments on commit 7a5fa4c

Please sign in to comment.