From 546f1a6ee3a3632a28ddc1a42bf2f4a80ae759a2 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Sun, 29 Dec 2019 20:52:43 +0100 Subject: [PATCH] Add scalafmt.conf and elm compile options --- .scalafmt.conf | 15 +++++++++++++++ build.sbt | 11 ++++++++--- elm-analyse.json | 7 +++++-- elm-package.json | 1 + project/ElmCompileMode.scala | 14 ++++++++++++++ project/plugins.sbt | 16 ++++++++++------ 6 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 .scalafmt.conf create mode 120000 elm-package.json create mode 100644 project/ElmCompileMode.scala diff --git a/.scalafmt.conf b/.scalafmt.conf new file mode 100644 index 00000000..c3220981 --- /dev/null +++ b/.scalafmt.conf @@ -0,0 +1,15 @@ +version = "2.3.0" + +align = most +#align.arrowEnumeratorGenerator = true + +maxColumn = 100 + +rewrite.rules = [ + AvoidInfix + RedundantBraces + RedundantParens + AsciiSortImports + PreferCurlyFors + SortModifiers +] diff --git a/build.sbt b/build.sbt index cf6055ba..42415808 100644 --- a/build.sbt +++ b/build.sbt @@ -3,6 +3,8 @@ import scala.sys.process._ import com.typesafe.sbt.SbtGit.GitKeys._ import docspell.build._ +val elmCompileMode = settingKey[ElmCompileMode]("How to compile elm sources") + val sharedSettings = Seq( organization := "com.github.eikek", scalaVersion := "2.13.1", @@ -31,12 +33,14 @@ val testSettings = Seq( ) val elmSettings = Seq( + elmCompileMode := ElmCompileMode.Debug, Compile/resourceGenerators += Def.task { compileElm(streams.value.log , (Compile/baseDirectory).value , (Compile/resourceManaged).value , name.value - , version.value) + , version.value + , elmCompileMode.value) }.taskValue, watchSources += Watched.WatchSource( (Compile/sourceDirectory).value/"elm" @@ -381,10 +385,11 @@ def copyWebjarResources(src: Seq[File], base: File, artifact: String, version: S } } -def compileElm(logger: Logger, wd: File, outBase: File, artifact: String, version: String): Seq[File] = { +def compileElm(logger: Logger, wd: File, outBase: File, artifact: String, version: String, mode: ElmCompileMode): Seq[File] = { logger.info("Compile elm files ...") val target = outBase/"META-INF"/"resources"/"webjars"/artifact/version/"docspell-app.js" - val proc = Process(Seq("elm", "make", "--output", target.toString) ++ Seq(wd/"src"/"main"/"elm"/"Main.elm").map(_.toString), Some(wd)) + val cmd = Seq("elm", "make") ++ mode.flags ++ Seq("--output", target.toString) + val proc = Process(cmd ++ Seq(wd/"src"/"main"/"elm"/"Main.elm").map(_.toString), Some(wd)) val out = proc.!! logger.info(out) Seq(target) diff --git a/elm-analyse.json b/elm-analyse.json index e1ba6c56..f480c705 100644 --- a/elm-analyse.json +++ b/elm-analyse.json @@ -1,5 +1,8 @@ { "excludedPaths": [ - "modules/webapp/target/elm-src" - ] + "modules/webapp/target/elm-src/" + ], + "checks" : { + "ImportAll": false + } } diff --git a/elm-package.json b/elm-package.json new file mode 120000 index 00000000..eb4d89bd --- /dev/null +++ b/elm-package.json @@ -0,0 +1 @@ +elm.json \ No newline at end of file diff --git a/project/ElmCompileMode.scala b/project/ElmCompileMode.scala new file mode 100644 index 00000000..f7cafbf5 --- /dev/null +++ b/project/ElmCompileMode.scala @@ -0,0 +1,14 @@ +trait ElmCompileMode { + def flags: Seq[String] +} +object ElmCompileMode { + case object Production extends ElmCompileMode { + val flags = Seq("--optimize") + } + case object Debug extends ElmCompileMode { + val flags = Seq("--debug") + } + case object Dev extends ElmCompileMode { + val flags = Seq.empty + } +} diff --git a/project/plugins.sbt b/project/plugins.sbt index c6ff1545..2f59529d 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,7 +1,11 @@ -addSbtPlugin("com.github.eikek" % "sbt-openapi-schema" % "0.5.0") -addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0") -addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0") -addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1") -addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.5.2") -addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1") addSbtPlugin("com.47deg" % "sbt-microsites" % "0.9.2") +addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0") +addSbtPlugin("com.github.eikek" % "sbt-openapi-schema" % "0.5.0") +addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.12") +addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1") +addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0") +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.5.2") +addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1") +addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.0.3") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.0") +addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.8.1")