-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sbt
158 lines (135 loc) · 5.69 KB
/
build.sbt
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import java.nio.file.{Files, Paths, StandardCopyOption}
import scala.sys.process._
import sbtcrossproject.CrossPlugin.autoImport.{CrossType, crossProject}
lazy val cloudformation = project
.in(file("."))
.aggregate(
languageServer.jvm,
languageServer.js,
browserLanguageServer
)
lazy val commonSettings = Seq(
version := "1.0",
resolvers += "dhpcs at bintray" at "https://dl.bintray.com/dhpcs/maven",
logLevel := Level.Info,
logBuffered in Test := false,
scalaVersion := "2.13.1",
scalacOptions += "-deprecation",
scalacOptions += "-feature",
scalacOptions += "-language:implicitConversions",
scalacOptions += "-language:postfixOps",
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.1.0" % "test"
)
lazy val assemblySettings = Seq(
assemblyJarName in assembly := name.value + ".jar",
test in assembly := {},
assemblyMergeStrategy in assembly := {
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case _ => MergeStrategy.first
}
)
def languageServerCommonTask(assemblyFile: String) = {
val extensionPath = Paths.get(".", "vscode-extension")
val outPath = extensionPath.resolve("out")
outPath.toFile.mkdir()
outPath.resolve("CloudFormationLanguageServer.jar").toFile.delete()
val extension = assemblyFile.split("\\.").last
Files.copy(Paths.get(assemblyFile),
outPath.resolve(s"CloudFormationLanguageServer.$extension"), StandardCopyOption.REPLACE_EXISTING)
val cfnSpecification = Paths.get(".", "CloudFormationResourceSpecification.json")
Files.copy(cfnSpecification,
outPath.resolve("CloudFormationResourceSpecification.json"), StandardCopyOption.REPLACE_EXISTING)
val yarn = Process(enableForWindows(Seq("yarn", "compile")), file("./vscode-extension"))
yarn
}
def enableForWindows(parts: Seq[String]): Seq[String] = {
val os = sys.props("os.name").toLowerCase
os match {
case x if x contains "windows" => Seq("cmd", "/C") ++ parts
case _ => parts
}
}
def vscodeCommonTask(assemblyFile: String) = {
val extensionDirectory = file("./vscode-extension").getAbsolutePath
val vscode = Process(Seq("code", s"--extensionDevelopmentPath=$extensionDirectory"), None)
languageServerCommonTask(assemblyFile).#&&(vscode)
}
lazy val languageServer = crossProject(JVMPlatform, JSPlatform).
crossType(CrossType.Full).
in(file("languageServer")).
settings(commonSettings: _*).
jvmSettings(assemblySettings: _*).
jvmSettings(
fastvscode := {
vscodeCommonTask(assembly.value.getAbsolutePath).run
},
vscodeprepublish := {
val assemblyFile: String = assembly.value.getAbsolutePath
val extensionPath = Paths.get(".", "vscode-extension")
val outPath = extensionPath.resolve("out")
Files.copy(Paths.get(assemblyFile),
outPath.resolve("CloudFormationLanguageServer.jar"), StandardCopyOption.REPLACE_EXISTING)
},
fullvscode := {
vscodeCommonTask(assembly.value.getAbsolutePath).run
}
).
jsSettings(
scalaJSUseMainModuleInitializer := true,
scalaJSModuleKind := ModuleKind.CommonJSModule,
fastvscode := {
val assemblyFile: String = (fastOptJS in Compile).value.data.getAbsolutePath
vscodeCommonTask(assemblyFile).run
},
vscodeprepublish := {
val extensionPath = Paths.get(".", "vscode-extension")
val outPath = extensionPath.resolve("out")
val assemblyFile: String = (fullOptJS in Compile).value.data.getAbsolutePath
Files.copy(Paths.get(assemblyFile),
outPath.resolve("CloudFormationLanguageServer.js"), StandardCopyOption.REPLACE_EXISTING)
val resourceSpecificationFile = Paths.get(".", "CloudFormationResourceSpecification.json")
Files.copy(resourceSpecificationFile,
outPath.resolve(resourceSpecificationFile.getFileName), StandardCopyOption.REPLACE_EXISTING)
},
fullvscode := {
val assemblyFile: String = (fullOptJS in Compile).value.data.getAbsolutePath
vscodeCommonTask(assemblyFile).run
}).
settings(
name := "languageServer",
mainClass in Compile := Some("cloudformation.Program"),
// https://mvnrepository.com/artifact/com.typesafe.play/play-json
libraryDependencies += "com.lihaoyi" %%% "upickle" % "0.8.0",
// https://mvnrepository.com/artifact/com.github.keyboardDrummer/modularlanguages
libraryDependencies += "com.github.keyboardDrummer" %%% "modularlanguages" % "0.1.4"
)
lazy val fastvscode = taskKey[Unit]("Run VS Code Fast")
lazy val vscodeprepublish = taskKey[Unit]("Build VS Code")
lazy val fullvscode = taskKey[Unit]("Run VS Code Optimized")
def browserLanguageServerCommonTask(assemblyFile: String) = {
val copy = Process(Seq("cp", assemblyFile, "./browserClientExample/localDependency/server.js"))
val yarn = Process(Seq("yarn", "dev"), file("./browserClientExample"))
copy.#&&(yarn)
}
lazy val browserLanguageServer = project.
in(file("browserLanguageServer")).
enablePlugins(ScalaJSPlugin).
settings(commonSettings: _*).
settings(
fastbrowser := {
val assemblyFile: String = (fastOptJS in Compile).value.data.getAbsolutePath
browserLanguageServerCommonTask(assemblyFile).run
},
fullbrowser := {
val assemblyFile: String = (fullOptJS in Compile).value.data.getAbsolutePath
browserLanguageServerCommonTask(assemblyFile).run
}).
settings(
name := "browserLanguageServer",
scalaJSUseMainModuleInitializer := false,
scalaJSModuleKind := ModuleKind.CommonJSModule,
// https://mvnrepository.com/artifact/com.typesafe.play/play-json
libraryDependencies += "com.lihaoyi" %%% "upickle" % "0.8.0"
).dependsOn(languageServer.js)
lazy val fastbrowser = taskKey[Unit]("Run Browser Example Fast")
lazy val fullbrowser = taskKey[Unit]("Run Browser Example Optimized")