Skip to content

Commit

Permalink
Set default htmx version from build info
Browse files Browse the repository at this point in the history
  • Loading branch information
eikek committed Sep 21, 2024
1 parent 0d1ac2c commit 118586b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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",
Expand Down
25 changes: 25 additions & 0 deletions project/HtmxCurrentVersion.scala
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 118586b

Please sign in to comment.