1
1
import com.github.gradle.node.npm.task.NpmTask
2
- import com.github.gradle.node.task.NodeTask
3
2
4
3
plugins {
5
4
base
6
- id(" com.github.node-gradle.node" ) version " 3.4.0 "
5
+ id(" com.github.node-gradle.node" ) version " 3.5.1 "
7
6
}
8
7
9
8
node {
10
- version.set(" 18.3.0 " )
11
- npmVersion.set(" 8.11.0 " )
9
+ version.set(" 18.12.1 " )
10
+ npmVersion.set(" 8.19.2 " )
12
11
download.set(true )
13
12
}
14
13
@@ -20,9 +19,38 @@ tasks.named("npm_run_build") {
20
19
outputs.dir(" dist" )
21
20
}
22
21
22
+ val patchKotlinExternals = tasks.create(" patchKotlinExternals" ) {
23
+ dependsOn(" npm_run_generateKotlin" )
24
+ doLast {
25
+ val annotationLine = """ @file:JsModule("@modelix/ts-model-api") @file:JsNonModule"""
26
+ val dukatDir = buildDir.resolve(" dukat" )
27
+ val files = dukatDir.listFiles()?.toList() ? : emptyList()
28
+ val matchingFiles = files.filter { it.name.contains(" @modelix_ts-model-api" ) }
29
+ if (matchingFiles.isEmpty()) throw RuntimeException (" No files found for patching in $dukatDir " )
30
+ val typealiases = HashSet <String >()
31
+ val allImports = HashSet <String >()
32
+ for (file in matchingFiles) {
33
+ var lines = file.readLines()
34
+ if (lines.isEmpty()) continue
35
+ if (lines.first() == annotationLine) continue
36
+ lines = listOf (annotationLine) + lines
37
+ typealiases + = lines.filter { it.startsWith(" typealias " ) }
38
+ allImports + = lines.filter { it.startsWith(" import " ) }
39
+ lines = lines.filterNot { it.startsWith(" typealias " ) }
40
+ file.writeText(lines.joinToString(" \n " ))
41
+ }
42
+ dukatDir.resolve(" typealiases.kt" ).writeText(allImports.joinToString(" \n " ) + " \n\n " + typealiases.joinToString(" \n " ))
43
+ }
44
+ }
45
+
23
46
tasks.named(" assemble" ) {
24
47
dependsOn(" npm_run_build" )
25
48
dependsOn(" npm_run_generateKotlin" )
49
+ dependsOn(patchKotlinExternals)
50
+ }
51
+
52
+ tasks.named(" npm_run_generateKotlin" ) {
53
+ finalizedBy(patchKotlinExternals)
26
54
}
27
55
28
56
val updateVersion = tasks.register<NpmTask >(" updateVersion" ) {
0 commit comments