Rewrite LWC purge, some fixes to WG regeneration.

Warning: This build is not tested at all.
Bo a backup before purging.