|
|
|
@ -6,49 +6,26 @@ let RemixCompiler = require('remix-solidity').Compiler |
|
|
|
|
|
|
|
|
|
// TODO: replace this with remix's own compiler code
|
|
|
|
|
|
|
|
|
|
function compileFile (filename, cb) { |
|
|
|
|
let compiler |
|
|
|
|
const sources = { |
|
|
|
|
'tests.sol': {content: fs.readFileSync('sol/tests.sol').toString()} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: for now assumes filepath dir contains all tests, later all this
|
|
|
|
|
// should be replaced with remix's & browser solidity compiler code
|
|
|
|
|
let filepath = path.dirname(filename) |
|
|
|
|
fs.readdirSync(filepath).forEach(file => { |
|
|
|
|
sources[file] = {content: fs.readFileSync(path.join(filepath, file)).toString()} |
|
|
|
|
}) |
|
|
|
|
function compileFileOrFiles (filename, isDirectory, cb) { |
|
|
|
|
let compiler, filepath |
|
|
|
|
|
|
|
|
|
async.waterfall([ |
|
|
|
|
function loadCompiler (next) { |
|
|
|
|
compiler = new RemixCompiler() |
|
|
|
|
compiler.onInternalCompilerLoaded() |
|
|
|
|
// compiler.event.register('compilerLoaded', this, function (version) {
|
|
|
|
|
next() |
|
|
|
|
// });
|
|
|
|
|
}, |
|
|
|
|
function doCompilation (next) { |
|
|
|
|
compiler.event.register('compilationFinished', this, function (success, data, source) { |
|
|
|
|
next(null, data) |
|
|
|
|
}) |
|
|
|
|
compiler.compile(sources, filepath) |
|
|
|
|
} |
|
|
|
|
], function (err, result) { |
|
|
|
|
cb(err, result.contracts) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function compileFiles (directory, cb) { |
|
|
|
|
let compiler |
|
|
|
|
const sources = { |
|
|
|
|
'tests.sol': {content: fs.readFileSync('sol/tests.sol').toString()} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: for now assumes filepath dir contains all tests, later all this
|
|
|
|
|
// should be replaced with remix's & browser solidity compiler code
|
|
|
|
|
fs.readdirSync(directory).forEach(file => { |
|
|
|
|
sources[file] = {content: fs.readFileSync(path.join(directory, file)).toString()} |
|
|
|
|
}) |
|
|
|
|
if (isDirectory) { |
|
|
|
|
filepath = filename |
|
|
|
|
fs.readdirSync(filename).forEach(file => { |
|
|
|
|
sources[file] = {content: fs.readFileSync(path.join(filename, file)).toString()} |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
filepath = path.dirname(filename) |
|
|
|
|
fs.readdirSync(filepath).forEach(file => { |
|
|
|
|
sources[file] = {content: fs.readFileSync(path.join(filepath, file)).toString()} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async.waterfall([ |
|
|
|
|
function loadCompiler (next) { |
|
|
|
@ -62,7 +39,7 @@ function compileFiles (directory, cb) { |
|
|
|
|
compiler.event.register('compilationFinished', this, function (success, data, source) { |
|
|
|
|
next(null, data) |
|
|
|
|
}) |
|
|
|
|
compiler.compile(sources, directory) |
|
|
|
|
compiler.compile(sources, filepath) |
|
|
|
|
} |
|
|
|
|
], function (err, result) { |
|
|
|
|
cb(err, result.contracts) |
|
|
|
@ -70,6 +47,5 @@ function compileFiles (directory, cb) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
module.exports = { |
|
|
|
|
compileFile: compileFile, |
|
|
|
|
compileFiles: compileFiles |
|
|
|
|
compileFileOrFiles: compileFileOrFiles |
|
|
|
|
} |
|
|
|
|