Skip to content

Commit

Permalink
Merge pull request #134 from codeconsole/6.0.x-restore-scripts
Browse files Browse the repository at this point in the history
Restore shell scripts
  • Loading branch information
codeconsole authored Sep 27, 2024
2 parents 0686913 + f448281 commit 8818fc4
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/scripts/CreateScaffoldController.groovy
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions src/main/scripts/GenerateAll.groovy
Original file line number Diff line number Diff line change
@@ -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"
}
41 changes: 41 additions & 0 deletions src/main/scripts/GenerateAsyncController.groovy
Original file line number Diff line number Diff line change
@@ -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"
}
51 changes: 51 additions & 0 deletions src/main/scripts/GenerateController.groovy
Original file line number Diff line number Diff line change
@@ -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"
}
45 changes: 45 additions & 0 deletions src/main/scripts/GenerateViews.groovy
Original file line number Diff line number Diff line change
@@ -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"
}
29 changes: 29 additions & 0 deletions src/main/scripts/InstallTemplates.groovy
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 8818fc4

Please sign in to comment.