-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
build.gradle.kts
54 lines (41 loc) · 1.34 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
plugins {
base
}
// Fake NPM task that would normally execute npm with its provided arguments
abstract class NpmTask : DefaultTask() {
@get:Input
val args = project.objects.listProperty<String>()
@get:Inject
abstract val projectLayout: ProjectLayout
@TaskAction
fun run() {
val bundleFile = projectLayout.buildDirectory.file("bundle.js").get().asFile
val scriptsFiles = projectLayout.projectDirectory.dir("scripts").asFile.listFiles()
bundleFile.outputStream().use { stream ->
scriptsFiles.sorted().forEach {
stream.write(it.readBytes())
}
}
}
}
// tag::bundle-task[]
tasks.register<NpmTask>("bundle") {
args = listOf("run", "bundle")
outputs.cacheIf { true }
inputs.dir(file("scripts"))
.withPropertyName("scripts")
.withPathSensitivity(PathSensitivity.RELATIVE)
inputs.files("package.json", "package-lock.json")
.withPropertyName("configFiles")
.withPathSensitivity(PathSensitivity.RELATIVE)
outputs.file(layout.buildDirectory.file("bundle.js"))
.withPropertyName("bundle")
}
// end::bundle-task[]
tasks.register("printBundle") {
dependsOn("bundle")
val projectLayout = layout
doLast {
println(projectLayout.buildDirectory.file("bundle.js").get().asFile.readText())
}
}