From d98ec8e0cc693e70a53d5a1b8d38dc6d168a3a9e Mon Sep 17 00:00:00 2001 From: Lachlan Heywood Date: Sat, 7 Mar 2020 23:28:11 +1000 Subject: [PATCH] feat: add a config validation function (#258) --- packages/shipit-deploy/src/extendShipit.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/shipit-deploy/src/extendShipit.js b/packages/shipit-deploy/src/extendShipit.js index bbec5b9..9c0a55d 100644 --- a/packages/shipit-deploy/src/extendShipit.js +++ b/packages/shipit-deploy/src/extendShipit.js @@ -42,8 +42,22 @@ function computeReleaseDirname(result) { return target.split(path.sep).pop() } +function validateConfig(config) { + const errors = [] + if (!config.deployTo) { + errors.push("Config must include a 'deployTo' property") + } + if (errors.length) { + console.log(errors) + throw new Error( + 'Config is invalid. Please refer to errors above and try again.', + ) + } +} + function extendShipit(shipit) { /* eslint-disable no-param-reassign */ + validateConfig(shipit.config) shipit.currentPath = path.join(shipit.config.deployTo, 'current') shipit.releasesPath = path.join(shipit.config.deployTo, 'releases') const config = {