mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-12 06:44:37 +00:00
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 commandName = "generate-ui";
|
||||||
|
|
||||||
const errorMessage = (message) => new Error(commandName + ": " + message);
|
//const errorMessage = (message) => new Error(commandName + ": " + message);
|
||||||
|
const formatReplyMsg = (message) => commandName + ": " + message;
|
||||||
|
|
||||||
class Scaffolding {
|
class Scaffolding {
|
||||||
constructor(embark, options){
|
constructor(embark, options){
|
||||||
@ -12,6 +13,15 @@ class Scaffolding {
|
|||||||
this.frameworkPlugin = null;
|
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){
|
isContract(contractName){
|
||||||
return this.embark.config.contractsConfig.contracts[contractName] !== undefined;
|
return this.embark.config.contractsConfig.contracts[contractName] !== undefined;
|
||||||
}
|
}
|
||||||
@ -25,25 +35,27 @@ class Scaffolding {
|
|||||||
} else {
|
} else {
|
||||||
let plugins = this.embark.plugins.getPluginsFor(this.framework);
|
let plugins = this.embark.plugins.getPluginsFor(this.framework);
|
||||||
if(plugins.length !== 1){
|
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;
|
frameworkPlugin = plugins[0].pluginModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(!this.isContract(contractName)){
|
|
||||||
return errorMessage("contract '" + contractName + "' does not exist");
|
|
||||||
}
|
|
||||||
|
|
||||||
const contract = this.embark.config.contractsConfig.contracts[contractName];
|
|
||||||
|
|
||||||
try {
|
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);
|
let uiFramework = new frameworkPlugin(this.embark, this.options);
|
||||||
let result = uiFramework.build(contract);
|
uiFramework.build(contract);
|
||||||
this.embark.logger.info(result);
|
|
||||||
} catch(err){
|
} catch(err){
|
||||||
throw errorMessage(err);
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return formatReplyMsg("done!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user