Skip to content

Commit 09a3eb9

Browse files
committed
Updated cleanup.gradle.kts with function to update AndroidManifest and TemplateApp.kt with proper project name. Added write permissions to cleanup.yml
1 parent f740699 commit 09a3eb9

2 files changed

Lines changed: 52 additions & 6 deletions

File tree

.github/workflows/cleanup.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
branches:
99
- main
1010

11+
12+
permissions:
13+
contents: write
14+
1115
jobs:
1216
template-cleanup:
1317
name: Template Cleanup
@@ -38,7 +42,7 @@ jobs:
3842
git commit -m "Template cleanup"
3943
# Push changes
4044
- name: Push changes
41-
uses: ad-m/github-push-action@v0.8.0
45+
uses: ad-m/github-push-action@master
4246
with:
4347
branch: main
4448
github_token: ${{ secrets.GITHUB_TOKEN }}

buildSrc/src/main/kotlin/cleanup.gradle.kts

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,16 @@ tasks.register("templateCleanup") {
3030
newValue = "rootProject.name = \"$name\""
3131
)
3232

33-
changePackageName(
34-
owner = owner,
35-
name = name
36-
)
33+
changePackageName(owner = owner, name = name)
34+
changeManifestFile(name = name)
3735

3836
// cleanup the cleanup :)
3937
file(path = ".github/workflows/cleanup.yml").delete()
4038
file(path = "build.gradle.kts").replace(
4139
oldValue = " cleanup\n",
4240
newValue = ""
4341
)
44-
file(path = "buildSrc/src/main/kotlin/cleanup.gradle.kts").delete()
42+
file(path = "buildSrc").deleteRecursively()
4543
}
4644
}
4745

@@ -107,4 +105,48 @@ fun changePackageName(owner: String, name: String) {
107105
}
108106
}
109107
}
108+
}
109+
110+
/**
111+
* Changes the Android manifest file and related app configurations.
112+
* @param name The name of the repository, usually the project name.
113+
*/
114+
fun changeManifestFile(name: String) {
115+
val capitalizedName = name.split("-", "_")
116+
.joinToString("") { it.replaceFirstChar { char -> char.uppercaseChar() } }
117+
118+
// Update AndroidManifest.xml files
119+
projectDir.walk()
120+
.filter { it.name == "AndroidManifest.xml" }
121+
.forEach { manifestFile ->
122+
manifestFile.replace(
123+
oldValue = "android:name=\".app.TemplateApp\"",
124+
newValue = "android:name=\".app.${capitalizedName}App\""
125+
)
126+
}
127+
128+
// Update strings.xml files
129+
projectDir.walk()
130+
.filter { it.name == "strings.xml" }
131+
.forEach { stringsFile ->
132+
stringsFile.replace(
133+
oldValue = "Compose Android Template",
134+
newValue = name.split("-", "_")
135+
.joinToString(" ") { it.replaceFirstChar { char -> char.uppercaseChar() } }
136+
)
137+
}
138+
139+
// Rename TemplateApp class files
140+
srcDirectories().forEach { srcDir ->
141+
srcDir.walk()
142+
.filter { it.isFile && it.name == "TemplateApp.kt" }
143+
.forEach { templateAppFile ->
144+
// Update class name inside the file
145+
templateAppFile.replace("class TemplateApp", "class ${capitalizedName}App")
146+
147+
// Rename the file itself
148+
val newFile = File(templateAppFile.parent, "${capitalizedName}App.kt")
149+
templateAppFile.renameTo(newFile)
150+
}
151+
}
110152
}

0 commit comments

Comments
 (0)