@@ -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