2018-05-09 21:02:17 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
const commandName = "generate-ui";
|
|
|
|
|
2018-05-10 15:25:31 +00:00
|
|
|
const errorMessage = (message) => new Error(commandName + ": " + message);
|
2018-05-09 21:02:17 +00:00
|
|
|
|
|
|
|
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){
|
2018-05-10 15:25:31 +00:00
|
|
|
throw errorMessage("Could not find plugin for framework '" + this.framework + "'");
|
2018-05-09 21:02:17 +00:00
|
|
|
}
|
|
|
|
frameworkPlugin = plugins[0].pluginModule;
|
|
|
|
}
|
|
|
|
|
2018-05-10 15:25:31 +00:00
|
|
|
|
|
|
|
if(!this.isContract(contractName)){
|
|
|
|
return errorMessage("contract '" + contractName + "' does not exist");
|
|
|
|
}
|
2018-05-09 21:02:17 +00:00
|
|
|
|
2018-05-10 15:25:31 +00:00
|
|
|
const contract = this.embark.config.contractsConfig.contracts[contractName];
|
|
|
|
|
|
|
|
try {
|
2018-05-09 21:02:17 +00:00
|
|
|
let uiFramework = new frameworkPlugin(this.embark, this.options);
|
2018-05-10 15:25:31 +00:00
|
|
|
let result = uiFramework.build(contract);
|
|
|
|
this.embark.logger.info(result);
|
2018-05-09 21:02:17 +00:00
|
|
|
} catch(err){
|
2018-05-10 15:25:31 +00:00
|
|
|
throw errorMessage(err);
|
2018-05-09 21:02:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = Scaffolding;
|