refactor to use method to determine app root path, instead of constantly using relative paths

This commit is contained in:
Iuri Matias 2017-02-19 19:44:16 -05:00
parent 8b5e3aa3ab
commit 73a536c52e
4 changed files with 15 additions and 9 deletions

View File

@ -2,7 +2,6 @@ var colors = require('colors');
var shelljs = require('shelljs');
var fs = require('../../core/fs.js');
var utils = require('../../core/utils.js');
var GethCommands = require('./geth_commands.js');
@ -57,7 +56,7 @@ Blockchain.prototype.initChainAndGetAddress = function() {
fs.mkdirpSync(this.datadir);
// copy mining script
fs.copySync(utils.joinPath(__dirname, "/../../../js"), ".embark/development/js", {overwrite: true});
fs.copySync(fs.embarkPath("js"), ".embark/development/js", {overwrite: true});
// check if an account already exists, create one if not, return address
result = this.runCommand(this.client.listAccountsCommand());

View File

@ -6,7 +6,7 @@ var TemplateGenerator = function(templateName) {
};
TemplateGenerator.prototype.generate = function(destinationFolder, name) {
var templatePath = utils.joinPath(__dirname, '/../../', this.templateName);
var templatePath = js.embarkPath(this.templateName);
console.log('Initializing Embark Template....'.green);
fs.copySync(templatePath, destinationFolder + name);

View File

@ -155,12 +155,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(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")});
readFiles.push({filename: 'web3.js', content: fs.readFileSync(fs.embarkPath("js/web3.js")).toString(), path: fs.embarkPath("js/web3.js")});
readFiles.push({filename: 'ipfs.js', content: fs.readFileSync(fs.embarkPath("js/ipfs.js")).toString(), path: fs.embarkPath("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(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")});
readFiles.push({filename: 'ipfs-api.js', content: fs.readFileSync(fs.embarkPath("js/ipfs-api.min.js")).toString(), path: fs.embarkPath("js/ipfs-api.min.js")});
readFiles.push({filename: 'orbit.js', content: fs.readFileSync(fs.embarkPath("js/orbit.min.js")).toString(), path: fs.embarkPath("js/orbit.min.js")});
readFiles.push({filename: 'embark.js', content: fs.readFileSync(fs.embarkPath("js/build/embark.bundle.js")).toString(), path: fs.embarkPath("js/build/embark.bundle.js")});
}
});

View File

@ -1,4 +1,5 @@
var fs = require('fs-extra');
var utils = require('./utils.js');
function mkdirpSync() {
return fs.mkdirpSync.apply(fs.mkdirpSync, arguments);
@ -24,12 +25,18 @@ function writeJSONSync() {
return fs.writeJSONSync.apply(fs.writeJSONSync, arguments);
}
// returns embarks root directory
function embarkPath(fileOrDir) {
return utils.joinPath(__dirname, '/../../', fileOrDir);
}
module.exports = {
mkdirpSync: mkdirpSync,
copySync: copySync,
readFileSync: readFileSync,
writeFileSync: writeFileSync,
readJSONSync: readJSONSync,
writeJSONSync: writeJSONSync
writeJSONSync: writeJSONSync,
embarkPath: embarkPath
};