Last active
June 30, 2017 04:53
-
-
Save stew/a4a01234d9bfe0b153e5f36a9f116ee8 to your computer and use it in GitHub Desktop.
make-scala-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
(defun stew-write-file (fn str) | |
(with-temp-buffer | |
(insert str) | |
(write-region (point-min) (point-max) fn t))) | |
(defun stew-make-build.properties (fn) | |
(let ((build.properties (concat "sbt.version=" sbt-version "\n"))) | |
(stew-write-file fn build.properties))) | |
(defun stew-make-plugins.sbt (fn) | |
(let ((plugins.sbt (concat | |
"resolvers += Resolver.url(\n" | |
" \"bintray-stew\",\n" | |
" url(\"http://dl.bintray.com/stew/plankton\"))(\n" | |
" Resolver.ivyStylePatterns)\n" | |
"\n" | |
"addSbtPlugin(\"io.github.stew\" % \"sbt-plankton\" % \"0.0.10\")\n"))) | |
(stew-write-file fn plugins.sbt))) | |
(defun stew-make-root-build.sbt (fn) | |
(let ((build.sbt (concat | |
"name := \"\"\n" | |
"\n" | |
"scalaOrganization in ThisBuild := \"org.typelevel\"\n" | |
"scalaVersion in ThisBuild := \"2.12.2-bin-typelevel-4\"\n" | |
"enablePlugins(ZooPlankton)\n"))) | |
(stew-write-file fn build.sbt))) | |
(defun stew-make-main.scala (fn) | |
(let ((build.sbt (concat | |
"import scala.Array\n" | |
"\n" | |
"object Hello {\n" | |
" final def main(argv: Array[String]): Unit =\n" | |
" println(\"1 and 1 and 1 is \" + (1 |+| 1 |+| 1).show)\n" | |
"}\n"))) | |
(stew-write-file fn build.sbt))) | |
(defun make-scala-project () | |
(interactive) | |
(let ((rootdir default-directory) | |
) | |
(if (y-or-n-p (concat "generate directory structure for project: " default-directory)) | |
(let* ((src (concat rootdir "/src")) | |
(project (concat rootdir "/project")) | |
(main (concat src "/main")) | |
(test (concat src "/test")) | |
(mainscala (concat main "/scala")) | |
(main.scala (concat mainscala "/main.scala"))) | |
(mkdir src t) | |
(mkdir project t) | |
(mkdir main t) | |
(mkdir test t) | |
(mkdir mainscala t) | |
(mkdir (concat test "/scala") t) | |
(stew-make-build.properties (concat project "/build.properties")) | |
(stew-make-root-build.sbt (concat rootdir "/build.sbt")) | |
(stew-make-plugins.sbt (concat project "/plubins.sbt")) | |
(stew-make-main.scala main.scala) | |
(find-file main.scala))))) |
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/sh | |
PROJECTNAME= | |
while [ -z "$PROJECTNAME" ] ; do | |
echo "Project name? " | |
read PROJECTNAME | |
done | |
ROOT=$(pwd)/"$PROJECTNAME" | |
if [ -e $ROOT ]; then | |
echo "$ROOT already exists" | |
exit 1 | |
fi | |
mkdir -p "$ROOT/project" | |
mkdir -p "$ROOT/src/main/scala/$PROJECTNAME" | |
cat <<EOF > $ROOT/build.sbt | |
name := "$PROJECTNAME" | |
scalaOrganization in ThisBuild := "org.typelevel" | |
scalaVersion in ThisBuild := "2.12.2-bin-typelevel-4" | |
enablePlugins(ZooPlankton) | |
EOF | |
cat <<EOF > "$ROOT/project/build.properties" | |
sbt.version=0.13.13 | |
EOF | |
cat <<EOF > "$ROOT/project/plugins.sbt" | |
resolvers += Resolver.url( | |
"bintray-stew", | |
url("http://dl.bintray.com/stew/plankton"))( | |
Resolver.ivyStylePatterns) | |
addSbtPlugin("io.github.stew" % "sbt-plankton" % "0.0.10") | |
EOF | |
cat <<EOF > "$ROOT/src/main/scala/$PROJECTNAME/main.scala" | |
package $PROJECTNAME | |
import scala.Array | |
object Hello { | |
final def main(argv: Array[String]): Unit = { | |
println("1 and 1 and 1 is " + (1 |+| 1 |+| 1).show) | |
} | |
} | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment