embark-area-51/lib/modules/solidity/solcP.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-03-29 17:50:05 +00:00
let solc;
2017-02-25 03:49:34 +00:00
2018-04-19 18:26:11 +00:00
const fs = require('fs-extra');
const path = require('path');
const constants = require('../../constants');
function findImports(filename) {
2018-04-12 21:57:55 +00:00
if (fs.existsSync(filename)) {
return {contents: fs.readFileSync(filename).toString()};
}
2018-04-12 21:57:55 +00:00
if (fs.existsSync(path.join('./node_modules/', filename))) {
return {contents: fs.readFileSync(path.join('./node_modules/', filename)).toString()};
}
2018-04-19 18:26:11 +00:00
if (fs.existsSync(path.join(constants.httpContractsDirectory, filename))) {
return {contents: fs.readFileSync(path.join('./.embark/contracts', filename)).toString()};
}
2018-04-12 21:57:55 +00:00
return {error: 'File not found'};
}
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') {
solc = require(msg.solcLocation);
2017-02-25 03:49:34 +00:00
process.send({result: "loadedCompiler"});
}
if (msg.action === 'compile') {
// TODO: only available in 0.4.11; need to make versions warn about this
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 () {
process.exit(0);
});