-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.sbt
75 lines (59 loc) · 2.28 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
name := "gitbucket-code-highlighter-plugin"
organization := "io.github.gitbucket"
version := "1.8.0"
scalaVersion := "2.13.10"
gitbucketVersion := "4.39.0"
ThisBuild / packageTimestamp := Package.gitCommitDateTimestamp
import scala.sys.process._
def BuildCommand(command: Seq[String]): Seq[String] = {
val os = sys.props("os.name").toLowerCase
if (os contains "windows") (Seq("cmd", "/c") ++ command) else command
}
def BuildNpmCommand(command: Seq[String]): Seq[String] = {
BuildCommand(Seq("npx", "--no-install") ++ command)
}
def ExecCommand(command: Seq[String], builder: (Seq[String]) => Seq[String], log: ProcessLogger): Unit = {
val ret = Process(builder(command)) ! log
if(ret != 0)
throw new MessageOnlyException(s"Failed to run `${command(0)}`")
}
// Compile TypeScript sources
Compile / resourceGenerators += Def.task {
// Output directory
val outDir: File = (Compile / resourceManaged).value / "assets"
// Need to delete the output directory first
IO.delete(outDir)
// Run webpack
val command = Seq("webpack", "--output-path", outDir.getPath)
ExecCommand(command, BuildNpmCommand, streams.value.log)
// List all files in 'outDir'
val finder: PathFinder = (outDir ** "*") filter { _.isFile }
finder.get
}.taskValue
// Add '@highlightjs/cdn-assets' to resources
Compile / resourceGenerators += Def.task {
// Source directory
val sourceDir: File = baseDirectory.value / "node_modules" / "@highlightjs" / "cdn-assets"
// Output directory
val outDir: File = (Compile / resourceManaged).value / "cdn-assets"
// Need to delete the output directory first
IO.delete(outDir)
// Copy highlight.js cdn-assets
IO.copyDirectory(sourceDir, outDir)
// Delete unused files in highlight.js cdn-assets
IO.delete(outDir / "es")
IO.delete(outDir / "highlight.js")
IO.delete(outDir / "highlight.min.js")
IO.delete(outDir / "package.json")
// List all files in 'outDir'
val finder: PathFinder = (outDir ** "*") filter { _.isFile }
finder.get
}.taskValue
// Disable renaming of readme and license files
ThisBuild / assemblyMergeStrategy := {
case PathList(ps @ _*) if Assembly.isReadme(ps.last) || Assembly.isLicenseFile(ps.last) =>
MergeStrategy.deduplicate
case x =>
val oldStrategy = (ThisBuild / assemblyMergeStrategy).value
oldStrategy(x)
}