Adding base command logic for scaffolding generation

This commit is contained in:
Richard Ramos 2018-05-09 17:02:17 -04:00 committed by Iuri Matias
parent c6af355593
commit 6d16125205
4 changed files with 103 additions and 0 deletions

View File

@ -19,6 +19,7 @@ class Cmd {
this.test();
this.reset();
this.graph();
this.scaffold();
this.upload();
this.versionCmd();
this.helpCmd();
@ -261,6 +262,29 @@ class Cmd {
});
}
scaffold() {
program
.command('scaffold [contract] [environment]')
.option('--framework', 'UI framework to use. (default: react)')
.action(function(contract, env, options){
let environment = env || 'development';
if(contract === undefined){
console.log("contract name is required");
process.exit(0);
}
embark.initConfig(environment, {
embarkConfig: 'embark.json', interceptLogs: false
});
options.contract = contract;
options.framework = options.framework || 'react';
options.env = environment;
embark.scaffold(options);
});
}
reset() {
program
.command('reset')

View File

@ -118,6 +118,10 @@ Plugin.prototype.registerPipeline = function(matcthingFiles, cb) {
this.addPluginType('pipeline');
};
Plugin.prototype.registerCustomType = function(type){
this.pluginTypes.push(type);
}
Plugin.prototype.addFileToPipeline = function(file, intendedPath, options) {
this.pipelineFiles.push({file: file, intendedPath: intendedPath, options: options});
this.addPluginType('pipelineFiles');

View File

@ -0,0 +1,14 @@
class ScaffoldingReact {
constructor(embark, options){
this.embark = embark;
this.options = options;
}
build(contract){
}
}
module.exports = ScaffoldingReact;

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;