Skip to content

Commit c7c45f4

Browse files
authored
Fully qualify module names (#37)
* Implement aliasing in Mermaid diagram with unique IDs and custom display names * Update README * Make AndroidApp have higher precedence than ReactNativeLibrary
1 parent 2243a28 commit c7c45f4

11 files changed

Lines changed: 174 additions & 174 deletions

File tree

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ moduleGraphConfig {
8181
excludedConfigurationsRegex = ".*test.*" // optional
8282
excludedModulesRegex = ".*moduleName.*" // optional
8383
focusedModulesRegex = ".*(projectName).*" // optional
84+
setStyleByPluginType = true // optional
8485
theme = Theme.NEUTRAL // optional
8586
// Or you can fully customize it by using the BASE theme:
8687
// theme = new Theme.BASE(
@@ -165,6 +166,7 @@ moduleGraphConfig {
165166
showFullPath.set(false) // optional
166167
orientation.set(Orientation.LEFT_TO_RIGHT) //optional
167168
linkText.set(LinkText.NONE) // optional
169+
setStyleByPluginType.set(true) // optional
168170
excludedConfigurationsRegex.set(".*test.*") // optional
169171
excludedModulesRegex.set(".*moduleName.*") // optional
170172
focusedModulesRegex.set(".*(projectName).*") // optional
@@ -212,13 +214,12 @@ Required settings:
212214

213215
Optional settings:
214216

215-
- **focusedModulesRegex**: The Pattern (Regex) to match nodes in the graph (project names) that should be focused. By
217+
- **setStyleByPluginType**: Whether to style the modules based on their type (KotlinMultiplatform, Android Library, etc). Default is `false`. [Read more](#module-type-based-styling).
218+
- **focusedModulesRegex**: The regex to match nodes in the graph (project names) that should be focused. By
216219
default, no nodes are focused.
217-
If set, the matching nodes will be highlighted. The color can be customized via the `focusColor` property
220+
If set, the matching nodes will be highlighted and only related nodes will be shown. The color can be customized via the `focusColor` property
218221
from `Theme.BASE`. [Read more](#focusing-on-specific-nodes).
219-
- **showFullPath**: Whether to show the full path of the modules in the graph. Default is `false`. **Use this if you
220-
have
221-
**modules with the same name in different paths**. This will remove the subgraphs from the graph.
222+
- **showFullPath**: Whether to show the full path of the modules in the graph. Default is `false`. This removes subgraphs.
222223
- **theme**: The [mermaid theme](https://mermaid.js.org/config/theming.html) to be used for styling
223224
the graph. Default is `NEUTRAL`.
224225
- Further customization is possible by setting the `themeVariables` property on the `BASE` theme. Check the
@@ -416,9 +417,9 @@ That's it. Just run the task and you'll get a graph identifying modules by their
416417

417418
We have default styling for these module types:
418419

420+
- Android Application
419421
- React Native
420422
- Kotlin Multiplatform
421-
- Android Application
422423
- Android Library
423424
- Kotlin
424425
- Java Library

plugin-build/modulegraph/src/main/kotlin/dev/iurysouza/modulegraph/ModuleType.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ internal fun Project.hasLibraryDependency(dependencyGroupAndName: String): Boole
102102

103103
internal val pluginPrecedenceOrder = listOf(
104104
ModuleType.Custom::class,
105+
ModuleType.AndroidApp::class,
105106
ModuleType.ReactNativeLibrary::class,
106107
ModuleType.KotlinMultiplatform::class,
107-
ModuleType.AndroidApp::class,
108108
ModuleType.AndroidLibrary::class,
109109
ModuleType.Kotlin::class,
110110
ModuleType.JavaLibrary::class,

plugin-build/modulegraph/src/main/kotlin/dev/iurysouza/modulegraph/graph/DigraphBuilder.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ internal object DigraphBuilder {
8787
val groups = split(":")
8888
if (groups.size == 1) return ""
8989
return groups
90-
.takeLast(2)
91-
.take(1)
92-
.joinToString("")
90+
.dropLast(1)
91+
.joinToString(":")
9392
}
9493
}

plugin-build/modulegraph/src/main/kotlin/dev/iurysouza/modulegraph/graph/DigraphCodeBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal object DigraphCodeBuilder {
2828
)
2929

3030
private fun toMermaid(it: DigraphModel, linkText: LinkText): CharSequence = """
31-
| ${it.source.name} ${linkText.toLinkString(it.target.config.value)} ${it.target.name}
31+
| ${it.source.fullName} ${linkText.toLinkString(it.target.config.value)} ${it.target.fullName}
3232
""".trimMargin()
3333
}
3434

plugin-build/modulegraph/src/main/kotlin/dev/iurysouza/modulegraph/graph/NodeStyleBuilder.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal object NodeStyleBuilder {
2626
fun build(digraphModel: List<DigraphModel>, options: GraphOptions): MermaidCode {
2727
val distinctNodes = digraphModel
2828
.flatMap { listOf(it.source, it.target) }
29-
.distinctBy { it.name }
29+
.distinctBy { it.fullName }
3030
val focusedNodes = distinctNodes.filter { it.isFocused }
3131

3232
val pluginTypeStyling = applyStylingByPluginType(options, distinctNodes)
@@ -57,7 +57,7 @@ internal object NodeStyleBuilder {
5757
}
5858
""".trimMargin() + """
5959
|
60-
|${nodeList.joinToString("\n") { "class ${it.name} ${it.pluginClass()}" }}
60+
|${nodeList.joinToString("\n") { "class ${it.fullName} ${it.pluginClass()}" }}
6161
""".trimMargin()
6262
} else {
6363
""
@@ -82,7 +82,7 @@ internal object NodeStyleBuilder {
8282
"""
8383
|
8484
|${defineStyleClass(FOCUS_CLASS_NAME, theme.focusColor())}
85-
|${nodeList.joinToString("\n") { "class ${it.name} $FOCUS_CLASS_NAME" }}
85+
|${nodeList.joinToString("\n") { "class ${it.fullName} $FOCUS_CLASS_NAME" }}
8686
""".trimMargin()
8787
},
8888
)

plugin-build/modulegraph/src/main/kotlin/dev/iurysouza/modulegraph/graph/SubgraphBuilder.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal object SubgraphBuilder {
3131
subgraphModel: List<Pair<String, List<ModuleNode>>>,
3232
): MermaidCode = MermaidCode(
3333
subgraphModel.joinToString("\n") { (parent, children) ->
34-
val childrenNames = children.joinToString("\n") { " ${it.name}" }
34+
val childrenNames = children.joinToString("\n") { """ ${it.fullName}["${it.name}"]""" }
3535
"""| subgraph $parent
3636
|$childrenNames
3737
| end
@@ -45,7 +45,7 @@ internal object SubgraphBuilder {
4545
.flatMap { listOf(it.source, it.target) }
4646
.filter { it.parent.isNotEmpty() }
4747
.groupBy { it.parent }
48-
.map { (parent, children) -> parent to children.distinctBy { it.name } }
48+
.map { (parent, children) -> parent to children.distinctBy { it.fullName } }
4949
.sortedBy { it.first }
5050
.toList()
5151
}

plugin-build/modulegraph/src/test/java/dev/iurysouza/modulegraph/ModuleGraphPluginFunctionalTest.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ class ModuleGraphPluginFunctionalTest {
8383
}%%
8484
8585
graph RL
86-
subgraph groupFolder
87-
example2
86+
subgraph :groupFolder
87+
:groupFolder:example2["example2"]
8888
end
89-
example --> example2
89+
:example --> :groupFolder:example2
9090
```
9191
""".trimIndent()
9292
assertEquals(expectedOutput, readmeFile.readText())
@@ -151,10 +151,10 @@ class ModuleGraphPluginFunctionalTest {
151151
}%%
152152
153153
graph LR
154-
subgraph groupFolder
155-
example2
154+
subgraph :groupFolder
155+
:groupFolder:example2["example2"]
156156
end
157-
example --> example2
157+
:example --> :groupFolder:example2
158158
```
159159
""".trimIndent()
160160
assertEquals(expectedOutput, readmeFile.readText())
@@ -267,12 +267,12 @@ class ModuleGraphPluginFunctionalTest {
267267
}%%
268268
269269
graph RL
270-
subgraph groupFolder
271-
example2
272-
example3
270+
subgraph :groupFolder
271+
:groupFolder:example2["example2"]
272+
:groupFolder:example3["example3"]
273273
end
274-
example -- implementation --> example2
275-
example -- runtimeOnly --> example3
274+
:example -- implementation --> :groupFolder:example2
275+
:example -- runtimeOnly --> :groupFolder:example3
276276
```
277277
""".trimIndent()
278278
assertEquals(expectedOutput, readmeFile.readText())
@@ -372,10 +372,10 @@ class ModuleGraphPluginFunctionalTest {
372372
}%%
373373
374374
graph RL
375-
subgraph groupFolder
376-
example2
375+
subgraph :groupFolder
376+
:groupFolder:example2["example2"]
377377
end
378-
example --> example2
378+
:example --> :groupFolder:example2
379379
```
380380
""".trimIndent()
381381
assertEquals(expectedOutput, readmeFile.readText())

plugin-build/modulegraph/src/test/java/dev/iurysouza/modulegraph/graph/DigraphCodeBuilderTest.kt

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class DigraphCodeBuilderTest {
1919
)
2020

2121
val expectedMermaidCode = """
22-
| alpha --> gama
23-
| gama --> zeta
22+
| :sample:alpha --> :sample:container:gama
23+
| :sample:container:gama --> :sample:zeta
2424
""".trimMargin()
2525
assertEquals(expectedMermaidCode, mermaidCode.value)
2626
}
@@ -51,26 +51,26 @@ class DigraphCodeBuilderTest {
5151
)
5252

5353
val expectedMermaidCode = """
54-
| footballinfo --> common
55-
| match-day --> common
56-
| match-day --> footballinfo
57-
| match-day --> design-system
58-
| match-day --> reddit
59-
| match-thread --> webview-to-native-player
60-
| match-thread --> common
61-
| match-thread --> footballinfo
62-
| match-thread --> design-system
63-
| match-thread --> reddit
64-
| playground --> webview-to-native-player
65-
| playground --> match-thread
66-
| playground --> design-system
67-
| playground --> match-day
68-
| reddit --> common
69-
| webview-to-native-player --> common
70-
| main --> match-thread
71-
| main --> match-day
72-
| main --> design-system
73-
| main --> common
54+
| :core:footballinfo --> :core:common
55+
| :features:match-day --> :core:common
56+
| :features:match-day --> :core:footballinfo
57+
| :features:match-day --> :core:design-system
58+
| :features:match-day --> :core:reddit
59+
| :features:match-thread --> :core:webview-to-native-player
60+
| :features:match-thread --> :core:common
61+
| :features:match-thread --> :core:footballinfo
62+
| :features:match-thread --> :core:design-system
63+
| :features:match-thread --> :core:reddit
64+
| :app:playground --> :core:webview-to-native-player
65+
| :app:playground --> :features:match-thread
66+
| :app:playground --> :core:design-system
67+
| :app:playground --> :features:match-day
68+
| :core:reddit --> :core:common
69+
| :core:webview-to-native-player --> :core:common
70+
| :app:main --> :features:match-thread
71+
| :app:main --> :features:match-day
72+
| :app:main --> :core:design-system
73+
| :app:main --> :core:common
7474
""".trimMargin()
7575
assertEquals(expectedMermaidCode, mermaidCode.value)
7676
}

0 commit comments

Comments
 (0)