Initial version of solc plugin
This commit is contained in:
commit
e2a076df12
|
@ -0,0 +1,4 @@
|
|||
node_modules
|
||||
.idea
|
||||
.eslintrc.json
|
||||
npm-debug.log
|
|
@ -0,0 +1,25 @@
|
|||
Embark-Bamboo
|
||||
======
|
||||
|
||||
Plugin for [Embark](https://github.com/embark-framework/embark) to compile contracts using solc
|
||||
|
||||
Installation
|
||||
======
|
||||
|
||||
In your embark dapp directory:
|
||||
```npm install embark-solc --save```
|
||||
|
||||
then add embark-solc to the plugins section in ```embark.json```:
|
||||
|
||||
```Json
|
||||
"plugins": {
|
||||
"embark-solc": {}
|
||||
}
|
||||
```
|
||||
|
||||
Requirements
|
||||
======
|
||||
|
||||
- Embark 3.0.0 or higher
|
||||
- Solc installed and available globally on your machine
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
/*global require, module*/
|
||||
const Compiler = require("./lib/Compiler");
|
||||
|
||||
module.exports = (embark) => {
|
||||
embark.registerCompiler('.sol', compileSolc);
|
||||
function compileSolc(contractFiles, cb) {
|
||||
if(!contractFiles || !contractFiles.length) {
|
||||
return cb();
|
||||
}
|
||||
Compiler.compileSolc(embark.logger, contractFiles, cb);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,65 @@
|
|||
const async = require('async');
|
||||
const path = require('path');
|
||||
const shelljs = require('shelljs');
|
||||
|
||||
function compileSolcContract(logger, filename, callback) {
|
||||
shelljs.exec(`solc --optimize --combined-json abi,bin,bin-runtime,compact-format,hashes,interface,metadata ${filename}`,
|
||||
{silent: true}, (code, stdout, stderr) => {
|
||||
|
||||
if (stderr) {
|
||||
logger.warn(stderr);
|
||||
}
|
||||
|
||||
if (code !== 0) {
|
||||
return callback(`solc exited with error code ${code}`);
|
||||
}
|
||||
|
||||
if (!stdout) {
|
||||
return callback('Execution returned nothing');
|
||||
}
|
||||
|
||||
callback(null, stdout.replace(/\n/g, ''));
|
||||
});
|
||||
}
|
||||
|
||||
function compileSolc(logger, contractFiles, cb) {
|
||||
if (!contractFiles || !contractFiles.length) {
|
||||
return cb();
|
||||
}
|
||||
logger.info("compiling solidity contracts with command line solc...");
|
||||
let compiled_object = {};
|
||||
async.each(contractFiles,
|
||||
function (file, fileCb) {
|
||||
compileSolcContract(logger, file.filename, (err, compileString) => {
|
||||
if (err) {
|
||||
return fileCb(err);
|
||||
}
|
||||
|
||||
let json = JSON.parse(compileString);
|
||||
|
||||
for (let contractFile in json.contracts) {
|
||||
let className = contractFile.substr( contractFile.indexOf(":") + 1);
|
||||
let fileName = contractFile.substr(0, contractFile.indexOf(":"));
|
||||
|
||||
let contract = json.contracts[contractFile];
|
||||
|
||||
compiled_object[className] = {};
|
||||
compiled_object[className].code = contract.bin
|
||||
compiled_object[className].runtimeBytecode = contract["bin-runtime"];
|
||||
compiled_object[className].functionHashes = contract.hashes;
|
||||
compiled_object[className].abiDefinition = JSON.parse(contract.abi);
|
||||
compiled_object[className].filename = fileName;
|
||||
}
|
||||
|
||||
fileCb();
|
||||
});
|
||||
},
|
||||
function (err) {
|
||||
cb(err, compiled_object);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
compileSolc,
|
||||
compileSolcContract
|
||||
};
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"name": "embark-solc",
|
||||
"version": "0.0.5",
|
||||
"description": "Solc plugin for Embark (uses command line)",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [
|
||||
"solidity",
|
||||
"solc",
|
||||
"plugin",
|
||||
"contracts",
|
||||
"ethereum"
|
||||
],
|
||||
"author": "Richard Ramos",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/embark-framework/embark-solc/issues"
|
||||
},
|
||||
"homepage": "https://github.com/embark-framework/embark-solc#readme",
|
||||
"devDependencies": {
|
||||
"eslint": "^4.19.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"async": "^2.6.0",
|
||||
"shelljs": "^0.8.1"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue