google / json_serializable.dart

Generates utilities to aid in serializing to/from JSON.
https://pub.dev/packages/json_serializable
BSD 3-Clause "New" or "Revised" License
1.55k stars 397 forks source link

Question about how to automate generation of .g.dart files. #1347

Open Tamerlanchiques opened 1 year ago

Tamerlanchiques commented 1 year ago

Hi. I would ask how to make integration of json_serializable more convenient in terms of repository that contains ready to run code base. I think that storing of generated files in repo is not optimal way and better to generate all necessary files on local machine. But new-comers in my project will be confused about how to generate missing files.

So my question is: Is that possible to automate process of generating missing .g.dart files? Maybe extension for VS Code or something?

My current thoughts is that I can make .sh script and run dart run build_runner build but it takes around 20 secs of time each run even if no files missing.

emesterhazy commented 1 year ago

How about a Makefile with the following contents:

watch:
        dart run build_runner watch -d

And then in your readme ask users to run make watch in their terminal. This will automatically re-generate code as needed.

3kdeveloper commented 7 months ago

You can just run this command, it will watch and regenerate the code if needed only.

dart run build_runner watch --delete-conflicting-outputs