From f1edc28f6dfeda56795673f4087fd7a90280c376 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Fri, 17 Aug 2018 17:55:39 -0500 Subject: [PATCH] anchoredPath helper (more DRY) --- lib/core/fs.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/core/fs.js b/lib/core/fs.js index cb52d5914..5e340e966 100644 --- a/lib/core/fs.js +++ b/lib/core/fs.js @@ -77,24 +77,21 @@ function removeSync() { return fs.removeSync.apply(fs.removeSync, arguments); } -function embarkPath() { - const _embarkPath = process.env.EMBARK_PATH; - if (!_embarkPath) { - const errMsg = 'process.env.EMBARK_PATH was not set'.bold.red; - console.error(errMsg); +function anchoredPath(envAnchor, ...args) { + const anchor = process.env[envAnchor]; + if (!anchor) { + console.error(`process.env.${envAnchor} was not set`.bold.red); process.exit(1); } - return utils.joinPath(_embarkPath, ...arguments); + return utils.joinPath(anchor, ...args); +} + +function embarkPath() { + return anchoredPath('EMBARK_PATH', ...arguments); } function dappPath() { - const _dappPath = process.env.DAPP_PATH; - if (!_dappPath) { - const errMsg = 'process.env.DAPP_PATH was not set'.bold.red; - console.error(errMsg); - process.exit(1); - } - return utils.joinPath(_dappPath, ...arguments); + return anchoredPath('DAPP_PATH', ...arguments); } function createWriteStream() {