import fs from 'fs' ; import Ajv from 'ajv/dist/2019' ; export const readConfigurationFile = async ( configurationPath ) => { const fileContent = await fs . promises . readFile ( configurationPath ) ; return JSON . parse ( fileContent . toString ( 'utf-8' ) ) ; } ; export const validateConfigurationContent = ( configurationContent , configurationSchema ) => { const configValidator = new Ajv ( ) . compile ( configurationSchema ) ; const isConfigValid = configValidator ( configurationContent ) ; if ( ! isConfigValid ) { throw new Error ( `Invalid configuration: ${ JSON . stringify ( configValidator . errors ) }` ) ; } } ; export const readValidateConfiguration = async ( configurationPath , configurationSchema ) => { const configurationContent = await readConfigurationFile ( configurationPath ) ; validateConfigurationContent ( configurationContent , configurationSchema ) ; return configurationContent ; } ;