UNPKG

bundlewatch

Version:
71 lines (58 loc) 2.68 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _ValidationError = require('../errors/ValidationError'); var _ValidationError2 = _interopRequireDefault(_ValidationError); var _logger = require('../../logger'); var _logger2 = _interopRequireDefault(_logger); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const COMPRESSION_TYPES = ['gzip', 'brotli', 'none']; const ensureValid = config => { if (!Array.isArray(config.files)) { throw new _ValidationError2.default('config.files must be an Array'); } // TODO: more validation per file, path, maxSize, compression etc // const FILE_TYPE = { // path: '', // required // maxSize, // basically required (defaults to Infinity) // compression, // optional // } if (!COMPRESSION_TYPES.includes(config.defaultCompression)) { throw new _ValidationError2.default('config.compression must be a valid type'); } if (!Array.isArray(config.ci.trackBranches)) { throw new _ValidationError2.default('config.ci.trackBranches must be an Array'); } const requiredOptionsToConnectToBuild = ['githubAccessToken', 'repoOwner', 'repoName', 'commitSha']; const missingOptions = requiredOptionsToConnectToBuild.reduce((optionAccumulator, option) => { if (!config.ci[option]) { optionAccumulator.push(option); } return optionAccumulator; }, []); if (missingOptions.length === 0) { if (!config.bundlewatchServiceHost) { _logger2.default.warn(`bundlewatchServiceHost was not supplied, bundlewatch comparisons unavilable: Learn more at: http://bundlewatch.io/#/getting-started/the-best-parts `); } else { if (!config.ci.repoBranchBase) { _logger2.default.warn(`The ci.repoBranchCase was not supplied, bundlewatch comparisons unavailable: Learn more at: http://bundlewatch.io/#/getting-started/the-best-parts `); } if (!config.ci.repoCurrentBranch) { _logger2.default.warn(`The ci.repoCurrentBranch was not supplied, bundlewatch results with not be saved: Learn more at: http://bundlewatch.io/#/getting-started/the-best-parts `); } } } else { _logger2.default.warn(`Some CI configuration options were not found (${missingOptions.join(', ')}): bundlewatch will be unable to report build status, or save comparison data Learn more at: http://bundlewatch.io/#/getting-started/the-best-parts `); } }; exports.default = ensureValid;