import { object, SchemaOf, string } from 'yup';
interface BaseBootstrapSchema {
APPLICATION_NAME: string;
LOG_PATH: string;
}
const bootstrapValidationSchema: SchemaOf<BaseBootstrapSchema> = object({
LOG_PATH: string().required("The 'LOG_PATH' ENV variable is required"),
APPLICATION_NAME: string().required("The 'APPLICATION_NAME' ENV variable is required"),
});
module.exports = (schema: SchemaOf<BaseBootstrapSchema>) =>
new Promise((resolve, reject) =>
schema
.validate(process.env, { abortEarly: false })
.then(() => resolve(true))
.catch((error: any) => {
if (error.errors.length > 1) {
reject(new Error(`${error.message},\n${error.errors.join(',\n')}`));
} else {
reject(new Error(error.message));
}
})
);