From 8b223058338897affcce9cd9e53b3aa5666d3971 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 11 May 2018 18:10:48 -0400 Subject: [PATCH 1/6] support js files besides json files --- lib/core/config.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/core/config.js b/lib/core/config.js index 44dace7b..5f2b0c2c 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -75,7 +75,7 @@ Config.prototype._mergeConfig = function(configFilePath, defaultConfig, env, ena return configToReturn; } - if (!fs.existsSync(configFilePath)) { + if (!fs.existsSync(configFilePath + '.js') && !fs.existsSync(configFilePath + ' .json')) { // TODO: remove this if if (this.logger) { this.logger.warn(__("no config file found at %s using default config", configFilePath)); @@ -83,7 +83,12 @@ Config.prototype._mergeConfig = function(configFilePath, defaultConfig, env, ena return defaultConfig['default'] || {}; } - let config = fs.readJSONSync(configFilePath); + let config; + if (fs.existsSync(configFilePath + '.js')) { + config = require(fs.dappPath(configFilePath + '.js')); + } else { + config = fs.readJSONSync(configFilePath); + } let configObject = utils.recursiveMerge(defaultConfig, config); if (env) { @@ -109,7 +114,7 @@ Config.prototype.loadBlockchainConfigFile = function() { } }; - let configFilePath = this._getFileOrOject(this.configDir, 'blockchain.json', 'blockchain'); + let configFilePath = this._getFileOrOject(this.configDir, 'blockchain', 'blockchain'); this.blockchainConfig = this._mergeConfig(configFilePath, configObject, this.env, true); }; @@ -142,7 +147,7 @@ Config.prototype.loadContractsConfigFile = function() { configObject = utils.recursiveMerge(configObject, pluginConfig); }); - let configFilePath = this._getFileOrOject(this.configDir, 'contracts.json', 'contracts'); + let configFilePath = this._getFileOrOject(this.configDir, 'contracts', 'contracts'); const newContractsConfig = this._mergeConfig(configFilePath, configObject, this.env); @@ -193,7 +198,7 @@ Config.prototype.loadStorageConfigFile = function() { } }; - let configFilePath = this._getFileOrOject(this.configDir, 'storage.json', 'storage'); + let configFilePath = this._getFileOrOject(this.configDir, 'storage', 'storage'); this.storageConfig = this._mergeConfig(configFilePath, configObject, this.env); }; @@ -210,7 +215,7 @@ Config.prototype.loadCommunicationConfigFile = function() { } }; - let configFilePath = this._getFileOrOject(this.configDir, 'communication.json', 'communication'); + let configFilePath = this._getFileOrOject(this.configDir, 'communication', 'communication'); this.communicationConfig = this._mergeConfig(configFilePath, configObject, this.env); }; @@ -220,7 +225,7 @@ Config.prototype.loadWebServerConfigFile = function() { "enabled": true, "host": "localhost", "port": 8000 }; - let configFilePath = this._getFileOrOject(this.configDir, 'webserver.json', 'webserver'); + let configFilePath = this._getFileOrOject(this.configDir, 'webserver', 'webserver'); this.webServerConfig = this._mergeConfig(configFilePath, configObject, false); }; From 2793432b87f61e58134872046a770835cfbdca79 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 11 May 2018 18:11:05 -0400 Subject: [PATCH 2/6] convert test_app contracts.json to contracts.js --- package-lock.json | 1 - test_apps/test_app/config/{contracts.json => contracts.js} | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) rename test_apps/test_app/config/{contracts.json => contracts.js} (98%) diff --git a/package-lock.json b/package-lock.json index 3c070462..66af9eee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9929,7 +9929,6 @@ "resolved": "https://registry.npmjs.org/taskgroup/-/taskgroup-4.3.1.tgz", "integrity": "sha1-feGT/r12gnPEV3MElwJNUSwnkVo=", "requires": { - "ambi": "2.5.0", "csextends": "1.2.0" } }, diff --git a/test_apps/test_app/config/contracts.json b/test_apps/test_app/config/contracts.js similarity index 98% rename from test_apps/test_app/config/contracts.json rename to test_apps/test_app/config/contracts.js index b1f0597f..3e9eb38f 100644 --- a/test_apps/test_app/config/contracts.json +++ b/test_apps/test_app/config/contracts.js @@ -1,4 +1,4 @@ -{ +module.exports = { "default": { "deployment": { "host": "localhost", @@ -95,4 +95,4 @@ } } } -} +}; From b804f51de537c80f9e9f395347ace7b4ce9b9287 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 11 May 2018 18:22:03 -0400 Subject: [PATCH 3/6] fix getting .json config file --- lib/core/config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/config.js b/lib/core/config.js index 5f2b0c2c..e23f444e 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -75,7 +75,7 @@ Config.prototype._mergeConfig = function(configFilePath, defaultConfig, env, ena return configToReturn; } - if (!fs.existsSync(configFilePath + '.js') && !fs.existsSync(configFilePath + ' .json')) { + if (!fs.existsSync(configFilePath + '.js') && !fs.existsSync(configFilePath + '.json')) { // TODO: remove this if if (this.logger) { this.logger.warn(__("no config file found at %s using default config", configFilePath)); @@ -87,7 +87,7 @@ Config.prototype._mergeConfig = function(configFilePath, defaultConfig, env, ena if (fs.existsSync(configFilePath + '.js')) { config = require(fs.dappPath(configFilePath + '.js')); } else { - config = fs.readJSONSync(configFilePath); + config = fs.readJSONSync(configFilePath + '.json'); } let configObject = utils.recursiveMerge(defaultConfig, config); From 24eadbd94f6e63c68ca332b10a22f6bbf09ba9ce Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 11 May 2018 18:22:32 -0400 Subject: [PATCH 4/6] convert test_app contracts config from json format to js object --- test_apps/test_app/config/contracts.js | 102 ++++++++++++------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/test_apps/test_app/config/contracts.js b/test_apps/test_app/config/contracts.js index 3e9eb38f..e6b19e9b 100644 --- a/test_apps/test_app/config/contracts.js +++ b/test_apps/test_app/config/contracts.js @@ -1,97 +1,97 @@ module.exports = { - "default": { - "deployment": { - "host": "localhost", - "port": 8545, - "type": "rpc" + default: { + deployment: { + host: "localhost", + port: 8545, + type: "rpc" }, - "dappConnection": [ + dappConnection: [ "$WEB3", "ws://localhost:8546", "http://localhost:8550", "http://localhost:8545", "http://localhost:8550" ], - "gas": "auto", - "contracts": { - "Ownable": { - "deploy": false + gas: "auto", + contracts: { + Ownable: { + deploy: false }, - "SimpleStorage": { - "fromIndex": 0, - "args": [ + SimpleStorage: { + fromIndex: 0, + args: [ 100 ] }, - "AnotherStorage": { - "args": [ + AnotherStorage: { + args: [ "$SimpleStorage" ] }, - "Token": { - "deploy": false, - "args": [1000] + Token: { + deploy: false, + args: [1000] }, - "Test": { - "onDeploy": [ + Test: { + onDeploy: [ "Test.methods.changeAddress('$MyToken')" ] }, - "MyToken": { - "instanceOf": "Token" + MyToken: { + instanceOf: "Token" }, - "MyToken2": { - "instanceOf": "Token", - "args": [200] + MyToken2: { + instanceOf: "Token", + args: [200] }, - "AlreadyDeployedToken": { - "address": "0xece374063fe5cc7efbaca0a498477cada94e5ad6", - "instanceOf": "Token" + AlreadyDeployedToken: { + address: "0xece374063fe5cc7efbaca0a498477cada94e5ad6", + instanceOf: "Token" }, - "MyToken3": { - "instanceOf": "Tokn" + MyToken3: { + instanceOf: "Tokn" }, - "ContractArgs": { - "args": { - "initialValue": 123, + ContractArgs: { + args: { + initialValue: 123, "_addresses": ["$MyToken2", "$SimpleStorage"] } }, - "SomeContract": { - "args": [ + SomeContract: { + args: [ ["$MyToken2", "$SimpleStorage"], 100 ] }, - "ERC20": { - "file": "zeppelin-solidity/contracts/token/ERC20/ERC20.sol" + ERC20: { + file: "zeppelin-solidity/contracts/token/ERC20/ERC20.sol" }, - "SimpleStorageTest": { - "file": "./some_folder/test_contract.sol", - "args": [ + SimpleStorageTest: { + file: "./some_folder/test_contract.sol", + args: [ 1000 ] }, - "Identity": { - "file": "https://github.com/status-im/contracts/blob/master/contracts/identity/Identity.sol" + Identity: { + file: "https://github.com/status-im/contracts/blob/master/contracts/identity/Identity.sol" }, - "SimpleStorageWithHttpImport": { - "fromIndex": 0, - "args": [ + SimpleStorageWithHttpImport: { + fromIndex: 0, + args: [ 100 ] } }, - "afterDeploy": [ + afterDeploy: [ "Test.methods.changeAddress('$MyToken')", "web3.eth.getAccounts((err, accounts) => Test.methods.changeAddress(accounts[0]))" ] }, - "development": { - "contracts": { - "MyToken2": { - "instanceOf": "Token", - "args": [2000] + development: { + contracts: { + MyToken2: { + instanceOf: "Token", + args: [2000] } } } From cc3b748232d0aecaac73be6ca00b48450809bb3a Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 11 May 2018 18:51:11 -0400 Subject: [PATCH 5/6] update contracts configs from json to js --- templates/boilerplate/config/contracts.js | 23 +++++++++++++++++++++ templates/boilerplate/config/contracts.json | 16 -------------- templates/demo/config/contracts.js | 23 +++++++++++++++++++++ templates/demo/config/contracts.json | 22 -------------------- templates/simple/contracts.js | 23 +++++++++++++++++++++ templates/simple/contracts.json | 16 -------------- templates/simple/embark.json | 2 +- 7 files changed, 70 insertions(+), 55 deletions(-) create mode 100644 templates/boilerplate/config/contracts.js delete mode 100644 templates/boilerplate/config/contracts.json create mode 100644 templates/demo/config/contracts.js delete mode 100644 templates/demo/config/contracts.json create mode 100644 templates/simple/contracts.js delete mode 100644 templates/simple/contracts.json diff --git a/templates/boilerplate/config/contracts.js b/templates/boilerplate/config/contracts.js new file mode 100644 index 00000000..f768afdc --- /dev/null +++ b/templates/boilerplate/config/contracts.js @@ -0,0 +1,23 @@ +module.exports = { + // default applies to all enviroments + default: { + // rpc to deploy the contracts + deployment: { + host: "localhost", + port: 8545, + type: "rpc" + }, + // order of connections the dapp should connect to + dappConnection: [ + "$WEB3", // uses pre existing web3 object if available (e.g in Mist) + "http://localhost:8545" + ], + gas: "auto", + contracts: { + // example: + //SimpleStorage: { + // args: [ 100 ] + //} + } + } +} diff --git a/templates/boilerplate/config/contracts.json b/templates/boilerplate/config/contracts.json deleted file mode 100644 index 8ea794ea..00000000 --- a/templates/boilerplate/config/contracts.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "default": { - "deployment": { - "host": "localhost", - "port": 8545, - "type": "rpc" - }, - "dappConnection": [ - "$WEB3", - "http://localhost:8545" - ], - "gas": "auto", - "contracts": { - } - } -} diff --git a/templates/demo/config/contracts.js b/templates/demo/config/contracts.js new file mode 100644 index 00000000..1d8c5b23 --- /dev/null +++ b/templates/demo/config/contracts.js @@ -0,0 +1,23 @@ +module.exports = { + // default applies to all enviroments + default: { + // rpc to deploy the contracts + deployment: { + host: "localhost", + port: 8545, + type: "rpc" + }, + // order of connections the dapp should connect to + dappConnection: [ + "$WEB3", // uses pre existing web3 object if available (e.g in Mist) + "http://localhost:8545" + ], + gas: "auto", + contracts: { + SimpleStorage: { + fromIndex: 0, + args: [ 100 ] + } + } + } +} diff --git a/templates/demo/config/contracts.json b/templates/demo/config/contracts.json deleted file mode 100644 index da746390..00000000 --- a/templates/demo/config/contracts.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "default": { - "deployment": { - "host": "localhost", - "port": 8545, - "type": "rpc" - }, - "dappConnection": [ - "$WEB3", - "http://localhost:8545" - ], - "gas": "auto", - "contracts": { - "SimpleStorage": { - "fromIndex": 0, - "args": [ - 100 - ] - } - } - } -} diff --git a/templates/simple/contracts.js b/templates/simple/contracts.js new file mode 100644 index 00000000..f768afdc --- /dev/null +++ b/templates/simple/contracts.js @@ -0,0 +1,23 @@ +module.exports = { + // default applies to all enviroments + default: { + // rpc to deploy the contracts + deployment: { + host: "localhost", + port: 8545, + type: "rpc" + }, + // order of connections the dapp should connect to + dappConnection: [ + "$WEB3", // uses pre existing web3 object if available (e.g in Mist) + "http://localhost:8545" + ], + gas: "auto", + contracts: { + // example: + //SimpleStorage: { + // args: [ 100 ] + //} + } + } +} diff --git a/templates/simple/contracts.json b/templates/simple/contracts.json deleted file mode 100644 index 8ea794ea..00000000 --- a/templates/simple/contracts.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "default": { - "deployment": { - "host": "localhost", - "port": 8545, - "type": "rpc" - }, - "dappConnection": [ - "$WEB3", - "http://localhost:8545" - ], - "gas": "auto", - "contracts": { - } - } -} diff --git a/templates/simple/embark.json b/templates/simple/embark.json index 35edb539..81232490 100644 --- a/templates/simple/embark.json +++ b/templates/simple/embark.json @@ -3,7 +3,7 @@ "app": {}, "buildDir": "build/", "config": { - "contracts": "contracts.json", + "contracts": "contracts.js", "blockchain": false, "storage": false, "communication": false, From e8210607b77c30eca24b380b6f1198c70c868b0d Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 11 May 2018 19:09:38 -0400 Subject: [PATCH 6/6] fix for when config is specified in embark.json --- lib/core/config.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/core/config.js b/lib/core/config.js index e23f444e..55e20ad1 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -75,6 +75,8 @@ Config.prototype._mergeConfig = function(configFilePath, defaultConfig, env, ena return configToReturn; } + // due to embark.json; TODO: refactor this + configFilePath = configFilePath.replace('.js', '').replace('.json',''); if (!fs.existsSync(configFilePath + '.js') && !fs.existsSync(configFilePath + '.json')) { // TODO: remove this if if (this.logger) {