embark/lib/cmds/scaffolding.js

48 lines
1.4 KiB
JavaScript
Raw Normal View History

class Scaffolding {
constructor(engine, options){
this.engine = engine;
this.options = options;
this.framework = options.framework;
this.frameworkPlugin = null;
}
isContract(contractName){
return this.engine.config.contractsConfig.contracts[contractName] !== undefined;
}
generate(contractName){
2018-08-02 19:17:40 +00:00
if(this.framework === 'react'){
this.engine.plugins.loadInternalPlugin('scaffolding-react', this.options);
}
2018-05-11 19:49:06 +00:00
let dappGenerators = this.engine.plugins.getPluginsFor('dappGenerator');
2018-05-11 19:49:06 +00:00
let build = null;
dappGenerators.forEach((plugin) => {
plugin.dappGenerators.forEach((d) => {
2018-08-02 19:17:40 +00:00
if(d.framework === this.framework){
2018-05-11 19:49:06 +00:00
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
}
if(!this.isContract(contractName)){
throw new Error("contract '" + contractName + "' does not exist");
}
this.engine.events.request("contracts:list", (_err, contractsList) => {
if(_err) throw new Error(_err);
const contract = contractsList.find(x => x.className === contractName);
build(contract);
});
}
}
module.exports = Scaffolding;