See below for an example script that prints "Hello World":

    1. description "Example description", "grails hello-world"

    The description method is used to define the output seen by grails help and to aid users of the script. The following is a more complete example of providing a description taken from the generate-all command:

    As you can see this description profiles usage instructions, a flag and an argument. This allows the command to be used as follows:

    1. grails generate-all MyClass --force

    Template Generation

    Every Grails script implements the TemplateRenderer interface which makes it trivial to render templates to the users project workspace.

    The following is an example of the command written in Groovy:

    If a script is defined in a plugin or profile, the template(String) method will search for the template in the application before using the template provided by your plugin or profile. This allows users of your plugin or profile to customize what gets generated.

    1. templates("angular/**/*").each { Resource r ->
    2. String path = r.URL.toString().replaceAll(/^.*?META-INF/, "src/main")
    3. if (path.endsWith('/')) {
    4. mkdir(path)
    5. File to = new File(path)
    6. SpringIOUtils.copy(r, to)
    7. }
    8. }

    The "model"

    Executing the model method with a Class/String/File/Resource will return an instance of . The model contains several properties that can help you generate code.

    Example:

    In addition, an asMap method is available to turn all of the properties into a map to pass to the method.

    Working with files