I also just have to recompile invalid objects more than once.
Do you guys have script to identify the dependency first before
the creation of the script to recompile invalid objects?

If such script is available, then compilation of invalid objects will only be done once, and that's great :-))