diff --git a/buildSrc/src/main/kotlin/dough_base.gradle.kts b/buildSrc/src/main/kotlin/dough_base.gradle.kts new file mode 100644 index 0000000..a0cd7d4 --- /dev/null +++ b/buildSrc/src/main/kotlin/dough_base.gradle.kts @@ -0,0 +1,36 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + `java-base` + + kotlin("multiplatform") + kotlin("plugin.serialization") +} + +repositories { + mavenCentral() +} + +java { + val javaVersion = JavaVersion.toVersion(17) + sourceCompatibility = javaVersion + targetCompatibility = javaVersion +} + +tasks.withType { + kotlinOptions.jvmTarget = "17" +} + +kotlin { + jvm() + + sourceSets { + commonMain { + dependencies { + api("org.jetbrains.kotlin:kotlin-bom") + api("org.jetbrains.kotlin:kotlin-stdlib") + api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1") + } + } + } +} diff --git a/buildSrc/src/main/kotlin/dough_component.gradle.kts b/buildSrc/src/main/kotlin/dough_component.gradle.kts index 7199428..34efc10 100644 --- a/buildSrc/src/main/kotlin/dough_component.gradle.kts +++ b/buildSrc/src/main/kotlin/dough_component.gradle.kts @@ -1,56 +1,4 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { - `maven-publish` - - kotlin("multiplatform") - kotlin("plugin.serialization") -} - -repositories { - mavenCentral() -} - -kotlin { - jvm() - - sourceSets { - commonMain { - dependencies { - api("org.jetbrains.kotlin:kotlin-bom") - api("org.jetbrains.kotlin:kotlin-stdlib") - api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1") - } - } - } -} - -java { - val javaVersion = JavaVersion.toVersion(17) - sourceCompatibility = javaVersion - targetCompatibility = javaVersion -} - -tasks.withType { - kotlinOptions.jvmTarget = "17" -} - -publishing { - repositories { - mavenLocal() - - var githubPackagesToken = System.getenv("GITHUB_TOKEN") - if (githubPackagesToken == null) { - githubPackagesToken = project.findProperty("github.token") as String? - } - - maven { - name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/gaypizzaspecifications/dough") - credentials { - username = project.findProperty("github.username") as String? ?: "gaypizzaspecifications" - password = githubPackagesToken - } - } - } + id("dough_base") + id("dough_publishing") } diff --git a/buildSrc/src/main/kotlin/dough_publishing.gradle.kts b/buildSrc/src/main/kotlin/dough_publishing.gradle.kts new file mode 100644 index 0000000..d2cd32d --- /dev/null +++ b/buildSrc/src/main/kotlin/dough_publishing.gradle.kts @@ -0,0 +1,25 @@ +plugins { + id("dough_base") + + `maven-publish` +} + +publishing { + repositories { + mavenLocal() + + var githubPackagesToken = System.getenv("GITHUB_TOKEN") + if (githubPackagesToken == null) { + githubPackagesToken = project.findProperty("github.token") as String? + } + + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/gaypizzaspecifications/dough") + credentials { + username = project.findProperty("github.username") as String? ?: "gaypizzaspecifications" + password = githubPackagesToken + } + } + } +} diff --git a/buildSrc/src/main/kotlin/dough_sample.gradle.kts b/buildSrc/src/main/kotlin/dough_sample.gradle.kts new file mode 100644 index 0000000..f458511 --- /dev/null +++ b/buildSrc/src/main/kotlin/dough_sample.gradle.kts @@ -0,0 +1,3 @@ +plugins { + id("dough_base") +} diff --git a/dough-fs/src/commonMain/kotlin/gay/pizza/dough/fs/DefaultFsPathSerializer.kt b/dough-fs/src/commonMain/kotlin/gay/pizza/dough/fs/DefaultFsPathSerializer.kt index 3e21ec3..b5e1ddc 100644 --- a/dough-fs/src/commonMain/kotlin/gay/pizza/dough/fs/DefaultFsPathSerializer.kt +++ b/dough-fs/src/commonMain/kotlin/gay/pizza/dough/fs/DefaultFsPathSerializer.kt @@ -1,3 +1,3 @@ package gay.pizza.dough.fs -object DefaultFsPathSerializer : FsPathSerializer({ FsPath(it) }) +object DefaultFsPathSerializer : FsPathSerializer(PlatformFsProvider) diff --git a/dough-fs/src/commonMain/kotlin/gay/pizza/dough/fs/FsPathResolver.kt b/dough-fs/src/commonMain/kotlin/gay/pizza/dough/fs/FsPathResolver.kt new file mode 100644 index 0000000..7941b63 --- /dev/null +++ b/dough-fs/src/commonMain/kotlin/gay/pizza/dough/fs/FsPathResolver.kt @@ -0,0 +1,5 @@ +package gay.pizza.dough.fs + +interface FsPathResolver { + fun resolve(path: String): FsPath +} diff --git a/dough-fs/src/commonMain/kotlin/gay/pizza/dough/fs/FsPathSerializer.kt b/dough-fs/src/commonMain/kotlin/gay/pizza/dough/fs/FsPathSerializer.kt index 6665f3e..7f6d66c 100644 --- a/dough-fs/src/commonMain/kotlin/gay/pizza/dough/fs/FsPathSerializer.kt +++ b/dough-fs/src/commonMain/kotlin/gay/pizza/dough/fs/FsPathSerializer.kt @@ -6,11 +6,11 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -open class FsPathSerializer(val construct: (String) -> FsPath) : KSerializer { +open class FsPathSerializer(val resolver: FsPathResolver) : KSerializer { override val descriptor: SerialDescriptor = String.serializer().descriptor override fun deserialize(decoder: Decoder): FsPath { - return construct(decoder.decodeString()) + return resolver.resolve(decoder.decodeString()) } override fun serialize(encoder: Encoder, value: FsPath) { diff --git a/dough-fs/src/commonMain/kotlin/gay/pizza/dough/fs/FsProvider.kt b/dough-fs/src/commonMain/kotlin/gay/pizza/dough/fs/FsProvider.kt index 7294973..cfbc7ca 100644 --- a/dough-fs/src/commonMain/kotlin/gay/pizza/dough/fs/FsProvider.kt +++ b/dough-fs/src/commonMain/kotlin/gay/pizza/dough/fs/FsProvider.kt @@ -1,8 +1,6 @@ package gay.pizza.dough.fs -interface FsProvider { +interface FsProvider : FsPathResolver { val currentWorkingDirectory: FsPath val operations: FsOperations - - fun resolve(path: String): FsPath } diff --git a/samples/current-time/build.gradle.kts b/samples/current-time/build.gradle.kts new file mode 100644 index 0000000..6895fb6 --- /dev/null +++ b/samples/current-time/build.gradle.kts @@ -0,0 +1,20 @@ +plugins { + dough_sample +} + +kotlin { + js(IR) { + nodejs() + browser() + + binaries.executable() + } + + sourceSets { + commonMain { + dependencies { + implementation(project(":dough-core")) + } + } + } +} diff --git a/samples/current-time/src/commonMain/kotlin/main.kt b/samples/current-time/src/commonMain/kotlin/main.kt new file mode 100644 index 0000000..7e02bf1 --- /dev/null +++ b/samples/current-time/src/commonMain/kotlin/main.kt @@ -0,0 +1,5 @@ +import gay.pizza.dough.core.PlatformClock + +fun main() { + println(PlatformClock.now().millisecondsSinceEpoch) +} diff --git a/samples/fs-walk/build.gradle.kts b/samples/fs-walk/build.gradle.kts new file mode 100644 index 0000000..1a2828f --- /dev/null +++ b/samples/fs-walk/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + dough_sample +} + +kotlin { + sourceSets { + commonMain { + dependencies { + implementation(project(":dough-fs")) + } + } + } +} \ No newline at end of file diff --git a/samples/fs-walk/src/commonMain/kotlin/main.kt b/samples/fs-walk/src/commonMain/kotlin/main.kt new file mode 100644 index 0000000..3854ed6 --- /dev/null +++ b/samples/fs-walk/src/commonMain/kotlin/main.kt @@ -0,0 +1,10 @@ +import gay.pizza.dough.fs.PlatformFsProvider +import gay.pizza.dough.fs.walk + +fun main() { + val currentWorkingDirectory = PlatformFsProvider.currentWorkingDirectory + for (item in currentWorkingDirectory.walk()) { + val relative = item.relativeTo(currentWorkingDirectory) + println(relative.fullPathString) + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 7c39e8f..2a490a0 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,18 @@ rootProject.name = "dough" -include( - "dough-core", - "dough-fs" -) +val topLevelModules = rootProject.projectDir.listFiles { item: File -> + item.name.startsWith("dough-") && + item.isDirectory && + item.resolve("build.gradle.kts").exists() +}?.toList() ?: emptyList() + +val samples = rootProject.projectDir.resolve("samples").listFiles { item: File -> + item.isDirectory && + item.resolve("build.gradle.kts").exists() +}?.toList() ?: emptyList() + +(topLevelModules + samples).map { file -> + file.relativeTo(rootProject.projectDir) +}.forEach { file -> + include(file.path.replace(File.separator, ":")) +}