Fixed plugin loading logic

This commit is contained in:
Richard Ramos 2018-05-11 15:49:06 -04:00 committed by Pascal Precht
parent 435b18d074
commit 6f249df4bf
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
4 changed files with 30 additions and 24 deletions

View File

@ -1,5 +1,3 @@
const fs = require('fs');
const commandName = "generate-ui";
const errorMessage = (message) => new Error(commandName + ": " + message);
@ -16,30 +14,33 @@ class Scaffolding {
return this.embark.config.contractsConfig.contracts[contractName] !== undefined;
}
generate(contractName){
let frameworkPlugin;
generate(contractName, contractConfiguration){
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){
throw errorMessage("Could not find plugin for framework '" + this.framework + "'");
}
frameworkPlugin = plugins[0].pluginModule;
}
let dappGenerators = this.embark.plugins.getPluginsFor('dappGenerator');
let build = null;
dappGenerators.forEach((plugin) => {
plugin.dappGenerators.forEach((d) => {
if(d.framework == this.framework){
build = d.cb;
}
});
});
if(build === null){
throw errorMessage("Could not find plugin for framework '" + this.framework + "'");
}
if(!this.isContract(contractName)){
return errorMessage("contract '" + contractName + "' does not exist");
}
const contract = this.embark.config.contractsConfig.contracts[contractName];
const contract = contractConfiguration.contracts[contractName];
try {
let uiFramework = new frameworkPlugin(this.embark, this.options);
let result = uiFramework.build(contract);
let result = build(contract);
this.embark.logger.info(result);
} catch(err){
throw errorMessage(err);

View File

@ -20,6 +20,7 @@ var Plugin = function(options) {
this.contractsFiles = [];
this.compilers = [];
this.serviceChecks = [];
this.dappGenerators = [];
this.pluginTypes = [];
this.uploadCmds = [];
this.imports = [];
@ -123,8 +124,9 @@ Plugin.prototype.registerPipeline = function(matcthingFiles, cb) {
this.addPluginType('pipeline');
};
Plugin.prototype.registerCustomType = function(type){
this.pluginTypes.push(type);
Plugin.prototype.registerDappGenerator = function(framework, cb){
this.dappGenerators.push({framework: framework, cb: cb});
this.pluginTypes.push('dappGenerator');
};
Plugin.prototype.addFileToPipeline = function(file, intendedPath, options) {

View File

@ -359,6 +359,8 @@ class Embark {
}
scaffold(options) {
const Scaffolding = require('./cmds/scaffolding.js');
// initialise embark engine
let engine = new Engine({
env: options.env,
@ -368,16 +370,13 @@ class Embark {
});
engine.init();
// load plugins
this.plugins.loadInternalPlugin('scaffolding', options);
let scaffoldPlugin = this.plugins.plugins.filter(x => x.name == "scaffolding")[0].pluginModule;
let self = this;
async.waterfall([
function generateUI(callback){
engine.events.on('contractsDeployed', function () {
let scaffold = new scaffoldPlugin(engine, options);
let result = scaffold.generate(options.contract);
let scaffold = new Scaffolding(self, options);
let result = scaffold.generate(options.contract, engine.config.contractsConfig);
engine.logger.info(result);
callback();
});

View File

@ -49,6 +49,8 @@ class ScaffoldingReact {
constructor(embark, options){
this.embark = embark;
this.options = options;
this.embark.registerDappGenerator('react', this.build.bind(this));
}
_generateFile(contract, templateFilename, extension, data){
@ -95,6 +97,8 @@ class ScaffoldingReact {
embarkJson.app[filename + ".html"] = "app/" + filename + '.html';
fs.writeFileSync("./embark.json", JSON.stringify(embarkJson, null, 4));
return filename + ".html generated";
}
}