diff --git a/lib/blockchain.js b/lib/blockchain.js index d2209c48..fd07fd5d 100644 --- a/lib/blockchain.js +++ b/lib/blockchain.js @@ -2,7 +2,7 @@ var mkdirp = require('mkdirp'); var wrench = require('wrench'); var colors = require('colors'); var GethCommands = require('./geth_commands.js'); -var path = require('path'); +var utils = require('./utils.js'); var Blockchain = function(blockchainConfig, Client) { this.blockchainConfig = blockchainConfig; @@ -55,7 +55,7 @@ Blockchain.prototype.initChainAndGetAddress = function() { mkdirp.sync(this.datadir); // copy mining script - wrench.copyDirSyncRecursive(path.join(__dirname, "/../js"), ".embark/development/js", {forceDelete: true}); + wrench.copyDirSyncRecursive(utils.joinPath(__dirname, "/../js"), ".embark/development/js", {forceDelete: true}); // check if an account already exists, create one if not, return address result = this.runCommand(this.client.listAccountsCommand()); diff --git a/lib/config.js b/lib/config.js index b017291d..bc3236a2 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,8 +1,8 @@ var fs = require('fs'); var grunt = require('grunt'); var merge = require('merge'); -var path = require('path'); var Plugins = require('./plugins.js'); +var utils = require('./utils.js'); // TODO: add wrapper for fs so it can also work in the browser // can work with both read and save @@ -157,12 +157,12 @@ Config.prototype.loadFiles = function(files) { return file.indexOf('.') >= 0; }).filter(function(file) { if (file === 'embark.js') { - readFiles.push({filename: 'web3.js', content: fs.readFileSync(path.join(__dirname, "/../js/web3.js")).toString(), path: path.join(__dirname, "/../js/web3.js")}); - readFiles.push({filename: 'ipfs.js', content: fs.readFileSync(path.join(__dirname, "/../js/ipfs.js")).toString(), path: path.join(__dirname, "/../js/ipfs.js")}); + readFiles.push({filename: 'web3.js', content: fs.readFileSync(utils.joinPath(__dirname, "/../js/web3.js")).toString(), path: utils.joinPath(__dirname, "/../js/web3.js")}); + readFiles.push({filename: 'ipfs.js', content: fs.readFileSync(utils.joinPath(__dirname, "/../js/ipfs.js")).toString(), path: utils.joinPath(__dirname, "/../js/ipfs.js")}); // TODO: remove duplicated files if funcitonality is the same for storage and orbit - readFiles.push({filename: 'ipfs-api.js', content: fs.readFileSync(path.join(__dirname, "/../js/ipfs-api.min.js")).toString(), path: path.join(__dirname, "/../js/ipfs-api.min.js")}); - readFiles.push({filename: 'orbit.js', content: fs.readFileSync(path.join(__dirname, "/../js/orbit.min.js")).toString(), path: path.join(__dirname, "/../js/orbit.min.js")}); - readFiles.push({filename: 'embark.js', content: fs.readFileSync(path.join(__dirname, "/../js/build/embark.bundle.js")).toString(), path: path.join(__dirname, "/../js/build/embark.bundle.js")}); + readFiles.push({filename: 'ipfs-api.js', content: fs.readFileSync(utils.joinPath(__dirname, "/../js/ipfs-api.min.js")).toString(), path: utils.joinPath(__dirname, "/../js/ipfs-api.min.js")}); + readFiles.push({filename: 'orbit.js', content: fs.readFileSync(utils.joinPath(__dirname, "/../js/orbit.min.js")).toString(), path: utils.joinPath(__dirname, "/../js/orbit.min.js")}); + readFiles.push({filename: 'embark.js', content: fs.readFileSync(utils.joinPath(__dirname, "/../js/build/embark.bundle.js")).toString(), path: utils.joinPath(__dirname, "/../js/build/embark.bundle.js")}); } }); diff --git a/lib/plugin.js b/lib/plugin.js index c0e1147f..a0e7bab6 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -1,7 +1,7 @@ /*jshint esversion: 6, loopfunc: true */ var grunt = require('grunt'); var fs = require('fs'); -var path = require('path'); +var utils = require('./utils.js'); // TODO: pass other params like blockchainConfig, contract files, etc.. var Plugin = function(options) { @@ -34,7 +34,7 @@ Plugin.prototype.loadPluginFile = function(filename) { }; Plugin.prototype.pathToFile = function(filename) { - return path.join(this.pluginPath, filename); + return utils.joinPath(this.pluginPath, filename); }; Plugin.prototype.interceptLogs = function(context) { diff --git a/lib/plugins.js b/lib/plugins.js index 352b773f..3627881b 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -1,5 +1,4 @@ var Plugin = require('./plugin.js'); -var path = require('path'); var Plugins = function(options) { this.pluginList = options.plugins || []; @@ -26,7 +25,7 @@ Plugins.prototype.listPlugins = function() { }; Plugins.prototype.loadPlugin = function(pluginName, pluginConfig) { - var pluginPath = path.join(process.env.PWD, 'node_modules', pluginName); + var pluginPath = utils.joinPath(process.env.PWD, 'node_modules', pluginName); var plugin = require(pluginPath); var pluginWrapper = new Plugin({name: pluginName, pluginModule: plugin, pluginConfig: pluginConfig, logger: this.logger, pluginPath: pluginPath, interceptLogs: this.interceptLogs}); diff --git a/lib/template_generator.js b/lib/template_generator.js index 038b3afd..3c35ddeb 100644 --- a/lib/template_generator.js +++ b/lib/template_generator.js @@ -1,7 +1,7 @@ // TODO: replace with something else more native to node require('shelljs/global'); -var path = require('path'); var wrench = require('wrench'); +var utils = require('./utils.js'); var run = function(cmd) { var result = exec(cmd, {silent: true}); @@ -20,7 +20,7 @@ var TemplateGenerator = function(templateName) { }; TemplateGenerator.prototype.generate = function(destinationFolder, name) { - var templatePath = path.join(__dirname, '/../', this.templateName); + var templatePath = utils.joinPath(__dirname, '/../', this.templateName); console.log('Initializing Embark Template....'.green); wrench.copyDirSyncRecursive(templatePath, destinationFolder + name); diff --git a/lib/utils.js b/lib/utils.js new file mode 100644 index 00000000..2228fb39 --- /dev/null +++ b/lib/utils.js @@ -0,0 +1,10 @@ +var path = require('path'); + +function joinPath() { + return path.join.apply(path.join, arguments); +} + +module.exports = { + joinPath: joinPath +}; +