You create your own code generator. There are several existing tools for this. One is Apache Velocity, a Java-based template engine. It can be used to automatically generate text files and also text-based UML diagrams, such as PlantUML.
Velocity offers the possibility to create templates, fill them with context and save them as a file. For the context, the first thing to be developed is a model, to store all components and the associated relations in. There is now only a little bit of code that must be written around it to parse the information from the existing diagram, storing it in the model and passes it to the template. When parsing, it is possible to specify whether certain packages are to be completely ignored or possibly treated differently.