• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
5apply from: rootProject.file('gradle/node-js.gradle')
6
7kotlin {
8    targets {
9        fromPreset(presets.js, 'js')
10    }
11
12    sourceSets {
13        jsMain.dependencies {
14            api "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
15        }
16
17        jsTest.dependencies {
18            api "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
19        }
20    }
21}
22
23// When source sets are configured
24apply from: rootProject.file('gradle/test-mocha-js.gradle')
25
26compileKotlinJs {
27    kotlinOptions.metaInfo = true
28    kotlinOptions.sourceMap = true
29    kotlinOptions.moduleKind = 'umd'
30
31    kotlinOptions {
32        // drop -js suffix from outputFile
33        def baseName = project.name - "-js"
34        outputFile = new File(outputFile.parent, baseName + ".js")
35    }
36}
37
38compileTestKotlinJs {
39    kotlinOptions.metaInfo = true
40    kotlinOptions.sourceMap = true
41    kotlinOptions.moduleKind = 'umd'
42}
43
44task populateNodeModules(type: Copy, dependsOn: compileTestKotlinJs) {
45    // we must copy output that is transformed by atomicfu
46    from(kotlin.targets.js.compilations.main.output.allOutputs)
47    into "$node.nodeModulesDir/node_modules"
48
49    def configuration = configurations.jsTestRuntimeClasspath
50    from(files {
51        configuration.collect { File file ->
52            file.name.endsWith(".jar") ?
53                    zipTree(file.absolutePath).matching {
54                        include '*.js'
55                        include '*.js.map'
56                    } : files()
57        }
58    }.builtBy(configuration))
59}
60
61npmInstall.dependsOn populateNodeModules
62