mirror of
https://github.com/embarklabs/embark-solc.git
synced 2025-02-28 14:30:36 +00:00
Can specify "outputBinary" config to gen a .bin file of contract
This commit is contained in:
parent
dadf7dcd32
commit
34b053c8cf
2
index.js
2
index.js
@ -7,6 +7,6 @@ module.exports = (embark) => {
|
||||
if(!contractFiles || !contractFiles.length) {
|
||||
return cb();
|
||||
}
|
||||
Compiler.compileSolc(embark.logger, contractFiles, cb);
|
||||
Compiler.compileSolc(embark, contractFiles, cb);
|
||||
}
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
const async = require('async');
|
||||
const path = require('path');
|
||||
const shelljs = require('shelljs');
|
||||
const fs = require('fs');
|
||||
|
||||
function compileSolcContract(logger, filename, callback) {
|
||||
shelljs.exec(`solc --optimize --combined-json abi,bin,bin-runtime,compact-format,hashes,interface,metadata ${filename}`,
|
||||
@ -22,11 +22,15 @@ function compileSolcContract(logger, filename, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function compileSolc(logger, contractFiles, cb) {
|
||||
function compileSolc(embark, contractFiles, cb) {
|
||||
if (!contractFiles || !contractFiles.length) {
|
||||
return cb();
|
||||
}
|
||||
|
||||
const logger = embark.logger;
|
||||
const outputBinary = embark.pluginConfig.outputBinary;
|
||||
const outputDir = embark.config.buildDir + embark.config.contractDirectories[0];
|
||||
|
||||
const solc = shelljs.which('solc');
|
||||
if (!solc) {
|
||||
logger.warn('solc is not installed on your machine');
|
||||
@ -35,6 +39,7 @@ function compileSolc(logger, contractFiles, cb) {
|
||||
}
|
||||
|
||||
logger.info("compiling solidity contracts with command line solc...");
|
||||
|
||||
let compiled_object = {};
|
||||
async.each(contractFiles,
|
||||
function (file, fileCb) {
|
||||
@ -59,6 +64,13 @@ function compileSolc(logger, contractFiles, cb) {
|
||||
compiled_object[className].functionHashes = contract.hashes;
|
||||
compiled_object[className].abiDefinition = JSON.parse(contract.abi);
|
||||
compiled_object[className].filename = fileName;
|
||||
|
||||
if(outputBinary){
|
||||
fs.writeFile(outputDir + className + ".bin", contract.bin, (err) => {
|
||||
if (err) logger.error(err);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fileCb();
|
||||
|
Loading…
x
Reference in New Issue
Block a user