2017-03-29 17:50:05 +00:00
|
|
|
let solc;
|
2017-02-25 03:49:34 +00:00
|
|
|
|
2018-04-12 21:55:57 +00:00
|
|
|
let fs = require('fs-extra');
|
|
|
|
let path = require('path');
|
|
|
|
|
|
|
|
function findImports(filename) {
|
|
|
|
console.dir(filename);
|
|
|
|
if (!fs.existsSync(filename)) {
|
|
|
|
if (fs.existsSync(path.join('./node_modules/', filename))) {
|
|
|
|
return {contents: fs.readFileSync(path.join('./node_modules/', filename)).toString()};
|
|
|
|
} else {
|
|
|
|
return {error: 'File not found'};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {contents: fs.readFileSync(filename).toString()};
|
|
|
|
}
|
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
process.on('message', function (msg) {
|
2017-02-25 03:49:34 +00:00
|
|
|
if (msg.action === 'loadCompiler') {
|
2017-07-05 12:35:51 +00:00
|
|
|
solc = require(msg.solcLocation);
|
2017-02-25 03:49:34 +00:00
|
|
|
process.send({result: "loadedCompiler"});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg.action === 'compile') {
|
2018-01-27 20:07:48 +00:00
|
|
|
// TODO: only available in 0.4.11; need to make versions warn about this
|
2018-04-12 21:55:57 +00:00
|
|
|
let output = solc.compileStandardWrapper(JSON.stringify(msg.jsonObj), findImports);
|
2017-02-25 03:49:34 +00:00
|
|
|
process.send({result: "compilation", output: output});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
process.on('exit', function () {
|
2017-02-26 03:39:40 +00:00
|
|
|
process.exit(0);
|
|
|
|
});
|
|
|
|
|