From 118586b1aa7ca0dd0b33dcfd322e472db1c72bbe Mon Sep 17 00:00:00 2001 From: eikek Date: Sat, 21 Sep 2024 08:55:39 +0200 Subject: [PATCH] Set default htmx version from build info --- build.sbt | 2 +- .../scala/htmx4s/http4s/WebjarRoute.scala | 3 ++- project/HtmxCurrentVersion.scala | 25 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 project/HtmxCurrentVersion.scala diff --git a/build.sbt b/build.sbt index bbf215f..297d0f5 100644 --- a/build.sbt +++ b/build.sbt @@ -79,7 +79,7 @@ val buildInfoSettings = Seq( val constants = project .in(file("modules/constants")) - .enablePlugins(HtmxSourceGeneratorPlugin) + .enablePlugins(HtmxSourceGeneratorPlugin, HtmxCurrentVersion) .disablePlugins(RevolverPlugin) .settings(sharedSettings) .settings(testSettings) diff --git a/modules/http4s/src/main/scala/htmx4s/http4s/WebjarRoute.scala b/modules/http4s/src/main/scala/htmx4s/http4s/WebjarRoute.scala index a710ba0..6690321 100644 --- a/modules/http4s/src/main/scala/htmx4s/http4s/WebjarRoute.scala +++ b/modules/http4s/src/main/scala/htmx4s/http4s/WebjarRoute.scala @@ -4,6 +4,7 @@ import cats.data.Kleisli import cats.data.OptionT import cats.effect.Sync +import htmx4s.constants.HtmxCurrentVersion import htmx4s.http4s.WebjarRoute.Webjar import org.http4s.* @@ -80,7 +81,7 @@ object WebjarRoute: def apply(segment: String)(name: String, version: String, path: String*): Webjar = Webjar(segment, name, version, path.toList) def htmx(version: String): Webjar = Webjar("htmx")("htmx.org", version, "dist") - val htmx2 = htmx("2.0.1") + val htmx2 = htmx(HtmxCurrentVersion.value) val defaultExtensions = Set( ".js", diff --git a/project/HtmxCurrentVersion.scala b/project/HtmxCurrentVersion.scala new file mode 100644 index 0000000..046c897 --- /dev/null +++ b/project/HtmxCurrentVersion.scala @@ -0,0 +1,25 @@ +import sbt._ + +object HtmxCurrentVersion extends AutoPlugin { + + override def projectSettings = Seq( + Compile / Keys.sourceGenerators += Def.task { + writeFile("htmx4s.constants", (Compile / Keys.sourceManaged).value) + }.taskValue, + ) + + private val version = Dependencies.V.htmx + + def writeFile(pkg: String, out: File): Seq[File] = { + val target = out / "htmx-constanst" / "HtmxCurrentVersion.scala" + IO.createDirectory(out.getParentFile) + val fields = s""" val value: String = "${version}"""" + val content = s"""package $pkg + |object HtmxCurrentVersion { + |$fields + |} + |""".stripMargin + IO.write(target, content) + Seq(target) + } +}