forked from wasabifx/wasabi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
155 lines (111 loc) · 3.33 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
public static String getDomain(String s) {
String[] f = s.split('\\.')
return f[1].capitalize()
}
defaultTasks 'help'
tasks.addRule("Pattern: <property>=<value>: Passes arguments to the scripts") { String taskName ->
def match = taskName =~ /(.*?)=(.*?$)/
if(match){
task(taskName) << {
}
}
}
task help << {
println ("""\
Welcome to Wasabi
To get started run: gradle -q server -Pdir={directory} -Ppackage={package}
e.g.: gradle -q server -Pdir=/home/username/project/myAppfolder -Ppackage=org.domain
""")
}
task setup << {
if(!project.hasProperty('dir')||!project.hasProperty('package')){
throw new GradleException('You need to specify a dir and package parameters')
} else {
def directory = new File(project.dir)
println('Here we go...\n')
directory.mkdirs()
println('Creating directory ' + project.dir + '...')
def sourcedir = new File(project.dir + '/src/main/kotlin')
sourcedir.mkdirs()
println('Creating src directory ...')
def testdir = new File(project.dir + '/src/test/kotlin')
testdir.mkdirs()
println('Creating test directory ...')
}
}
task createGradle(dependsOn: setup) << {
println('Creating build.gradle file ...')
def gradleFile = new File(project.dir+'/build.gradle')
def mainClass = project.package + '.' + 'ServerKt'
gradleFile.append("""\
buildscript {
project.ext.kotlin_version = '0.1-SNAPSHOT'
repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:\$kotlin_version"
}
}
apply plugin: 'kotlin'
apply plugin: 'application'
mainClassName = '${mainClass}'
repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
maven {
url "http://repository.jetbrains.com/all"
}
}
dependencies {
compile "org.wasabi:wasabi:0.1-SNAPSHOT"
compile "org.jetbrains.kotlin:kotlin-stdlib:\$kotlin_version"
}
sourceSets {
src {
main {
kotlin
}
}
test {
main {
kotlin
}
}
main.java.srcDirs += 'src/main/kotlin'
}
task wrapper(type: Wrapper) {
gradleVersion = '1.8'
}
""")
}
task server(dependsOn: createGradle) << {
println('Creating server ...')
def serverFile = new File(project.dir+'/src/main/kotlin/server.kt')
serverFile.append("""\
package ${project.package}
import org.wasabi.app.AppServer
fun main(args: Array<String>) {
val server = AppServer()
// insert routes here
server.get("/", { response.send ("Hello Wasabi")})
server.start()
}
""")
println('Done!')
println("""
You can now import your Gradle project into your favorite IDE or use an editor.
A default template has been created for you called server.kt. Define your routes there.
Once you're ready to deploy, run:
gradle distZip
This will create a zip file with your application under build/distributions.
Inside the zip there is a bin folder with two files named the same as your application.
One is a shell script for Linux/OSX, the other for Windows. Running it will start your application.
Have fun!
""")
}