/**
 * @license Copyright (c) 2017-2025, CKSource Holding sp. z o.o. All rights reserved.
 * For licensing, see LICENSE.md.
 */

'use strict';

const upath = require( 'upath' );
const fs = require( 'fs' );

module.exports = rootPath => {
	const configPath = upath.join( rootPath, 'umberto-main.json' );
	let config;

	if ( fs.existsSync( configPath ) ) {
		try {
			config = JSON.parse( fs.readFileSync( configPath, 'utf8' ) );
		} catch ( err ) {
			throw new Error( 'Error when reading umberto-main.json:', err );
		}
	} else {
		throw new Error( 'umberto-main.json config file not found.' );
	}

	return config;
};
