mirror of https://github.com/embarklabs/embark.git
build web3js generation from pipeline to code_generator
This commit is contained in:
parent
256276c884
commit
1f6e386d9b
|
@ -96,6 +96,10 @@ class CodeGenerator {
|
|||
cb(vanillaABI, contractsJSON);
|
||||
});
|
||||
|
||||
this.events.setCommandHandlerOnce('code-generator:web3js', function(cb) {
|
||||
self.buildWeb3JS(cb);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
generateContext() {
|
||||
|
@ -318,6 +322,50 @@ class CodeGenerator {
|
|||
cb();
|
||||
});
|
||||
}
|
||||
|
||||
buildWeb3JS(cb) {
|
||||
const self = this;
|
||||
let code = "";
|
||||
|
||||
async.waterfall([
|
||||
function getWeb3Location(next) {
|
||||
self.events.request("version:get:web3", function(web3Version) {
|
||||
if (web3Version === "1.0.0-beta") {
|
||||
return next(null, utils.joinPath(fs.embarkPath("js/web3-1.0.min.js")));
|
||||
} else {
|
||||
self.events.request("version:getPackageLocation", "web3", web3Version, function(err, location) {
|
||||
return next(null, fs.dappPath(location));
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
function getImports(web3Location, next) {
|
||||
web3Location = web3Location.replace(/\\/g, '/'); // Import paths must always have forward slashes
|
||||
code += "\nimport Web3 from '" + web3Location + "';\n";
|
||||
|
||||
code += "\n if (typeof web3 !== 'undefined') {";
|
||||
code += "\n } else {";
|
||||
code += "\n var web3 = new Web3();\n";
|
||||
code += "\n }";
|
||||
|
||||
let providerCode = self.generateProvider(false);
|
||||
code += providerCode;
|
||||
code += "\nglobal.__embarkContext = __mainContext.__loadManagerInstance;\n";
|
||||
code += "\nwindow.web3 = web3;\n";
|
||||
code += "\nexport default web3;\n";
|
||||
next();
|
||||
},
|
||||
function makeDirectory(next) {
|
||||
fs.mkdirp(fs.dappPath(".embark"), (err, _result) => {
|
||||
next(err);
|
||||
});
|
||||
},
|
||||
function writeFile(next) {
|
||||
fs.writeFile(fs.dappPath(".embark", 'web3_instance.js'), code, next);
|
||||
}
|
||||
], cb);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = CodeGenerator;
|
||||
|
|
|
@ -31,7 +31,7 @@ class Pipeline {
|
|||
self.buildContracts(contractsJSON, next);
|
||||
},
|
||||
function buildWeb3(next) {
|
||||
self.buildWeb3JS(next);
|
||||
self.events.request('code-generator:web3js', next);
|
||||
},
|
||||
function createImportList(next) {
|
||||
importsList["Embark/EmbarkJS"] = fs.dappPath(".embark", 'embark.js');
|
||||
|
@ -211,49 +211,6 @@ class Pipeline {
|
|||
});
|
||||
}
|
||||
|
||||
buildWeb3JS(cb) {
|
||||
const self = this;
|
||||
let code = "";
|
||||
|
||||
async.waterfall([
|
||||
function getWeb3Location(next) {
|
||||
self.events.request("version:get:web3", function(web3Version) {
|
||||
if (web3Version === "1.0.0-beta") {
|
||||
return next(null, utils.joinPath(fs.embarkPath("js/web3-1.0.min.js")));
|
||||
} else {
|
||||
self.events.request("version:getPackageLocation", "web3", web3Version, function(err, location) {
|
||||
return next(null, fs.dappPath(location));
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
function getImports(web3Location, next) {
|
||||
web3Location = web3Location.replace(/\\/g, '/'); // Import paths must always have forward slashes
|
||||
code += "\nimport Web3 from '" + web3Location + "';\n";
|
||||
|
||||
code += "\n if (typeof web3 !== 'undefined') {";
|
||||
code += "\n } else {";
|
||||
code += "\n var web3 = new Web3();\n";
|
||||
code += "\n }";
|
||||
|
||||
self.events.request('provider-code', function(providerCode) {
|
||||
code += providerCode;
|
||||
code += "\nglobal.__embarkContext = __mainContext.__loadManagerInstance;\n";
|
||||
code += "\nwindow.web3 = web3;\n";
|
||||
code += "\nexport default web3;\n";
|
||||
next();
|
||||
});
|
||||
},
|
||||
function makeDirectory(next) {
|
||||
fs.mkdirp(fs.dappPath(".embark"), (err, _result) => {
|
||||
next(err);
|
||||
});
|
||||
},
|
||||
function writeFile(next) {
|
||||
fs.writeFile(fs.dappPath(".embark", 'web3_instance.js'), code, next);
|
||||
}
|
||||
], cb);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Pipeline;
|
||||
|
|
Loading…
Reference in New Issue