Skip to content

Commit

Permalink
Merge pull request #32 from danieletorelli/sbt-wasm-component
Browse files Browse the repository at this point in the history
Use sbt-wasm-component-plugin
  • Loading branch information
vigoo authored Jun 13, 2024
2 parents 5165dcc + d86d9cc commit 11b40c6
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 43 deletions.
41 changes: 3 additions & 38 deletions examples/scala2/scala2-shopping-cart/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,8 @@ ThisBuild / version := "0.1.0"
ThisBuild / scalaVersion := "2.13.12"

lazy val root = (project in file("."))
.enablePlugins(WasmComponentPlugin)
.settings(
name := "component-name"
name := "component-name",
wasmComponentPackageName := "example"
)
.enablePlugins(ScalaJSPlugin)
.settings(
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule) },
Compile / fullLinkJS / scalaJSLinkerOutputDirectory := target.value / "dist"
)

lazy val witBindgen = taskKey[Unit]("Runs golem-scalajs-wit-bindgen to generate WIT bindings")

witBindgen := {
import scala.sys.process._

Seq("bash", "-xc", "golem-scalajs-wit-bindgen -w wit/main.wit -p example").!!
}

lazy val component = taskKey[Unit]("Runs componentize-js on the generated main.js file")

component := {
import scala.sys.process._

Seq("bash", "-xc", "npm install").!!
Seq("bash", "-xc", "npm run build").!!
}

component := (component dependsOn (Compile / fullLinkJS)).value

Compile / sourceGenerators += Def.task {
import scala.sys.process._

val file = (Compile / sourceManaged).value / "scala" / "example" / "Api.scala"

IO.write(
file,
Seq("bash", "-xc", "golem-scalajs-wit-bindgen -w wit/main.wit -p example").!!
)

Seq(file)
}.taskValue
2 changes: 1 addition & 1 deletion examples/scala2/scala2-shopping-cart/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.2")
addSbtPlugin("cloud.golem" % "sbt-wasm-component" % "0.1.0")
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package example

import scala.scalajs.js.annotation.{ JSExportAll, JSExportTopLevel }

final case class State(userId: String, items: List[ProductItem]) { self =>
def withUserId(userId: String): State = self.copy(userId = userId)

Expand All @@ -21,8 +19,7 @@ object State {
val empty = State(userId = "", items = List.empty)
}

@JSExportTopLevel("api")
@JSExportAll
@cloud.golem.WitExport
object ComponentName extends Api { self =>
private var state = State.empty

Expand Down

0 comments on commit 11b40c6

Please sign in to comment.