This way should be more reliable, because config() is available only after publishing module, however I can't publish module when it does not have config (module.json). In this way I can select all modules from database and generate module.json for each of them.