Created
March 4, 2017 16:14
-
-
Save timjstewart/b828b1ea8e18e4a94a0f881b0e97dfc7 to your computer and use it in GitHub Desktop.
Create an Scala SBT project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
scala_version=2.12.1 | |
function create_directories() | |
{ | |
project_name=$1 | |
mkdir -p ${project_name}/src/{main,test}/scala/com/timjstewart | |
} | |
function create_build_sbt_file() | |
{ | |
name=$1 | |
if [ ! -f ./build.sbt ] | |
then | |
echo " CREATE build.sbt..." | |
cat << EOF > build.sbt | |
name := "${name}" | |
scalaVersion := "${scala_version}" | |
version := "0.1.0" | |
// versions | |
val scalazVersion = "7.2.9" | |
val scalaCheckVersion = "1.13.4" | |
val scalaTestVersion = "3.0.1" | |
scalacOptions ++= Seq("-unchecked", "-deprecation") | |
libraryDependencies ++= Seq( | |
// all dependencies | |
"org.scalaz" %% "scalaz-core" % scalazVersion, | |
// testing dependencies | |
"org.scalacheck" %% "scalacheck" % scalaCheckVersion % "test", | |
"org.scalatest" %% "scalatest" % scalaTestVersion % "test" | |
) | |
EOF | |
else | |
echo " IGNORE build.sbt" | |
fi | |
} | |
function create_main_source_file() | |
{ | |
src_file="src/main/scala/com/timjstewart/Main.scala" | |
if [ ! -f ${src_file} ] | |
then | |
echo " CREATE ${src_file}..." | |
cat << EOF > ${src_file} | |
package com.timjstewart | |
import scalaz._ | |
import Scalaz._ | |
object Main { | |
def main(args: Array[String]): Unit = { | |
println("Hello, world!") | |
} | |
} | |
EOF | |
else | |
echo " IGNORE ${src_file}" | |
fi | |
} | |
function create_main_test_file() | |
{ | |
src_file="src/test/scala/com/timjstewart/Main.scala" | |
if [ ! -f ${src_file} ] | |
then | |
echo " CREATE ${src_file}..." | |
cat << EOF > ${src_file} | |
package com.timjstewart | |
import org.scalatest._ | |
class MainSpec extends FunSpec with Matchers { | |
describe("A Set") { | |
describe("when empty") { | |
it("should have size 0") { | |
assert(Set.empty.size == 0) | |
} | |
it("should produce NoSuchElementException when head is invoked") { | |
assertThrows[NoSuchElementException] { | |
Set.empty.head | |
} | |
} | |
} | |
} | |
} | |
EOF | |
else | |
echo " IGNORE ${src_file}" | |
fi | |
} | |
function init_ensime() | |
{ | |
echo " CONFIG ensime" | |
sbt ensimeConfig > /dev/null | |
} | |
if [ "$#" == "1" ] | |
then | |
project_name=$1 | |
echo "Creating SBT Project: ${project_name}" | |
create_directories ${project_name} | |
cd ${project_name} | |
create_build_sbt_file ${project_name} | |
create_main_source_file | |
create_main_test_file | |
init_ensime | |
echo "Done." | |
else | |
echo "usage: new-sbt PROJECT_NAME" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment