diff --git a/lib/cmds/blockchain/geth_commands.js b/lib/cmds/blockchain/geth_commands.js index f89c325a6..d6b1e4c5d 100644 --- a/lib/cmds/blockchain/geth_commands.js +++ b/lib/cmds/blockchain/geth_commands.js @@ -1,7 +1,7 @@ -var async = require('async'); +let async = require('async'); // TODO: make all of this async -var GethCommands = function(options) { +let GethCommands = function(options) { this.config = options.config; this.env = options.env || 'development'; this.name = "Go-Ethereum (https://github.com/ethereum/go-ethereum)"; @@ -9,8 +9,8 @@ var GethCommands = function(options) { }; GethCommands.prototype.commonOptions = function() { - var config = this.config; - var cmd = ""; + let config = this.config; + let cmd = ""; cmd += this.determineNetworkType(config); @@ -34,7 +34,7 @@ GethCommands.prototype.commonOptions = function() { }; GethCommands.prototype.determineNetworkType = function(config) { - var cmd = ""; + let cmd = ""; if (config.networkType === 'testnet') { cmd += "--testnet "; } else if (config.networkType === 'olympic') { @@ -46,8 +46,8 @@ GethCommands.prototype.determineNetworkType = function(config) { }; GethCommands.prototype.initGenesisCommmand = function() { - var config = this.config; - var cmd = this.geth_bin + " " + this.commonOptions(); + let config = this.config; + let cmd = this.geth_bin + " " + this.commonOptions(); if (config.genesisBlock) { cmd += "init \"" + config.genesisBlock + "\" "; @@ -65,7 +65,7 @@ GethCommands.prototype.listAccountsCommand = function() { }; GethCommands.prototype.determineRpcOptions = function(config) { - var cmd = ""; + let cmd = ""; cmd += "--port " + config.port + " "; cmd += "--rpc "; @@ -88,17 +88,17 @@ GethCommands.prototype.determineRpcOptions = function(config) { }; GethCommands.prototype.mainCommand = function(address, done) { - var self = this; - var config = this.config; - var rpc_api = (this.config.rpcApi || ['eth', 'web3', 'net']); + let self = this; + let config = this.config; + let rpc_api = (this.config.rpcApi || ['eth', 'web3', 'net']); async.series([ function commonOptions(callback) { - var cmd = self.commonOptions(); + let cmd = self.commonOptions(); callback(null, cmd); }, function rpcOptions(callback) { - var cmd = self.determineRpcOptions(self.config); + let cmd = self.determineRpcOptions(self.config); callback(null, cmd); }, function dontGetPeers(callback) { @@ -114,7 +114,7 @@ GethCommands.prototype.mainCommand = function(address, done) { callback(null, ""); }, function maxPeers(callback) { - var cmd = "--maxpeers " + config.maxpeers; + let cmd = "--maxpeers " + config.maxpeers; callback(null, cmd); }, function mining(callback) { @@ -140,7 +140,7 @@ GethCommands.prototype.mainCommand = function(address, done) { callback(null, '--rpcapi "' + rpc_api.join(',') + '"'); }, function accountToUnlock(callback) { - var accountAddress = config.account.address || address; + let accountAddress = config.account.address || address; if (accountAddress) { return callback(null, "--unlock=" + accountAddress); } diff --git a/lib/cmds/simulator.js b/lib/cmds/simulator.js index 47554c123..6a9adde86 100644 --- a/lib/cmds/simulator.js +++ b/lib/cmds/simulator.js @@ -1,11 +1,11 @@ -var shelljs = require('shelljs'); +let shelljs = require('shelljs'); -var Simulator = function(options) { +let Simulator = function(options) { this.blockchainConfig = options.blockchainConfig; }; Simulator.prototype.run = function(options) { - var cmds = []; + let cmds = []; cmds.push("-p " + (this.blockchainConfig.rpcPort || options.port || 8545)); cmds.push("-h " + (this.blockchainConfig.rpcHost || options.host || 'localhost')); diff --git a/lib/cmds/template_generator.js b/lib/cmds/template_generator.js index 42c632882..d2355a34d 100644 --- a/lib/cmds/template_generator.js +++ b/lib/cmds/template_generator.js @@ -1,12 +1,12 @@ -var fs = require('../core/fs.js'); -var utils = require('../utils/utils.js'); +let fs = require('../core/fs.js'); +let utils = require('../utils/utils.js'); -var TemplateGenerator = function(templateName) { +let TemplateGenerator = function(templateName) { this.templateName = templateName; }; TemplateGenerator.prototype.generate = function(destinationFolder, name) { - var templatePath = fs.embarkPath(this.templateName); + let templatePath = fs.embarkPath(this.templateName); console.log('Initializing Embark Template....'.green); fs.copySync(templatePath, destinationFolder + name); diff --git a/lib/contracts/abi.js b/lib/contracts/abi.js index 479b9f771..bede90dcd 100644 --- a/lib/contracts/abi.js +++ b/lib/contracts/abi.js @@ -1,5 +1,5 @@ -var ABIGenerator = function(options) { +let ABIGenerator = function(options) { this.blockchainConfig = options.blockchainConfig || {}; this.storageConfig = options.storageConfig || {}; this.communicationConfig = options.communicationConfig || {}; @@ -10,9 +10,9 @@ var ABIGenerator = function(options) { }; ABIGenerator.prototype.generateProvider = function() { - var self = this; - var result = ""; - var providerPlugins; + let self = this; + let result = ""; + let providerPlugins; if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) { return ""; @@ -39,9 +39,9 @@ ABIGenerator.prototype.generateProvider = function() { }; ABIGenerator.prototype.generateContracts = function(useEmbarkJS) { - var self = this; - var result = "\n"; - var contractsPlugins; + let self = this; + let result = "\n"; + let contractsPlugins; if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) { return ""; @@ -56,11 +56,11 @@ ABIGenerator.prototype.generateContracts = function(useEmbarkJS) { result += plugin.generateContracts({contracts: self.contractsManager.contracts}); }); } else { - for(var className in this.contractsManager.contracts) { - var contract = this.contractsManager.contracts[className]; + for(let className in this.contractsManager.contracts) { + let contract = this.contractsManager.contracts[className]; - var abi = JSON.stringify(contract.abiDefinition); - var gasEstimates = JSON.stringify(contract.gasEstimates); + let abi = JSON.stringify(contract.abiDefinition); + let gasEstimates = JSON.stringify(contract.gasEstimates); if (useEmbarkJS) { result += "\n" + className + " = new EmbarkJS.Contract({abi: " + abi + ", address: '" + contract.deployedAddress + "', code: '" + contract.code + "', gasEstimates: " + gasEstimates + "});"; @@ -76,8 +76,8 @@ ABIGenerator.prototype.generateContracts = function(useEmbarkJS) { }; ABIGenerator.prototype.generateStorageInitialization = function(useEmbarkJS) { - var self = this; - var result = "\n"; + let self = this; + let result = "\n"; if (!useEmbarkJS || self.storageConfig === {}) return ""; @@ -89,8 +89,8 @@ ABIGenerator.prototype.generateStorageInitialization = function(useEmbarkJS) { }; ABIGenerator.prototype.generateCommunicationInitialization = function(useEmbarkJS) { - var self = this; - var result = "\n"; + let self = this; + let result = "\n"; if (!useEmbarkJS || self.communicationConfig === {}) return ""; @@ -104,7 +104,7 @@ ABIGenerator.prototype.generateCommunicationInitialization = function(useEmbarkJ }; ABIGenerator.prototype.generateABI = function(options) { - var result = ""; + let result = ""; result += this.generateProvider(); result += this.generateContracts(options.useEmbarkJS); diff --git a/lib/contracts/contracts.js b/lib/contracts/contracts.js index 4123f543b..e6e2dc875 100644 --- a/lib/contracts/contracts.js +++ b/lib/contracts/contracts.js @@ -1,12 +1,12 @@ -var toposort = require('toposort'); -var async = require('async'); +let toposort = require('toposort'); +let async = require('async'); -var Compiler = require('./compiler.js'); +let Compiler = require('./compiler.js'); // TODO: create a contract object -var adjustGas = function(contract) { - var maxGas, adjustedGas; +let adjustGas = function(contract) { + let maxGas, adjustedGas; if (contract.gas === 'auto') { if (contract.deploy || contract.deploy === undefined) { if (contract.gasEstimates.creation !== undefined) { @@ -25,7 +25,7 @@ var adjustGas = function(contract) { } }; -var ContractsManager = function(options) { +let ContractsManager = function(options) { this.contractFiles = options.contractFiles; this.contractsConfig = options.contractsConfig; this.contracts = {}; @@ -36,17 +36,17 @@ var ContractsManager = function(options) { }; ContractsManager.prototype.build = function(done) { - var self = this; + let self = this; async.waterfall([ function compileContracts(callback) { - var compiler = new Compiler({plugins: self.plugins, logger: self.logger}); + let compiler = new Compiler({plugins: self.plugins, logger: self.logger}); compiler.compile_contracts(self.contractFiles, function(err, compiledObject) { self.compiledContracts = compiledObject; callback(err); }); }, function prepareContractsFromConfig(callback) { - var className, contract; + let className, contract; for(className in self.contractsConfig.contracts) { contract = self.contractsConfig.contracts[className]; @@ -58,7 +58,7 @@ ContractsManager.prototype.build = function(done) { callback(); }, function setDeployIntention(callback) { - var className, contract; + let className, contract; for(className in self.contracts) { contract = self.contracts[className]; contract.deploy = (contract.deploy === undefined) || contract.deploy; @@ -66,7 +66,7 @@ ContractsManager.prototype.build = function(done) { callback(); }, function prepareContractsFromCompilation(callback) { - var className, compiledContract, contractConfig, contract; + let className, compiledContract, contractConfig, contract; for(className in self.compiledContracts) { compiledContract = self.compiledContracts[className]; contractConfig = self.contractsConfig.contracts[className]; @@ -94,7 +94,7 @@ ContractsManager.prototype.build = function(done) { }, /*eslint complexity: ["error", 11]*/ function dealWithSpecialConfigs(callback) { - var className, contract, parentContractName, parentContract; + let className, contract, parentContractName, parentContract; for(className in self.contracts) { contract = self.contracts[className]; @@ -136,7 +136,7 @@ ContractsManager.prototype.build = function(done) { callback(); }, function removeContractsWithNoCode(callback) { - var className, contract; + let className, contract; for(className in self.contracts) { contract = self.contracts[className]; @@ -149,15 +149,15 @@ ContractsManager.prototype.build = function(done) { callback(); }, function determineDependencies(callback) { - var className, contract; + let className, contract; for(className in self.contracts) { contract = self.contracts[className]; if (contract.args === []) continue; - var ref = contract.args; - for (var j = 0; j < ref.length; j++) { - var arg = ref[j]; + let ref = contract.args; + for (let j = 0; j < ref.length; j++) { + let arg = ref[j]; if (arg[0] === "$") { self.contractDependencies[className] = self.contractDependencies[className] || []; self.contractDependencies[className].push(arg.substr(1)); @@ -180,20 +180,20 @@ ContractsManager.prototype.getContract = function(className) { }; ContractsManager.prototype.sortContracts = function(contractList) { - var converted_dependencies = [], i; + let converted_dependencies = [], i; - for(var contract in this.contractDependencies) { - var dependencies = this.contractDependencies[contract]; + for(let contract in this.contractDependencies) { + let dependencies = this.contractDependencies[contract]; for(i=0; i < dependencies.length; i++) { converted_dependencies.push([contract, dependencies[i]]); } } - var orderedDependencies = toposort(converted_dependencies).reverse(); + let orderedDependencies = toposort(converted_dependencies).reverse(); - var newList = contractList.sort(function(a,b) { - var order_a = orderedDependencies.indexOf(a.className); - var order_b = orderedDependencies.indexOf(b.className); + let newList = contractList.sort(function(a,b) { + let order_a = orderedDependencies.indexOf(a.className); + let order_b = orderedDependencies.indexOf(b.className); return order_a - order_b; }); @@ -202,21 +202,21 @@ ContractsManager.prototype.sortContracts = function(contractList) { // TODO: should be built contracts ContractsManager.prototype.listContracts = function() { - var contracts = []; - for(var className in this.contracts) { - var contract = this.contracts[className]; + let contracts = []; + for(let className in this.contracts) { + let contract = this.contracts[className]; contracts.push(contract); } return this.sortContracts(contracts); }; ContractsManager.prototype.contractsState = function() { - var data = []; + let data = []; - for(var className in this.contracts) { - var contract = this.contracts[className]; + for(let className in this.contracts) { + let contract = this.contracts[className]; - var contractData; + let contractData; if (contract.deploy === false) { contractData = [ diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index 5e3ae70ac..42c33e47b 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -1,11 +1,11 @@ -var async = require('async'); +let async = require('async'); -var RunCode = require('../core/runCode.js'); +let RunCode = require('../core/runCode.js'); -var DeployTracker = require('./deploy_tracker.js'); -var ABIGenerator = require('./abi.js'); +let DeployTracker = require('./deploy_tracker.js'); +let ABIGenerator = require('./abi.js'); -var Deploy = function(options) { +let Deploy = function(options) { this.web3 = options.web3; this.contractsManager = options.contractsManager; this.logger = options.logger; @@ -17,7 +17,7 @@ var Deploy = function(options) { }; Deploy.prototype.determineArguments = function(suppliedArgs) { - var realArgs = [], l, arg, contractName, referedContract; + let realArgs = [], l, arg, contractName, referedContract; for (l = 0; l < suppliedArgs.length; l++) { arg = suppliedArgs[l]; @@ -34,13 +34,13 @@ Deploy.prototype.determineArguments = function(suppliedArgs) { }; Deploy.prototype.checkAndDeployContract = function(contract, params, callback) { - var self = this; - var suppliedArgs; - var realArgs; - var arg; - var l; - var contractName; - var referedContract; + let self = this; + let suppliedArgs; + let realArgs; + let arg; + let l; + let contractName; + let referedContract; contract.error = false; if (contract.deploy === false) { @@ -59,7 +59,7 @@ Deploy.prototype.checkAndDeployContract = function(contract, params, callback) { return callback(); } - var trackedContract = self.deployTracker.getContract(contract.className, contract.realRuntimeBytecode, contract.args); + let trackedContract = self.deployTracker.getContract(contract.className, contract.realRuntimeBytecode, contract.args); if (trackedContract && this.web3.eth.getCode(trackedContract.address) !== "0x") { self.logger.info(contract.className.bold.cyan + " already deployed at ".green + trackedContract.address.bold.cyan); @@ -80,9 +80,9 @@ Deploy.prototype.checkAndDeployContract = function(contract, params, callback) { if (contract.onDeploy !== undefined) { self.logger.info('executing onDeploy commands'); - var abiGenerator = new ABIGenerator({contractsManager: self.contractsManager}); - var abi = abiGenerator.generateContracts(false); - var cmds = contract.onDeploy.join(';\n'); + let abiGenerator = new ABIGenerator({contractsManager: self.contractsManager}); + let abi = abiGenerator.generateContracts(false); + let cmds = contract.onDeploy.join(';\n'); RunCode.doEval(abi + "\n" + cmds, self.web3); } @@ -94,10 +94,10 @@ Deploy.prototype.checkAndDeployContract = function(contract, params, callback) { }; Deploy.prototype.deployContract = function(contract, params, callback) { - var self = this; - var contractObject = this.web3.eth.contract(contract.abiDefinition); + let self = this; + let contractObject = this.web3.eth.contract(contract.abiDefinition); - var contractParams = (params || contract.args).slice(); + let contractParams = (params || contract.args).slice(); this.web3.eth.getAccounts(function(err, accounts) { if (err) { @@ -121,7 +121,7 @@ Deploy.prototype.deployContract = function(contract, params, callback) { if (err) { self.logger.error("error deploying contract: " + contract.className.cyan); - var errMsg = err.toString(); + let errMsg = err.toString(); if (errMsg === 'Error: The contract code couldn\'t be stored, please check your gas amount.') { errMsg = 'The contract code couldn\'t be stored, out of gas or constructor error'; } @@ -141,7 +141,7 @@ Deploy.prototype.deployContract = function(contract, params, callback) { }; Deploy.prototype.deployAll = function(done) { - var self = this; + let self = this; this.logger.info("deploying contracts"); async.eachOfSeries(this.contractsManager.listContracts(), diff --git a/lib/contracts/deploy_tracker.js b/lib/contracts/deploy_tracker.js index 79152057d..931a4ee12 100644 --- a/lib/contracts/deploy_tracker.js +++ b/lib/contracts/deploy_tracker.js @@ -1,6 +1,6 @@ -var fs = require('../core/fs.js'); +let fs = require('../core/fs.js'); -var DeployTracker = function(options) { +let DeployTracker = function(options) { this.logger = options.logger; this.env = options.env; this.chainConfig = options.chainConfig; @@ -12,8 +12,8 @@ var DeployTracker = function(options) { } // TODO: need to make this async - var block = this.web3.eth.getBlock(0); - var chainId = block.hash; + let block = this.web3.eth.getBlock(0); + let chainId = block.hash; if (this.chainConfig[chainId] === undefined) { this.chainConfig[chainId] = {contracts: {}}; @@ -40,7 +40,7 @@ DeployTracker.prototype.trackContract = function(contractName, code, args, addre }; DeployTracker.prototype.getContract = function(contractName, code, args) { - var contract = this.currentChain.contracts[this.web3.sha3(code + contractName + args.join(','))]; + let contract = this.currentChain.contracts[this.web3.sha3(code + contractName + args.join(','))]; if (contract && contract.address === undefined) { return false; } return contract; }; diff --git a/lib/contracts/solcP.js b/lib/contracts/solcP.js index 2332091fd..47cbc98d0 100644 --- a/lib/contracts/solcP.js +++ b/lib/contracts/solcP.js @@ -1,4 +1,4 @@ -var solc; +let solc; process.on('message', function(msg) { if (msg.action === 'loadCompiler') { @@ -7,7 +7,7 @@ process.on('message', function(msg) { } if (msg.action === 'compile') { - var output = solc.compile(msg.obj, msg.optimize); + let output = solc.compile(msg.obj, msg.optimize); process.send({result: "compilation", output: output}); } }); diff --git a/lib/contracts/solcW.js b/lib/contracts/solcW.js index e9a0f9ada..e9d980cd1 100644 --- a/lib/contracts/solcW.js +++ b/lib/contracts/solcW.js @@ -1,8 +1,8 @@ -var utils = require('../utils/utils.js'); -var solcProcess; -var compilerLoaded = false; +let utils = require('../utils/utils.js'); +let solcProcess; +let compilerLoaded = false; -var SolcW = function() { +let SolcW = function() { }; SolcW.prototype.load_compiler = function(done) { diff --git a/lib/core/core.js b/lib/core/core.js index 424eda08c..5632edd25 100644 --- a/lib/core/core.js +++ b/lib/core/core.js @@ -1,5 +1,5 @@ -var Core = function() {}; +let Core = function() {}; module.exports = Core; diff --git a/lib/core/engine.js b/lib/core/engine.js index 9f7a87361..e107fadcb 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -1,20 +1,20 @@ -var http = require('http'); -var Web3 = require('web3'); -var utils = require('../utils/utils.js'); +let http = require('http'); +let Web3 = require('web3'); +let utils = require('../utils/utils.js'); -var Events = require('./events.js'); -var Logger = require('./logger.js'); -var Config = require('./config.js'); +let Events = require('./events.js'); +let Logger = require('./logger.js'); +let Config = require('./config.js'); -var DeployManager = require('../contracts/deploy_manager.js'); -var ABIGenerator = require('../contracts/abi.js'); -var ServicesMonitor = require('./services_monitor.js'); -var Pipeline = require('../pipeline/pipeline.js'); -var Server = require('../pipeline/server.js'); -var Watch = require('../pipeline/watch.js'); -var version = require('../../package.json').version; +let DeployManager = require('../contracts/deploy_manager.js'); +let ABIGenerator = require('../contracts/abi.js'); +let ServicesMonitor = require('./services_monitor.js'); +let Pipeline = require('../pipeline/pipeline.js'); +let Server = require('../pipeline/server.js'); +let Watch = require('../pipeline/watch.js'); +let version = require('../../package.json').version; -var Engine = function(options) { +let Engine = function(options) { this.env = options.env; this.embarkConfig = options.embarkConfig; this.interceptLogs = options.interceptLogs; @@ -22,8 +22,8 @@ var Engine = function(options) { }; Engine.prototype.init = function(_options) { - var self = this; - var options = _options || {}; + let self = this; + let options = _options || {}; this.events = new Events(); this.logger = options.logger || new Logger({logLevel: 'debug'}); this.config = new Config({env: this.env, logger: this.logger, events: this.events}); @@ -37,9 +37,9 @@ Engine.prototype.init = function(_options) { }; Engine.prototype.startMonitor = function() { - var self = this; + let self = this; if (this.plugins) { - var servicePlugins = this.plugins.getPluginsFor('serviceChecks'); + let servicePlugins = this.plugins.getPluginsFor('serviceChecks'); servicePlugins.forEach(function(plugin) { plugin.serviceChecks.forEach(function(pluginCheck) { self.servicesMonitor.addCheck(pluginCheck.checkName, pluginCheck.checkFn, pluginCheck.time); @@ -50,9 +50,9 @@ Engine.prototype.startMonitor = function() { }; Engine.prototype.startService = function(serviceName, _options) { - var options = _options || {}; + let options = _options || {}; - var services = { + let services = { "pipeline": this.pipelineService, "abi": this.abiService, "deployment": this.deploymentService, @@ -62,7 +62,7 @@ Engine.prototype.startService = function(serviceName, _options) { "web3": this.web3Service }; - var service = services[serviceName]; + let service = services[serviceName]; if (!service) { throw new Error("unknown service: " + serviceName); @@ -74,9 +74,9 @@ Engine.prototype.startService = function(serviceName, _options) { }; Engine.prototype.pipelineService = function(options) { - var self = this; + let self = this; this.logger.setStatus("Building Assets"); - var pipeline = new Pipeline({ + let pipeline = new Pipeline({ buildDir: this.config.buildDir, contractsFiles: this.config.contractsFiles, assetFiles: this.config.assetFiles, @@ -100,18 +100,18 @@ Engine.prototype.pipelineService = function(options) { }; Engine.prototype.abiService = function(options) { - var self = this; - var generateABICode = function(contractsManager) { - var abiGenerator = new ABIGenerator({ + let self = this; + let generateABICode = function(contractsManager) { + let abiGenerator = new ABIGenerator({ blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, plugins: self.plugins, storageConfig: self.config.storageConfig, communicationConfig: self.config.communicationConfig }); - var embarkJSABI = abiGenerator.generateABI({useEmbarkJS: true}); - var vanillaABI = abiGenerator.generateABI({useEmbarkJS: false}); - var vanillaContractsABI = abiGenerator.generateContracts(false); + let embarkJSABI = abiGenerator.generateABI({useEmbarkJS: true}); + let vanillaABI = abiGenerator.generateABI({useEmbarkJS: false}); + let vanillaContractsABI = abiGenerator.generateContracts(false); self.events.emit('abi-contracts-vanila', vanillaContractsABI); self.events.emit('abi-vanila', vanillaABI); @@ -122,7 +122,7 @@ Engine.prototype.abiService = function(options) { }; Engine.prototype.deploymentService = function(options) { - var self = this; + let self = this; this.deployManager = new DeployManager({ web3: options.web3 || self.web3, trackContracts: options.trackContracts, @@ -144,27 +144,27 @@ Engine.prototype.deploymentService = function(options) { Engine.prototype.fileWatchService = function(options) { this.logger.setStatus("Watching for changes"); - var watch = new Watch({logger: this.logger, events: this.events}); + let watch = new Watch({logger: this.logger, events: this.events}); watch.start(); }; Engine.prototype.webServerService = function(options) { - var self = this; - var webServerConfig = this.config.webServerConfig; + let self = this; + let webServerConfig = this.config.webServerConfig; if (!webServerConfig.enabled) { return; } - var host = options.host || webServerConfig.host; - var port = options.port || webServerConfig.port; + let host = options.host || webServerConfig.host; + let port = options.port || webServerConfig.port; this.logger.setStatus("Starting Server"); - var server = new Server({ + let server = new Server({ logger: this.logger, host: host, port: port }); self.servicesMonitor.addCheck('Webserver', function(cb) { - var devServer = 'Webserver (http://' + host + ':' + port + ')'; + let devServer = 'Webserver (http://' + host + ':' + port + ')'; return cb({name: devServer, status: 'green'}); }); @@ -173,7 +173,7 @@ Engine.prototype.webServerService = function(options) { }; Engine.prototype.ipfsService = function(options) { - var self = this; + let self = this; self.servicesMonitor.addCheck('IPFS', function(cb) { utils.checkIsAvailable('http://localhost:5001', function(available) { if (available) { @@ -181,13 +181,13 @@ Engine.prototype.ipfsService = function(options) { //The URL should also be flexible to accept non-default IPFS url self.logger.trace("Checking IPFS version..."); http.get('http://localhost:5001/api/v0/version', function(res) { - var body = ''; + let body = ''; res.on('data', function(d) { body += d; }); res.on('end', function() { try{ - var parsed = JSON.parse(body); + let parsed = JSON.parse(body); if(parsed.Version){ return cb({name: ("IPFS " + parsed.Version), status: 'green'}); } @@ -213,11 +213,11 @@ Engine.prototype.ipfsService = function(options) { }; Engine.prototype.web3Service = function(options) { - var self = this; + let self = this; this.web3 = options.web3; if (this.web3 === undefined) { this.web3 = new Web3(); - var web3Endpoint = 'http://' + this.config.blockchainConfig.rpcHost + ':' + this.config.blockchainConfig.rpcPort; + let web3Endpoint = 'http://' + this.config.blockchainConfig.rpcHost + ':' + this.config.blockchainConfig.rpcPort; this.web3.setProvider(new this.web3.providers.HttpProvider(web3Endpoint)); } diff --git a/lib/core/fs.js b/lib/core/fs.js index a88816e4d..56d8aefaa 100644 --- a/lib/core/fs.js +++ b/lib/core/fs.js @@ -1,5 +1,5 @@ -var fs = require('fs-extra'); -var utils = require('../utils/utils.js'); +let fs = require('fs-extra'); +let utils = require('../utils/utils.js'); function mkdirpSync() { return fs.mkdirpSync.apply(fs.mkdirpSync, arguments); diff --git a/lib/core/logger.js b/lib/core/logger.js index 442544a70..f8fa4ebad 100644 --- a/lib/core/logger.js +++ b/lib/core/logger.js @@ -1,6 +1,6 @@ -var colors = require('colors'); +let colors = require('colors'); -var Logger = function(options) { +let Logger = function(options) { this.logLevels = ['error', 'warn', 'info', 'debug', 'trace']; this.logLevel = options.logLevel || 'info'; this.logFunction = options.logFunction || console.log; diff --git a/lib/core/runCode.js b/lib/core/runCode.js index 7134b94af..6c89be039 100644 --- a/lib/core/runCode.js +++ b/lib/core/runCode.js @@ -1,5 +1,5 @@ -var Web3 = require('web3'); -var web3; +let Web3 = require('web3'); +let web3; // ====================== // the eval is used for evaluating some of the contact calls for different purposes diff --git a/lib/core/services_monitor.js b/lib/core/services_monitor.js index 2685c5c2e..d221f0876 100644 --- a/lib/core/services_monitor.js +++ b/lib/core/services_monitor.js @@ -1,9 +1,9 @@ -var async = require('../utils/async_extend.js'); +let async = require('../utils/async_extend.js'); // TODO: need to separate colors from states // i.e use status: /on|off|warn/ not /red|green/ // it's up to the logger or console to determine the color -var ServicesMonitor = function(options) { +let ServicesMonitor = function(options) { this.events = options.events; this.logger = options.logger; this.checkList = {}; @@ -13,8 +13,8 @@ var ServicesMonitor = function(options) { }; ServicesMonitor.prototype.initCheck = function(checkName) { - var self = this; - var check = this.checkList[checkName]; + let self = this; + let check = this.checkList[checkName]; if (!check) { return false; } @@ -45,7 +45,7 @@ ServicesMonitor.prototype.initCheck = function(checkName) { }; ServicesMonitor.prototype.addCheck = function(checkName, checkFn, time) { - var self = this; + let self = this; this.logger.trace('add check: ' + checkName); this.checkList[checkName] = {fn: checkFn, interval: time || 5000}; @@ -62,7 +62,7 @@ ServicesMonitor.prototype.stopCheck = function(name) { }; ServicesMonitor.prototype.startMonitor = function() { - var self = this; + let self = this; this.working = true; this.logger.trace('startMonitor'); diff --git a/lib/core/test.js b/lib/core/test.js index d4b216e45..5117702d0 100644 --- a/lib/core/test.js +++ b/lib/core/test.js @@ -1,4 +1,4 @@ -var getSimulator = function() { +let getSimulator = function() { try { return require('ethereumjs-testrpc'); } catch (e) { @@ -17,18 +17,18 @@ var getSimulator = function() { } }; -var Test; +let Test; Test = (function (options) { - var async = require('async'); - var opts = options === undefined ? {} : options; + let async = require('async'); + let opts = options === undefined ? {} : options; opts.logLevel = opts.hasOwnProperty('logLevel') ? opts.logLevel : 'debug'; opts.simulatorOptions = opts.hasOwnProperty('simulatorOptions') ? opts.simulatorOptions : {}; - var sim = getSimulator(); + let sim = getSimulator(); function newWebThree() { try { - var Web3 = require('web3'); - var web3 = new Web3(); + let Web3 = require('web3'); + let web3 = new Web3(); web3.setProvider(sim.provider(opts.simulatorOptions)); return web3; } catch (e) { @@ -37,11 +37,11 @@ Test = (function (options) { } function deployAll(contractsConfig, cb) { - var RunCode = require('./runCode.js'); - var self = this; + let RunCode = require('./runCode.js'); + let self = this; function newEngine () { - var Engine = require('./engine.js'); + let Engine = require('./engine.js'); return new Engine({ env: opts.env || 'test', // TODO: confi will need to detect if this is a obj diff --git a/lib/core/test_logger.js b/lib/core/test_logger.js index 7795f1a41..d1f8616d4 100644 --- a/lib/core/test_logger.js +++ b/lib/core/test_logger.js @@ -1,8 +1,8 @@ -var colors = require('colors'); +let colors = require('colors'); // TODO: just logFunction changes, probably doesn't need a whole new module just // for this -var TestLogger = function(options) { +let TestLogger = function(options) { this.logLevels = ['error', 'warn', 'info', 'debug', 'trace']; this.logs = []; this.logLevel = options.logLevel || 'info'; diff --git a/lib/dashboard/command_history.js b/lib/dashboard/command_history.js index 43e1d2d9d..ba990ba8a 100644 --- a/lib/dashboard/command_history.js +++ b/lib/dashboard/command_history.js @@ -1,5 +1,5 @@ -var CommandHistory = function() { +let CommandHistory = function() { this.history = []; this.pointer = -1; }; diff --git a/lib/dashboard/dashboard.js b/lib/dashboard/dashboard.js index 367b77b85..c3222c247 100644 --- a/lib/dashboard/dashboard.js +++ b/lib/dashboard/dashboard.js @@ -1,9 +1,9 @@ -var async = require('async'); +let async = require('async'); -var Monitor = require('./monitor.js'); -var Console = require('./console.js'); +let Monitor = require('./monitor.js'); +let Console = require('./console.js'); -var Dashboard = function(options) { +let Dashboard = function(options) { this.logger = options.logger; this.plugins = options.plugins; this.version = options.version; @@ -11,8 +11,8 @@ var Dashboard = function(options) { }; Dashboard.prototype.start = function(done) { - var console, monitor; - var self = this; + let console, monitor; + let self = this; async.waterfall([ function startConsole(callback) { diff --git a/lib/dashboard/monitor.js b/lib/dashboard/monitor.js index b1a243c48..d70f6ce13 100644 --- a/lib/dashboard/monitor.js +++ b/lib/dashboard/monitor.js @@ -1,11 +1,11 @@ /*jshint esversion: 6 */ -var blessed = require("blessed"); -var CommandHistory = require('./command_history.js'); -var version = require('../../package.json').version; +let blessed = require("blessed"); +let CommandHistory = require('./command_history.js'); +let version = require('../../package.json').version; function Dashboard(options) { - var title = (options && options.title) || "Embark " + version; + let title = (options && options.title) || "Embark " + version; this.env = options.env; this.console = options.console; this.history = new CommandHistory(); @@ -41,8 +41,8 @@ function Dashboard(options) { } Dashboard.prototype.availableServices = function(_services) { - var services = []; - var checkName; + let services = []; + let checkName; for (checkName in _services) { services.push(_services[checkName]); } @@ -57,7 +57,7 @@ Dashboard.prototype.setStatus = function(status) { }; Dashboard.prototype.setContracts = function(contracts) { - var data = []; + let data = []; data.push(["Contract Name", "Address", "Status"]); @@ -314,7 +314,7 @@ Dashboard.prototype.layoutCmd = function() { } }); - var self = this; + let self = this; this.input.key(["C-c"], function() { process.exit(0); @@ -326,13 +326,13 @@ Dashboard.prototype.layoutCmd = function() { }); this.input.key(["up"], function() { - var cmd = self.history.getPreviousCommand(); + let cmd = self.history.getPreviousCommand(); self.input.setValue(cmd); self.input.focus(); }); this.input.key(["down"], function() { - var cmd = self.history.getNextCommand(); + let cmd = self.history.getNextCommand(); self.input.setValue(cmd); self.input.focus(); }); diff --git a/lib/pipeline/pipeline.js b/lib/pipeline/pipeline.js index 08016070a..190f22224 100644 --- a/lib/pipeline/pipeline.js +++ b/lib/pipeline/pipeline.js @@ -1,7 +1,7 @@ /*jshint esversion: 6, loopfunc: true */ -var fs = require('../core/fs.js'); +let fs = require('../core/fs.js'); -var Pipeline = function(options) { +let Pipeline = function(options) { this.buildDir = options.buildDir; this.contractsFiles = options.contractsFiles; this.assetFiles = options.assetFiles; @@ -10,13 +10,13 @@ var Pipeline = function(options) { }; Pipeline.prototype.build = function(abi, path) { - var self = this; - for(var targetFile in this.assetFiles) { + let self = this; + for(let targetFile in this.assetFiles) { - var contentFiles = this.assetFiles[targetFile].map(file => { + let contentFiles = this.assetFiles[targetFile].map(file => { self.logger.trace("reading " + file.filename); - var pipelinePlugins = this.plugins.getPluginsFor('pipeline'); + let pipelinePlugins = this.plugins.getPluginsFor('pipeline'); if (file.filename === 'embark.js') { return {content: file.content + "\n" + abi, filename: file.filename, path: file.path, modified: true}; @@ -46,27 +46,27 @@ Pipeline.prototype.build = function(abi, path) { } }); - var dir = targetFile.split('/').slice(0, -1).join('/'); + let dir = targetFile.split('/').slice(0, -1).join('/'); self.logger.trace("creating dir " + this.buildDir + dir); fs.mkdirpSync(this.buildDir + dir); // if it's a directory if (targetFile.slice(-1) === '/' || targetFile.indexOf('.') === -1) { - var targetDir = targetFile; + let targetDir = targetFile; if (targetDir.slice(-1) !== '/') { targetDir = targetDir + '/'; } contentFiles.map(function(file) { - var filename = file.filename.replace('app/', ''); + let filename = file.filename.replace('app/', ''); filename = filename.replace(targetDir, ''); self.logger.info("writing file " + (self.buildDir + targetDir + filename).bold.dim); fs.copySync(self.buildDir + targetDir + filename, file.path, {overwrite: true}); }); } else { - var content = contentFiles.map(function(file) { + let content = contentFiles.map(function(file) { return file.content; }).join("\n"); diff --git a/lib/pipeline/server.js b/lib/pipeline/server.js index afbdad2a8..c3b781886 100644 --- a/lib/pipeline/server.js +++ b/lib/pipeline/server.js @@ -1,8 +1,8 @@ -var finalhandler = require('finalhandler'); -var http = require('http'); -var serveStatic = require('serve-static'); +let finalhandler = require('finalhandler'); +let http = require('http'); +let serveStatic = require('serve-static'); -var Server = function(options) { +let Server = function(options) { this.dist = options.dist || 'dist/'; this.port = options.port || 8000; this.hostname = options.host || 'localhost'; @@ -10,9 +10,9 @@ var Server = function(options) { }; Server.prototype.start = function(callback) { - var serve = serveStatic(this.dist, {'index': ['index.html', 'index.htm']}); + let serve = serveStatic(this.dist, {'index': ['index.html', 'index.htm']}); - var server = http.createServer(function onRequest (req, res) { + let server = http.createServer(function onRequest (req, res) { serve(req, res, finalhandler(req, res)); }); diff --git a/lib/pipeline/watch.js b/lib/pipeline/watch.js index d1b1c8b79..07a59401a 100644 --- a/lib/pipeline/watch.js +++ b/lib/pipeline/watch.js @@ -1,20 +1,20 @@ /*jshint esversion: 6 */ -var chokidar = require('chokidar'); +let chokidar = require('chokidar'); -var fs = require('../core/fs.js'); +let fs = require('../core/fs.js'); // TODO: this should be receiving the config object not re-reading the // embark.json file -var Watch = function(options) { +let Watch = function(options) { this.logger = options.logger; this.events = options.events; }; Watch.prototype.start = function() { - var self = this; + let self = this; // TODO: should come from the config object instead of reading the file // directly - var embarkConfig = fs.readJSONSync("embark.json"); + let embarkConfig = fs.readJSONSync("embark.json"); this.watchAssets(embarkConfig, function() { self.logger.trace('ready to watch asset changes'); @@ -32,11 +32,11 @@ Watch.prototype.start = function() { }; Watch.prototype.watchAssets = function(embarkConfig, callback) { - var self = this; - var appConfig = embarkConfig.app; - var filesToWatch = []; + let self = this; + let appConfig = embarkConfig.app; + let filesToWatch = []; - for(var targetFile in appConfig) { + for(let targetFile in appConfig) { filesToWatch.push(appConfig[targetFile]); } @@ -54,7 +54,7 @@ Watch.prototype.watchAssets = function(embarkConfig, callback) { }; Watch.prototype.watchContracts = function(embarkConfig, callback) { - var self = this; + let self = this; this.watchFiles( [embarkConfig.contracts], function(eventName, path) { @@ -69,7 +69,7 @@ Watch.prototype.watchContracts = function(embarkConfig, callback) { }; Watch.prototype.watchConfigs = function(callback) { - var self = this; + let self = this; this.watchFiles( "config/**/contracts.json", function(eventName, path) { @@ -87,7 +87,7 @@ Watch.prototype.watchFiles = function(files, changeCallback, doneCallback) { this.logger.trace('watchFiles'); this.logger.trace(files); - var configWatcher = chokidar.watch(files, { + let configWatcher = chokidar.watch(files, { ignored: /[\/\\]\./, persistent: true, ignoreInitial: true, followSymlinks: true }); diff --git a/lib/upload/ipfs.js b/lib/upload/ipfs.js index 09da3cf46..b21fb7f3c 100644 --- a/lib/upload/ipfs.js +++ b/lib/upload/ipfs.js @@ -1,8 +1,8 @@ -var colors = require('colors'); -var async = require('async'); -var shelljs = require('shelljs'); +let colors = require('colors'); +let async = require('async'); +let shelljs = require('shelljs'); -var IPFS = function(options) { +let IPFS = function(options) { this.options = options; this.buildDir = options.buildDir || 'dist/'; this.plugins = options.plugins; @@ -11,10 +11,10 @@ var IPFS = function(options) { }; IPFS.prototype.deploy = function() { - var self = this; + let self = this; async.waterfall([ function findBinary(callback) { - var ipfs_bin = shelljs.exec('which ' + self.configIpfsBin).output.split("\n")[0]; + let ipfs_bin = shelljs.exec('which ' + self.configIpfsBin).output.split("\n")[0]; if (ipfs_bin === 'ipfs not found' || ipfs_bin === ''){ console.log(('=== WARNING: ' + self.configIpfsBin + ' not found or not in the path. Guessing ~/go/bin/ipfs for path').yellow); @@ -24,17 +24,17 @@ IPFS.prototype.deploy = function() { return callback(null, ipfs_bin); }, function runCommand(ipfs_bin, callback) { - var cmd = ipfs_bin + " add -r " + self.buildDir; + let cmd = ipfs_bin + " add -r " + self.buildDir; console.log(("=== adding " + self.buildDir + " to ipfs").green); console.log(cmd.green); - var result = shelljs.exec(cmd); + let result = shelljs.exec(cmd); return callback(null, result); }, function getHashFromOutput(result, callback) { - var rows = result.output.split("\n"); - var dir_row = rows[rows.length - 2]; - var dir_hash = dir_row.split(" ")[1]; + let rows = result.output.split("\n"); + let dir_row = rows[rows.length - 2]; + let dir_hash = dir_row.split(" ")[1]; return callback(null, dir_hash); }, diff --git a/lib/upload/swarm.js b/lib/upload/swarm.js index 667e0e6c9..894c09da3 100644 --- a/lib/upload/swarm.js +++ b/lib/upload/swarm.js @@ -1,17 +1,17 @@ -var colors = require('colors'); -var async = require('async'); -var shelljs = require('shelljs'); +let colors = require('colors'); +let async = require('async'); +let shelljs = require('shelljs'); -var Swarm = function(options) { +let Swarm = function(options) { this.options = options; this.buildDir = options.buildDir || 'dist/'; }; Swarm.prototype.deploy = function() { - var self = this; + let self = this; async.waterfall([ function findBinary(callback) { - var swarm_bin = shelljs.exec('which swarm').output.split("\n")[0]; + let swarm_bin = shelljs.exec('which swarm').output.split("\n")[0]; if (swarm_bin==='swarm not found' || swarm_bin === ''){ console.log('=== WARNING: Swarm not in an executable path. Guessing ~/go/bin/swarm for path'.yellow); @@ -21,10 +21,10 @@ Swarm.prototype.deploy = function() { return callback(null, swarm_bin); }, function runCommand(swarm_bin, callback) { - var cmd = swarm_bin + " --defaultpath " + self.buildDir + "index.html --recursive up " + self.buildDir; + let cmd = swarm_bin + " --defaultpath " + self.buildDir + "index.html --recursive up " + self.buildDir; console.log(("=== adding " + self.buildDir + " to swarm").green); console.log(cmd.green); - var result = shelljs.exec(cmd); + let result = shelljs.exec(cmd); return callback(null, result); }, @@ -33,8 +33,8 @@ Swarm.prototype.deploy = function() { return callback("couldn't upload, is the swarm daemon running?"); } - var rows = result.output.split("\n"); - var dir_hash = rows.reverse()[1]; + let rows = result.output.split("\n"); + let dir_hash = rows.reverse()[1]; return callback(null, dir_hash); }, diff --git a/lib/utils/async_extend.js b/lib/utils/async_extend.js index 1c6db4f5c..5c024c60a 100644 --- a/lib/utils/async_extend.js +++ b/lib/utils/async_extend.js @@ -1,4 +1,4 @@ -var async = require('async'); +let async = require('async'); function asyncEachObject(object, iterator, callback) { async.each( diff --git a/lib/utils/debug_util.js b/lib/utils/debug_util.js index 9fa0233ff..3bebe506f 100644 --- a/lib/utils/debug_util.js +++ b/lib/utils/debug_util.js @@ -6,8 +6,8 @@ function extend(filename, async) { } async._waterfall = async.waterfall; async.waterfall = function(_tasks, callback) { - var tasks = _tasks.map(function(t) { - var fn = function() { + let tasks = _tasks.map(function(t) { + let fn = function() { console.log("async " + filename + ": " + t.name); t.apply(t, arguments); };