diff --git a/lib/contracts/code_generator.js b/lib/contracts/code_generator.js index 3072cd81b..6b8306aec 100644 --- a/lib/contracts/code_generator.js +++ b/lib/contracts/code_generator.js @@ -19,6 +19,8 @@ const Templates = { class CodeGenerator { constructor(options) { this.blockchainConfig = options.blockchainConfig || {}; + this.rpcHost = this.blockchainConfig.rpcHost || ''; + this.rpcPort = this.blockchainConfig.rpcPort || ''; this.contractsConfig = options.contractsConfig || {}; this.storageConfig = options.storageConfig || {}; this.communicationConfig = options.communicationConfig || {}; diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index 7cfb7b16e..1551331c5 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -280,17 +280,17 @@ class Deploy { // calling each beforeDeploy handler declared by the plugin async.eachSeries(plugin.beforeDeploy, (beforeDeployFn, eachCb) => { + function beforeDeployCb(resObj){ + contract.code = resObj.contractCode; + eachCb(); + } beforeDeployFn({ embarkDeploy: self, pluginConfig: plugin.pluginConfig, deploymentAccount: deploymentAccount, contract: contract, - callback: - (function(resObj){ - contract.code = resObj.contractCode; - eachCb(); - }) - }); + callback: beforeDeployCb + }, beforeDeployCb); }, () => { //self.logger.info('All beforeDeploy handlers of the plugin has processed.'); eachPluginCb(); diff --git a/lib/core/config.js b/lib/core/config.js index 75e5b86f3..7061faddd 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -286,7 +286,7 @@ Config.prototype.loadFiles = function(files) { } }); filesFromPlugins.filter(function(file) { - if (utils.fileMatchesPattern(files, file.intendedPath)) { + if ((file.intendedPath && utils.fileMatchesPattern(files, file.intendedPath)) || utils.fileMatchesPattern(files, file.file)) { readFiles.push(file); } }); @@ -301,7 +301,7 @@ Config.prototype.loadPluginContractFiles = function() { contractsPlugins.forEach(function(plugin) { plugin.contractsFiles.forEach(function(file) { var filename = file.replace('./',''); - self.contractsFiles.push(new File({filename: filename, type: File.types.custom, resolver: function(callback) { + self.contractsFiles.push(new File({filename: filename, type: File.types.custom, path: filename, resolver: function(callback) { callback(plugin.loadPluginFile(file)); }})); }); diff --git a/lib/index.js b/lib/index.js index 340d1e54c..1f45d1d1e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -324,7 +324,9 @@ class Embark { if (cmdPlugins.length > 0) { cmdPlugin = cmdPlugins.find((pluginCmd) => { - return pluginCmd.name == platform; + return pluginCmd.uploadCmds.some(uploadCmd => { + return uploadCmd.cmd === platform; + }); }); } if (!cmdPlugin) { diff --git a/test_apps/test_app/extensions/embark-service/contracts/pluginSimpleStorage.sol b/test_apps/test_app/extensions/embark-service/contracts/pluginSimpleStorage.sol new file mode 100644 index 000000000..4d01d6b32 --- /dev/null +++ b/test_apps/test_app/extensions/embark-service/contracts/pluginSimpleStorage.sol @@ -0,0 +1,10 @@ +pragma solidity ^0.4.18; +contract PluginStorage { + address public simpleStorageAddress; + address simpleStorageAddress2; + + function PluginStorage(address addr) public { + simpleStorageAddress = addr; + } + +} diff --git a/test_apps/test_app/extensions/embark-service/fileInPipeline.js b/test_apps/test_app/extensions/embark-service/fileInPipeline.js new file mode 100644 index 000000000..85f768539 --- /dev/null +++ b/test_apps/test_app/extensions/embark-service/fileInPipeline.js @@ -0,0 +1 @@ +console.log('File added to the pipeline using embark.addFileToPipeline'); diff --git a/test_apps/test_app/extensions/embark-service/index.js b/test_apps/test_app/extensions/embark-service/index.js index 0ca3ff1d5..fb5a56bd4 100644 --- a/test_apps/test_app/extensions/embark-service/index.js +++ b/test_apps/test_app/extensions/embark-service/index.js @@ -1,12 +1,47 @@ -var Haml = require('haml'); +const Haml = require('haml'); -module.exports = function(embark) { - embark.registerServiceCheck('PluginService', function(cb) { +module.exports = function (embark) { + embark.registerServiceCheck('PluginService', function (cb) { cb({name: "ServiceName", status: "on"}); }); - embark.registerPipeline((embark.pluginConfig.files || ['**/*.haml']), function(opts) { - var source = opts.source; - return Haml.render(source); + embark.registerPipeline((embark.pluginConfig.files || ['**/*.haml']), function (opts) { + return Haml.render(opts.source); }); + + embark.registerContractConfiguration({ + "default": { + "contracts": { + "PluginStorage": { + "args": ["$SimpleStorage"] + } + } + } + }); + embark.addContractFile("./contracts/pluginSimpleStorage.sol"); + + embark.addFileToPipeline('./fileInPipeline.js'); + embark.addFileToPipeline('./fileInPipeline.js', 'js/fileInPipeline.js'); + + embark.registerBeforeDeploy(function (options, callback) { + // Just calling register to prove it works. We don't actually want to change the contracts + callback({contractCode: options.contract.code}); + }); + + embark.registerClientWeb3Provider(function(options) { + return "web3 = new Web3(new Web3.providers.HttpProvider('http://" + options.rpcHost + ":" + options.rpcPort + "'));"; + }); + + embark.registerConsoleCommand((cmd) => { + if (cmd === "hello") { + return "hello there!"; + } + // continue to embark or next plugin; + return false; + }); + + embark.events.on("contractsDeployed", function() { + embark.logger.info("plugin says: your contracts have been deployed"); + }); + }; diff --git a/test_apps/test_app/package.json b/test_apps/test_app/package.json index 8711dde1d..b29e3d6ca 100644 --- a/test_apps/test_app/package.json +++ b/test_apps/test_app/package.json @@ -14,11 +14,11 @@ }, "dependencies": { "bootstrap": "^3.3.6", - "embark-service": "./extensions/embark-service", + "embark-service": "file:extensions/embark-service", "jquery": "^1.11.3", "react": "^16.0.0", "react-bootstrap": "^0.32.0", "react-dom": "^16.2.0", - "zeppelin-solidity": "^1.8.0" + "zeppelin-solidity": "1.8.0" } } diff --git a/test_apps/test_app/test/plugin_storage_spec.js b/test_apps/test_app/test/plugin_storage_spec.js new file mode 100644 index 000000000..24a58c4e8 --- /dev/null +++ b/test_apps/test_app/test/plugin_storage_spec.js @@ -0,0 +1,26 @@ +/*global contract, before, EmbarkSpec, PluginStorage, SimpleStorage, it*/ +const assert = require('assert'); + +contract("PluginSimpleStorage", function () { + this.timeout(0); + + before((done) => { + const contractsConfig = { + "SimpleStorage": { + args: [100] + }, + "PluginStorage": { + args: ["$SimpleStorage"] + } + }; + EmbarkSpec.deployAll(contractsConfig, () => { + done(); + }); + }); + + it("set SimpleStorage address", async function () { + let result = await PluginStorage.methods.simpleStorageAddress().call(); + assert.equal(result.toString(), SimpleStorage.options.address); + }); + +}); diff --git a/test_apps/test_app/test/token_spec.js b/test_apps/test_app/test/token_spec.js index c76728c04..88dfc1a87 100644 --- a/test_apps/test_app/test/token_spec.js +++ b/test_apps/test_app/test/token_spec.js @@ -13,8 +13,6 @@ describe("Token", function() { var contractsConfig = { "ZAMyLib": { }, - "Token": { - }, "SimpleStorage": { args: [100] },