Skip to content

Commit

Permalink
Generate gradle version catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
terrakok committed Mar 21, 2023
1 parent 3c8ffb5 commit 798d211
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.jetbrains.webwiz.models.SourceSetDelegate.CREATING
import org.jetbrains.webwiz.models.SourceSetDelegate.GETTING
import org.jetbrains.webwiz.models.SourceSetType.MAIN
import org.jetbrains.webwiz.models.SourceSetType.TEST
import org.jetbrains.webwiz.models.Target //don't remove it!

class ModuleBuildGradle(val projectInfo: ProjectInfo) : ProjectFile {
override val path = "${projectInfo.moduleName}/build.gradle.kts"
Expand Down Expand Up @@ -85,7 +84,7 @@ kotlin {
val compilation = type.sourceSetTypeName
val deps = projectInfo.dependencies
.filter { it.targets.size > 1 && !it.targets.isNativeTargets() && it.sourceSetType == type }
.map { "implementation(\"${it.dep}\")" }
.map { "implementation(libs.${it.versionCatalogName})" }
.toMutableList()

if (type == TEST) {
Expand Down Expand Up @@ -114,15 +113,15 @@ kotlin {
} else {
"""val $sourceSetName by ${sourceSetDelegate.delegate} {
| dependencies {
| ${deps.joinToString("\n| ") { "implementation(\"${it}\")" }}
| ${deps.joinToString("\n| ") { "implementation($it)" }}
| }
| }"""
}
}

private fun Target.getDeps(compilation: SourceSetType) = projectInfo.dependencies
.filter { it.targets.size == 1 && it.targets.single() == this && it.sourceSetType == compilation }
.map { it.dep }
.map { "libs." + it.versionCatalogName }

private fun targetSourceSets(type: SourceSetType): String {
val compilation = type.sourceSetTypeName
Expand Down Expand Up @@ -151,7 +150,7 @@ kotlin {
it.targets.size > 1
&& it.targets.all { t -> t.isNative() }
&& it.sourceSetType == type
}.map { it.dep }
}.map { "libs." + it.versionCatalogName }
}

return projectInfo.targets.joinToString("\n| ") {
Expand Down Expand Up @@ -196,7 +195,7 @@ kotlin {
&& d.targets.isNativeTargets()
&& d.sourceSetType == type
}
.map { "implementation(\"${it.dep}\")" }
.map { "implementation(libs.${it.versionCatalogName})" }
return if (deps.isEmpty()) {
"val native$compilation by ${CREATING.delegate}"
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
package org.jetbrains.webwiz.generator.files

import org.jetbrains.webwiz.generator.ProjectFile
import org.jetbrains.webwiz.models.AndroidGradlePluginVersion
import org.jetbrains.webwiz.models.GradlePlugin
import org.jetbrains.webwiz.models.KmpLibrary
import org.jetbrains.webwiz.models.ProjectInfo
import org.jetbrains.webwiz.models.RealmVersion
import org.jetbrains.webwiz.models.SqlDelightVersion
import org.jetbrains.webwiz.models.Target

class RootBuildGradle(val projectInfo: ProjectInfo) : ProjectFile {
override val path = "build.gradle.kts"
override val content: String
get() = buildString {
appendLine("plugins {")
appendLine(" kotlin(\"multiplatform\").version(\"${projectInfo.kotlinVersion.versionName}\").apply(false)")
appendLine(" kotlin(\"multiplatform\").apply(false)")
if (projectInfo.dependencies.contains(KmpLibrary.SERIALIZATION)) {
appendLine(" kotlin(\"plugin.serialization\").version(\"${projectInfo.kotlinVersion.versionName}\").apply(false)")
appendLine(" kotlin(\"plugin.serialization\").apply(false)")
}
if (projectInfo.targets.contains(Target.ANDROID)) {
appendLine(" id(\"com.android.library\").version(\"$AndroidGradlePluginVersion\").apply(false)")
appendLine(" id(\"com.android.library\").apply(false)")
}
if (GradlePlugin.SQL_DELIGHT in projectInfo.gradlePlugins) {
appendLine(" id(\"com.squareup.sqldelight\").version(\"$SqlDelightVersion\").apply(false)")
appendLine(" id(\"com.squareup.sqldelight\").apply(false)")
}
if (GradlePlugin.REALM in projectInfo.gradlePlugins) {
appendLine(" id(\"io.realm.kotlin\").version(\"$RealmVersion\").apply(false)")
appendLine(" id(\"io.realm.kotlin\").apply(false)")
}
appendLine("}")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,58 @@
package org.jetbrains.webwiz.generator.files

import org.jetbrains.webwiz.generator.NAN
import org.jetbrains.webwiz.generator.ProjectFile
import org.jetbrains.webwiz.generator.deleteNans
import org.jetbrains.webwiz.models.*

class SettingsGradle(
val projectName: String,
val moduleName: String,
val addDevMaven: Boolean
) : ProjectFile {
class SettingsGradle(val projectInfo: ProjectInfo) : ProjectFile {
private val addDevMaven = projectInfo.kotlinVersion == KotlinVersion.EAP
override val path = "settings.gradle.kts"
override val content: String
get() = """
pluginManagement {
repositories {
google()
gradlePluginPortal()
mavenCentral()
${if (addDevMaven) "maven(\"https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/\")" else NAN}
}
}
get() = buildString {
appendLine("rootProject.name = \"${projectInfo.projectName.replace(' ', '_')}\"")
appendLine("include(\":${projectInfo.moduleName}\")")
appendLine()
appendLine("pluginManagement {")
appendLine(" repositories {")
appendLine(" google()")
appendLine(" gradlePluginPortal()")
appendLine(" mavenCentral()")
if (addDevMaven) {
appendLine(" maven(\"https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/\")")
}
appendLine(" }")
appendLine(" plugins {")
appendLine(" kotlin(\"multiplatform\").version(\"${projectInfo.kotlinVersion.versionName}\")")
if (projectInfo.dependencies.contains(KmpLibrary.SERIALIZATION)) {
appendLine(" kotlin(\"plugin.serialization\").version(\"${projectInfo.kotlinVersion.versionName}\")")
}
if (projectInfo.targets.contains(Target.ANDROID)) {
appendLine(" id(\"com.android.library\").version(\"$AndroidGradlePluginVersion\")")
}
if (GradlePlugin.SQL_DELIGHT in projectInfo.gradlePlugins) {
appendLine(" id(\"com.squareup.sqldelight\").version(\"$SqlDelightVersion\")")
}
if (GradlePlugin.REALM in projectInfo.gradlePlugins) {
appendLine(" id(\"io.realm.kotlin\").version(\"$RealmVersion\")")
}

dependencyResolutionManagement {
repositories {
google()
mavenCentral()
${if (addDevMaven) "maven(\"https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/\")" else NAN}
}
}
rootProject.name = "${projectName.replace(' ', '_')}"
include(":$moduleName")
""".trimIndent().deleteNans()
appendLine(" }")
appendLine("}")
appendLine()
appendLine("dependencyResolutionManagement {")
appendLine(" repositories {")
appendLine(" google()")
appendLine(" mavenCentral()")
if (addDevMaven) {
appendLine(" maven(\"https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/\")")
}
appendLine(" }")
appendLine(" versionCatalogs {")
appendLine(" create(\"libs\") {")
projectInfo.dependencies.forEach { dep ->
appendLine(" library(\"${dep.versionCatalogName.replace(".", "-")}\",\"${dep.dep}\")")
}
appendLine(" }")
appendLine(" }")
appendLine("}")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package org.jetbrains.webwiz.generator
import org.jetbrains.webwiz.generator.files.*
import org.jetbrains.webwiz.models.GradlePlugin
import org.jetbrains.webwiz.models.GradleVersion
import org.jetbrains.webwiz.models.KotlinVersion
import org.jetbrains.webwiz.models.ProjectInfo
import org.jetbrains.webwiz.models.Target.ANDROID
import org.jetbrains.webwiz.models.isCommonNativeTargetPresent

interface ProjectFile {
Expand All @@ -23,7 +21,7 @@ fun ProjectInfo.generate(): List<ProjectFile> = mutableListOf<ProjectFile>().app
add(GradleWrapperJar())

add(RootBuildGradle(info))
add(SettingsGradle(projectName, moduleName, kotlinVersion == KotlinVersion.EAP))
add(SettingsGradle(info))
add(GradleProperties())

add(ModuleBuildGradle(info))
Expand Down
17 changes: 17 additions & 0 deletions src/commonMain/kotlin/org/jetbrains/webwiz/models/KmpLibraries.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,102 +12,119 @@ internal const val RealmVersion = "1.5.2"
enum class KmpLibrary(
val targets: Set<Target>,
val userName: String,
val versionCatalogName: String,
val dep: String,
val sourceSetType: SourceSetType
) {
COROUTINES(
setOf(ANDROID, JVM, JS, MACOS, IOS, TV_OS, WATCH_OS, LINUX, WINDOWS),
"KotlinX Coroutines",
"kotlinx.coroutines.core",
"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4",
MAIN
),
SERIALIZATION(
setOf(ANDROID, JVM, JS, MACOS, IOS, TV_OS, WATCH_OS, LINUX, WINDOWS),
"KotlinX Serialization",
"kotlinx.serialization.json",
"org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1",
MAIN
),
DATE_TIME(
setOf(ANDROID, JVM, JS, MACOS, IOS, TV_OS, WATCH_OS, LINUX, WINDOWS),
"KotlinX DateTime",
"kotlinx.datetime",
"org.jetbrains.kotlinx:kotlinx-datetime:0.4.0",
MAIN
),
KERMIT_LOGGER(
setOf(ANDROID, JVM, JS, MACOS, IOS, TV_OS, WATCH_OS, LINUX, WINDOWS),
"Kermit Logger",
"touchlab.kermit",
"co.touchlab:kermit:1.2.2",
MAIN
),
NAPIER_LOGGER(
setOf(ANDROID, JVM, JS, MACOS, IOS, TV_OS, WATCH_OS),
"Napier logger",
"aakira.napier",
"io.github.aakira:napier:2.6.1",
MAIN
),
REALM_KOTLIN(
setOf(JVM, ANDROID, IOS, MACOS),
"Realm Kotlin Multiplatform",
"realm.base",
"io.realm.kotlin:library-base:$RealmVersion",
MAIN
),
KTOR_CORE(
setOf(JVM, ANDROID, JS, IOS, LINUX, MACOS, WINDOWS),
"Ktor Core",
"ktor.client.core",
"io.ktor:ktor-client-core:$KtorVersion",
MAIN
),
KTOR_CLIENT_IOS(
setOf(IOS),
"Ktor iOS Client",
"ktor.client.ios",
"io.ktor:ktor-client-ios:$KtorVersion",
MAIN
),
KTOR_CLIENT_ANDROID(
setOf(ANDROID),
"Ktor Android Client",
"ktor.client.okhttp",
"io.ktor:ktor-client-okhttp:$KtorVersion",
MAIN
),
KTOR_CLIENT_JVM(
setOf(JVM),
"Ktor JVM Client",
"ktor.client.jvm",
"io.ktor:ktor-client-jvm:$KtorVersion",
MAIN
),
KTOR_CLIENT_JS(
setOf(JS),
"Ktor JS Client",
"ktor.client.js",
"io.ktor:ktor-client-js:$KtorVersion",
MAIN
),
SQLDELIGHT_COROUTINES(
setOf(ANDROID, JVM, JS, IOS, LINUX, MACOS, WINDOWS, TV_OS, WATCH_OS),
"SQLDelight Coroutines",
"sqldelight.coroutines",
"com.squareup.sqldelight:coroutines-extensions:$SqlDelightVersion",
MAIN
),
SQLDELIGHT_DRIVER_ANDROID(
setOf(ANDROID),
"SQLDelight Android Driver",
"sqldelight.driver.android",
"com.squareup.sqldelight:android-driver:$SqlDelightVersion",
MAIN
),
SQLDELIGHT_DRIVER_JVM(
setOf(JVM),
"SQLDelight JVM Driver",
"sqldelight.driver.jvm",
"com.squareup.sqldelight:sqlite-driver:$SqlDelightVersion",
MAIN
),
SQLDELIGHT_DRIVER_JS(
setOf(JS),
"SQDelight JS Driver",
"sqldelight.driver.js",
"com.squareup.sqldelight:sqljs-driver:$SqlDelightVersion",
MAIN
),
SQLDELIGHT_DRIVER_NATIVE(
setOf(MACOS, IOS, TV_OS, WATCH_OS, LINUX, WINDOWS),
"SQLDelight Native Driver",
"sqldelight.driver.native",
"com.squareup.sqldelight:native-driver:$SqlDelightVersion",
MAIN
);
Expand Down
6 changes: 1 addition & 5 deletions src/jsMain/kotlin/org/jetbrains/webwiz/content/Chips.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ package org.jetbrains.webwiz.content

import androidx.compose.runtime.Composable
import org.jetbrains.compose.web.attributes.disabled
import org.jetbrains.compose.web.dom.CheckboxInput
import org.jetbrains.compose.web.dom.Div
import org.jetbrains.compose.web.dom.Label
import org.jetbrains.compose.web.dom.Span
import org.jetbrains.compose.web.dom.Text
import org.jetbrains.compose.web.dom.*
import org.jetbrains.webwiz.models.GradlePlugin
import org.jetbrains.webwiz.models.KmpLibrary
import org.jetbrains.webwiz.models.ProjectInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.compose.runtime.Composable
import org.jetbrains.compose.web.attributes.InputType
import org.jetbrains.compose.web.attributes.name
import org.jetbrains.compose.web.css.*
import org.jetbrains.compose.web.css.selectors.CSSSelector
import org.jetbrains.compose.web.dom.Form
import org.jetbrains.compose.web.dom.Input
import org.jetbrains.compose.web.dom.Label
Expand Down
16 changes: 4 additions & 12 deletions src/jsMain/kotlin/org/jetbrains/webwiz/content/IntroSection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,11 @@ package org.jetbrains.webwiz.content
import androidx.compose.runtime.Composable
import org.jetbrains.compose.web.attributes.ATarget
import org.jetbrains.compose.web.attributes.target
import org.jetbrains.compose.web.css.*
import org.jetbrains.compose.web.dom.A
import org.jetbrains.compose.web.dom.Div
import org.jetbrains.compose.web.dom.H1
import org.jetbrains.compose.web.dom.Img
import org.jetbrains.compose.web.dom.P
import org.jetbrains.compose.web.dom.Text
import org.jetbrains.compose.web.css.AlignSelf
import org.jetbrains.compose.web.css.alignSelf
import org.jetbrains.compose.web.dom.*
import org.jetbrains.webwiz.components.ContainerInSection
import org.jetbrains.webwiz.style.AppStylesheet
import org.jetbrains.webwiz.style.WtCols
import org.jetbrains.webwiz.style.WtOffsets
import org.jetbrains.webwiz.style.WtRows
import org.jetbrains.webwiz.style.WtTexts
import org.jetbrains.webwiz.style.*

@Composable
fun Intro() {
Expand Down
11 changes: 1 addition & 10 deletions src/jsMain/kotlin/org/jetbrains/webwiz/style/WtCol.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
package org.jetbrains.webwiz.style

import org.jetbrains.compose.web.css.CSSBuilder
import org.jetbrains.compose.web.css.CSSUnitValue
import org.jetbrains.compose.web.css.GenericStyleSheetBuilder
import org.jetbrains.compose.web.css.StyleSheet
import org.jetbrains.compose.web.css.flexGrow
import org.jetbrains.compose.web.css.maxWidth
import org.jetbrains.compose.web.css.media
import org.jetbrains.compose.web.css.percent
import org.jetbrains.compose.web.css.px
import org.jetbrains.compose.web.css.mediaMaxWidth
import org.jetbrains.compose.web.css.*
import org.jetbrains.compose.web.css.selectors.CSSSelector

fun <TBuilder> GenericStyleSheetBuilder<TBuilder>.mediaMaxWidth(
Expand Down
4 changes: 2 additions & 2 deletions src/jsMain/resources/ic_kotlin_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 798d211

Please sign in to comment.