#!/bin/bash
set -o errexit
set -o xtrace

function make_sbt_project {
local DESTINATION_FOLDER=$1
local PROJECT_NAME=${2:-zoox-sbt}

[ ! -d $DESTINATION_FOLDER ] && mkdir -p $DESTINATION_FOLDER

local PROJECT_ROOT="$DESTINATION_FOLDER/$PROJECT_NAME"
mkdir $PROJECT_ROOT

local BUILDFILE="$PROJECT_ROOT/build.sbt"
cat > $BUILDFILE <<- EOM

scalaVersion := "2.12.10"

Compile / PB.targets:= Seq(
  scalapb.gen() -> (Compile / sourceManaged).value / "scalapb"
)

exportJars := true
EOM

local PROJECT_FOLDER="$PROJECT_ROOT/project"
mkdir $PROJECT_FOLDER

cat > $PROJECT_FOLDER/plugins.sbt <<- EOM
addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.2")
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.1"
EOM

mkdir -p $PROJECT_ROOT/src/main/protobuf
}

make_sbt_project $1 $2
