A fully functional Android app built entirely with Kotlin and Jetpack Compose
π§ββοΈ Mermaid Graphs legends
Simon Marquis5009c37bbcbf
diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Graph.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Graph.ktindex 85d5b956d..c7222d730 100644--- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Graph.kt+++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/Graph.kt@@ -132,11 +132,13 @@ internal fun Project.configureGraphTasks() {projectPath = [email protected]dependencies = graph.dependencies()plugins = graph.plugins()- output = [email protected]("mermaid.txt")+ output = [email protected]("mermaid/graph.txt")+ legend = [email protected]("mermaid/legend.txt")}tasks.register<GraphUpdateTask>("graphUpdate") {projectPath = [email protected]input = dumpTask.flatMap { it.output }+ legend = dumpTask.flatMap { it.legend }output = [email protected]("README.md")}}@@ -156,11 +158,15 @@ private abstract class GraphDumpTask : DefaultTask() {@get:OutputFileabstract val output: RegularFileProperty+ @get:OutputFile+ abstract val legend: RegularFileProperty+override fun getDescription() = "Dumps project dependencies to a mermaid file."@TaskActionoperator fun invoke() {output.get().asFile.writeText(mermaid())+ legend.get().asFile.writeText(legend())logger.lifecycle(output.get().asFile.toPath().toUri().toString())}@@ -208,6 +214,27 @@ private abstract class GraphDumpTask : DefaultTask() {PluginType.entries.forEach { appendLine(it.classDef()) }}+ private fun legend() = buildString {+ appendLine("graph TB")+ listOf(+ "application" to PluginType.AndroidApplication,+ "feature" to PluginType.AndroidFeature,+ "library" to PluginType.AndroidLibrary,+ "jvm" to PluginType.Jvm,+ ).forEach { (name, type) ->+ appendLine(name.alias(indent = 2, type))+ }+ appendLine()+ listOf(+ Dependency("application", "implementation", "feature"),+ Dependency("library", "api", "jvm"),+ ).forEach {+ appendLine(it.link(indent = 2))+ }+ appendLine()+ PluginType.entries.forEach { appendLine(it.classDef()) }+ }+private class Dependency(val project: String, val configuration: String, val dependency: String)private fun Pair<String, String>.toDependency(project: String) =@@ -246,6 +273,10 @@ private abstract class GraphUpdateTask : DefaultTask() {@get:PathSensitive(NONE)abstract val input: RegularFileProperty+ @get:InputFile+ @get:PathSensitive(NONE)+ abstract val legend: RegularFileProperty+@get:OutputFileabstract val output: RegularFileProperty@@ -266,15 +297,24 @@ private abstract class GraphUpdateTask : DefaultTask() {""".trimIndent(),)}+ val mermaid = input.get().asFile.readText().trimTrailingNewLines()+ val legend = legend.get().asFile.readText().trimTrailingNewLines()val regex = """(<!--region graph-->)(.*?)(<!--endregion-->)""".toRegex(DOT_MATCHES_ALL)val text = readText().replace(regex) { match ->val (start, _, end) = match.destructured- val mermaid = input.get().asFile.readText().trimTrailingNewLines()"""|$start|```mermaid|$mermaid|```+ |+ |<details><summary>π Graph legend</summary>+ |+ |```mermaid+ |$legend+ |```+ |+ |</details>|$end""".trimMargin()}