Skip to content

Instantly share code, notes, and snippets.

@jodersky
Last active March 6, 2021 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jodersky/26793057c4d0bb67f9113f0a28f56477 to your computer and use it in GitHub Desktop.
Save jodersky/26793057c4d0bb67f9113f0a28f56477 to your computer and use it in GitHub Desktop.
Initialize a directory with a basic Mill build configuration, using the latest available version of Mill
#!/bin/bash
#
# millinit - fetch mill and initialize a project in a directory
#
# This script will query GitHub to find the newest available version of Mill. It
# will download it and initialize a directory with a basic build configuration.
#
# Usage: millinit <directory>
set -o errexit
root="$1"
[[ -z $root ]] && echo -e "Please specify the directory into which you would like to initialize the project.\nUsage:'millinit <directory>'" >&2 && exit 1
mkdir -p "$root"
# Download mill wrapper script
latest_tag=$(curl -sS https://api.github.com/repos/com-lihaoyi/mill/releases/latest | jq -r '.tag_name')
echo "$latest_tag" > "$root/.mill-version"
curl -sS -L "https://github.com/com-lihaoyi/mill/releases/download/$latest_tag/$latest_tag" > "$root/mill"
chmod +x "$root/mill"
# Setup sample project files
cat << 'EOF' > "$root/build.sc"
import mill._, scalalib._, scalafmt._
object app extends ScalaModule with ScalafmtModule {
def scalaVersion = "3.0.0-RC1"
object test extends Tests {
def testFrameworks = Seq("utest.runner.Framework")
def ivyDeps = Agg(
ivy"com.lihaoyi::utest::0.7.7"
)
}
}
EOF
mkdir -p "$root/app/src"
cat << 'EOF' > "$root/app/src/main.scala"
@main def run() = println("hello, world")
EOF
mkdir -p "$root/app/test/src"
cat << 'EOF' > "$root/app/test/src/Test.scala"
import utest._
object Test extends TestSuite {
val tests = Tests {
test("a test") {
assert(1+1==2)
}
}
}
EOF
# Done
echo -e "\e[0;32mSuccess!\e[0m" >&2
echo "The directory '$root' has been initialized with a new Mill build configuration." >&2
echo "The build is configured in the file 'build.sc'. Consult Mill's documentation online at https://com-lihaoyi.github.io/mill/" >&2
echo "It is safe to ignore Mill's output directory 'out':" >&2
echo " echo out/ >> .gitignore" >&2
echo "The project has been initialized with a couple of default tasks, for example:" >&2
echo "- to run the example application" >&2
echo " ./mill app" >&2
echo "- to run some unit tests" >&2
echo " ./mill app.test" >&2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment