diff --git a/lib/modules/scaffolding/index.js b/lib/modules/scaffolding/index.js index 677978475..09643167c 100644 --- a/lib/modules/scaffolding/index.js +++ b/lib/modules/scaffolding/index.js @@ -2,7 +2,8 @@ const fs = require('fs'); const commandName = "generate-ui"; -const errorMessage = (message) => new Error(commandName + ": " + message); +//const errorMessage = (message) => new Error(commandName + ": " + message); +const formatReplyMsg = (message) => commandName + ": " + message; class Scaffolding { constructor(embark, options){ @@ -12,6 +13,15 @@ class Scaffolding { this.frameworkPlugin = null; } + createDirectories(contractName){ + const dir = './app/' + contractName; + if (!fs.existsSync(dir)){ + fs.mkdirSync(dir); + } else { + throw formatReplyMsg("directory ./app/" + contractName + " already exists"); + } + } + isContract(contractName){ return this.embark.config.contractsConfig.contracts[contractName] !== undefined; } @@ -25,25 +35,27 @@ class Scaffolding { } else { let plugins = this.embark.plugins.getPluginsFor(this.framework); if(plugins.length !== 1){ - throw errorMessage("Could not find plugin for framework '" + this.framework + "'"); + //throw errorMessage("Could not find plugin for framework '" + this.framework + "'"); + return formatReplyMsg("Could not find plugin for framework '" + this.framework + "'"); } frameworkPlugin = plugins[0].pluginModule; } - - if(!this.isContract(contractName)){ - return errorMessage("contract '" + contractName + "' does not exist"); + try { + if(!this.isContract(contractName)){ + return formatReplyMsg("contract '" + contractName + "' does not exist"); + } + + const contract = this.embark.config.contractsConfig.contracts[contractName]; + + this.createDirectories(contractName); + let uiFramework = new frameworkPlugin(this.embark, this.options); + uiFramework.build(contract); + } catch(err){ + return err; } - 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); - } + return formatReplyMsg("done!"); } }