Fixed plugin loading logic

This commit is contained in:
Richard Ramos 2018-05-11 15:49:06 -04:00 committed by Pascal Precht
parent 1e4aa12665
commit 8f1e19f1a2
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
2 changed files with 56 additions and 4 deletions

View File

@ -1,3 +1,7 @@
const commandName = "generate-ui";
const errorMessage = (message) => new Error(commandName + ": " + message);
class Scaffolding { class Scaffolding {
constructor(embark, options){ constructor(embark, options){
this.embark = embark; this.embark = embark;
@ -26,15 +30,21 @@ class Scaffolding {
}); });
if(build === null){ if(build === null){
throw new Error("Could not find plugin for framework '" + this.framework + "'"); throw errorMessage("Could not find plugin for framework '" + this.framework + "'");
} }
if(!this.isContract(contractName)){ if(!this.isContract(contractName)){
return new Error("contract '" + contractName + "' does not exist"); return errorMessage("contract '" + contractName + "' does not exist");
} }
const contract = contractConfiguration.contracts[contractName]; const contract = contractConfiguration.contracts[contractName];
build(contract);
try {
let result = build(contract);
this.embark.logger.info(result);
} catch(err){
throw errorMessage(err);
}
} }
} }

View File

@ -0,0 +1,42 @@
class Scaffolding {
constructor(embark, options){
this.embark = embark;
this.options = options;
this.framework = options.framework;
this.frameworkPlugin = null;
}
isContract(contractName){
return this.embark.config.contractsConfig.contracts[contractName] !== undefined;
}
generate(contractName, contractConfiguration){
if(this.framework == 'react'){
this.embark.plugins.loadInternalPlugin('scaffolding-react', this.options);
}
let dappGenerators = this.embark.plugins.getPluginsFor('dappGenerator');
let build = null;
dappGenerators.forEach((plugin) => {
plugin.dappGenerators.forEach((d) => {
if(d.framework == this.framework){
build = d.cb;
}
});
});
if(build === null){
throw new Error("Could not find plugin for framework '" + this.framework + "'");
}
if(!this.isContract(contractName)){
return new Error("contract '" + contractName + "' does not exist");
}
const contract = contractConfiguration.contracts[contractName];
build(contract);
}
}
module.exports = Scaffolding;