mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-11 06:25:57 +00:00
Fixed plugin loading logic
This commit is contained in:
parent
435b18d074
commit
6f249df4bf
@ -1,5 +1,3 @@
|
|||||||
const fs = require('fs');
|
|
||||||
|
|
||||||
const commandName = "generate-ui";
|
const commandName = "generate-ui";
|
||||||
|
|
||||||
const errorMessage = (message) => new Error(commandName + ": " + message);
|
const errorMessage = (message) => new Error(commandName + ": " + message);
|
||||||
@ -16,30 +14,33 @@ class Scaffolding {
|
|||||||
return this.embark.config.contractsConfig.contracts[contractName] !== undefined;
|
return this.embark.config.contractsConfig.contracts[contractName] !== undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
generate(contractName){
|
generate(contractName, contractConfiguration){
|
||||||
let frameworkPlugin;
|
|
||||||
|
|
||||||
if(this.framework == 'react'){
|
if(this.framework == 'react'){
|
||||||
this.embark.plugins.loadInternalPlugin('scaffolding-react', this.options);
|
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)){
|
if(!this.isContract(contractName)){
|
||||||
return errorMessage("contract '" + contractName + "' does not exist");
|
return errorMessage("contract '" + contractName + "' does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
const contract = this.embark.config.contractsConfig.contracts[contractName];
|
const contract = contractConfiguration.contracts[contractName];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let uiFramework = new frameworkPlugin(this.embark, this.options);
|
let result = build(contract);
|
||||||
let result = uiFramework.build(contract);
|
|
||||||
this.embark.logger.info(result);
|
this.embark.logger.info(result);
|
||||||
} catch(err){
|
} catch(err){
|
||||||
throw errorMessage(err);
|
throw errorMessage(err);
|
@ -20,6 +20,7 @@ var Plugin = function(options) {
|
|||||||
this.contractsFiles = [];
|
this.contractsFiles = [];
|
||||||
this.compilers = [];
|
this.compilers = [];
|
||||||
this.serviceChecks = [];
|
this.serviceChecks = [];
|
||||||
|
this.dappGenerators = [];
|
||||||
this.pluginTypes = [];
|
this.pluginTypes = [];
|
||||||
this.uploadCmds = [];
|
this.uploadCmds = [];
|
||||||
this.imports = [];
|
this.imports = [];
|
||||||
@ -123,8 +124,9 @@ Plugin.prototype.registerPipeline = function(matcthingFiles, cb) {
|
|||||||
this.addPluginType('pipeline');
|
this.addPluginType('pipeline');
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.registerCustomType = function(type){
|
Plugin.prototype.registerDappGenerator = function(framework, cb){
|
||||||
this.pluginTypes.push(type);
|
this.dappGenerators.push({framework: framework, cb: cb});
|
||||||
|
this.pluginTypes.push('dappGenerator');
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.addFileToPipeline = function(file, intendedPath, options) {
|
Plugin.prototype.addFileToPipeline = function(file, intendedPath, options) {
|
||||||
|
11
lib/index.js
11
lib/index.js
@ -359,6 +359,8 @@ class Embark {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scaffold(options) {
|
scaffold(options) {
|
||||||
|
const Scaffolding = require('./cmds/scaffolding.js');
|
||||||
|
|
||||||
// initialise embark engine
|
// initialise embark engine
|
||||||
let engine = new Engine({
|
let engine = new Engine({
|
||||||
env: options.env,
|
env: options.env,
|
||||||
@ -368,16 +370,13 @@ class Embark {
|
|||||||
});
|
});
|
||||||
engine.init();
|
engine.init();
|
||||||
|
|
||||||
// load plugins
|
|
||||||
this.plugins.loadInternalPlugin('scaffolding', options);
|
|
||||||
let scaffoldPlugin = this.plugins.plugins.filter(x => x.name == "scaffolding")[0].pluginModule;
|
|
||||||
let self = this;
|
let self = this;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function generateUI(callback){
|
function generateUI(callback){
|
||||||
engine.events.on('contractsDeployed', function () {
|
engine.events.on('contractsDeployed', function () {
|
||||||
let scaffold = new scaffoldPlugin(engine, options);
|
let scaffold = new Scaffolding(self, options);
|
||||||
let result = scaffold.generate(options.contract);
|
let result = scaffold.generate(options.contract, engine.config.contractsConfig);
|
||||||
engine.logger.info(result);
|
engine.logger.info(result);
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
@ -49,6 +49,8 @@ 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
_generateFile(contract, templateFilename, extension, data){
|
_generateFile(contract, templateFilename, extension, data){
|
||||||
@ -95,6 +97,8 @@ class ScaffoldingReact {
|
|||||||
embarkJson.app[filename + ".html"] = "app/" + filename + '.html';
|
embarkJson.app[filename + ".html"] = "app/" + filename + '.html';
|
||||||
|
|
||||||
fs.writeFileSync("./embark.json", JSON.stringify(embarkJson, null, 4));
|
fs.writeFileSync("./embark.json", JSON.stringify(embarkJson, null, 4));
|
||||||
|
|
||||||
|
return filename + ".html generated";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user