mirror of https://github.com/embarklabs/embark.git
Adding base command logic for scaffolding generation
This commit is contained in:
parent
1800f506b1
commit
8861588726
|
@ -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){
|
||||||
|
@ -342,7 +341,7 @@ class Cmd {
|
||||||
});
|
});
|
||||||
|
|
||||||
options.contract = contract;
|
options.contract = contract;
|
||||||
options.framework = options.framework || 'react';
|
options.framework = options.framework || 'react';
|
||||||
options.env = environment;
|
options.env = environment;
|
||||||
embark.scaffold(options);
|
embark.scaffold(options);
|
||||||
});
|
});
|
||||||
|
|
|
@ -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');
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
Loading…
Reference in New Issue