-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sbt
156 lines (136 loc) · 4.79 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
name := "open-spaces-board"
organization := "com.wintertechforum"
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.13.14"
libraryDependencies += guice
libraryDependencies += ws
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0" % Test
val elmMakeAdmin = taskKey[Seq[File]]("elm-make-admin")
elmMakeAdmin := {
import scala.sys.process._
import com.typesafe.sbt.web.LineBasedProblem
import play.sbt.PlayExceptions.CompilationException
val outputPath: String = "public/javascripts/admin.js"
val debugFlag: String =
if (sys.props.getOrElse("elm.debug", "false").toLowerCase != "true") ""
else "--debug"
var outErrLines: List[String] = Nil
var srcFilePath: Option[String] = None
var lineNum: Option[String] = None
var offset: Option[String] = None
Seq(
"bash", "-c",
"elm-make " +
(file("app/assets/javascripts/Admin") ** "*.elm").get.mkString(" ") +
s" --output ${outputPath} " +
s"--yes ${debugFlag} --warn"
).!(
new ProcessLogger {
override def out(s: => String): Unit = {
streams.value.log.info(s)
outErrLines = s :: outErrLines
}
override def err(s: => String): Unit = {
streams.value.log.warn(s)
val SrcFilePathExtractor = """-- [A-Z ]+ -+ (app/assets/javascripts/.+\.elm)""".r
val LineNumExtractor = """([0-9]+)\|.*""".r
val PosExtractor = """ *\^+ *""".r
s match {
case SrcFilePathExtractor(path: String) =>
srcFilePath = srcFilePath orElse Some(path)
case LineNumExtractor(num: String) =>
lineNum = lineNum orElse Some(num)
case PosExtractor() =>
offset = offset orElse Some(s)
case _ =>
}
outErrLines = s :: outErrLines
}
override def buffer[T](f: => T): T = f
}
) match {
case 0 =>
streams.value.log.success("elm-make (for Admin) completed.")
Seq(file(outputPath))
case 127 =>
streams.value.log.warn("elm-make not found in PATH. Skipping Elm build.")
Nil
case _ =>
throw CompilationException(
new LineBasedProblem(
message = outErrLines.reverse.mkString("\n"),
severity = null,
lineNumber = lineNum.map(_.toInt).getOrElse(0),
characterOffset = offset.map(_.indexOf('^') - 2 - lineNum.map(_.length).getOrElse(0)).getOrElse(0),
lineContent = "",
source = file(srcFilePath.getOrElse(""))
)
)
}
}
Assets / sourceGenerators += elmMakeAdmin.taskValue
val elmMakeBoard = taskKey[Seq[File]]("elm-make-board")
elmMakeBoard := {
import scala.sys.process._
import com.typesafe.sbt.web.LineBasedProblem
import play.sbt.PlayExceptions.CompilationException
val outputPath: String = "public/javascripts/board.js"
val debugFlag: String =
if (sys.props.getOrElse("elm.debug", "false").toLowerCase != "true") ""
else "--debug"
var outErrLines: List[String] = Nil
var srcFilePath: Option[String] = None
var lineNum: Option[String] = None
var offset: Option[String] = None
Seq(
"bash", "-c",
"elm-make " +
(file("app/assets/javascripts/Board") ** "*.elm").get.mkString(" ") +
s" --output ${outputPath} " +
s"--yes ${debugFlag} --warn"
).!(
new ProcessLogger {
override def out(s: => String): Unit = {
streams.value.log.info(s)
outErrLines = s :: outErrLines
}
override def err(s: => String): Unit = {
streams.value.log.warn(s)
val SrcFilePathExtractor = """-- [A-Z ]+ -+ (app/assets/javascripts/.+\.elm)""".r
val LineNumExtractor = """([0-9]+)\|.*""".r
val PosExtractor = """ *\^+ *""".r
s match {
case SrcFilePathExtractor(path: String) =>
srcFilePath = srcFilePath orElse Some(path)
case LineNumExtractor(num: String) =>
lineNum = lineNum orElse Some(num)
case PosExtractor() =>
offset = offset orElse Some(s)
case _ =>
}
outErrLines = s :: outErrLines
}
override def buffer[T](f: => T): T = f
}
) match {
case 0 =>
streams.value.log.success("elm-make (for Board) completed.")
Seq(file(outputPath))
case 127 =>
streams.value.log.warn("elm-make not found in PATH. Skipping Elm build.")
Nil
case _ =>
throw CompilationException(
new LineBasedProblem(
message = outErrLines.reverse.mkString("\n"),
severity = null,
lineNumber = lineNum.map(_.toInt).getOrElse(0),
characterOffset = offset.map(_.indexOf('^') - 2 - lineNum.map(_.length).getOrElse(0)).getOrElse(0),
lineContent = "",
source = file(srcFilePath.getOrElse(""))
)
)
}
}
Assets / sourceGenerators += elmMakeBoard.taskValue