validateConfig.js.flow 900 B

12345678910111213141516171819202122232425262728293031323334
  1. // eslint-disable-next-line import/default
  2. import validateConfig from '../dist/validateConfig';
  3. // eslint-disable-next-line import/default
  4. import validateStreamConfig from '../dist/validateStreamConfig';
  5. const validate = {
  6. 'config.json': validateConfig,
  7. 'streamConfig.json': validateStreamConfig
  8. };
  9. /**
  10. * @param {string} schemaId
  11. * @param {formatData~config} config
  12. * @returns {undefined}
  13. */
  14. export default (schemaId, config = {}) => {
  15. if (!validate[schemaId](config)) {
  16. const errors = validate[schemaId].errors.map((error) => {
  17. return {
  18. dataPath: error.dataPath,
  19. message: error.message,
  20. params: error.params,
  21. schemaPath: error.schemaPath
  22. };
  23. });
  24. /* eslint-disable no-console */
  25. console.log('config', config);
  26. console.log('errors', errors);
  27. /* eslint-enable no-console */
  28. throw new Error('Invalid config.');
  29. }
  30. };