diff --git a/tutorials/checker/build.gradle.kts b/tutorials/checker/build.gradle.kts index 80d2404efb..c46fac1018 100644 --- a/tutorials/checker/build.gradle.kts +++ b/tutorials/checker/build.gradle.kts @@ -50,16 +50,16 @@ fun cloneTemplate(template: String, index: Int, content: String): File { return tempDir } -fun checkDirs(dirs: List, template: String) { +fun checkDirs(dirs: List, template: String, buildCmd: String = "build") { val snippets = findSnippets(dirs) snippets.forEachIndexed { index, snippet -> println("process snippet $index at ${snippet.file}:${snippet.lineNumber} with $template") snippet.tempDir = cloneTemplate(template, index, snippet.content) val isWin = System.getProperty("os.name").startsWith("Win") val procBuilder = if (isWin) { - ProcessBuilder("gradlew.bat", "build") + ProcessBuilder("gradlew.bat", "$buildCmd") } else { - ProcessBuilder("bash", "./gradlew", "build") + ProcessBuilder("bash", "./gradlew", "$buildCmd") } val proc = procBuilder .directory(snippet.tempDir) @@ -78,18 +78,48 @@ fun checkDirs(dirs: List, template: String) { // NOTICE: currently we use a bit hacky approach, when "```kotlin" marks code that shall be checked, while "``` kotlin" // with whitespace marks code that shall not be checked. tasks.register("check") { + val checks = CheckSpec.createCheckSpecs( + checkTargets = (project.property("CHECK_TARGET")?.toString() ?: "all").toLowerCase() + ) + doLast { - for (dir in listOf(".", "Web")) { + for (check in checks) { val subdirs = project .projectDir .parentFile - .resolve(dir) + .resolve(check.dir) .listFiles() .filter { it.isDirectory && it.name[0].isUpperCase() } .map { it.name } - checkDirs(subdirs.map { "$dir/$it" }, if (dir == ".") "desktop-template" else "web-template") + + checkDirs( + dirs = subdirs.map { "${check.dir}/$it" }, + template = check.template, + buildCmd = check.gradleCmd + ) + } + } +} + +data class CheckSpec( + val gradleCmd: String, + val dir: String, + val template: String +) { + + companion object { + fun desktop() = CheckSpec(gradleCmd = "build", dir = ".", template = "desktop-template") + fun web() = CheckSpec(gradleCmd = "compileKotlinJs", dir = "Web", template = "web-template") + fun all() = listOf(desktop(), web()) + + fun createCheckSpecs(checkTargets: String = "all"): List { + return when (checkTargets) { + "web" -> listOf(web()) + "desktop" -> listOf(desktop()) + else -> all() + } } } } diff --git a/tutorials/checker/gradle.properties b/tutorials/checker/gradle.properties index 7fc6f1ff27..2a37fcc005 100644 --- a/tutorials/checker/gradle.properties +++ b/tutorials/checker/gradle.properties @@ -1 +1,5 @@ kotlin.code.style=official + +# Helps running check only for specified target (or all of them) +# Available values (case insensitive): web, desktop, all +CHECK_TARGET=ALL