From 4075490fee4a13f0848e97a8b16b239a808267c4 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sat, 10 Dec 2016 10:20:04 -0500 Subject: [PATCH] add plugin for pipeline --- lib/index.js | 6 ++++-- lib/pipeline.js | 11 +++++++++++ lib/plugin.js | 11 +++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 010f269bb..32c315582 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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(); diff --git a/lib/pipeline.js b/lib/pipeline.js index 11ab55169..9dbfbb465 100644 --- a/lib/pipeline.js +++ b/lib/pipeline.js @@ -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); diff --git a/lib/plugin.js b/lib/plugin.js index 7d7a16ef7..cfda13937 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -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;