Created
November 4, 2018 18:09
-
-
Save dodgex/2ea338d21fa065b27df3c1b57f3e6a23 to your computer and use it in GitHub Desktop.
unpack webjars into version less directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create configuration | |
val webjars = configurations.create("webjar") | |
// add dependencies | |
dependencies { | |
"webjar"("org.webjars.bower:bootstrap:4.1.3") | |
"webjar"("org.webjars.bower:jquery:3.3.1") | |
} | |
// add task | |
task<Sync>("unzipWebjars") { | |
configurations["webjar"]?.files?.forEach { from(zipTree(it)) } | |
val webjars = configurations["webjar"]?.dependencies.orEmpty() | |
into("build/webjar/unzipped") | |
doLast { | |
val basePath = "${project.projectDir}/build/webjar" | |
webjars.forEach { webjar -> | |
val properties = Paths.get("$basePath/unzipped/META-INF/maven/${webjar.group}/${webjar.name}/pom.properties") | |
val version = Files.readAllLines(properties) | |
.first { it.startsWith("version=") } | |
.substring(8) | |
val files = Paths.get("$basePath/unzipped/META-INF/resources/webjars/${webjar.name}/$version") | |
val target = Paths.get("$basePath/${webjar.group}/${webjar.name}") | |
Files.createDirectories(target) | |
Files.walk(files) | |
.forEach { source -> | |
Files.copy(source, target.resolve(files.relativize(source)), StandardCopyOption.REPLACE_EXISTING) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment