fix(templates): .gitignore files are not generated in templates (closes #1014)

This commit is contained in:
Akash Yadav
2023-06-01 22:54:50 +05:30
parent 273893e2ef
commit 799d6f7e90
6 changed files with 122 additions and 4 deletions
@@ -0,0 +1,83 @@
# Built application files
*.apk
*.aar
*.ap_
*.aab
# Files for the ART/Dalvik VM
*.dex
# Java class files
*.class
# Generated files
/bin/
/gen/
/out/
# Uncomment the following line in case you need and you don't have the release build type files in your app
# Gradle files
.gradle/
/build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
# Android Studio captures folder
captures/
# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml
# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore
# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
.cxx/
# Google Services (e.g. APIs or Firebase)
# google-services.json
# Freeline
freeline.py
freeline/
freeline_project_description.json
# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md
# Version control
vcs.xml
# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/
@@ -21,6 +21,7 @@ import com.android.SdkConstants.ANDROID_MANIFEST_XML
import com.itsaky.androidide.templates.ModuleType.AndroidLibrary
import com.itsaky.androidide.templates.RecipeExecutor
import com.itsaky.androidide.templates.SrcSet
import com.itsaky.androidide.templates.base.modules.android.androidGitignoreSrc
import com.itsaky.androidide.templates.base.modules.android.buildGradleSrc
import com.itsaky.androidide.templates.base.modules.android.proguardRules
import com.itsaky.androidide.templates.base.util.AndroidManifestBuilder
@@ -119,6 +120,10 @@ class AndroidModuleTemplateBuilder : ModuleTemplateBuilder() {
}
override fun RecipeExecutor.postConfig() {
// Write .gitignore
gitignore()
manifest.apply {
generate(manifestFile())
}
@@ -141,4 +146,12 @@ class AndroidModuleTemplateBuilder : ModuleTemplateBuilder() {
override fun RecipeExecutor.buildGradle() {
save(buildGradleSrc(isComposeModule), buildGradleFile())
}
/**
* Writes the `.gitignore` file in the mdoule directory.
*/
fun RecipeExecutor.gitignore() {
val gitignore = File(data.projectDir, ".gitignore")
save(androidGitignoreSrc(), gitignore)
}
}
@@ -157,8 +157,7 @@ abstract class ModuleTemplateBuilder :
* @param extraConfig Called after the [recipe] is executed. Caller can perform its own
* post-recipe configuration here.
*/
fun commonPostRecipe(isComposeModule: Boolean = false,
extraConfig: TemplateRecipeFinalizer = {}
fun commonPostRecipe(extraConfig: TemplateRecipeFinalizer = {}
): TemplateRecipeFinalizer = {
// Write build.gradle[.kts]
@@ -169,7 +168,9 @@ abstract class ModuleTemplateBuilder :
}
/**
* Add the dependency with the given maven coordinates to this module with the [DependencyConfiguration.Implementation] configuration.
* Add the dependency with the given maven coordinates to this module with the
* [Implementation][com.itsaky.androidide.templates.base.models.DependencyConfiguration.Implementation]
* configuration.
*
* @param group The group ID of the dependency.
* @param artifact The artifact of the dependency.
@@ -177,7 +178,9 @@ abstract class ModuleTemplateBuilder :
* @param isPlatform Whether this dependency declares a BOM.
*/
@JvmOverloads
fun addDependency(group: String, artifact: String, version: String, isPlatform: Boolean = false) {
fun addDependency(group: String, artifact: String, version: String,
isPlatform: Boolean = false
) {
addDependency(defaultDependency(group, artifact, version), isPlatform)
}
@@ -131,6 +131,14 @@ class ProjectTemplateBuilder :
gradleWrapperProps()
}
/**
* Writes the `.gitignore` file in the project directory.
*/
fun gitignore() {
val gitignore = File(data.projectDir, ".gitignore")
executor.copyAsset(baseAsset("gitignore"), gitignore)
}
override fun buildInternal(): ProjectTemplate {
return ProjectTemplate(modules, templateName!!, thumb!!, description,
widgets!!, recipe!!)
@@ -130,6 +130,9 @@ fun baseProject(sdkFilter: ((Sdk) -> Boolean)? = null,
// gradle/wrapper/gradle-wrapper.jar
// gradle/wrapper/gradle-wrapper.properties
gradleWrapper()
// .gitignore
gitignore()
}
block()
@@ -34,3 +34,11 @@ fun AndroidModuleTemplateBuilder.proguardRules() {
val file = proguardRulesFile()
executor.copyAsset(baseAsset(file.name), file)
}
/**
* `.gitignore` file source for android modules.
*/
fun AndroidModuleTemplateBuilder.androidGitignoreSrc()
= """
/build
""".trimIndent()