move join path into utils module

This commit is contained in:
Iuri Matias 2017-02-18 14:10:01 -05:00
parent 55275136b0
commit 561caa9b0b
6 changed files with 23 additions and 14 deletions

View File

@ -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());

View File

@ -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")});
}
});

View File

@ -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) {

View File

@ -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});

View File

@ -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);

10
lib/utils.js Normal file
View File

@ -0,0 +1,10 @@
var path = require('path');
function joinPath() {
return path.join.apply(path.join, arguments);
}
module.exports = {
joinPath: joinPath
};