From f4482818a1614715e77f0fc27da8bc11a133690d Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Thu, 26 Sep 2024 17:46:44 -0700 Subject: [PATCH] Restore shell scripts --- .../scripts/CreateScaffoldController.groovy | 16 ++++++ src/main/scripts/GenerateAll.groovy | 15 ++++++ .../scripts/GenerateAsyncController.groovy | 41 +++++++++++++++ src/main/scripts/GenerateController.groovy | 51 +++++++++++++++++++ src/main/scripts/GenerateViews.groovy | 45 ++++++++++++++++ src/main/scripts/InstallTemplates.groovy | 29 +++++++++++ 6 files changed, 197 insertions(+) create mode 100644 src/main/scripts/CreateScaffoldController.groovy create mode 100644 src/main/scripts/GenerateAll.groovy create mode 100644 src/main/scripts/GenerateAsyncController.groovy create mode 100644 src/main/scripts/GenerateController.groovy create mode 100644 src/main/scripts/GenerateViews.groovy create mode 100644 src/main/scripts/InstallTemplates.groovy diff --git a/src/main/scripts/CreateScaffoldController.groovy b/src/main/scripts/CreateScaffoldController.groovy new file mode 100644 index 0000000..8259200 --- /dev/null +++ b/src/main/scripts/CreateScaffoldController.groovy @@ -0,0 +1,16 @@ +description("Creates a scaffolded controller") { + usage 'create-controller [controller name]' + completer org.grails.cli.interactive.completers.DomainClassCompleter + argument name:'Controller Name', description:"The name of controller", required:true + flag name:'force', description:"Whether to overwrite existing files" + } + +def model = model(args[0]) +def overwrite = flag('force') ? true : false + +render template: template('scaffolding/ScaffoldedController.groovy'), + destination: file("grails-app/controllers/${model.packagePath}/${model.convention("Controller")}.groovy"), + model: model, + overwrite: overwrite + +return true diff --git a/src/main/scripts/GenerateAll.groovy b/src/main/scripts/GenerateAll.groovy new file mode 100644 index 0000000..7005231 --- /dev/null +++ b/src/main/scripts/GenerateAll.groovy @@ -0,0 +1,15 @@ +import org.grails.cli.interactive.completers.DomainClassCompleter + +description("Generates a controller that performs CRUD operations and the associated views") { + usage "grails generate-all [DOMAIN CLASS]" + argument name: 'Domain Class', description: "The name of the domain class", required: true + completer DomainClassCompleter + flag name: 'force', description: "Whether to overwrite existing files" +} + +if (args) { + generateController(*args) + generateViews(*args) +} else { + error "No domain class specified" +} diff --git a/src/main/scripts/GenerateAsyncController.groovy b/src/main/scripts/GenerateAsyncController.groovy new file mode 100644 index 0000000..108eb50 --- /dev/null +++ b/src/main/scripts/GenerateAsyncController.groovy @@ -0,0 +1,41 @@ +import org.grails.cli.interactive.completers.DomainClassCompleter + +description( "Generates an asynchronous controller that performs CRUD operations" ) { + usage "grails generate-async-controller [DOMAIN CLASS]" + completer DomainClassCompleter + flag name:'force', description:"Whether to overwrite existing files" +} + + +if(args) { + def classNames = args + if(args[0] == '*') { + classNames = resources("file:grails-app/domain/**/*.groovy") + .collect { className(it) } + } + for(arg in classNames) { + def sourceClass = source(arg) + def overwrite = flag('force') ? true : false + if(sourceClass) { + def model = model(sourceClass) + render template: template('scaffolding/AsyncController.groovy'), + destination: file("grails-app/controllers/${model.packagePath}/${model.convention('Controller')}.groovy"), + model: model, + overwrite: overwrite + + render template: template('scaffolding/AsyncSpec.groovy'), + destination: file("src/test/groovy/${model.packagePath}/${model.convention('ControllerSpec')}.groovy"), + model: model, + overwrite: overwrite + + + addStatus "Scaffolding completed for ${projectPath(sourceClass)}" + } + else { + error "Domain class not found for name $arg" + } + } +} +else { + error "No domain class specified" +} diff --git a/src/main/scripts/GenerateController.groovy b/src/main/scripts/GenerateController.groovy new file mode 100644 index 0000000..42ef375 --- /dev/null +++ b/src/main/scripts/GenerateController.groovy @@ -0,0 +1,51 @@ +import org.grails.cli.interactive.completers.DomainClassCompleter + +description( "Generates a controller that performs CRUD operations" ) { + usage "grails generate-controller [DOMAIN CLASS]" + completer DomainClassCompleter + flag name:'force', description:"Whether to overwrite existing files" +} + + +if(args) { + def classNames = args + if(args[0] == '*') { + classNames = resources("file:grails-app/domain/**/*.groovy") + .collect { className(it) } + } + for(arg in classNames) { + def sourceClass = source(arg) + def overwrite = flag('force') ? true : false + if(sourceClass) { + def model = model(sourceClass) + render template: template('scaffolding/Controller.groovy'), + destination: file("grails-app/controllers/${model.packagePath}/${model.convention('Controller')}.groovy"), + model: model, + overwrite: overwrite + + render template: template('scaffolding/Service.groovy'), + destination: file("grails-app/services/${model.packagePath}/${model.convention('Service')}.groovy"), + model: model, + overwrite: overwrite + + render template: template('scaffolding/Spec.groovy'), + destination: file("src/test/groovy/${model.packagePath}/${model.convention('ControllerSpec')}.groovy"), + model: model, + overwrite: overwrite + + render template: template('scaffolding/ServiceSpec.groovy'), + destination: file("src/integration-test/groovy/${model.packagePath}/${model.convention('ServiceSpec')}.groovy"), + model: model, + overwrite: overwrite + + + addStatus "Scaffolding completed for ${projectPath(sourceClass)}" + } + else { + error "Domain class not found for name $arg" + } + } +} +else { + error "No domain class specified" +} diff --git a/src/main/scripts/GenerateViews.groovy b/src/main/scripts/GenerateViews.groovy new file mode 100644 index 0000000..4da9c09 --- /dev/null +++ b/src/main/scripts/GenerateViews.groovy @@ -0,0 +1,45 @@ +import org.grails.cli.interactive.completers.DomainClassCompleter + +description( "Generates GSP views for the specified domain class" ) { + usage "grails generate-views [DOMAIN CLASS]|*" + argument name:'Domain Class', description:"The name of the domain class, or '*' for all", required:true + completer DomainClassCompleter + flag name:'force', description:"Whether to overwrite existing files" +} + +if(args) { + def classNames = args + if(args[0] == '*') { + classNames = resources("file:grails-app/domain/**/*.groovy").collect { className(it) } + } + def viewNames = resources("file:src/main/templates/scaffolding/*.gsp") + .collect { + it.filename + } + if(!viewNames) { + viewNames = resources("classpath*:META-INF/templates/scaffolding/*.gsp") + .collect { + it.filename + } + } + + for(arg in classNames) { + def sourceClass = source(arg) + def overwrite = flag('force') ? true : false + if(sourceClass) { + def model = model(sourceClass) + viewNames.each { + render template: template('scaffolding/'+it), + destination: file("grails-app/views/${model.propertyName}/"+it), + model: model, + overwrite: overwrite + } + + addStatus "Views generated for ${projectPath(sourceClass)}" + } else { + error "Domain class not found for name $arg" + } + } +} else { + error "No domain class specified" +} diff --git a/src/main/scripts/InstallTemplates.groovy b/src/main/scripts/InstallTemplates.groovy new file mode 100644 index 0000000..0fb3d5f --- /dev/null +++ b/src/main/scripts/InstallTemplates.groovy @@ -0,0 +1,29 @@ +/* + * Copyright 2012 Rob Fletcher + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +description "Installs scaffolding templates that use f:all to render properties", "grails install-templates" + +updateStatus "Copying scaffolding templates" +mkdir "src/main/templates/scaffolding" +copy { + from templates("scaffolding/*.gsp") + into "src/main/templates/scaffolding" +} +copy { + from templates("scaffolding/*.groovy") + into "src/main/templates/scaffolding" +} +addStatus "Template installation complete"