apply plugin: 'kotlin-platform-js'
apply plugin: 'kotlinx-serialization'

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'
}

dependencies {
    expectedBy project(":kvision-modules:kvision-common-remote")
    expectedBy project(":kvision-modules:kvision-common-types")
    compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion"
    compile "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$coroutinesVersion"
    compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serializationVersion"
    compile "pl.treksoft:jquery-kotlin:$jqueryKotlinVersion"
}