embark/lib/contracts/compiler.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-03-30 02:18:00 +09:00
let async = require('../utils/async_extend.js');
2017-02-17 07:14:44 -05:00
2017-03-30 20:12:39 +09:00
class Compiler {
constructor(options) {
this.plugins = options.plugins;
this.logger = options.logger;
}
2017-01-28 21:31:09 -05:00
2017-03-30 20:12:39 +09:00
compile_contracts(contractFiles, cb) {
2017-12-16 15:39:30 -05:00
let available_compilers = {};
2017-01-28 21:31:09 -05:00
2017-12-29 08:26:31 -05:00
let pluginCompilers = this.plugins.getPluginsProperty('compilers', 'compilers');
pluginCompilers.forEach(function (compilerObject) {
available_compilers[compilerObject.extension] = compilerObject.cb;
});
2017-01-28 21:31:09 -05:00
2017-03-30 20:12:39 +09:00
let compiledObject = {};
2017-01-28 21:31:09 -05:00
2017-03-30 20:12:39 +09:00
async.eachObject(available_compilers,
function (extension, compiler, callback) {
// TODO: warn about files it doesn't know how to compile
let matchingFiles = contractFiles.filter(function (file) {
2017-06-29 07:39:12 -04:00
let fileMatch = file.filename.match(/\.[0-9a-z]+$/);
return (fileMatch && (fileMatch[0] === extension));
2017-03-30 20:12:39 +09:00
});
2016-08-14 08:04:34 -04:00
2017-03-30 20:12:39 +09:00
compiler.call(compiler, matchingFiles || [], function (err, compileResult) {
Object.assign(compiledObject, compileResult);
callback(err, compileResult);
});
},
function (err) {
cb(err, compiledObject);
}
2017-03-30 20:12:39 +09:00
);
}
}
2016-08-14 08:04:34 -04:00
module.exports = Compiler;