2018-05-09 21:02:17 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-05-11 19:49:06 +00:00
|
|
|
generate(contractName, contractConfiguration){
|
2018-05-09 21:02:17 +00:00
|
|
|
if(this.framework == 'react'){
|
|
|
|
this.embark.plugins.loadInternalPlugin('scaffolding-react', this.options);
|
|
|
|
}
|
2018-05-11 19:49:06 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2018-05-14 13:42:29 +00:00
|
|
|
|
2018-05-11 19:49:06 +00:00
|
|
|
if(build === null){
|
2018-05-14 13:42:29 +00:00
|
|
|
throw new Error("Could not find plugin for framework '" + this.framework + "'");
|
2018-05-11 19:49:06 +00:00
|
|
|
}
|
|
|
|
|
2018-05-10 15:25:31 +00:00
|
|
|
if(!this.isContract(contractName)){
|
2018-05-14 13:42:29 +00:00
|
|
|
return new Error("contract '" + contractName + "' does not exist");
|
2018-05-10 15:25:31 +00:00
|
|
|
}
|
2018-05-09 21:02:17 +00:00
|
|
|
|
2018-05-11 19:49:06 +00:00
|
|
|
const contract = contractConfiguration.contracts[contractName];
|
2018-05-15 20:19:39 +00:00
|
|
|
build(contract);
|
2018-05-09 21:02:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = Scaffolding;
|