aboutsummaryrefslogtreecommitdiff
path: root/kvision-modules/shared.gradle
blob: 640d8478bbe8feb3547e62311a71e29981509a38 (plain)
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
apply plugin: 'kotlin-platform-js'
apply plugin: 'org.jetbrains.kotlin.frontend'
apply plugin: 'kotlinx-serialization'

kotlinFrontend {

    npm {
        devDependency("karma", "4.3.0")
        devDependency("karma-chrome-launcher", "3.1.0")
        devDependency("karma-webpack", "4.0.2")
        devDependency("qunit", "2.9.2")
    }

    webpackBundle {
        bundleName = "main"
        contentPath = file('src/main/web')
        mode = production ? "production" : "development"
    }

    define "PRODUCTION", production

    karma {
        plugins = ["karma-chrome-launcher"]
        browsers = ["ChromeHeadless"]
    }
}


dependencies {
    if (!project.gradle.startParameter.taskNames.contains("generatePomFileForMavenProjectPublication")) {
        compile project(":kvision-modules:kvision-base")
    } else {
        compile rootProject
    }
}

task cleanLibs(type: Delete) {
    delete 'build/js', 'build/libs'
}

if (project.gradle.startParameter.taskNames.contains("jar")) {
    compileKotlin2Js.dependsOn 'cleanLibs'
}

jar {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

compileKotlin2Js {
    kotlinOptions.metaInfo = true
    kotlinOptions.outputFile = "$project.buildDir.path/js/${project.name}.js"
    kotlinOptions.sourceMap = !production
    kotlinOptions.moduleKind = 'umd'
}

compileTestKotlin2Js {
    kotlinOptions.metaInfo = true
    kotlinOptions.outputFile = "$project.buildDir.path/js-tests/${project.name}-tests.js"
    kotlinOptions.sourceMap = !production
    kotlinOptions.moduleKind = 'umd'
}

task copyResources(type: Copy) {
    from "src/main/resources"
    into file(buildDir.path + "/js")
}

task copyResourcesForTests(type: Copy) {
    from "src/main/resources"
    into file(buildDir.path + "/js-tests/")
}

afterEvaluate {
    tasks.getByName("webpack-bundle") { dependsOn(copyResources) }
    tasks.getByName("webpack-run") { dependsOn(copyResources) }
    tasks.getByName("karma-start") { dependsOn(copyResources, copyResourcesForTests) }
}