Scala-TS

Logo

Simple tool to transpile Scala datamodel

View the Project on GitHub scala-ts/scala-ts

Configuration

Scala-TS can be configured in many ways.

Compiler settings

The Scala code base to be considered to generate TypeScript from can be filtered using the following build options.

A rule set such as compilationRuleSet is described with multiple include and/or excludes rules:

compilationRuleSet {
   includes = [ "ScalaParserSpec\\.scala", "Transpiler.*" ]
   excludes = [ "foo" ]
}

typeRuleSet {
  # Regular expressions on type full names.
  # Can be prefixed with either 'object:' or 'class:' (for class or trait).
  includes = [ "org\\.scalats\\.core\\..*" ]

  excludes = [
    ".*Spec", 
    "ScalaRuntimeFixtures$", 
    "object:.*ScalaParserResults", 
    "FamilyMember(2|3)"
  ]
}

Also the settings can be used from advanced configuration.

javadoc

SBT plugin settings

The compiler plugin settings can be configured as SBT settings, using the scalats prefix; e.g. The scalatsIndent SBT setting corresponds to the compiler plugin setting indent.

scalatsIndent := "\t"

The SBT plugin also has some specific settings.

Since SBT 1.5, the slash syntax must be used; e.g. scalatsOnCompile / sourceManaged.

The following utilities are provided to ease setting up the printer prelude.

// In memory prelude
scalatsPrinterPrelude := scalatsPrinterInMemoryPrelude(
  "line 1",
  "line 2",
  "...",
  "line N")

// Or, from file/URL
scalatsPrinterPrelude := scalatsPrinterUrlPrelude(
  (baseDirectory.value / "project" / "prelude.ts").toURI.toURL)

More than the prelude, the printer can be further customized through the scalatsPrinter settings, with the utilities provided along the SBT plugin.

scalatsPrinter := scalatsSingleFilePrinter

scalatsPrinter := scalatsSingleFilePrinter // Default single file 'scala.ts'

scalatsPrinter := scalatsPrinterForClass[CustomPrinter]()

Optionally the following argument can be passed.

Advanced settings

TODO

When specifying classes for the advanced settings (such as typeMappers), the classes must be loadable in the classloader for the compiler plugins (different from either the SBT/SBT plugins own classpath or the classpath to compile the Scala sources).

The Scala version for the compiler plugins must be the same as the one for the sources to be compiled (cf scalaVersion SBT setting).

As long as the sources and the SBT Scala versions are the same (for SBT 1.x, Scala 2.12), the classes for the advanced settings can be implemented in project/ directory of the SBT build definition (see example).

If the Scala versions differ, these classes must be provided as cross versions Scala library to be appended to the scalatsAdditionalClass as below.

scalatsAddScalatsDependency("org" %% "name" % "ver")