diff --git a/lib/core/config.js b/lib/core/config.js index 44dace7b0..55e20ad1f 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -75,7 +75,9 @@ Config.prototype._mergeConfig = function(configFilePath, defaultConfig, env, ena return configToReturn; } - if (!fs.existsSync(configFilePath)) { + // 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) { this.logger.warn(__("no config file found at %s using default config", configFilePath)); @@ -83,7 +85,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 + '.json'); + } let configObject = utils.recursiveMerge(defaultConfig, config); if (env) { @@ -109,7 +116,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 +149,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 +200,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 +217,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 +227,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); }; diff --git a/package-lock.json b/package-lock.json index 3c0704628..66af9eee6 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/templates/boilerplate/config/contracts.js b/templates/boilerplate/config/contracts.js new file mode 100644 index 000000000..f768afdc6 --- /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 8ea794ea4..000000000 --- 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 000000000..1d8c5b237 --- /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 da7463900..000000000 --- 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 000000000..f768afdc6 --- /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 8ea794ea4..000000000 --- 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 35edb5397..812324905 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, diff --git a/test_apps/test_app/config/contracts.js b/test_apps/test_app/config/contracts.js new file mode 100644 index 000000000..e6b19e9b7 --- /dev/null +++ b/test_apps/test_app/config/contracts.js @@ -0,0 +1,98 @@ +module.exports = { + default: { + deployment: { + host: "localhost", + port: 8545, + type: "rpc" + }, + dappConnection: [ + "$WEB3", + "ws://localhost:8546", + "http://localhost:8550", + "http://localhost:8545", + "http://localhost:8550" + ], + gas: "auto", + contracts: { + Ownable: { + deploy: false + }, + SimpleStorage: { + fromIndex: 0, + args: [ + 100 + ] + }, + AnotherStorage: { + args: [ + "$SimpleStorage" + ] + }, + Token: { + deploy: false, + args: [1000] + }, + Test: { + onDeploy: [ + "Test.methods.changeAddress('$MyToken')" + ] + }, + MyToken: { + instanceOf: "Token" + }, + MyToken2: { + instanceOf: "Token", + args: [200] + }, + AlreadyDeployedToken: { + address: "0xece374063fe5cc7efbaca0a498477cada94e5ad6", + instanceOf: "Token" + }, + MyToken3: { + instanceOf: "Tokn" + }, + ContractArgs: { + args: { + initialValue: 123, + "_addresses": ["$MyToken2", "$SimpleStorage"] + } + }, + SomeContract: { + args: [ + ["$MyToken2", "$SimpleStorage"], + 100 + ] + }, + ERC20: { + file: "zeppelin-solidity/contracts/token/ERC20/ERC20.sol" + }, + SimpleStorageTest: { + file: "./some_folder/test_contract.sol", + args: [ + 1000 + ] + }, + Identity: { + file: "https://github.com/status-im/contracts/blob/master/contracts/identity/Identity.sol" + }, + SimpleStorageWithHttpImport: { + fromIndex: 0, + args: [ + 100 + ] + } + }, + afterDeploy: [ + "Test.methods.changeAddress('$MyToken')", + "web3.eth.getAccounts((err, accounts) => Test.methods.changeAddress(accounts[0]))" + ] + }, + development: { + contracts: { + MyToken2: { + instanceOf: "Token", + args: [2000] + } + } + } +}; diff --git a/test_apps/test_app/config/contracts.json b/test_apps/test_app/config/contracts.json deleted file mode 100644 index b1f0597fa..000000000 --- a/test_apps/test_app/config/contracts.json +++ /dev/null @@ -1,98 +0,0 @@ -{ - "default": { - "deployment": { - "host": "localhost", - "port": 8545, - "type": "rpc" - }, - "dappConnection": [ - "$WEB3", - "ws://localhost:8546", - "http://localhost:8550", - "http://localhost:8545", - "http://localhost:8550" - ], - "gas": "auto", - "contracts": { - "Ownable": { - "deploy": false - }, - "SimpleStorage": { - "fromIndex": 0, - "args": [ - 100 - ] - }, - "AnotherStorage": { - "args": [ - "$SimpleStorage" - ] - }, - "Token": { - "deploy": false, - "args": [1000] - }, - "Test": { - "onDeploy": [ - "Test.methods.changeAddress('$MyToken')" - ] - }, - "MyToken": { - "instanceOf": "Token" - }, - "MyToken2": { - "instanceOf": "Token", - "args": [200] - }, - "AlreadyDeployedToken": { - "address": "0xece374063fe5cc7efbaca0a498477cada94e5ad6", - "instanceOf": "Token" - }, - "MyToken3": { - "instanceOf": "Tokn" - }, - "ContractArgs": { - "args": { - "initialValue": 123, - "_addresses": ["$MyToken2", "$SimpleStorage"] - } - }, - "SomeContract": { - "args": [ - ["$MyToken2", "$SimpleStorage"], - 100 - ] - }, - "ERC20": { - "file": "zeppelin-solidity/contracts/token/ERC20/ERC20.sol" - }, - "SimpleStorageTest": { - "file": "./some_folder/test_contract.sol", - "args": [ - 1000 - ] - }, - "Identity": { - "file": "https://github.com/status-im/contracts/blob/master/contracts/identity/Identity.sol" - }, - "SimpleStorageWithHttpImport": { - "fromIndex": 0, - "args": [ - 100 - ] - } - }, - "afterDeploy": [ - "Test.methods.changeAddress('$MyToken')", - "web3.eth.getAccounts((err, accounts) => Test.methods.changeAddress(accounts[0]))" - ] - }, - "development": { - "contracts": { - "MyToken2": { - "instanceOf": "Token", - "args": [2000] - } - } - } -}