Skip to content

Commit

Permalink
Cross-compile to Scala.js 1.1+, fixed #5
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-podzigun committed Jul 28, 2021
1 parent e0b4f92 commit ad90327
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 23 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ env:
- secure: Ok8G8xfBIuWs37L+udA7ztnXcWyhg8iHOND9fwbVo49Zt8ZzWrkUKYlatJCS5sHD1RO9jaYTHWpAKsF91Ks/U/uLVDC1S1DVO/ZGCe60diD79vJTA3Je0u6K1EKB0ZJ4v8Yd3pkjq/Oi4Zruv5Ij7xVTNAJtJjxjRHWbv7v7UH7jvcsdaWfZGIYRmjbloxqxesnEdqJk8GJl2VPVtzGk8pqswLMIMo93dZLtAFDWixREP3y0GM8FOm7OFlFWApNFmF9iy7GNaNeSxYP+a1Kw93YLq6raNLpnPCsWXfFU4XlCLbdiMoX7+M5wdjTrBR3J9OoOb+n7ECBn6lBV0xq7MsSKp9gmWhH52pQxc3wnpD00gwZyRKwJNwFutuOgYEhJBQ10oonyXQSk/5ikfFhWlmSk6BA7aYbDLRllHTPA5jv5fHdMPBtVzU1aolm0rprVuB70W807wI0VX+AZ2wNarUmVkIeY4WyOlmdnGmMxzCbkKQ5R0wDFs8tqW6V1g87OXyqLegS8WRgJ7HqiRGkCJbw+yr9oXyh9uU5rDFJ5rAo2CV+zhBvlhbTQdWySBExuO3n3WBJrMgl8Qhlw3Li6WaIcTE4QEzqHEw96Z4wLZvz8vDyldcPC+XQpvYG0aJmBXKIyzUFzd3m/tl8FO1PFfalObgaZtXglIDvZ9O3iVfY=
- secure: M4EAZH5WhJ9VHIlAHr1d0YqrM6bpaeP4meyUmE26ITDSrMaSvwvilTgYkGmADJomlYk1zFV3WXuA2DobdFnqP5ERlqw0uvzKl4P5HEbNUgQ/4tqey3JEQ+TiCd/qVBdtIbN5PH0lkiyVr5Xwd+VWNR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QaP76v3A+dyw+inIFqVn38OrkWHjER2mYnudSu4xmuK5nLoZqFhOeulRIIgDnPyJ4Ufr5M3fM961x75waU+jkliH0fFoIwMaPEaF8o5pVuk4Xcg1s1gQ65lTC9AsA1gXYltgUp6i7TwJpSw7iUqa8p8=
jobs:
- SCALAJS_VERSION=0.6.31
- SCALAJS_VERSION=1.1.0
before_install:
- nvm install 12 &&
nvm use 12
Expand All @@ -24,10 +27,10 @@ script:
if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" -o "$TRAVIS_BRANCH" == "$TRAVIS_TAG" ]; then
if [ -z "$TRAVIS_TAG" ]; then
echo "Publish a snapshot";
sbt ";^^1.0.2 ;clean ;publish";
sbt ";^^1.2.8 ;clean ;publish";
else
echo "Publish a release version=$TRAVIS_TAG";
version=$TRAVIS_TAG sbt ";^^1.0.2 ;clean ;publishSigned ;sonatypeBundleRelease";
version=$TRAVIS_TAG sbt ";^^1.2.8 ;clean ;publishSigned ;sonatypeBundleRelease";
fi
else
echo "This is not a master branch commit. Skipping the publish/release step";
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
[![Build Status](https://travis-ci.com/scommons/sbt-scommons-plugin.svg?branch=master)](https://travis-ci.com/scommons/sbt-scommons-plugin)
[![Coverage Status](https://coveralls.io/repos/github/scommons/sbt-scommons-plugin/badge.svg?branch=master)](https://coveralls.io/github/scommons/sbt-scommons-plugin?branch=master)
[![scala-index](https://index.scala-lang.org/scommons/sbt-scommons-plugin/sbt-scommons-plugin/latest-by-scala-version.svg?targetType=Sbt)](https://index.scala-lang.org/scommons/sbt-scommons-plugin/sbt-scommons-plugin)
[![Scala.js](https://www.scala-js.org/assets/badges/scalajs-0.6.29.svg)](https://www.scala-js.org)
[![Scala.js 0.6](https://www.scala-js.org/assets/badges/scalajs-0.6.29.svg)](https://www.scala-js.org)
[![Scala.js 1.0](https://www.scala-js.org/assets/badges/scalajs-1.1.0.svg)](https://www.scala-js.org)

## sbt-scommons-plugin
Sbt auto-plugins with common tasks/utils for Scala Commons modules
Expand All @@ -12,7 +13,11 @@ Sbt auto-plugins with common tasks/utils for Scala Commons modules
```scala
// inside plugins.sbt

//for Scala.js 1.1+
addSbtPlugin("org.scommons.sbt" % "sbt-scommons-plugin" % [version])

//for Scala.js 0.6.29+
addSbtPlugin("org.scommons.sbt" % "sbt-scommons-plugin-sjs06" % [version])
```

## Documentation
Expand Down
26 changes: 22 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

val ideExcludedDirectories = SettingKey[Seq[File]]("ide-excluded-directories")

val scalaJSVersion =
Option(System.getenv("SCALAJS_VERSION")).getOrElse("0.6.31")

lazy val `sbt-scommons-plugin` = (project in file("."))
.enablePlugins(SbtPlugin)
.settings(
Expand All @@ -12,7 +15,10 @@ lazy val `sbt-scommons-plugin` = (project in file("."))
.settings(
sbtPlugin := true,
organization := "org.scommons.sbt",
name := "sbt-scommons-plugin",
name := {
if (scalaJSVersion.startsWith("0.6")) "sbt-scommons-plugin-sjs06"
else "sbt-scommons-plugin"
},
description := "Sbt auto-plugin with common Scala/Scala.js tasks/utils",
// scalaVersion := "2.12.7",
scalacOptions ++= Seq(
Expand Down Expand Up @@ -43,14 +49,26 @@ lazy val `sbt-scommons-plugin` = (project in file("."))
coverageExcludedPackages := ".*mecha.*;.*project.*",

addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0"),
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.31"),
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler-sjs06" % "0.18.0"),
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion),

if (scalaJSVersion.startsWith("0.6")) {
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler-sjs06" % "0.18.0")
}
else {
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.18.0")
},

//addSbtPlugin("com.storm-enroute" % "mecha" % "0.3"), //TODO: use version for sbt 1.x

libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.2.2" % "test",
"org.scalamock" %% "scalamock" % "4.4.0" % "test"

if (scalaJSVersion.startsWith("0.6")) {
"org.scalamock" %% "scalamock" % "4.4.0" % "test"
}
else {
"org.scalamock" %% "scalamock" % "5.0.0" % "test"
}
),

//resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ trait CommonClientModule extends CommonModule {
object CommonClientModule {

val settings: Seq[Setting[_]] = Seq(
scalaJSModuleKind := ModuleKind.CommonJSModule,

//Opt-in @ScalaJSDefined by default
scalacOptions += "-P:scalajs:sjsDefinedByDefault",
scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.CommonJSModule)
.withSourceMap(false)
.withESFeatures(_.withUseECMAScript2015(false))
},
requireJsDomEnv in Test := false,
version in webpack := "4.29.0",
emitSourceMaps := false,
webpackEmitSourceMaps := false,

npmDependencies in Compile ++= Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ object CommonMobileModule {
"org.scommons.react-native" % "scommons-react-native-test" % "*"
),

scalaJSModuleKind := ModuleKind.CommonJSModule,
scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.CommonJSModule)
.withSourceMap(false)
.withESFeatures(_.withUseECMAScript2015(false))
},
scalaJSUseMainModuleInitializer := false,
webpackBundlingMode := BundlingMode.LibraryOnly(),

//Opt-in @ScalaJSDefined by default
scalacOptions += "-P:scalajs:sjsDefinedByDefault",

// react-native DO NOT require DOM
requireJsDomEnv in Test := false,
version in webpack := "3.5.5", //TODO: migrate to 4.29.0
emitSourceMaps := false,
webpackEmitSourceMaps := false,

npmDependencies in Compile ++= Seq(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package scommons.sbtplugin.project

import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport.scalaJSVersion
import sbt._

trait CommonTestLibs {

val scalaTestVersion = "3.2.2"
val scalaTestPlusMockitoVersion = "3.2.2.0"
val scalaTestPlusPlayVersion = "5.1.0"
val scalaMockVersion = "4.4.0"
val scalaMockVersion: String =
if (scalaJSVersion.startsWith("0.6")) "4.4.0"
else "5.0.0"
val dockerTestkitVersion = "0.9.9"

val akkaVersion: String = CommonLibs.akkaVersion
Expand Down
8 changes: 5 additions & 3 deletions src/sbt-test/sbt-scommons-plugin/simple/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ lazy val client = (project in file("client"))
scommonsBundlesFileFilter := "*.sql",

//scala.js specific settings
//scalaJSModuleKind := ModuleKind.CommonJSModule,
scalaJSLinkerConfig ~= {
//_.withModuleKind(ModuleKind.CommonJSModule)
_.withSourceMap(false)
.withESFeatures(_.withUseECMAScript2015(false))
},
scalaJSUseMainModuleInitializer := true,
//webpackBundlingMode := BundlingMode.LibraryOnly(),
version in webpack := "4.29.0",
webpackConfigFile in fastOptJS := Some(baseDirectory.value / "client.webpack.config.js"),
webpackConfigFile in fullOptJS := Some(baseDirectory.value / "client.webpack.config.js"),
scommonsRequireWebpackInTest := true,
webpackConfigFile in Test := Some(baseDirectory.value / "test.webpack.config.js"),

emitSourceMaps := false,
webpackEmitSourceMaps := false,

npmDevDependencies in Compile ++= Seq(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@

package scommons.sbtplugin.test

import scala.scalajs.js.annotation.JSExport

object Main {

@JSExport
def main(args: Array[String]): Unit = {
println(s"test: ${MainCss.test}, test_btn: ${MainCss.test_btn}")
}
Expand Down
18 changes: 16 additions & 2 deletions src/sbt-test/sbt-scommons-plugin/simple/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@

resolvers += "Local Maven Repository" at "file://" + Path.userHome.absolutePath + "/.m2/repository"

val scalaJSVersion =
Option(System.getenv("SCALAJS_VERSION")).getOrElse("0.6.31")

//addSbtPlugin("org.scommons.sbt" % "sbt-scommons-plugin" % "0.1.0-SNAPSHOT")
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("org.scommons.sbt" % "sbt-scommons-plugin" % x)
case Some(x) =>
if (scalaJSVersion.startsWith("0.6")) {
addSbtPlugin("org.scommons.sbt" % "sbt-scommons-plugin-sjs06" % x)
}
else {
addSbtPlugin("org.scommons.sbt" % "sbt-scommons-plugin" % x)
}
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.8")

addSbtPlugin("ch.epfl.scala" % "sbt-web-scalajs-bundler-sjs06" % "0.18.0")
if (scalaJSVersion.startsWith("0.6")) {
addSbtPlugin("ch.epfl.scala" % "sbt-web-scalajs-bundler-sjs06" % "0.18.0")
}
else {
addSbtPlugin("ch.epfl.scala" % "sbt-web-scalajs-bundler" % "0.18.0")
}

0 comments on commit ad90327

Please sign in to comment.