FarazzShaikh / THREE-CustomShaderMaterial

🧩 Extend Three.js standard materials with your own shaders!
https://farazzshaikh.github.io/THREE-CustomShaderMaterial/
MIT License
890 stars 56 forks source link

Restructure Repository to streamline development & releasing #25

Closed hmans closed 2 years ago

hmans commented 2 years ago

Introduction & Important Notes

This is a big PR that changes a lot of things around in both the repository itself, and also in how the package is built. It implements a setup that I've been successfully using in my projects and been recommending to others, and is meant to be read as primarily a suggestion. There's a lot of stuff going on and I would understand 100% if you decide against adopting this; but do give it a try and see if it would work for you. If you have questions, I'd be happy to answer them.

First and foremost, this PR makes three major changes to the project:

Development

One of the benefits all this provides is that hacking on the code now just requires these three steps:

  1. Clone the repository
  2. yarn install
  3. yarn dev

The last step will fire up the waves example, and you can immediately start making changes to the CSM package's TypeScript code with reloading, HMR, and so on.

Releasing

Given at least one unreleased changeset in the repository, the process is now the following:

  1. Run yarn changeset version -- this will accumulate the unreleased changesets into updated CHANGELOG files and ask you to commit these changes (after review.)
  2. Run yarn release -- this will run the yarn ci task (which does integrity tests and builds the package) followed by changeset publish, which will publish the new version you created in the previous step to NPM.

All of this can be wrapped in a GitHub action that I'd be happy to set up in a separate PR.

Caveats

Other minor changes:

Todo:

FarazzShaikh commented 2 years ago

This looks great to me, i am able to run it by just using yarn dev no linking etc required! Amazing! Couple notes:

hmans commented 2 years ago

I dont really like packages/three-custom-shader-material, since there will only ever be one package in this repo, can it not just be called something like package? Or is it a limitation of the build system

We can probably change it to just ./package/ or similar. I will give it a go. Having ./packages/* is simply the typical monorepo convention (even if you're just dealing with a single package), but on a technical level, it won't make a difference.

What would be the flow for releases? Also how do i make pre-releases? Please share some guides if you have any

Sure! The tl;dr is:

  1. Make commits with changesets in them (changesets are just files that describe a change, and signal what kind of release -- minor, major, patch -- should be done next to release them.) Changesets are typically part of the commits that implement changes (or merge PRs implementing changes.)
  2. Once you're ready to do a release, yarn changeset version. This will accumulate all existing changesets, update the CHANGELOG.md, and bump all versions, but still wait for you to commit these updates (a useful feature because it gives you a chance to make some manual changes to the changelogs if necessary.)
  3. At this point, the version numbers in package.json will have been bumped, but the new versions will not have been released to NPM. To do this, you'll do yarn release, which will build the package, run the non-existing tests, and finally push the unreleased versions to NPM.
  4. Repeat. :-)

Note that steps 2 and 3 can be handled using a GitHub Action that creates PRs for you (see this one for an example) that you just merge whenever you want to release, and the action will perform everything for you (including the publishing.) Setting this up is recommended (because it's so convenient), but entirely optional. In fact, if you're new to changesets, I'd recommend doing a couple of releases manually (as described above), so you understand how changesets ticks, before automating them.

Let me know if you have more questions!

hmans commented 2 years ago

Addendum to the release process: it's important to note that you can still do releases the old-fashioned way (with the new updates in this PR, essentially yarn build, a manual edit of package.json, and yarn publish), if the changesets-driven approach is feeling intimidating.

hmans commented 2 years ago

I've made the change you requested about moving the package into a top-level package folder, and tested that everything still works as intended.

hmans commented 2 years ago

I've also added a GH action configuration for the changesets stuff. When merged, this will start creating release PRs as soon as new changesets are added to the repository, but it will never publish anything without your action. (It wouldn't be able to, anyway, since it doesn't have an NPM token yet.) But it'll be a good opportunity to look at what these things look like.