When you are updating a field inside a content type in Contentful you will need to re-generate the
contentfulTypes.d.tsfile and commit it with your changes with the following command:
yarn nx run api:contentful-types
We keep this file in the repository because in case contentful is down, the whole pipeline would fail and we won’t be able to build island.is. By keeping it in the repo, we ensure we can still build and we don't have to rely on an external service.
CONTENTFUL_ENVIRONMENTenvironment variable is used to determine which Contentful environment is used to generate types.
When creating a new content type in contentful, you can run a script that will generate models based on the content type's JSON from contentful.
yarn nx run api:contentType --id contentTypeId
The script take 3 arguments:
--idrequired, stringThe "contentTypeId" that you want to create types/models of
--sysoptional, stringvalues: id, createdAt, updatedAtA string of fields that you want to be added to the root model (separated by a comma)
--overwriteoptional, booleandefault: falseIf you want to overwrite the existing models while generating content type types/models
You will need a
CONTENTFUL_MANAGEMENT_ACCESS_TOKENto run the script locally. Don't run the api at the same time, wait until the script is done to restart the api
yarn start api.