org.scalajs.sbtplugin.ScalaJSPlugin Scala Examples

The following examples show how to use org.scalajs.sbtplugin.ScalaJSPlugin. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: Lib.scala    From nyaya   with GNU Lesser General Public License v2.1 5 votes vote down vote up
import sbt._
import Keys._
import com.typesafe.sbt.pgp.PgpKeys._
import org.scalajs.sbtplugin.ScalaJSPlugin
import sbtcrossproject.CrossProject
import ScalaJSPlugin.autoImport._
import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._
import sbtcrossproject.CrossPlugin.autoImport._
import scalajscrossproject.ScalaJSCrossPlugin.autoImport._
import scala.language.implicitConversions

object Lib {
  type CPE = CrossProject => CrossProject
  type PE = Project => Project

  class ConfigureBoth(val jvm: PE, val js: PE) {
    def jvmConfigure(f: PE) = new ConfigureBoth(f compose jvm, js)
    def  jsConfigure(f: PE) = new ConfigureBoth(jvm, f compose js)
  }

  def ConfigureBoth(both: PE) = new ConfigureBoth(both, both)

  implicit def _configureBothToCPE(p: ConfigureBoth): CPE =
    _.jvmConfigure(p.jvm).jsConfigure(p.js)

  def addCommandAliases(m: (String, String)*): PE = {
    val s = m.map(p => addCommandAlias(p._1, p._2)).reduce(_ ++ _)
    _.settings(s: _*)
  }

  implicit class CrossProjectExt(val cp: CrossProject) extends AnyVal {
    def bothConfigure(fs: PE*): CrossProject =
      fs.foldLeft(cp)((q, f) =>
        q.jvmConfigure(f).jsConfigure(f))
  }
  implicit def CrossProjectExtB(b: CrossProject.Builder) =
    new CrossProjectExt(b)

  def publicationSettings(ghProject: String) =
    ConfigureBoth(
      _.settings(
        publishTo := {
          val nexus = "https://oss.sonatype.org/"
          if (isSnapshot.value)
            Some("snapshots" at nexus + "content/repositories/snapshots")
          else
            Some("releases"  at nexus + "service/local/staging/deploy/maven2")
        },
        pomExtra :=
          <scm>
            <connection>scm:git:github.com/japgolly/{ghProject}</connection>
            <developerConnection>scm:git:[email protected]:japgolly/{ghProject}.git</developerConnection>
            <url>github.com:japgolly/{ghProject}.git</url>
          </scm>
          <developers>
            <developer>
              <id>japgolly</id>
              <name>David Barri</name>
            </developer>
          </developers>))
    .jsConfigure(
      sourceMapsToGithub(ghProject))

  def sourceMapsToGithub(ghProject: String): PE =
    p => p.settings(
      scalacOptions ++= (if (isSnapshot.value) Seq.empty else Seq({
        val a = p.base.toURI.toString.replaceFirst("[^/]+/?$", "")
        val g = s"https://raw.githubusercontent.com/japgolly/$ghProject"
        s"-P:scalajs:mapSourceURI:$a->$g/v${version.value}/"
      }))
    )

  def preventPublication: PE =
    _.settings(
      publish            := {},
      publishLocal       := {},
      publishSigned      := {},
      publishLocalSigned := {},
      publishArtifact    := false,
      publishTo          := Some(Resolver.file("Unused transient repository", target.value / "fakepublish")),
      packagedArtifacts  := Map.empty)
    // .disablePlugins(plugins.IvyPlugin)
} 
Example 2
Source File: ReactiveBuild.scala    From Principles-of-Reactive-Programming   with GNU General Public License v3.0 5 votes vote down vote up
import sbt._
import Keys._
import ch.epfl.lamp.CourseraBuild
import ch.epfl.lamp.SbtCourseraPlugin.autoImport._

import org.scalajs.sbtplugin.ScalaJSPlugin
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._

object ProgfunBuild extends CourseraBuild {
  override def assignmentSettings: Seq[Setting[_]] = Seq(
    // This setting allows to restrict the source files that are compiled and tested
    // to one specific project. It should be either the empty string, in which case all
    // projects are included, or one of the project names from the projectDetailsMap.
    currentProject := "",

    // Packages in src/main/scala that are used in every project. Included in every
    // handout, submission.
    commonSourcePackages += "common",

    // Packages in src/test/scala that are used for grading projects. Always included
    // compiling tests, grading a project.

    libraryDependencies += "ch.epfl.lamp" %% "scala-grading-runtime" % "0.1",

    // Files that we hand out to the students
    handoutFiles <<= (baseDirectory, projectDetailsMap, commonSourcePackages) map {
      (basedir, detailsMap, commonSrcs) =>
      (projectName: String) => {
        val details = detailsMap.getOrElse(projectName, sys.error("Unknown project name: "+ projectName))
        val commonFiles = (PathFinder.empty /: commonSrcs)((files, pkg) =>
          files +++ (basedir / "src" / "main" / "scala" / pkg ** "*.scala")
        )
        val forAll = {
          (basedir / "src" / "main" / "scala" / details.packageName ** "*.scala") +++
          commonFiles +++
          (basedir / "src" / "main" / "resources" / details.packageName / "*") +++
          (basedir / "src" / "test" / "scala" / details.packageName ** "*.scala") +++
          (basedir / "build.sbt") +++
          (basedir / "project" / "build.properties") +++
          (basedir / "project" ** ("*.scala" || "*.sbt")) +++
          (basedir / "project" / "scalastyle_config_reactive.xml") +++
          (basedir / "lib_managed" ** "*.jar") +++
          (basedir * (".classpath" || ".project")) +++
          (basedir / ".settings" / "org.scala-ide.sdt.core.prefs")
        }
        if (projectName == "calculator") {
          forAll +++
          (basedir / "webui.sbt") +++
          (basedir / "web-ui" / "index.html") +++
          (basedir / "web-ui" / "src" / "main" / "scala" ** "*.scala")
        } else
          forAll
      }
    })
} 
Example 3
Source File: ReactiveBuild.scala    From Principles-of-Reactive-Programming   with GNU General Public License v3.0 5 votes vote down vote up
import sbt._
import Keys._
import ch.epfl.lamp.CourseraBuild
import ch.epfl.lamp.SbtCourseraPlugin.autoImport._

import org.scalajs.sbtplugin.ScalaJSPlugin
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._

object ProgfunBuild extends CourseraBuild {
  override def assignmentSettings: Seq[Setting[_]] = Seq(
    // This setting allows to restrict the source files that are compiled and tested
    // to one specific project. It should be either the empty string, in which case all
    // projects are included, or one of the project names from the projectDetailsMap.
    currentProject := "",

    // Packages in src/main/scala that are used in every project. Included in every
    // handout, submission.
    commonSourcePackages += "common",

    // Packages in src/test/scala that are used for grading projects. Always included
    // compiling tests, grading a project.

    libraryDependencies += "ch.epfl.lamp" %% "scala-grading-runtime" % "0.1",

    // Files that we hand out to the students
    handoutFiles <<= (baseDirectory, projectDetailsMap, commonSourcePackages) map {
      (basedir, detailsMap, commonSrcs) =>
      (projectName: String) => {
        val details = detailsMap.getOrElse(projectName, sys.error("Unknown project name: "+ projectName))
        val commonFiles = (PathFinder.empty /: commonSrcs)((files, pkg) =>
          files +++ (basedir / "src" / "main" / "scala" / pkg ** "*.scala")
        )
        val forAll = {
          (basedir / "src" / "main" / "scala" / details.packageName ** "*.scala") +++
          commonFiles +++
          (basedir / "src" / "main" / "resources" / details.packageName / "*") +++
          (basedir / "src" / "test" / "scala" / details.packageName ** "*.scala") +++
          (basedir / "build.sbt") +++
          (basedir / "project" / "build.properties") +++
          (basedir / "project" ** ("*.scala" || "*.sbt")) +++
          (basedir / "project" / "scalastyle_config_reactive.xml") +++
          (basedir / "lib_managed" ** "*.jar") +++
          (basedir * (".classpath" || ".project")) +++
          (basedir / ".settings" / "org.scala-ide.sdt.core.prefs")
        }
        if (projectName == "calculator") {
          forAll +++
          (basedir / "webui.sbt") +++
          (basedir / "web-ui" / "index.html") +++
          (basedir / "web-ui" / "src" / "main" / "scala" ** "*.scala")
        } else
          forAll --- (basedir / "src" / "test" / "scala" / "kvstore" / "given" ***)
      }
    })
} 
Example 4
Source File: ReactiveBuild.scala    From Principles-of-Reactive-Programming   with GNU General Public License v3.0 5 votes vote down vote up
import sbt._
import Keys._
import ch.epfl.lamp.CourseraBuild
import ch.epfl.lamp.SbtCourseraPlugin.autoImport._

import org.scalajs.sbtplugin.ScalaJSPlugin
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._

object ProgfunBuild extends CourseraBuild {
  override def assignmentSettings: Seq[Setting[_]] = Seq(
    // This setting allows to restrict the source files that are compiled and tested
    // to one specific project. It should be either the empty string, in which case all
    // projects are included, or one of the project names from the projectDetailsMap.
    currentProject := "",

    // Packages in src/main/scala that are used in every project. Included in every
    // handout, submission.
    commonSourcePackages += "common",

    // Packages in src/test/scala that are used for grading projects. Always included
    // compiling tests, grading a project.

    libraryDependencies += "ch.epfl.lamp" %% "scala-grading-runtime" % "0.1",

    // Files that we hand out to the students
    handoutFiles <<= (baseDirectory, projectDetailsMap, commonSourcePackages) map {
      (basedir, detailsMap, commonSrcs) =>
      (projectName: String) => {
        val details = detailsMap.getOrElse(projectName, sys.error("Unknown project name: "+ projectName))
        val commonFiles = (PathFinder.empty /: commonSrcs)((files, pkg) =>
          files +++ (basedir / "src" / "main" / "scala" / pkg ** "*.scala")
        )
        val forAll = {
          (basedir / "src" / "main" / "scala" / details.packageName ** "*.scala") +++
          commonFiles +++
          (basedir / "src" / "main" / "resources" / details.packageName / "*") +++
          (basedir / "src" / "test" / "scala" / details.packageName ** "*.scala") +++
          (basedir / "build.sbt") +++
          (basedir / "project" / "build.properties") +++
          (basedir / "project" ** ("*.scala" || "*.sbt")) +++
          (basedir / "project" / "scalastyle_config_reactive.xml") +++
          (basedir / "lib_managed" ** "*.jar") +++
          (basedir * (".classpath" || ".project")) +++
          (basedir / ".settings" / "org.scala-ide.sdt.core.prefs")
        }
        if (projectName == "calculator") {
          forAll +++
          (basedir / "webui.sbt") +++
          (basedir / "web-ui" / "index.html") +++
          (basedir / "web-ui" / "src" / "main" / "scala" ** "*.scala")
        } else
          forAll
      }
    })
} 
Example 5
Source File: ReactiveBuild.scala    From Principles-of-Reactive-Programming   with GNU General Public License v3.0 5 votes vote down vote up
import sbt._
import Keys._
import ch.epfl.lamp.CourseraBuild
import ch.epfl.lamp.SbtCourseraPlugin.autoImport._

import org.scalajs.sbtplugin.ScalaJSPlugin
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._

object ProgfunBuild extends CourseraBuild {
  override def assignmentSettings: Seq[Setting[_]] = Seq(
    // This setting allows to restrict the source files that are compiled and tested
    // to one specific project. It should be either the empty string, in which case all
    // projects are included, or one of the project names from the projectDetailsMap.
    currentProject := "",

    // Packages in src/main/scala that are used in every project. Included in every
    // handout, submission.
    commonSourcePackages += "common",

    // Packages in src/test/scala that are used for grading projects. Always included
    // compiling tests, grading a project.

    libraryDependencies += "ch.epfl.lamp" %% "scala-grading-runtime" % "0.1",

    // Files that we hand out to the students
    handoutFiles <<= (baseDirectory, projectDetailsMap, commonSourcePackages) map {
      (basedir, detailsMap, commonSrcs) =>
      (projectName: String) => {
        val details = detailsMap.getOrElse(projectName, sys.error("Unknown project name: "+ projectName))
        val commonFiles = (PathFinder.empty /: commonSrcs)((files, pkg) =>
          files +++ (basedir / "src" / "main" / "scala" / pkg ** "*.scala")
        )
        val forAll = {
          (basedir / "src" / "main" / "scala" / details.packageName ** "*.scala") +++
          commonFiles +++
          (basedir / "src" / "main" / "resources" / details.packageName / "*") +++
          (basedir / "src" / "test" / "scala" / details.packageName ** "*.scala") +++
          (basedir / "build.sbt") +++
          (basedir / "project" / "build.properties") +++
          (basedir / "project" ** ("*.scala" || "*.sbt")) +++
          (basedir / "project" / "scalastyle_config_reactive.xml") +++
          (basedir / "lib_managed" ** "*.jar") +++
          (basedir * (".classpath" || ".project")) +++
          (basedir / ".settings" / "org.scala-ide.sdt.core.prefs")
        }
        if (projectName == "calculator") {
          forAll +++
          (basedir / "webui.sbt") +++
          (basedir / "web-ui" / "index.html") +++
          (basedir / "web-ui" / "src" / "main" / "scala" ** "*.scala")
        } else
          forAll
      }
    })
} 
Example 6
Source File: ReactiveBuild.scala    From Principles-of-Reactive-Programming   with GNU General Public License v3.0 5 votes vote down vote up
import sbt._
import Keys._
import ch.epfl.lamp.CourseraBuild
import ch.epfl.lamp.SbtCourseraPlugin.autoImport._

import org.scalajs.sbtplugin.ScalaJSPlugin
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._

object ProgfunBuild extends CourseraBuild {
  override def assignmentSettings: Seq[Setting[_]] = Seq(
    // This setting allows to restrict the source files that are compiled and tested
    // to one specific project. It should be either the empty string, in which case all
    // projects are included, or one of the project names from the projectDetailsMap.
    currentProject := "",

    // Packages in src/main/scala that are used in every project. Included in every
    // handout, submission.
    commonSourcePackages += "common",

    // Packages in src/test/scala that are used for grading projects. Always included
    // compiling tests, grading a project.

    libraryDependencies += "ch.epfl.lamp" %% "scala-grading-runtime" % "0.1",

    // Files that we hand out to the students
    handoutFiles <<= (baseDirectory, projectDetailsMap, commonSourcePackages) map {
      (basedir, detailsMap, commonSrcs) =>
      (projectName: String) => {
        val details = detailsMap.getOrElse(projectName, sys.error("Unknown project name: "+ projectName))
        val commonFiles = (PathFinder.empty /: commonSrcs)((files, pkg) =>
          files +++ (basedir / "src" / "main" / "scala" / pkg ** "*.scala")
        )
        val forAll = {
          (basedir / "src" / "main" / "scala" / details.packageName ** "*.scala") +++
          commonFiles +++
          (basedir / "src" / "main" / "resources" / details.packageName / "*") +++
          (basedir / "src" / "test" / "scala" / details.packageName ** "*.scala") +++
          (basedir / "build.sbt") +++
          (basedir / "project" / "build.properties") +++
          (basedir / "project" ** ("*.scala" || "*.sbt")) +++
          (basedir / "project" / "scalastyle_config_reactive.xml") +++
          (basedir / "lib_managed" ** "*.jar") +++
          (basedir * (".classpath" || ".project")) +++
          (basedir / ".settings" / "org.scala-ide.sdt.core.prefs")
        }
        if (projectName == "calculator") {
          forAll +++
          (basedir / "webui.sbt") +++
          (basedir / "web-ui" / "index.html") +++
          (basedir / "web-ui" / "src" / "main" / "scala" ** "*.scala")
        } else
          forAll
      }
    })
} 
Example 7
Source File: TravisScalaJs.scala    From sbt-best-practice   with Apache License 2.0 5 votes vote down vote up
package com.thoughtworks.sbtBestPractice.travis

import sbt._
import org.scalajs.sbtplugin.ScalaJSPlugin
import scala.language.reflectiveCalls


object TravisScalaJs extends AutoPlugin {
  private def reflectiveLinkerSetting[
      StandardConfig <: {
        def withBatchMode(batchMode: Boolean): StandardConfig
      }
  ](key: SettingKey[StandardConfig]): Def.Setting[StandardConfig] = {
    key := {
      key.value.withBatchMode(Travis.travisRepoSlug.?.value.isDefined)
    }
  }

  private def scalaJSLinkerConfig06[
      StandardConfig <: {
        def withBatchMode(batchMode: Boolean): StandardConfig
      }
  ] = {
    // The type of ScalaJSPlugin v0.6
    type ScalaJSPlugin06 = {
      def autoImport: {
        def scalaJSLinkerConfig: SettingKey[StandardConfig]
      }
    }
    ScalaJSPlugin.asInstanceOf[ScalaJSPlugin06].autoImport.scalaJSLinkerConfig
  }

  override def projectSettings: Seq[Def.Setting[_]] = {
    Seq(try {
      // sbt-scalajs 1.x
      reflectiveLinkerSetting(ScalaJSPlugin.autoImport.scalaJSLinkerConfig)
    } catch {
      case _: NoClassDefFoundError =>
        // sbt-scalajs 0.6.x
        reflectiveLinkerSetting(scalaJSLinkerConfig06)
    })
  }

  override def requires = {
    try {
      ScalaJSPlugin && Travis
    } catch {
      case _: NoClassDefFoundError =>
        Travis
    }
  }

  override def trigger = {
    if (requires == Travis) {
      noTrigger
    } else {
      allRequirements
    }
  }
} 
Example 8
Source File: ChromeSbtPlugin.scala    From scala-js-chrome   with MIT License 5 votes vote down vote up
package net.lullabyte

import chrome.Manifest
import org.scalajs.sbtplugin.ScalaJSPlugin
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
import sbt.Keys._
import sbt._

object ChromeSbtPlugin extends AutoPlugin {

  override def requires: Plugins = ScalaJSPlugin

  object autoImport {

    val chromeUnpackedOpt = TaskKey[File]("chromeUnpackedOpt")
    val chromeUnpackedFast = TaskKey[File]("chromeUnpackedFast")
    val chromePackage = TaskKey[File]("chromePackage")
    val chromeGenerateManifest = TaskKey[File]("chromeGenerateManifest")
    val chromeManifest = TaskKey[Manifest]("chromeManifest")
    val fullOptJsLib = TaskKey[Attributed[File]]("fullOptJsLib")
    val fastOptJsLib = TaskKey[Attributed[File]]("fastOptJsLib")

    private val chromeDir = "chrome"

    lazy val baseSettings: Seq[Def.Setting[_]] = Seq(
      fastOptJsLib := (fastOptJS in Compile).value,
      chromeUnpackedFast := {
        Chrome.buildUnpackedDirectory(target.value / chromeDir / "unpacked-fast")(
          (chromeGenerateManifest in Compile).value,
          fastOptJsLib.value.data,
          (packageJSDependencies in Compile).value,
          (resourceDirectories in Compile).value
        )
      },
      fullOptJsLib := (fullOptJS in Compile).value,
      chromeUnpackedOpt := {
        Chrome.buildUnpackedDirectory(target.value / chromeDir / "unpacked-opt")(
          (chromeGenerateManifest in Compile).value,
          fullOptJsLib.value.data,
          (packageMinifiedJSDependencies in Compile).value,
          (resourceDirectories in Compile).value
        )
      },
      chromePackage := {
        val out = target.value / chromeDir
        val chromeAppDir = chromeUnpackedOpt.value
        val zipFile = new File(out, s"${name.value}.zip")
        val excludeFileNames = Set(
          ".DS_Store"
        )
        val fileFilter = AllPassFilter - new SimpleFilter(excludeFileNames.contains)
        IO.zip(Path.selectSubpaths(chromeAppDir, fileFilter), zipFile)
        zipFile
      },
      chromeGenerateManifest := {
        Chrome.generateManifest(target.value / chromeDir / "generated_manifest.json")(
          (chromeManifest in Compile).value
        )
      }
    )

  }


  import autoImport._

  override val projectSettings = baseSettings

} 
Example 9
Source File: ConfigPlugin.scala    From sbt-node   with MIT License 5 votes vote down vote up
//     Project: sbt-node
//      Module:
// Description:
package de.surfice.sbtnpm

import java.io.{File => _, _}
import java.net.JarURLConnection

import sbt.{Def, _}
import Keys._
import com.typesafe.config.{Config, ConfigFactory}
import org.scalajs.sbtplugin.ScalaJSPlugin
import sbt.impl.DependencyBuilders

object ConfigPlugin extends AutoPlugin {

  override val requires: Plugins = ScalaJSPlugin

  object autoImport {

    val npmProjectConfig: TaskKey[Config] =
      taskKey[Config]("Configuration loaded from package.conf files in libraries")

    val npmProjectConfigString: TaskKey[String] =
      taskKey[String]("Concatenation of all package.conf and project.conf files")

    val npmProjectConfigFile: SettingKey[File] =
      settingKey[File]("Project configuration file")
  }

  import autoImport._


  override def projectSettings: Seq[Def.Setting[_]] = Seq(
    libraryDependencies += DepBuilder.toGroupID("de.surfice") %% "sbt-node-config" % Versions.sbtNode,

    npmProjectConfigFile := baseDirectory.value / "project.conf",

    npmProjectConfigString :=
      loadPackageConfigs((dependencyClasspath in Compile).value, npmProjectConfigFile.value)
        .foldLeft(""){ (s,in) =>
          s + "# SOURCE: "+in._1+"\n"+
            IO.readLines(new BufferedReader(new InputStreamReader(in._2))).mkString("\n") + "\n\n"
        },

    npmProjectConfig :=
      ConfigFactory.parseString(npmProjectConfigString.value).resolve()

  )
  private def loadPackageConfigs(dependencyClasspath: Classpath, projectConfig: File): Seq[(String,InputStream)] =
    loadDepPackageConfigs(dependencyClasspath) ++ loadProjectConfig(projectConfig)

  private def loadProjectConfig(projectConfig: File): Option[(String,InputStream)] =
    if(projectConfig.canRead)
      Some((projectConfig.getAbsolutePath,fin(projectConfig)))
    else None

  private def loadDepPackageConfigs(cp: Classpath): Seq[(String,InputStream)] = {
    val (dirs,jars) = cp.files.partition(_.isDirectory)
    loadJarPackageConfigs(jars) // ++ loadDirPackageConfigs(dirs,log)
  }

  private def loadJarPackageConfigs(jars: Seq[File]): Seq[(String,InputStream)] = {
    val files = jars
      .map( f => (f.getName, new URL("jar:" + f.toURI + "!/package.conf").openConnection()) )
      .map {
        case (f,c: JarURLConnection) => try{
          Some((f,c.getInputStream))
        } catch {
          case _: FileNotFoundException => None
        }
      }
      .collect{
        case Some(in) => in
      }
      // ensure that default configuration provided by sbt-node is loaded first
      .partition(_._1.startsWith("sbt-node-config_"))
    files._1 ++ files._2
  }


  private def fin(file: File): BufferedInputStream = new BufferedInputStream(new FileInputStream(file))

  private object DepBuilder extends DependencyBuilders
}