Skip to content

Commit

Permalink
Merge pull request #27 from filosganga/support-scalajs
Browse files Browse the repository at this point in the history
feat: add scalajs support
  • Loading branch information
SystemFw authored Feb 12, 2023
2 parents b409c61 + b99089c commit 8f936a0
Show file tree
Hide file tree
Showing 21 changed files with 529 additions and 78 deletions.
48 changes: 26 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.6, 3.0.0, 2.12.14]
java: [[email protected]11]
scala: [2.13.6, 3.2.0, 2.12.14]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Java and Scala
uses: olafurpg/setup-scala@v10
- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v2
with:
java-version: ${{ matrix.java }}
distribution: temurin
java-version: 11

- name: Cache sbt
uses: actions/cache@v2
Expand All @@ -53,15 +55,15 @@ jobs:
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Check that workflows are up to date
run: sbt --client '++${{ matrix.scala }}; githubWorkflowCheck'
run: sbt ++${{ matrix.scala }} githubWorkflowCheck

- run: sbt --client '++${{ matrix.scala }}; ci'
- run: sbt ++${{ matrix.scala }} ci

- if: matrix.scala == '2.13.6'
run: sbt --client '++${{ matrix.scala }}; docs/mdoc'
run: sbt ++${{ matrix.scala }} docs/mdoc

- name: Compress target directories
run: tar cf targets.tar target modules/core/target project/target
run: tar cf targets.tar target modules/core/js/target modules/core/jvm/target project/target

- name: Upload target directories
uses: actions/upload-artifact@v2
Expand All @@ -77,18 +79,20 @@ jobs:
matrix:
os: [ubuntu-latest]
scala: [2.13.6]
java: [[email protected]11]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Java and Scala
uses: olafurpg/setup-scala@v10
- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v2
with:
java-version: ${{ matrix.java }}
distribution: temurin
java-version: 11

- name: Cache sbt
uses: actions/cache@v2
Expand All @@ -112,12 +116,12 @@ jobs:
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.0.0)
- name: Download target directories (3.2.0)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-3.0.0-${{ matrix.java }}
name: target-${{ matrix.os }}-3.2.0-${{ matrix.java }}

- name: Inflate target directories (3.0.0)
- name: Inflate target directories (3.2.0)
run: |
tar xf targets.tar
rm targets.tar
Expand All @@ -135,7 +139,7 @@ jobs:
- name: Import signing key
run: echo $PGP_SECRET | base64 -d | gpg --import

- run: sbt --client '++${{ matrix.scala }}; release'
- run: sbt ++${{ matrix.scala }} release

docs:
name: Deploy docs
Expand All @@ -145,7 +149,7 @@ jobs:
matrix:
os: [ubuntu-latest]
scala: [2.13.6]
java: [[email protected]11]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
- name: Download target directories (2.13.6)
Expand All @@ -158,12 +162,12 @@ jobs:
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.0.0)
- name: Download target directories (3.2.0)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-3.0.0-${{ matrix.java }}
name: target-${{ matrix.os }}-3.2.0-${{ matrix.java }}

- name: Inflate target directories (3.0.0)
- name: Inflate target directories (3.2.0)
run: |
tar xf targets.tar
rm targets.tar
Expand All @@ -182,4 +186,4 @@ jobs:
uses: peaceiris/actions-gh-pages@v3
with:
publish_dir: ./target/website
github_token: ${{ secrets.GITHUB_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/clean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ jobs:
printf "Deleting '%s' #%d, %'d bytes\n" $name ${ARTCOUNT[$name]} $size
ghapi -X DELETE $REPO/actions/artifacts/$id
done
done
done
52 changes: 33 additions & 19 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,57 @@ Global / excludeLintKeys += scmInfo
val Scala213 = "2.13.6"
ThisBuild / spiewakMainBranches := Seq("main")

ThisBuild / crossScalaVersions := Seq(Scala213, "3.0.0", "2.12.14")
ThisBuild / crossScalaVersions := Seq(Scala213, "3.2.0", "2.12.14")
ThisBuild / versionIntroduced := Map("3.0.0" -> "0.3.0")
ThisBuild / scalaVersion := (ThisBuild / crossScalaVersions).value.head
ThisBuild / initialCommands := """
|import cats._, data._, syntax.all._
|import dynosaur._
""".stripMargin
ThisBuild / testFrameworks += new TestFramework("munit.Framework")

def dep(org: String, prefix: String, version: String)(modules: String*)(
testModules: String*
) =
modules.map(m => org %% (prefix ++ m) % version) ++
testModules.map(m => org %% (prefix ++ m) % version % Test)

lazy val root = project
.in(file("."))
.enablePlugins(NoPublishPlugin, SonatypeCiReleasePlugin)
.aggregate(core)
.aggregate(core.js, core.jvm)

lazy val core = project
lazy val core = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Full)
.in(file("modules/core"))
.settings(
name := "dynosaur-core",
scalafmtOnCompile := true,
libraryDependencies ++=
dep("org.typelevel", "cats-", "2.6.1")("core", "free")() ++
dep("org.typelevel", "", "2.6.1")("alleycats-core")() ++
dep("org.scodec", "scodec-bits", "1.1.27")("")() ++
dep("org.scalameta", "munit", "0.7.25")()("", "-scalacheck") ++
dep("org.typelevel", "paiges-", "0.4.2")("core", "cats")() ++
Seq("software.amazon.awssdk" % "dynamodb" % "2.17.100")
libraryDependencies ++= List(
"org.typelevel" %%% "cats-core" % "2.6.1",
"org.typelevel" %%% "cats-free" % "2.6.1",
"org.typelevel" %%% "alleycats-core" % "2.6.1",
"org.typelevel" %%% "paiges-core" % "0.4.2",
"org.typelevel" %%% "paiges-cats" % "0.4.2",
"org.scodec" %%% "scodec-bits" % "1.1.34",
"org.scalameta" %%% "munit" % "0.7.29" % Test,
"org.scalameta" %%% "munit-scalacheck" % "0.7.29" % Test
)
)
.jvmSettings(
libraryDependencies ++= Seq(
"software.amazon.awssdk" % "dynamodb" % "2.14.15"
)
)

lazy val coreJS = core.js
lazy val coreJVM = core.jvm

lazy val jsdocs = project
.dependsOn(core.js)
.settings(
githubWorkflowArtifactUpload := false,
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "2.3.0"
)
.enablePlugins(ScalaJSPlugin)

lazy val docs = project
.in(file("mdoc"))
.settings(
mdocJS := Some(jsdocs),
mdocIn := file("docs"),
mdocOut := file("target/website"),
mdocVariables := Map(
Expand All @@ -65,10 +79,10 @@ lazy val docs = project
githubWorkflowArtifactUpload := false,
fatalWarningsInCI := false
)
.dependsOn(core)
.dependsOn(core.jvm)
.enablePlugins(MdocPlugin, NoPublishPlugin)

ThisBuild / githubWorkflowJavaVersions := Seq("[email protected]")
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("11"))

ThisBuild / githubWorkflowBuildPostamble ++= List(
WorkflowStep.Sbt(
Expand Down
58 changes: 58 additions & 0 deletions modules/core/js/src/main/scala/AttributeValue.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2020 Fabio Labella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dynosaur

import scala.scalajs.js
import scala.scalajs.js.typedarray.Uint8Array

@js.native
trait AttributeValue extends js.Object {
def S: js.UndefOr[String] = js.native
def N: js.UndefOr[String] = js.native
def B: js.UndefOr[Uint8Array] = js.native
def SS: js.UndefOr[js.Array[String]] = js.native
def NS: js.UndefOr[js.Array[String]] = js.native
def BS: js.UndefOr[js.Array[Uint8Array]] = js.native
def M: js.UndefOr[js.Dictionary[AttributeValue]] = js.native
def L: js.UndefOr[js.Array[AttributeValue]] = js.native
def NULL: js.UndefOr[Boolean] = js.native
def BOOL: js.UndefOr[Boolean] = js.native
def $unknown: js.UndefOr[js.Tuple2[String, js.Any]] = js.native
}

object AttributeValue {
val NULL: AttributeValue =
js.Dynamic.literal(NULL = true).asInstanceOf[AttributeValue]
def BOOL(value: Boolean): AttributeValue =
js.Dynamic.literal(BOOL = value).asInstanceOf[AttributeValue]
def S(value: String): AttributeValue =
js.Dynamic.literal(S = value).asInstanceOf[AttributeValue]
def N(value: String): AttributeValue =
js.Dynamic.literal(N = value).asInstanceOf[AttributeValue]
def B(value: Uint8Array): AttributeValue =
js.Dynamic.literal(B = value).asInstanceOf[AttributeValue]
def M(value: js.Dictionary[AttributeValue]): AttributeValue =
js.Dynamic.literal(M = value).asInstanceOf[AttributeValue]
def L(value: js.Array[AttributeValue]): AttributeValue =
js.Dynamic.literal(L = value).asInstanceOf[AttributeValue]
def SS(value: js.Array[String]): AttributeValue =
js.Dynamic.literal(SS = value).asInstanceOf[AttributeValue]
def NS(value: js.Array[String]): AttributeValue =
js.Dynamic.literal(NS = value).asInstanceOf[AttributeValue]
def BS(value: js.Array[Uint8Array]): AttributeValue =
js.Dynamic.literal(BS = value).asInstanceOf[AttributeValue]
}
Loading

0 comments on commit 8f936a0

Please sign in to comment.