bigbuffet-rw/app/soapbox/custom.ts

16 lines
495 B
TypeScript
Raw Normal View History

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 */
export const custom = (filename: string, fallback: any = {}): any => {
if (BuildConfig.NODE_ENV === 'test') return fallback;
2022-03-21 11:09:01 -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;
};