diff --git a/lib/cmds/scaffolding.js b/lib/cmds/scaffolding.js index c7eae44c..73416d93 100644 --- a/lib/cmds/scaffolding.js +++ b/lib/cmds/scaffolding.js @@ -1,3 +1,7 @@ +const commandName = "generate-ui"; + +const errorMessage = (message) => new Error(commandName + ": " + message); + class Scaffolding { constructor(embark, options){ this.embark = embark; @@ -24,17 +28,23 @@ class Scaffolding { } }); }); - + 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)){ - return new Error("contract '" + contractName + "' does not exist"); + return errorMessage("contract '" + contractName + "' does not exist"); } const contract = contractConfiguration.contracts[contractName]; - build(contract); + + try { + let result = build(contract); + this.embark.logger.info(result); + } catch(err){ + throw errorMessage(err); + } } } diff --git a/lib/cmds/scaffolding.js~develop_51 b/lib/cmds/scaffolding.js~develop_51 new file mode 100644 index 00000000..c7eae44c --- /dev/null +++ b/lib/cmds/scaffolding.js~develop_51 @@ -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; diff --git a/lib/modules/scaffolding/index.js b/lib/modules/scaffolding/index.js deleted file mode 100644 index 67797847..00000000 --- a/lib/modules/scaffolding/index.js +++ /dev/null @@ -1,51 +0,0 @@ -const fs = require('fs'); - -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; - } - - generate(contractName){ - let frameworkPlugin; - - if(this.framework == 'react'){ - this.embark.plugins.loadInternalPlugin('scaffolding-react', this.options); - frameworkPlugin = this.embark.plugins.plugins.filter(x => x.name == "scaffolding-react")[0].pluginModule; - } else { - let plugins = this.embark.plugins.getPluginsFor(this.framework); - if(plugins.length !== 1){ - throw errorMessage("Could not find plugin for framework '" + this.framework + "'"); - } - frameworkPlugin = plugins[0].pluginModule; - } - - - if(!this.isContract(contractName)){ - return errorMessage("contract '" + contractName + "' does not exist"); - } - - const contract = this.embark.config.contractsConfig.contracts[contractName]; - - try { - let uiFramework = new frameworkPlugin(this.embark, this.options); - let result = uiFramework.build(contract); - this.embark.logger.info(result); - } catch(err){ - throw errorMessage(err); - } - } -} - - -module.exports = Scaffolding;