diff --git a/lib/preloader/actions.js b/lib/preloader/actions.js index 6ba9ab880..4ceb773a9 100644 --- a/lib/preloader/actions.js +++ b/lib/preloader/actions.js @@ -12,12 +12,15 @@ import getSites from './sites'; import parseUrl from './parse-url'; import { hasAnyBehaviors, convertSchema } from '../core-data/behaviors2input'; import { getItem } from '../utils/local'; +import logger from '../utils/log'; + /** * @module preloader */ -const hbs = clayHBS(); +const hbs = clayHBS(), + log = logger(__filename); /** * get component models so we can mount them on window.kiln.componentModels @@ -135,10 +138,16 @@ function getSchemas(schemas, kilnjs) { schema = convertSchema(schema, name); } - const kilnFile = kilnjs[name]; + const kilnJsFile = kilnjs[name]; + + if (kilnJsFile) { + const kilnFileSchema = kilnJsFile({ ..._.cloneDeep(schema), schemaName: name }); - if (kilnFile) { - schema = kilnFile({ ..._.cloneDeep(schema), schemaName: name }); + if (kilnFileSchema) { + schema = kilnFileSchema; + } else { + log.warn(`The kiln.js file of (${name}) component is returning undefined`, { action: 'loading kiln.js file', schema: name }); + } } return schema; diff --git a/lib/validators/actions.js b/lib/validators/actions.js index fef8a1dba..31a515af4 100644 --- a/lib/validators/actions.js +++ b/lib/validators/actions.js @@ -180,7 +180,7 @@ export function runKilnjsValidators(schemas = {}, components = {}) { export function getSchemasWithValidationRules(schemas = {}) { const validationSchemas = {}; - Object.keys(schemas).forEach(schemaName => schemas[schemaName].validation ? validationSchemas[schemaName] = _.cloneDeep(schemas[schemaName]) : null); + Object.keys(schemas).forEach(schemaName => _.has(schemas, `${schemaName}.validation`) ? validationSchemas[schemaName] = _.cloneDeep(schemas[schemaName]) : null); return validationSchemas; }