Is your feature request related to a problem? Please describe.
I need some way to check whether the generated code is up-to-date with the source code, so that I can check before every commit with husky and during CI.
Describe the solution you'd like
There could be a --check flag in the CLI that would generate all the code in memory, compare to what's in my working directory and exit with an error if they are different.
Describe alternatives you've considered
None.
Additional context
It would be similar to how prettier --check or prettier --list-different works.
This is so heavily needed. Amazing idea!!!
We are currently doing
npm run codegen
git status --porcelain
git diff-index --quiet HEAD
in gitlab CI to make a pipeline fail if the generated code differs from what was commited.
I see benefit on a check as part of my pre commit hook while in development as well.
@ajotaos we recommend not to commit your generated files. It bloats the git repo with files that would change anyway...
You鈥檙e right I misread the issue, I meant that I could check whether the generated files are up to date with my configuration and schema. Like it could try to generate the files and if it succeeds, exits with zero and nothing gets created but if it runs and doesn鈥檛 match the in-memory doesn鈥檛 the generated file, it exists with non-zero. That way even the codegen file is validated.
Is there a similar flow available?
At the moment we don't an internal flow for that.
You can implement it with a git-hook (using husky or similar tools). And just run codegen and then run git add to the generated files. This way it will make sure you are always committing the updated files.
In most setups, running codegen takes less than a second, so it shouldn't be an overhead for running this during commit or push hooks.
Wouldn鈥檛 that end up commuting the generated files to git?
I thought that was your goal, and the author of that issue.
As I said, I don't recommend to commit the generated files, but if you decide to, some actions should be taken to make sure it's always in sync.
I鈥檒l open up another issue, it鈥檚 true it鈥檚 no the same from the author.
Most helpful comment
We are currently doing
in gitlab CI to make a pipeline fail if the generated code differs from what was commited.