2022-03-03 21:38:59 -08:00
|
|
|
/**
|
|
|
|
* Functions for dealing with custom build configuration.
|
|
|
|
*/
|
2022-11-15 12:48:54 -08:00
|
|
|
import * as BuildConfig from 'soapbox/build-config';
|
2022-03-03 21:38:59 -08:00
|
|
|
|
|
|
|
/** Require a custom JSON file if it exists */
|
2022-04-12 13:23:18 -07:00
|
|
|
export const custom = (filename: string, fallback: any = {}): any => {
|
|
|
|
if (BuildConfig.NODE_ENV === 'test') return fallback;
|
2022-03-21 11:09:01 -07:00
|
|
|
|
2022-04-12 13:23:18 -07:00
|
|
|
// @ts-ignore: yes it does
|
2022-03-03 21:38:59 -08:00
|
|
|
const context = require.context('custom', false, /\.json$/);
|
|
|
|
const path = `./${filename}.json`;
|
|
|
|
|
|
|
|
return context.keys().includes(path) ? context(path) : fallback;
|
|
|
|
};
|