forked from EasyKotlin/reakt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreakt.kts
executable file
·63 lines (49 loc) · 1.84 KB
/
reakt.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
import java.io.File
import java.io.FileFilter
val srcPath = File("./front/dist/")
val templatesPath = "src/main/resources/templates/"
val jsFile = "src/main/resources/static/js/"
val cssPath = "src/main/resources/static/css/"
val templatesDir = File("src/main/resources/templates/")
val cssDir = File("src/main/resources/static/css/")
val jsDir = File("src/main/resources/static/js/")
if (!templatesDir.exists()) templatesDir.mkdirs()
if (!cssDir.exists()) cssDir.mkdirs()
if (!jsDir.exists()) jsDir.mkdirs()
srcPath.listFiles().forEach {
val fileName = it.name
when {
fileName.endsWith(".html") -> {
println("Copy file: $fileName")
val htmlFile = File("$templatesPath$fileName")
it.copyTo(target = htmlFile, overwrite = true)
replaceJsCssSrc(htmlFile)
}
fileName.endsWith(".js") -> {
println("Copy file: $fileName")
it.copyTo(target = File("$jsFile$fileName"), overwrite = true)
}
fileName.endsWith(".css") -> {
println("Copy file: $fileName")
it.copyTo(target = File("$cssPath$fileName"), overwrite = true)
}
}
}
fun replaceJsCssSrc(htmlFile: File) {
val oldJsSrc = """<script src="/"""
val oldJsSrcParticular = """<script src="//"""
val newJsSrc = """<script src="/js/"""
val oldCssSrc = """<link rel="stylesheet" href="/"""
val newCssSrc = """<link rel="stylesheet" href="/css/"""
var lines = StringBuilder()
htmlFile.readLines().forEach {
var line = it
if (line.contains(oldJsSrc) && !line.contains(oldJsSrcParticular)) {
line = line.replace(oldJsSrc, newJsSrc)
} else if (line.contains(oldCssSrc)) {
line = line.replace(oldCssSrc, newCssSrc)
}
lines.append(line + "\n")
}
htmlFile.writeText(lines.toString())
}