-
Notifications
You must be signed in to change notification settings - Fork 19
/
skinny
executable file
·277 lines (269 loc) · 10 KB
/
skinny
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/bin/bash
current_dir="."
current_project=`ls | grep project`
script_dir=`dirname $0`
sbt_path=${script_dir}/sbt
sbt_debug_path=${script_dir}/sbt-debug
chmod +x ${sbt_path}
chmod +x ${sbt_debug_path}
# prepared deps
if [ -d "${script_dir}/ivy2" ]; then
mkdir -p $HOME/.ivy2/cache/
cp -prn ${script_dir}/ivy2/cache/* $HOME/.ivy2/cache/.
if [[ ! "$0" =~ /usr/local/Cellar/skinny/.* ]]; then
rm -rf ${script_dir}/ivy2
fi
fi
function verify_skinny_project() {
if [ "${current_project}" == "" ]; then
echo "Skinny application not found here!"
exit 1
fi
}
function run_app() {
${sbt_path} "~;container:restart"
}
function run_precompile_app() {
${sbt_path} "project precompileDev" "~;container:restart"
}
function run_debuggable_app() {
${sbt_debug_path} $1 "~;container:restart"
}
function setup_build() {
rm -rf build
mkdir build
cp -pr src build/src
}
function setup_standalone_build() {
rm -rf standalone-build
mkdir standalone-build
cp -pr src standalone-build/src
cp -p _skinny_assembly_settings.sbt standalone-build/
}
function copy_resources_to_task() {
rm -rf task/src/main/resources
mkdir -p task/src/main/resources
cp -pr src/main/resources/* task/src/main/resources/.
rm -f task/src/main/resources/logback.*
}
function setup_scalajs() {
setting_file="${current_dir}/project/_skinny_scalajs.sbt"
if [ ! -f "${setting_file}" ]; then
echo "resolvers += \"scala-js-release\" at \"http://dl.bintray.com/scala-js/scala-js-releases\"
addSbtPlugin(\"org.scala-js\" % \"sbt-scalajs\" % \"0.6.21\")" > ${setting_file}
echo "lazy val scalajs = (project in file(\"src/main/webapp/WEB-INF/assets\")).settings(
name := \"application\", // JavaScript file name
scalaVersion := \"2.12.4\",
unmanagedSourceDirectories in Compile += baseDirectory(_ / \"scala\").value,
fullResolvers ~= { _.filterNot(_.name == \"jcenter\") },
libraryDependencies ++= Seq(
\"org.scala-js\" %%% \"scalajs-dom\" % \"0.9.3\",
\"be.doeraene\" %%% \"scalajs-jquery\" % \"0.9.2\",
\"io.monix\" %% \"minitest\" % \"1.1.1\" % \"test\"
),
crossTarget in Compile := baseDirectory(_ / \"..\" / \"..\" / \"assets\" / \"js\").value
).enablePlugins(ScalaJSPlugin)" > ${current_dir}/_skinny_scalajs_settings.sbt
fi
}
command="$1"
if [ "$command" != "" -a "$command" != "new" ]; then
verify_skinny_project
fi
if [ "$command" == "new" ]; then
name="$2"
if [ "$name" == "" ]; then
echo "Usage: ./skinny new [application name]"
exit 1
fi
if [ -d "$script_dir/skinny-blank-app" ]; then
cp -pr $script_dir/skinny-blank-app $name
echo " ******************************************** "
echo " New Skinny application has been created!"
echo ""
echo " $ cd ./${name}"
echo " $ ./skinny run"
echo ""
echo " Enjoy Scala programming!"
echo ""
echo " ******************************************** "
echo ""
else
echo " ******************************************** "
echo " !!! ERROR !!!"
echo ""
echo " skinny new command is unsupported when running local skinny script."
echo ' Run `brew install skinny` and then use the global script.'
echo ""
echo " ******************************************** "
exit 1
fi
elif [ "$command" == "run" -o "$command" == "s" -o "$command" == "server" ]; then
option="$2"
if [ "$option" == "-precompile" -o "$option" == "--precompile" ]; then
run_precompile_app
else
run_app
fi
elif [ "$command" == "debug" -o "$command" == "d" ]; then
port="$2"
[ -z "${port}" ] && port=5005
run_debuggable_app ${port}
elif [ "$command" == "clean" ]; then
${sbt_path} dev/clean
${sbt_path} task/clean
copy_resources_to_task
elif [ "$command" == "update" ]; then
${sbt_path} update
elif [ "$command" == "console" ]; then
${sbt_path} dev/console
elif [ "$command" == "~compile" ]; then
${sbt_path} "project dev" "~;compile"
elif [ "$command" == "compile" ]; then
${sbt_path} dev/compile
elif [ "$command" == "test" ]; then
export SKINNY_ENV="test"
${sbt_path} dev/test
elif [ "$command" == "~test" ]; then
export SKINNY_ENV="test"
${sbt_path} "project dev" "~;test"
elif [ "$command" == "test-quick" -o "$command" == "testQuick" ]; then
export SKINNY_ENV="test"
${sbt_path} dev/testQuick
elif [ "$command" == "~test-quick" -o "$command" == "~testQuick" ]; then
export SKINNY_ENV="test"
${sbt_path} "project dev" "~;testQuick"
elif [ "$command" == "test-only" -o "$command" == "testOnly" ]; then
export SKINNY_ENV="test"
${sbt_path} "dev/testOnly $2"
elif [ "$command" == "~test-only" -o "$command" == "~testOnly" ]; then
export SKINNY_ENV="test"
${sbt_path} "project dev" "~;testOnly $2"
elif [ "$command" == "test:coverage" ]; then
export SKINNY_ENV="test"
${sbt_path} "coverage" "dev/test"
elif [ "$command" == "scalajs:watch" ]; then
setup_scalajs
${sbt_path} "project scalajs" "~;fastOptJS"
elif [ "$command" == "scalajs:package" ]; then
setup_scalajs
${sbt_path} "project scalajs" fullOptJS
elif [ "$command" == "task:clean" ]; then
${sbt_path} "task/clean"
copy_resources_to_task
elif [ "$command" == "task:run" ]; then
copy_resources_to_task
shift
command="task/run $@"
${sbt_path} "${command}"
elif [ "$command" == "g" -o "$command" == "generate" ]; then
generator_type="$2"
shift
shift
if [ "$generator_type" == "" ]; then
echo "Usage: ./skinny g/generate [type] [options...]"
else
copy_resources_to_task
command="task/run generate:$generator_type $@"
${sbt_path} "${command}"
fi
elif [ "$command" == "routes" ]; then
copy_resources_to_task
shift
${sbt_path} "task/run routes $@"
elif [ "$command" == "db:migrate" ]; then
copy_resources_to_task
env="$2"
db_name="$3"
shift
${sbt_path} "task/run db:migrate $env $db_name"
elif [ "$command" == "db:repair" ]; then
copy_resources_to_task
env="$2"
db_name="$3"
shift
${sbt_path} "task/run db:repair $env $db_name"
elif [ "$command" == "eclipse" ]; then
setting_file="${current_dir}/project/_skinny_eclipse.sbt"
if [ ! -f "${setting_file}" ]; then
echo "addSbtPlugin(\"com.typesafe.sbteclipse\" % \"sbteclipse-plugin\" % \"5.2.4\")" > ${setting_file}
fi
${sbt_path} eclipse
elif [ "$command" == "idea" -o "$command" == "gen-idea" ]; then
${sbt_path} gen-idea
elif [ "$command" == "package" ]; then
setup_build
copy_resources_to_task
${sbt_path} "task/run assets:precompile" build/package
elif [ "$command" == "package:standalone" ]; then
setting_file="${current_dir}/project/_skinny_assembly.sbt"
if [ ! -f "${setting_file}" ]; then
echo "addSbtPlugin(\"com.eed3si9n\" % \"sbt-assembly\" % \"0.14.6\")" > ${setting_file}
echo "mainClass in assembly := Some(\"skinny.standalone.JettyLauncher\")
_root_.sbt.Keys.test in assembly := {}
resourceGenerators in Compile += (Def.task {
val (managedBase, base) = (resourceManaged.value, baseDirectory.value)
val webappBase = base / \"src\" / \"main\" / \"webapp\"
for ( (from, to) <- webappBase ** \"*\" \`pair\` rebase(webappBase, managedBase / \"main/\") )
yield {
Sync.copy(from, to)
to
}
}).taskValue" > "${current_dir}/_skinny_assembly_settings.sbt"
fi
setup_standalone_build
copy_resources_to_task
${sbt_path} "task/run assets:precompile standalone-build"
${sbt_path} standaloneBuild/assembly
elif [ "$command" == "publish" ]; then
setup_build
copy_resources_to_task
${sbt_path} "task/run assets:precompile" build/publish
else
echo ""
echo " Usage: ./skinny [COMMAND] [OPTIONS]..."
echo ""
echo " new : will create new Skinny application"
echo " run/server/s : will run application for local development"
echo " run -precompile : will run application with Scalate precompilation"
echo " debug/d : will run application with JDWP. default port 5005"
echo " clean : will clear target directory"
echo " update : will run sbt update"
echo " console : will run sbt console"
echo " compile : will compile all the classes"
echo " ~compile : will compile all the classes when changes are detected"
echo " db:migrate : will execute database migration"
echo " db:repair : will recover when previous migration failed"
echo " routes : will display routes information"
echo " test : will run all the tests"
echo " ~test : will run all the tests when changes are detected"
echo " testQuick : will run only failed tests"
echo " ~testQuick : will run only failed tests when changes are detected"
echo " testOnly : will run the specified test"
echo " ~testOnly : will run the specified test when changes are detected"
echo " test:coverage : will run all the tests and output coverage reports"
echo " package : will create *.war file to deploy"
echo " package:standalone : will create *.jar file to run as stand alone app"
echo " publish : will publish *.war file to repository"
echo ""
echo " scalajs:watch : will watch Scala.js Scala code change and convert to JS"
echo " scalajs:package : will convert Scala.js Scala code to JS file"
echo ""
echo " eclipse : will setup Scala IDE settings"
echo " idea/gen-idea : will setup IntelliJ IDEA settings"
echo ""
echo " task:clean : will clean task project's target directory"
echo " task:run : will run tasks"
echo ""
echo " g/generate controller : will generate controller"
echo " g/generate model : will generate model"
echo " g/generate migration : will generate db migration file"
echo ""
echo " g/generate scaffold : will generate scaffold files with ssp templates"
echo " g/generate scaffold:scaml : will generate scaffold files with scaml templates"
echo " g/generate scaffold:jade : will generate scaffold files with jade templates"
echo ""
echo " g/generate reverse-scaffold : will generate scaffold from existing database"
echo " g/generate reverse-scaffold:scaml : will generate scaffold from existing database"
echo " g/generate reverse-scaffold:jade : will generate scaffold from existing database"
echo ""
fi