From e97df669a4277888f574ae980350876c338c1e82 Mon Sep 17 00:00:00 2001 From: Carlos Martino Date: Wed, 17 Sep 2025 14:25:27 -0300 Subject: [PATCH] Initial commit --- .editorconfig | 14 ++++++ build.gradle.kts | 4 +- checks.gradle.kts | 43 +++++++++++++++++++ composeApp/build.gradle.kts | 19 +++++--- .../carlosmartino/triplogic/MainActivity.kt | 2 +- .../triplogic/Platform.android.kt | 2 +- .../kotlin/dev/carlosmartino/triplogic/App.kt | 12 +++--- .../dev/carlosmartino/triplogic/Greeting.kt | 6 +-- .../dev/carlosmartino/triplogic/Platform.kt | 2 +- .../triplogic/ComposeAppCommonTest.kt | 3 +- .../triplogic/MainViewController.kt | 2 +- .../carlosmartino/triplogic/Platform.ios.kt | 4 +- gradle.properties | 4 +- settings.gradle.kts | 2 +- 14 files changed, 91 insertions(+), 28 deletions(-) create mode 100644 .editorconfig create mode 100644 checks.gradle.kts diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..96715f8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +[*.{kt,kts}] +ktlint_code_style = ktlint_official +ktlint_function_naming_ignore_when_annotated_with = Composable +ktlint_standard_filename = disabled +ktlint_standard_max-line-length = 140 +ktlint_standard_multiline-expression-wrapping = disabled +ktlint_standard_backing-property-naming = disabled +ktlint_standard_function-naming = disabled +ktlint_chain_method_rule_force_multiline_when_chain_operator_count_greater_or_equal_than = 5 + +[**/build/**] +generated_code = true +ij_formatter_enabled = false +ktlint = disabled diff --git a/build.gradle.kts b/build.gradle.kts index 430c60f..08ef576 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,4 +4,6 @@ plugins { alias(libs.plugins.composeMultiplatform) apply false alias(libs.plugins.composeCompiler) apply false alias(libs.plugins.kotlinMultiplatform) apply false -} \ No newline at end of file +} + +apply("checks.gradle.kts") diff --git a/checks.gradle.kts b/checks.gradle.kts new file mode 100644 index 0000000..9d782b2 --- /dev/null +++ b/checks.gradle.kts @@ -0,0 +1,43 @@ +tasks.register("ensureChecksPreCommitHook") { + group = "verification" + description = "Ensures that the Git pre-commit hook for ktlint is properly set up" + + doLast { + val gitHooksDir = rootProject.file(".git/hooks") + val preCommitHookFile = gitHooksDir.resolve("pre-commit") + val requiredHookContent = + """ + #!/bin/sh + + # https://github.com/pinterest/ktlint pre-commit hook + + ktlint + """.trimIndent() + + if (!gitHooksDir.exists()) { + logger.warn("Git hooks directory not found. Is this a Git repository?") + return@doLast + } + + if (!preCommitHookFile.exists()) { + logger.lifecycle("Creating ktlint pre-commit hook") + preCommitHookFile.writeText(requiredHookContent) + preCommitHookFile.setExecutable(true) + } else { + val currentContent = preCommitHookFile.readText() + if (!currentContent.contains(requiredHookContent)) { + logger.lifecycle("Updating pre-commit hook with ktlint check") + preCommitHookFile.writeText(requiredHookContent) + preCommitHookFile.setExecutable(true) + } else { + logger.lifecycle("ktlint pre-commit hook is already properly configured") + } + } + } +} + +gradle.projectsEvaluated { + tasks.matching { it.name != "ensureChecksPreCommitHook" }.configureEach { + dependsOn("ensureChecksPreCommitHook") + } +} diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index 68a8d9b..d5f537c 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -14,17 +14,17 @@ kotlin { jvmTarget.set(JvmTarget.JVM_11) } } - + listOf( iosArm64(), - iosSimulatorArm64() + iosSimulatorArm64(), ).forEach { iosTarget -> iosTarget.binaries.framework { baseName = "ComposeApp" isStatic = true } } - + sourceSets { androidMain.dependencies { implementation(compose.preview) @@ -48,12 +48,18 @@ kotlin { android { namespace = "dev.carlosmartino.triplogic" - compileSdk = libs.versions.android.compileSdk.get().toInt() + compileSdk = libs.versions.android.compileSdk + .get() + .toInt() defaultConfig { applicationId = "dev.carlosmartino.triplogic" - minSdk = libs.versions.android.minSdk.get().toInt() - targetSdk = libs.versions.android.targetSdk.get().toInt() + minSdk = libs.versions.android.minSdk + .get() + .toInt() + targetSdk = libs.versions.android.targetSdk + .get() + .toInt() versionCode = 1 versionName = "1.0" } @@ -76,4 +82,3 @@ android { dependencies { debugImplementation(compose.uiTooling) } - diff --git a/composeApp/src/androidMain/kotlin/dev/carlosmartino/triplogic/MainActivity.kt b/composeApp/src/androidMain/kotlin/dev/carlosmartino/triplogic/MainActivity.kt index 2805db0..1b912fe 100644 --- a/composeApp/src/androidMain/kotlin/dev/carlosmartino/triplogic/MainActivity.kt +++ b/composeApp/src/androidMain/kotlin/dev/carlosmartino/triplogic/MainActivity.kt @@ -22,4 +22,4 @@ class MainActivity : ComponentActivity() { @Composable fun AppAndroidPreview() { App() -} \ No newline at end of file +} diff --git a/composeApp/src/androidMain/kotlin/dev/carlosmartino/triplogic/Platform.android.kt b/composeApp/src/androidMain/kotlin/dev/carlosmartino/triplogic/Platform.android.kt index 2fee6d6..88ee662 100644 --- a/composeApp/src/androidMain/kotlin/dev/carlosmartino/triplogic/Platform.android.kt +++ b/composeApp/src/androidMain/kotlin/dev/carlosmartino/triplogic/Platform.android.kt @@ -6,4 +6,4 @@ class AndroidPlatform : Platform { override val name: String = "Android ${Build.VERSION.SDK_INT}" } -actual fun getPlatform(): Platform = AndroidPlatform() \ No newline at end of file +actual fun getPlatform(): Platform = AndroidPlatform() diff --git a/composeApp/src/commonMain/kotlin/dev/carlosmartino/triplogic/App.kt b/composeApp/src/commonMain/kotlin/dev/carlosmartino/triplogic/App.kt index b97ff8f..bcfacec 100644 --- a/composeApp/src/commonMain/kotlin/dev/carlosmartino/triplogic/App.kt +++ b/composeApp/src/commonMain/kotlin/dev/carlosmartino/triplogic/App.kt @@ -10,15 +10,16 @@ import androidx.compose.foundation.layout.safeContentPadding import androidx.compose.material3.Button import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text -import androidx.compose.runtime.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import org.jetbrains.compose.resources.painterResource import org.jetbrains.compose.ui.tooling.preview.Preview -import triplogic.composeapp.generated.resources.Res -import triplogic.composeapp.generated.resources.compose_multiplatform - @Composable @Preview fun App() { @@ -40,10 +41,9 @@ fun App() { modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally, ) { - Image(painterResource(Res.drawable.compose_multiplatform), null) Text("Compose: $greeting") } } } } -} \ No newline at end of file +} diff --git a/composeApp/src/commonMain/kotlin/dev/carlosmartino/triplogic/Greeting.kt b/composeApp/src/commonMain/kotlin/dev/carlosmartino/triplogic/Greeting.kt index 01f374d..5b8bd81 100644 --- a/composeApp/src/commonMain/kotlin/dev/carlosmartino/triplogic/Greeting.kt +++ b/composeApp/src/commonMain/kotlin/dev/carlosmartino/triplogic/Greeting.kt @@ -3,7 +3,5 @@ package dev.carlosmartino.triplogic class Greeting { private val platform = getPlatform() - fun greet(): String { - return "Hello, ${platform.name}!" - } -} \ No newline at end of file + fun greet(): String = "Hello, ${platform.name}!" +} diff --git a/composeApp/src/commonMain/kotlin/dev/carlosmartino/triplogic/Platform.kt b/composeApp/src/commonMain/kotlin/dev/carlosmartino/triplogic/Platform.kt index 559159b..c41b0c0 100644 --- a/composeApp/src/commonMain/kotlin/dev/carlosmartino/triplogic/Platform.kt +++ b/composeApp/src/commonMain/kotlin/dev/carlosmartino/triplogic/Platform.kt @@ -4,4 +4,4 @@ interface Platform { val name: String } -expect fun getPlatform(): Platform \ No newline at end of file +expect fun getPlatform(): Platform diff --git a/composeApp/src/commonTest/kotlin/dev/carlosmartino/triplogic/ComposeAppCommonTest.kt b/composeApp/src/commonTest/kotlin/dev/carlosmartino/triplogic/ComposeAppCommonTest.kt index 874043d..a28a11e 100644 --- a/composeApp/src/commonTest/kotlin/dev/carlosmartino/triplogic/ComposeAppCommonTest.kt +++ b/composeApp/src/commonTest/kotlin/dev/carlosmartino/triplogic/ComposeAppCommonTest.kt @@ -4,9 +4,8 @@ import kotlin.test.Test import kotlin.test.assertEquals class ComposeAppCommonTest { - @Test fun example() { assertEquals(3, 1 + 2) } -} \ No newline at end of file +} diff --git a/composeApp/src/iosMain/kotlin/dev/carlosmartino/triplogic/MainViewController.kt b/composeApp/src/iosMain/kotlin/dev/carlosmartino/triplogic/MainViewController.kt index b7220d7..5c7131f 100644 --- a/composeApp/src/iosMain/kotlin/dev/carlosmartino/triplogic/MainViewController.kt +++ b/composeApp/src/iosMain/kotlin/dev/carlosmartino/triplogic/MainViewController.kt @@ -2,4 +2,4 @@ package dev.carlosmartino.triplogic import androidx.compose.ui.window.ComposeUIViewController -fun MainViewController() = ComposeUIViewController { App() } \ No newline at end of file +fun MainViewController() = ComposeUIViewController { App() } diff --git a/composeApp/src/iosMain/kotlin/dev/carlosmartino/triplogic/Platform.ios.kt b/composeApp/src/iosMain/kotlin/dev/carlosmartino/triplogic/Platform.ios.kt index a2b2ace..c7f424e 100644 --- a/composeApp/src/iosMain/kotlin/dev/carlosmartino/triplogic/Platform.ios.kt +++ b/composeApp/src/iosMain/kotlin/dev/carlosmartino/triplogic/Platform.ios.kt @@ -2,8 +2,8 @@ package dev.carlosmartino.triplogic import platform.UIKit.UIDevice -class IOSPlatform: Platform { +class IOSPlatform : Platform { override val name: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion } -actual fun getPlatform(): Platform = IOSPlatform() \ No newline at end of file +actual fun getPlatform(): Platform = IOSPlatform() diff --git a/gradle.properties b/gradle.properties index 6f8e6ea..a01df05 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,8 @@ #Kotlin kotlin.code.style=official -kotlin.daemon.jvmargs=-Xmx3072M +kotlin.daemon.jvmargs=-Xmx4096M +kotlin.native.ignoreDisabledTargets=true +kotlin.mpp.enableCInteropCommonization=true #Gradle org.gradle.jvmargs=-Xmx4096M -Dfile.encoding=UTF-8 diff --git a/settings.gradle.kts b/settings.gradle.kts index d7ce749..a90c96d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -28,4 +28,4 @@ dependencyResolutionManagement { } } -include(":composeApp") \ No newline at end of file +include(":composeApp")