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 1800f506b1
commit 8861588726
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
4 changed files with 66 additions and 3 deletions

View File

@ -329,7 +329,6 @@ class Cmd {
.command('scaffold [contract] [environment]') .command('scaffold [contract] [environment]')
.option('--framework <framework>', 'UI framework to use. (default: react)') .option('--framework <framework>', 'UI framework to use. (default: react)')
.action(function(contract, env, options){ .action(function(contract, env, options){
let environment = env || 'development'; let environment = env || 'development';
if(contract === undefined){ if(contract === undefined){

View File

@ -129,6 +129,10 @@ Plugin.prototype.registerDappGenerator = function(framework, cb){
this.pluginTypes.push('dappGenerator'); this.pluginTypes.push('dappGenerator');
}; };
Plugin.prototype.registerCustomType = function(type){
this.pluginTypes.push(type);
}
Plugin.prototype.addFileToPipeline = function(file, intendedPath, options) { Plugin.prototype.addFileToPipeline = function(file, intendedPath, options) {
this.pipelineFiles.push({file: file, intendedPath: intendedPath, options: options}); this.pipelineFiles.push({file: file, intendedPath: intendedPath, options: options});
this.addPluginType('pipelineFiles'); this.addPluginType('pipelineFiles');

View File

@ -45,7 +45,6 @@ class ScaffoldingReact {
constructor(embark, options){ constructor(embark, options){
this.embark = embark; this.embark = embark;
this.options = options; this.options = options;
this.embark.registerDappGenerator('react', this.build.bind(this)); this.embark.registerDappGenerator('react', this.build.bind(this));
} }

View File

@ -0,0 +1,61 @@
const fs = require('fs');
const commandName = "generate-ui";
const formatReplyMsg = (message) => commandName + ": " + message;
class Scaffolding {
constructor(embark, options){
this.embark = embark;
this.options = options;
this.framework = options.framework;
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;
}
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){
return formatReplyMsg("Could not find plugin for framework '" + this.framework + "'");
}
frameworkPlugin = plugins[0].pluginModule;
}
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;
}
return formatReplyMsg("done!");
}
}
module.exports = Scaffolding;