Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function getOptions(pkg: { [key: string]: any }): JMOptions {
if (options) {
return options
}
const schemaPath = path.join(__dirname, '../lib/option.schema.json')
const schema = fs.readJsonSync(schemaPath)
if (key in pkg) {
const ajv = new Ajv({ jsonPointers: true })
const validate = ajv.compile(schema)
if (validate(pkg[key])) {
return (options = { ...defaultOptions, ...pkg[key] })
}
const errors = prepareErrors(validate.errors)
const output = betterAjvErrors(schema, pkg[key], errors, { indent: 2 })
console.log(
chalk.red(`❌ Configuration error. Check property ${chalk.cyan(key)} of the ${chalk.cyan('package.json')}`),
)
console.log(output)
process.exit(1)
}
return (options = defaultOptions)
}