Adding base command logic for scaffolding generation

This commit is contained in:
Richard Ramos 2018-05-09 17:02:17 -04:00 committed by Pascal Precht
parent ea16a865bd
commit 2aa00a415b
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
1 changed files with 26 additions and 14 deletions

View File

@ -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!");
}
}