-
Notifications
You must be signed in to change notification settings - Fork 3
/
platform_js.gradle
107 lines (90 loc) · 3.13 KB
/
platform_js.gradle
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* This file contains shared configuration for javascript platform modules.
*/
project.ext.js_submods = subprojects.findAll {
it.name.endsWith('-js')
}
println("javascript submodules: ${fmtMods(js_submods)}")
/* Collect paths of all javascript platform modules and other js dependencies. */
def js_dep_paths = js_submods.collect { "${it.jsTargetDir}" } +
["${buildDir.path}/node_modules/kotlin", "${buildDir.path}/node_modules/kotlin-test"]
apply plugin: 'com.moowork.node'
/* Make sure node and npm are available for running code and tests. */
node {
download = true
version = '9.4.0'
npmVersion = '5.6.0'
nodeModulesDir = buildDir
}
/* Install the Kotlin javascript files and copy them to the output folder. */
task installKotlinJs(type: NpmTask) {
args = ['install', '--silent', "kotlin@$kotlin_version", "kotlin-test@$kotlin_version"]
}
/* Install QUnit for running tests and run it when testing. */
task installQunit(type: NpmTask) {
args = ['install', '--silent', 'qunit']
}
/* All javascript platform subprojects. */
configure(js_submods) {
apply plugin: 'kotlin-platform-js'
apply plugin: 'com.moowork.node'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
}
def (parentCommon, depNames) = rootProject.deriveDependencyNames(project)
dependencies {
expectedBy parentCommon
compile depNames.collect { project(it) }
}
compileKotlin2Js {
kotlinOptions {
outputFile = file("${jsTargetDir}/${project.name}.js")
moduleKind = "umd"
sourceMap = true
metaInfo = true
}
}
compileTestKotlin2Js {
kotlinOptions {
moduleKind = "umd"
sourceMap = true
metaInfo = true
outputFile = file("${jsTargetDir}/test_${project.name}.js")
}
}
assemble.dependsOn installKotlinJs
/* Set up the QUnit test runner. */
def testsFile = file(compileTestKotlin2Js.outputFile)
def testsFileRelPath = jsTargetDir.toPath().relativize(testsFile.toPath())
task runQunit(type: NodeTask) {
dependsOn compileTestKotlin2Js
dependsOn installQunit
workingDir = jsTargetDir
script = file("${rootProject.buildDir.path}/node_modules/qunit/bin/qunit")
args = ['--seed', '1', testsFileRelPath]
doFirst {
assert testsFile.exists()
println("run ${testsFileRelPath} with qunit")
}
}
test.dependsOn runQunit
/* Add Kotlin and dependencies to the node path. */
tasks.withType(NodeTask) {
/* Make all node tasks have the correct path to find sources. */
environment NODE_PATH: js_dep_paths.join(':')
}
}
/* Make a task that collects all the javascript files */
project(":") {
task collectWeb(type: Copy) {
dependsOn js_submods.collect { it.build }
dependsOn installKotlinJs
from js_dep_paths
include "*.js"
into "${jsTargetDir}"
doFirst {
js_dep_paths.collect { assert file(it).exists() }
}
}
}