From 8be1090a445c070399d82228055a9913fa6eea97 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Fri, 17 Aug 2018 12:41:07 -0500 Subject: [PATCH] prefer joinPath to +'ing strings together --- lib/core/config.js | 2 +- lib/pipeline/pipeline.js | 21 +++++++++------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/core/config.js b/lib/core/config.js index 13372037d..a43d4c5dc 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -169,7 +169,7 @@ Config.prototype._getFileOrOject = function(object, filePath, property) { if (typeof (this.configDir) === 'object') { return this.configDir[property]; } - return this.configDir + filePath; + return utils.joinPath(this.configDir, filePath); }; Config.prototype.loadBlockchainConfigFile = function() { diff --git a/lib/pipeline/pipeline.js b/lib/pipeline/pipeline.js index d830de593..2f95ba544 100644 --- a/lib/pipeline/pipeline.js +++ b/lib/pipeline/pipeline.js @@ -31,10 +31,7 @@ class Pipeline { function createPlaceholderPage(next){ self.events.request('embark-building-placeholder', (html) => { fs.mkdirpSync(self.buildDir); // create dist/ folder if not already exists - fs.writeFile(self.buildDir + 'index.html', html, next); - // ^ ?? should this use path.join instead? templates' embark.json - // files have a '/' hardcoded on the end of buildDir but that doesn't - // seem too resilient + fs.writeFile(utils.joinPath(self.buildDir, 'index.html'), html, next); }); }, function buildTheContracts(next) { @@ -117,7 +114,7 @@ class Pipeline { const isDir = targetFile.slice(-1) === '/' || targetFile.indexOf('.') === -1; // if it's not a directory if (!isDir) { - self.logger.info(__("writing file") + " " + (self.buildDir + targetFile).bold.dim); + self.logger.info(__("writing file") + " " + (utils.joinPath(self.buildDir, targetFile)).bold.dim); } async.map( files, @@ -160,8 +157,8 @@ class Pipeline { self.logger.error(__('errors found while generating') + ' ' + targetFile); } let dir = targetFile.split('/').slice(0, -1).join('/'); - self.logger.trace("creating dir " + self.buildDir + dir); - fs.mkdirpSync(self.buildDir + dir); + self.logger.trace("creating dir " + utils.joinPath(self.buildDir, dir)); + fs.mkdirpSync(utils.joinPath(self.buildDir, dir)); // if it's a directory if (isDir) { @@ -173,9 +170,9 @@ class Pipeline { async.each(contentFiles, function (file, mapCb) { let filename = file.filename.replace(file.basedir + '/', ''); - self.logger.info("writing file " + (self.buildDir + targetDir + filename).bold.dim); + self.logger.info("writing file " + (utils.joinPath(self.buildDir, targetDir, filename)).bold.dim); - fs.copy(file.path, self.buildDir + targetDir + filename, {overwrite: true}, mapCb); + fs.copy(file.path, utils.joinPath(self.buildDir, targetDir, filename), {overwrite: true}, mapCb); }, cb); return; } @@ -191,7 +188,7 @@ class Pipeline { targetFile = targetFile.replace('index', 'index-temp'); placeholderPage = targetFile; } - fs.writeFile(self.buildDir + targetFile, content, cb); + fs.writeFile(utils.joinPath(self.buildDir, targetFile), content, cb); } ); }, @@ -199,8 +196,8 @@ class Pipeline { ); }, function removePlaceholderPage(next){ - let placeholderFile = self.buildDir + placeholderPage; - fs.access(self.buildDir + placeholderPage, (err) => { + let placeholderFile = utils.joinPath(self.buildDir, placeholderPage); + fs.access(utils.joinPath(self.buildDir, placeholderPage), (err) => { if (err) return next(); // index-temp doesn't exist, do nothing // rename index-temp.htm/l to index.htm/l, effectively replacing our placeholder page