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