slice-machine icon indicating copy to clipboard operation
slice-machine copied to clipboard

feat: generate TypeScript types on save

Open lihbr opened this issue 3 years ago • 1 comments

Types of changes

  • [ ] Bug fix (a non-breaking change which fixes an issue)
  • [x] New feature (a non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Description

As requested by @Duaner, this PR adds an early integration of TypeScript inside Slice Machine by generating types for Slices and Custom Types on save and rename.

  • A types.ts file is now created alongside Custom Types index.json model;
  • A types.ts file is now created alongside Slices model.json model.

⚠  This code will have to be removed when switching to plugins. Plugins are already handling TypeScript integration the same way as the one implemented in this PR.

Checklist:

  • [ ] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly. (PR: #)
  • [x] All new and existing tests are passing. (existing tests were failing on Windows because of win32/posix paths inconsistencies)

lihbr avatar Jul 25 '22 10:07 lihbr

Should Slice template be modified to include the types ?

Done, for now, it's only possible to streamline it for templates using @prismicio/react.

prismic-dom, prismic-reactjs, and @prismicio/vue@2 cannot have it automated the same way because the component prop types depend on the user setup/the slice zone they use. Users, especially TypeScript ones, will still be able to take advantage of it, but manually, not from the template.

As you're adding a new feature, could you add the corresponding test / modify the existing one to match the expected behavior please 🙏

How would you test this and can it be tested?

prismic-ts-codegen is the library doing the bulk of the work and is already extensively tested. Regarding its integration with Slice Machine, we'd be mainly interested in testing that the types file is indeed created and updated when needed.

In that regard, I haven't seen tests regarding Slices/Custom Types save events (unit & e2e). If I missed them let me know where I can find them, happy to add a few. If this part of the codebase is not covered yet, I don't think it's part of the scope of this PR to start covering it (especially since this PR's additions are temporary).

lihbr avatar Jul 25 '22 11:07 lihbr

Update the branch :)

MarcMcIntosh avatar Aug 30 '22 11:08 MarcMcIntosh

Closed in favor of #583

lihbr avatar Sep 02 '22 11:09 lihbr