Add watching to resources folder

This commit is contained in:
Ricardo Matias
2019-11-19 15:28:41 +01:00
parent 6a65fdba5d
commit a8a5a07dbc
2 changed files with 51 additions and 1 deletions

View File

@@ -18,7 +18,7 @@ private fun <T> Event<T>.restoreListeners(store: Map<Event<*>, List<(Any) -> Uni
listeners.retainAll(store[this] ?: emptyList<T>())
}
class Olive<P : Program> : Extension {
class Olive<P : Program>(val resources: Resources? = null) : Extension {
override var enabled: Boolean = true
var session: Session? = null
@@ -110,5 +110,26 @@ class Olive<P : Program> : Extension {
}
setupScript(script)
scriptChange = ::setupScript
if (resources != null) {
val srcPath = "src/main/resources"
var src = File(srcPath)
resources.watch(src) { file ->
val dest = "build/resources/main"
val filePath = file.path.split(Regex(srcPath), 2).getOrNull(1)
val destFile = File("$dest/${filePath}").absoluteFile
program.watchFile(file) {
if (resources[file]!! && filePath != null) {
file.copyTo(destFile, overwrite = true)
reload()
} else {
resources[file] = true
}
}
}
}
}
}