Customize the way the spring-initializr works?

前端 未结 2 1060
忘了有多久
忘了有多久 2021-02-06 14:25

As an enterprise we would like to host the initializr internally on our PCF instance, which I can do. I\'ve also been able to modify application.yml to default some of the selec

2条回答
  •  [愿得一人]
    2021-02-06 15:06

    I have done a bunch of this for our internal usage and will be presenting this at a talk tomorrow at gr8conf.

    Putting in custom files and adding default selections is pretty easy and requires a bit of knowledge of modifying the java, css and html. You can get the source for the work I have done to demo this here: https://github.com/Grails-Plugin-Consortium/initializr/tree/master

    The code requried to change is lengthy so the easiest way to get a sense of the work I had to do to accomplish this is to just link the diff from adding the "Default" selections and app profiles.

    https://github.com/Grails-Plugin-Consortium/initializr/commit/feae678fdd4503c2314635cebdaabc04b4d80ace

    Adding custom files to get added to generated apps is a bit easier and only requires that you add the files to the templates in initializr-generator and then add a link in ProjectGenerator.java to copy the file similar to how the existing code is already implemented.

    protected void generateDockerFile(File dir, Map model){
        write(new File(dir, "Dockerfile"), "Dockerfile", model);
        write(new File(dir, "docker.sh"), "docker.sh", model);
        write(new File(dir, "docker-run.sh"), "docker-run.sh", model);
    }
    

    The method above added to the ProjectGenerator will add the following files stored in initializr/initializr-generator/src/main/resources/templates/

    All of the heavy lifting for generation lives in this file: https://github.com/Grails-Plugin-Consortium/initializr/blob/9b302d31bb069c9c702f36ed765ad3f55debff84/initializr-generator/src/main/java/io/spring/initializr/generator/ProjectGenerator.java

提交回复
热议问题