Skip to content

Commit

Permalink
Use custom resource directories for font variants
Browse files Browse the repository at this point in the history
The font files are now downloaded to the build directory and directly used from there.
  • Loading branch information
tclement0922 committed Oct 19, 2024
1 parent 028b514 commit 25d63dc
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
3 changes: 1 addition & 2 deletions font-fa/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/build
/*/build
*.otf
/*/build
6 changes: 1 addition & 5 deletions font-fa/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ val downloadFiles by tasks.creating(Download::class) {
path = if (name.endsWith(".json")) {
"build/icons.json"
} else {
fonts[name] + "/src/commonMain/composeResources/font/fontawesome_${fonts[name]}.otf"
"${fonts[name]}/build/composeResources/font/fontawesome_${fonts[name]}.otf"
}
}
overwrite(false)
Expand Down Expand Up @@ -120,10 +120,6 @@ val createFAFile by tasks.creating(Task::class) {
}
}

tasks.clean {
delete.add(downloadFiles.outputs.files)
}

childProjects.forEach { (_, child) ->
child.afterEvaluate {
child.tasks.named("copyNonXmlValueResourcesForCommonMain") { dependsOn(downloadFiles) }
Expand Down
3 changes: 1 addition & 2 deletions font-symbols/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/build
/*/build
*.ttf
/*/build
6 changes: 1 addition & 5 deletions font-symbols/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ val downloadFiles by tasks.creating(Download::class) {
"build/$name"
} else {
val variant = fonts[name.removeSuffix(".ttf")]
"$variant/src/commonMain/composeResources/font/material_symbols_$variant.ttf"
"$variant/build/composeResources/font/material_symbols_$variant.ttf"
}
}
overwrite(false)
Expand Down Expand Up @@ -137,10 +137,6 @@ val createSymbolsFile by tasks.creating(Task::class) {
}
}

tasks.clean {
delete.add(downloadFiles.outputs.files)
}

childProjects.forEach { (_, child) ->
child.afterEvaluate {
child.tasks.named("copyNonXmlValueResourcesForCommonMain") { dependsOn(downloadFiles) }
Expand Down
9 changes: 9 additions & 0 deletions plugins/src/main/kotlin/dev/tclement/fonticons/FAVariant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.support.uppercaseFirstChar
import org.jetbrains.compose.ComposeExtension
import org.jetbrains.compose.resources.ResourcesExtension
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension

private const val TARGET_PACKAGE = "dev.tclement.fonticons.fa"
Expand Down Expand Up @@ -81,4 +84,10 @@ fun Project.setupSourcesForFAVariant(variant: String) {
kotlinExtension.sourceSets.named("commonMain") {
kotlin.srcDir(createFAVariantFiles.output)
}

configure<ComposeExtension> {
configure<ResourcesExtension> {
customDirectory("commonMain", project.layout.buildDirectory.dir("composeResources"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.support.uppercaseFirstChar
import org.jetbrains.compose.ComposeExtension
import org.jetbrains.compose.resources.ResourcesExtension
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension

private const val TARGET_PACKAGE = "dev.tclement.fonticons.symbols"
Expand Down Expand Up @@ -161,4 +164,10 @@ fun Project.setupSourcesForSymbolsVariant(variant: String) {
kotlinExtension.sourceSets.named("androidMain") {
kotlin.srcDir(createSymbolsVariantFiles.androidOutput)
}

configure<ComposeExtension> {
configure<ResourcesExtension> {
customDirectory("commonMain", project.layout.buildDirectory.dir("composeResources"))
}
}
}

0 comments on commit 25d63dc

Please sign in to comment.