Type generation CLI
Generating database metadata improves DX and runtime validation.
- Create a script in your app:
json
{
"scripts": {
"notion:generate": "source .env && npx @mikemajara/notion-cms generate -t $NOTION_API_KEY -d $NOTION_CMS_DATABASE_ID -o ./lib/notion"
}
}
- Run the generator with required env vars (database IDs, output path). Each project typically maintains a
notion-types-*.tsfile checked into source control. - Import the generated file early in your app (e.g.,
_app.tsx, entry server file) soregisterDatabaseruns before queries. Alternatively, import theNotionCMSfrom your types directory (./lib/notionin the example above), this will ensure the database is registered when you use it.
Last updated: