From c664ccbe24d81d7ec39b0156da6c0d4b3bcb081d Mon Sep 17 00:00:00 2001 From: Ben Chen Date: Wed, 19 Jan 2022 21:09:29 -0500 Subject: [PATCH] fix: account for case where content type id contains dash --- lib/bootstrap/jsonToScript.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/bootstrap/jsonToScript.js b/lib/bootstrap/jsonToScript.js index 0fdcbac..8d896e8 100644 --- a/lib/bootstrap/jsonToScript.js +++ b/lib/bootstrap/jsonToScript.js @@ -1,5 +1,7 @@ const eslint = require('eslint') +const normalizeContentTypeID = (id) => id.replaceAll('-', '_') + const removeNullValues = (value) => { if (value instanceof Array) { return value.map(removeNullValues) @@ -26,17 +28,17 @@ const rejectEmptyObjects = ([, value]) => { } const createField = (itemId, field) => ` - ${itemId}.createField("${field.id}")${''.concat(...Object.entries(field.props).filter(rejectEmptyObjects).map(createProp))}; + ${normalizeContentTypeID(itemId)}.createField("${field.id}")${''.concat(...Object.entries(field.props).filter(rejectEmptyObjects).map(createProp))}; ` const createChangeFieldControl = (itemId, field) => { const { fieldId, widgetId, settings } = field - const baseString = `${itemId}.changeFieldControl("${fieldId}", "builtin", "${widgetId}"` + const baseString = `${normalizeContentTypeID(itemId)}.changeFieldControl("${fieldId}", "builtin", "${widgetId}"` return settings ? `${baseString}, ${JSON.stringify(settings)});` : `${baseString});` } const createContentType = (item, editorInterface) => ` - const ${item.id} = migration.createContentType('${item.id}')${''.concat(...Object.entries(item.props).map(createProp))}; + const ${normalizeContentTypeID(item.id)} = migration.createContentType('${item.id}')${''.concat(...Object.entries(item.props).map(createProp))}; ${''.concat(...item.fields.map(field => createField(item.id, field)))} ${editorInterface.map(field => createChangeFieldControl(item.id, field)).join('\n')} `