I am using img2simg
first to create a sparse image from the ext4 (that’s available as a package in my debian).
Then I use img2sdat to create the dat-files.
and then i pass it through brotli -q 6
(also available in debian) to create the brotli-files.
I do this for system, vendor and product.
The rest of the partitions are straight dd-images.
You can do the reverse process for confirming they result in the same images.
Then update META-INF/com/android/metadata
and META-INF/com/google/android/updater-script
with the ROM-information.
Should probably create a sript that does all this automatically.