prismicio / prismic-ts-codegen

A Prismic model-to-TypeScript-type generator.
Apache License 2.0
18 stars 6 forks source link

Unnecessary changes made to output when a model is updated #8

Closed seanlail closed 2 years ago

seanlail commented 2 years ago

Versions

Reproduction

The only way to reproduce this is to have 2 documents in Prismic dashboard and then make a change.

Steps to reproduce

  1. Create 2 different documents in Prismic content modeller.
  2. Generate types with prismic-ts-codegen
  3. Make a change to the oldest (or newest depending on the order) document content model.
  4. Generate types with prismic-ts-codegen

What is expected?

Generate type should only slightly change (based on change in step 3)

What is actually happening?

Order of the documents has changed and so the rendered output has a much larger diff than needed.

As with others, I'm happy to take a look at this.

seanlail commented 2 years ago

I think the issue is here https://github.com/prismicio/prismic-ts-codegen/blob/0953400db747a111fa68385a518ae190da1d929f/src/cli/loadModels.ts#L85-L86

Those arrays need to be sorted by id perhaps?

angeloashmore commented 2 years ago

You're 100% right; the models need to be sorted before generating types.

I opened a PR with the fix and left details in the description here: #9


The fix has been published in v0.0.3. 🎉

To upgrade, install the latest version and re-generate your types:

npm install prismic-ts-codegen@latest
npx prismic-ts-codegen