-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
build.gradle.kts
145 lines (131 loc) · 3.97 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
139
140
141
142
143
144
145
/*
* Copyright 2020 Kazimierz Pogoda
*
* This file is part of shader-web-background.
*
* shader-web-background is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* shader-web-background is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with shader-web-background. If not, see <https://www.gnu.org/licenses/>.
*/
val closureCompilerVersion = "v20210106"
plugins {
kotlin("jvm") version "1.4.21"
}
dependencies {
implementation("com.google.javascript:closure-compiler:$closureCompilerVersion")
}
repositories {
jcenter()
}
fun getMapJsBackPath(path: String) =
path.count { char -> char == '/' }
.let { count -> "../".repeat(count) }
fun updateEmbeddedLib(
libOccurrence: Regex,
code: String,
distDir: String,
mapJsPath: String,
path: String
) = File(path).let { file ->
file.writeText(
file.readText().replaceFirst(
libOccurrence,
code
.replaceFirst(
mapJsPath,
"${getMapJsBackPath(path)}$distDir/$mapJsPath"
)
.replace("\\", "\\\\")
)
)
}
fun updateEmbeddedLibs(
libOccurrence: Regex,
distDir: String,
distJs: String,
mapJsPath: String,
vararg paths: String
) = File(distDir, distJs).readText().let { code ->
paths.forEach { path ->
updateEmbeddedLib(
libOccurrence,
code,
distDir,
mapJsPath,
path
)
}
}
task("closureCompilerHelp", JavaExec::class) {
group = "js"
main = "com.google.javascript.jscomp.CommandLineRunner"
args = listOf("--help")
classpath = sourceSets["main"].runtimeClasspath
}
task("compileJs", JavaExec::class) {
group = "js"
main = "com.xemantic.web.shader.background.ShaderWebBackgroundClosureCompilerKt"
val sourceDir = "src/main/js"
val outputDir = "dist"
val outputJs = "shader-web-background.min.js"
val outputJsMap = "$outputJs.map"
val namespace = "shaderWebBackground"
val wrapperBegin = "// -- https://xemantic.github.io/shader-web-background/"
val wrapperEnd = "//# sourceMappingURL=$outputJsMap"
args = listOf(
"--compilation_level", "ADVANCED",
"--js", "$sourceDir/*.js",
"--js_output_file", "$outputDir/$outputJs",
"--create_source_map", "$outputDir/$outputJs.map",
"--source_map_location_mapping", "$sourceDir|../$sourceDir",
"--language_in", "ECMASCRIPT6",
"--language_out", "ECMASCRIPT6",
"--output_wrapper",
"$wrapperBegin\nconst $namespace={};(()=>{%output%})()\n$wrapperEnd",
"--assume_function_wrapper=true",
"--jscomp_warning=accessControls",
"--jscomp_warning=checkRegExp",
"--jscomp_warning=constantProperty",
"--jscomp_warning=const",
"--jscomp_warning=deprecatedAnnotations",
"--jscomp_warning=deprecated",
"--jscomp_warning=missingProperties",
"--jscomp_warning=missingReturn",
"--jscomp_warning=reportUnknownTypes",
"--jscomp_warning=strictCheckTypes",
"--jscomp_warning=typeInvalidation",
"--jscomp_warning=undefinedNames",
"--jscomp_warning=unusedLocalVariables",
"--jscomp_warning=unusedPrivateMembers",
"--jscomp_warning=visibility",
"--process_closure_primitives=false",
"--rewrite_polyfills=false",
"--inject_libraries=false"
)
classpath = sourceSets["main"].runtimeClasspath
val libOccurrence = (
"(?s)"
+ wrapperBegin.replace(".", "\\.")
+ ".*"
+ outputJsMap.replace(".", "\\.") + "\n"
).toRegex()
doLast {
updateEmbeddedLibs(
libOccurrence,
outputDir,
outputJs,
outputJsMap,
"index.html",
"demo/minimal.html"
)
}
}