embark/lib/cmds/scaffolding.js

53 lines
1.5 KiB
JavaScript
Raw Normal View History

const commandName = "generate-ui";
const errorMessage = (message) => new Error(commandName + ": " + message);
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){
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-11 19:49:06 +00:00
if(build === null){
throw errorMessage("Could not find plugin for framework '" + this.framework + "'");
}
if(!this.isContract(contractName)){
return errorMessage("contract '" + contractName + "' does not exist");
}
2018-05-11 19:49:06 +00:00
const contract = contractConfiguration.contracts[contractName];
try {
2018-05-11 19:49:06 +00:00
let result = build(contract);
this.embark.logger.info(result);
} catch(err){
throw errorMessage(err);
}
}
}
module.exports = Scaffolding;