-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuild.sbt
More file actions
124 lines (109 loc) · 4.84 KB
/
build.sbt
File metadata and controls
124 lines (109 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}
val useScalaVersion = "2.13.14"
val releaseVersion = "1.1.3"
val sharedSettings = Seq(
scalaVersion := useScalaVersion,
version := releaseVersion,
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.8",
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8" % "test",
target := {
// From https://stackoverflow.com/questions/33184731/sbt-crossproject-build-broken-with-custom-compile-target
/* Hacky way to detect whether this is a Scala.js project
* without pulling the Scala.js sbt plugin on the classpath.
*/
val isScalaJS = libraryDependencies.value.exists { dep =>
dep.name.startsWith("scalajs-library") // not tested
}
file("tpParser") / (if (isScalaJS) "js" else "jvm") / "target" / name.value
}
)
lazy val tpParser =
crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Full)
.in(file("tpParser"))
.settings(sharedSettings :+ (name := "TigerPython Parser"))
.jsSettings(
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.9.8"
)
.jvmSettings()
lazy val tpParserModuleJS =
crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Full)
.in(file("tpParser"))
.settings(sharedSettings :+ (name := "TigerPython Parser Module"))
.jsSettings(
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.9.8",
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule) }
)
.jvmSettings()
// Disable tests in the module version because it complains about exporting:
tpParserModuleJS.js / test := {}
// Define the custom task
lazy val makeRelease = taskKey[Unit]("Run fullOptJS on both configurations and copy the output files to the release directory")
makeRelease := {
val log = streams.value.log
// Paths to the output files
val scalaDir = "scala-" + useScalaVersion.split("\\.").slice(0, 2).mkString(".")
val outputPlain = (tpParser.js / target).value / scalaDir / "tigerpython-parser-opt.js"
val outputModule = (tpParserModuleJS.js / target).value / scalaDir / "tigerpython-parser-module-opt.js"
val outputPlainMap = (tpParser.js / target).value / scalaDir / "tigerpython-parser-opt.js.map"
val outputModuleMap = (tpParserModuleJS.js / target).value / scalaDir / "tigerpython-parser-module-opt.js.map"
// Paths to the release directory
val releasePlain = baseDirectory.value / "release" / "tigerpython-parser.js"
val releaseModule = baseDirectory.value / "release" / "tigerpython-parser.mjs"
val releasePlainMap = baseDirectory.value / "release" / "tigerpython-parser.js.map"
val releaseModuleMap = baseDirectory.value / "release" / "tigerpython-parser.mjs.map"
// Run fullOptJS for the configuration without ESModule
log.info("Running fullOptJS for plain and module...")
(tpParser.js / Compile / fullOptJS).value
(tpParserModuleJS.js / Compile / fullOptJS).value
log.info(s"Copying ${outputPlain} to ${releasePlain}...")
IO.copyFile(outputPlain, releasePlain)
log.info(s"Copying ${outputModule} to ${releaseModule}...")
IO.copyFile(outputModule, releaseModule)
// Also copy the map-files, which are needed for debugging
log.info(s"Copying ${outputPlainMap} to ${releasePlainMap}...")
IO.copyFile(outputPlainMap, releasePlainMap)
log.info(s"Copying ${outputModuleMap} to ${releaseModuleMap}...")
IO.copyFile(outputModuleMap, releaseModuleMap)
// Regenerate the package.json and package-lock.json file:
val packageJsonString =
s"""
|{
| "name": "tigerpython-parser",
| "version": "${releaseVersion}",
| "description": "Enhanced error recognition in Python ",
| "main": "release/tigerpython-parser.mjs",
| "types": "tpParser/js/types/index.d.ts",
| "directories": {
| "doc": "doc"
| },
| "scripts": {
| "test": "sbt test",
| "build": "sbt makeRelease"
| },
| "repository": {
| "type": "git",
| "url": "git+https://github.com/Tobias-Kohn/TigerPython-Parser.git"
| },
| "author": "Tobias Kohn",
| "license": "MPL-2.0",
| "bugs": {
| "url": "https://github.com/Tobias-Kohn/TigerPython-Parser/issues"
| },
| "homepage": "https://github.com/Tobias-Kohn/TigerPython-Parser#readme",
| "dependencies": {}
|}
|""".stripMargin
val packageLockJsonString =
s"""
|{
| "name": "tigerpython-parser",
| "version": "${releaseVersion}",
| "lockfileVersion": 1
|}
|""".stripMargin
log.info("Regenerating package.json and package-lock.json")
java.nio.file.Files.writeString(new File("package.json").toPath, packageJsonString, java.nio.charset.StandardCharsets.UTF_8)
java.nio.file.Files.writeString(new File("package-lock.json").toPath, packageLockJsonString, java.nio.charset.StandardCharsets.UTF_8)
}