Serving scalajs artifacts and provide errors to js

This commit is contained in:
Eike Kettner 2021-03-02 00:51:13 +01:00
parent 71985244f1
commit d4006461f6
25 changed files with 45 additions and 9 deletions

View File

@ -86,7 +86,7 @@ val stylesSettings = Seq(
Compile / resourceGenerators += stylesBuild.taskValue
)
val webjarSettings = Seq(
def webjarSettings(queryJS: Project) = Seq(
Compile / resourceGenerators += Def.task {
copyWebjarResources(
Seq((sourceDirectory in Compile).value / "webjar"),
@ -96,6 +96,18 @@ val webjarSettings = Seq(
streams.value.log
)
}.taskValue,
Compile / resourceGenerators += Def.task {
val logger = streams.value.log
val out = (queryJS/Compile/fullOptJS).value
logger.info(s"Produced query js file: ${out.data}")
copyWebjarResources(
Seq(out.data),
(Compile/resourceManaged).value,
name.value,
version.value,
logger
)
}.taskValue,
watchSources += Watched.WatchSource(
(Compile / sourceDirectory).value / "webjar",
FileFilter.globFilter("*.js") || FileFilter.globFilter("*.css"),
@ -273,7 +285,6 @@ ${lines.map(_._1).mkString(",\n")}
val query =
crossProject(JSPlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Pure)
.in(file("modules/query"))
.disablePlugins(RevolverPlugin)
.settings(sharedSettings)
@ -446,7 +457,7 @@ val webapp = project
.settings(sharedSettings)
.settings(elmSettings)
.settings(stylesSettings)
.settings(webjarSettings)
.settings(webjarSettings(query.js))
.settings(
name := "docspell-webapp",
openapiTargetLanguage := Language.Elm,

View File

@ -0,0 +1,29 @@
package docspell.query.js
import scala.scalajs.js
import scala.scalajs.js.annotation._
import docspell.query.ItemQueryParser
@JSExportTopLevel("DsItemQueryParser")
object JSItemQueryParser {
@JSExport
def parseToFailure(input: String): Failure =
ItemQueryParser
.parse(input)
.swap
.toOption
.map(fr =>
new Failure(
fr.input,
fr.failedAt,
js.Array(fr.messages.toList.toSeq.map(_.msg): _*)
)
)
.orNull
@JSExportAll
case class Failure(input: String, failedAt: Int, messages: js.Array[String])
}

View File

@ -1,14 +1,10 @@
package docspell.query
import scala.scalajs.js.annotation._
import docspell.query.internal.ExprParser
import docspell.query.internal.ExprUtil
@JSExportTopLevel("DsItemQueryParser")
object ItemQueryParser {
@JSExport
def parse(input: String): Either[ParseFailure, ItemQuery] =
if (input.isEmpty) Right(ItemQuery.all)
else {
@ -22,5 +18,4 @@ object ItemQueryParser {
def parseUnsafe(input: String): ItemQuery =
parse(input).fold(m => sys.error(m.render), identity)
}

View File

@ -170,7 +170,8 @@ object TemplateRoutes {
chooseUi(uiVersion),
Seq(
"/app/assets" + Webjars.clipboardjs + "/clipboard.min.js",
s"/app/assets/docspell-webapp/${BuildInfo.version}/docspell-app.js"
s"/app/assets/docspell-webapp/${BuildInfo.version}/docspell-app.js",
s"/app/assets/docspell-webapp/${BuildInfo.version}/docspell-query-opt.js"
),
s"/app/assets/docspell-webapp/${BuildInfo.version}/favicon",
s"/app/assets/docspell-webapp/${BuildInfo.version}/docspell.js",