mirror of https://github.com/embarklabs/embark.git
Adding base command logic for scaffolding generation
This commit is contained in:
parent
ea16a865bd
commit
2aa00a415b
|
@ -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!");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue