feat: generate TypeScript types after sync and init#48
Conversation
Run prismic-ts-codegen after syncing models to automatically generate prismicio-types.d.ts, keeping type definitions in sync with remote content models. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| customTypes: customTypes.map((customType) => customType.model), | ||
| slices: slices.map((slice) => slice.model), | ||
| projectRoot, | ||
| }); |
There was a problem hiding this comment.
Duplicated type regeneration logic across two files
Low Severity
The inline code in init.ts that calls framework.getSlices(), framework.getCustomTypes(), framework.getProjectRoot(), and then generateAndWriteTypes() is an exact duplicate of the regenerateTypes function in sync.ts. If the codegen behavior ever needs to change (e.g., different options, added error handling), both locations need updating, and forgetting one would introduce a bug. The regenerateTypes helper could live in codegen.ts and be shared.
Additional Locations (1)
| changed.push("custom types"); | ||
| } | ||
|
|
||
| await regenerateTypes(framework); |
There was a problem hiding this comment.
Hash updates before codegen prevents retry on failure
Medium Severity
In the watch loop, lastRemoteSlicesHash and lastRemoteCustomTypesHash are updated (lines 140, 145) before regenerateTypes runs (line 149). If regenerateTypes throws, the error is caught by the outer catch, but the hashes are already committed. On the next poll, remote hashes match the stored hashes, so no changes are detected — the codegen is never retried for those changes. The prismicio-types.d.ts file remains stale until an entirely new remote change occurs.


Resolves:
Description
Automatically generates
prismicio-types.d.tsusingprismic-ts-codegenafter syncing models from Prismic. This runs after bothsync(including watch mode) andinit, so type definitions stay in sync with remote content models without a separate manual step.Checklist
Preview
How to QA 1
Note
Medium Risk
Automatically writing
prismicio-types.d.tsafter model sync adds a new side effect that can overwrite local type definitions and may impact projects with custom type generation workflows.Overview
After
prismic initandprismic sync, the CLI now auto-generatesprismicio-types.d.tsfrom the freshly synced remote Custom Type and Slice models usingprismic-ts-codegen.In
sync --watch, type generation is also re-run whenever remote model changes are detected, via a new sharedgenerateAndWriteTypeshelper.Written by Cursor Bugbot for commit 8982265. This will update automatically on new commits. Configure here.
Footnotes
Please use these labels when submitting a review:
⚠️ #issue: Strongly suggest a change.
❓ #ask: Ask a question.
💡 #idea: Suggest an idea.
🎉 #nice: Share a compliment. ↩