-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
138 lines (110 loc) · 3.62 KB
/
build.gradle.kts
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
import org.dicthub.*
import org.dicthub.Script
val kotlinVersion = "1.3.61"
val kotlinHtmlVersion = "0.6.12"
plugins {
id("kotlin2js") version "1.3.61"
}
allprojects {
repositories {
jcenter()
}
}
subprojects {
apply {
plugin("kotlin2js")
}
dependencies {
compile(kotlin("stdlib-js"))
compile("org.jetbrains.kotlinx:kotlinx-html-js:$kotlinHtmlVersion")
testCompile(kotlin("kotlin-test-js"))
}
}
dependencies {
compile(kotlin("stdlib-js"))
compile("org.jetbrains.kotlinx:kotlinx-html-js:$kotlinHtmlVersion")
testCompile("org.jetbrains.kotlin:kotlin-test-js:$kotlinVersion")
}
task<Copy>("extractLibs") {
group = "release"
description = "Extract javascript lib from dependency jars"
dependsOn("jar")
extra["jsLibDir"] = "$buildDir/include"
from(zipTree("$buildDir/libs/${rootProject.name}.jar"))
from(configurations.compile.files.map { zipTree(it) })
include("*.js")
into("${extra["jsLibDir"]}/js")
}
// TODO: Move into dependency format
val styleSheetsList = { page: String ->
val commonStyles = mutableListOf(
StyleSheet("lib/css/bootstrap.min.css"),
StyleSheet("css/style.css")
)
when(page) {
"popup", "overlay", "welcome" -> commonStyles
"options" -> commonStyles.apply {
add(StyleSheet("https://use.fontawesome.com/releases/v5.1.0/css/solid.css"))
add(StyleSheet("https://use.fontawesome.com/releases/v5.1.0/css/fontawesome.css"))
}
else -> listOf()
}
}
// TODO: Move into dependency format
val scriptList = { page: String ->
val commonScripts = mutableListOf(
Script("lib/js/jquery-3.2.1.slim.min.js"),
Script("lib/js/popper.min.js"),
Script("lib/js/bootstrap.min.js"),
Script("js/kotlin.js"),
Script("js/kotlinx-html-js.js"),
Script("js/DictHubExtension.js")
)
when(page) {
"popup", "overlay" -> commonScripts.apply {
add(Script("js/ga.js"))
}
"options" -> commonScripts.apply {
add(Script("js/ga.js"))
add(Script("lib/js/jquery.sortable.min.js"))
}
"sandbox", "welcome" -> commonScripts
else -> listOf()
}
}
val platforms = arrayOf("chrome", "firefox")
platforms.forEach { platform ->
val unpackedPath = "$buildDir/$platform"
val copyTask = task<Copy>("${platform}Copy") {
group = "release"
description = "Copy static files together to plugin directory"
dependsOn("extractLibs")
val jsLibDir: String by tasks["extractLibs"].extra
from("src/main/static/$platform")
from("src/main/static/shared")
from(jsLibDir)
into(unpackedPath)
}
val pages = arrayOf("popup", "overlay", "sandbox", "options", "welcome")
val generateTasks = pages.map { page ->
task<HtmlGenerationTask>("$platform${page}GenerateHtml") {
outputPath = "$unpackedPath/$page.html"
title = "DictHub $page Page"
bodyId = "${page}Body"
styleSheets = styleSheetsList(page)
scripts = scriptList(page)
}
}
val zipTask = task<Zip>("${platform}Zip") {
archiveFileName.set(when(platform) {
"chrome" -> "chrome.zip" // TODO: Sign into crx
else -> "$platform.zip"
})
from(unpackedPath)
destinationDirectory.set(file(buildDir))
dependsOn(copyTask, generateTasks)
}
task(platform).dependsOn(generateTasks, copyTask, zipTask)
}
tasks["build"].dependsOn(*platforms)
defaultTasks = mutableListOf("build")