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