mirror of https://github.com/embarklabs/embark.git
add plugin for pipeline
This commit is contained in:
parent
ccdfaf61f2
commit
4075490fee
|
@ -168,7 +168,8 @@ var Embark = {
|
|||
buildDir: self.config.buildDir,
|
||||
contractsFiles: self.config.contractsFiles,
|
||||
assetFiles: self.config.assetFiles,
|
||||
logger: self.logger
|
||||
logger: self.logger,
|
||||
plugins: self.plugins
|
||||
});
|
||||
pipeline.build(abi);
|
||||
callback();
|
||||
|
@ -291,7 +292,8 @@ var Embark = {
|
|||
buildDir: self.config.buildDir,
|
||||
contractsFiles: self.config.contractsFiles,
|
||||
assetFiles: self.config.assetFiles,
|
||||
logger: self.logger
|
||||
logger: self.logger,
|
||||
plugins: self.plugins
|
||||
});
|
||||
pipeline.build(abi);
|
||||
callback();
|
||||
|
|
|
@ -7,12 +7,15 @@ var Pipeline = function(options) {
|
|||
this.contractsFiles = options.contractsFiles;
|
||||
this.assetFiles = options.assetFiles;
|
||||
this.logger = options.logger;
|
||||
this.plugins = options.plugins;
|
||||
};
|
||||
|
||||
Pipeline.prototype.build = function(abi) {
|
||||
var self = this;
|
||||
for(var targetFile in this.assetFiles) {
|
||||
|
||||
// TODO: run the plugin here instead, for each file
|
||||
|
||||
var content = this.assetFiles[targetFile].map(file => {
|
||||
self.logger.info("reading " + file.filename);
|
||||
if (file.filename === 'embark.js') {
|
||||
|
@ -22,6 +25,14 @@ Pipeline.prototype.build = function(abi) {
|
|||
}
|
||||
}).join("\n");
|
||||
|
||||
var pipelinePlugins = this.plugins.getPluginsFor('pipeline');
|
||||
|
||||
if (pipelinePlugins.length > 0) {
|
||||
pipelinePlugins.forEach(function(plugin) {
|
||||
content = plugin.runPipeline({targetFile: targetFile, source: content});
|
||||
});
|
||||
}
|
||||
|
||||
var dir = targetFile.split('/').slice(0, -1).join('/');
|
||||
self.logger.info("creating dir " + this.buildDir + dir);
|
||||
mkdirp.sync(this.buildDir + dir);
|
||||
|
|
|
@ -5,6 +5,7 @@ var Plugin = function(options) {
|
|||
this.pluginModule = options.pluginModule;
|
||||
this.clientWeb3Providers = [];
|
||||
this.contractsGenerators = [];
|
||||
this.pipeline = [];
|
||||
this.pluginTypes = [];
|
||||
};
|
||||
|
||||
|
@ -23,6 +24,12 @@ Plugin.prototype.registerContractsGeneration = function(cb) {
|
|||
this.pluginTypes.push('contractGeneration');
|
||||
};
|
||||
|
||||
Plugin.prototype.registerPipeline = function(cb) {
|
||||
// TODO: generate error for more than one pipeline per plugin
|
||||
this.pipeline.push(cb);
|
||||
this.pluginTypes.push('pipeline');
|
||||
};
|
||||
|
||||
Plugin.prototype.has = function(pluginType) {
|
||||
return this.pluginTypes.indexOf(pluginType) >= 0;
|
||||
};
|
||||
|
@ -39,4 +46,8 @@ Plugin.prototype.generateContracts = function(args) {
|
|||
}).join("\n");
|
||||
};
|
||||
|
||||
Plugin.prototype.runPipeline = function(args) {
|
||||
return this.pipeline[0].call(this, args);
|
||||
};
|
||||
|
||||
module.exports = Plugin;
|
||||
|
|
Loading…
Reference in New Issue