From bd263516e4e216c3b75f2314279c23b27b5930d9 Mon Sep 17 00:00:00 2001 From: "Daniel A. A. Pelsmaeker" Date: Thu, 1 Aug 2024 16:04:46 +0200 Subject: [PATCH] Add forceGenerate option --- repoman/build.gradle.kts | 5 ++-- .../org/metaborg/repoman/GenerateCommand.kt | 27 +++++++++++-------- .../org/metaborg/repoman/meta/RepoMetadata.kt | 12 ++++----- .../resources/templates/build.gradle.kts.kte | 1 + 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/repoman/build.gradle.kts b/repoman/build.gradle.kts index f166faf..1dc1379 100644 --- a/repoman/build.gradle.kts +++ b/repoman/build.gradle.kts @@ -16,10 +16,11 @@ version = gitonium.version group = "org.metaborg" description = "Repository manager for Metaborg/Spoofax projects." +val jteVersion = "3.1.12" dependencies { implementation("com.github.ajalt.clikt:clikt:4.4.0") // CLI interface - implementation("gg.jte:jte:3.1.12") // Templating engine - implementation("gg.jte:jte-kotlin:3.1.12") // Templating engine (Kotlin support) + implementation("gg.jte:jte:$jteVersion") // Templating engine + implementation("gg.jte:jte-kotlin:$jteVersion") // Templating engine (Kotlin support) implementation("com.charleskorn.kaml:kaml:0.59.0") // Deserialize YAML files testImplementation (libs.kotest) diff --git a/repoman/src/main/kotlin/org/metaborg/repoman/GenerateCommand.kt b/repoman/src/main/kotlin/org/metaborg/repoman/GenerateCommand.kt index be2fd3c..7f34d53 100644 --- a/repoman/src/main/kotlin/org/metaborg/repoman/GenerateCommand.kt +++ b/repoman/src/main/kotlin/org/metaborg/repoman/GenerateCommand.kt @@ -48,9 +48,14 @@ object GenerateCommand: CliktCommand( val gradleBin: String by option("--gradle-bin", help = "The Gradle binary to invoke") .default("gradle") + /** Whether to force generating files if they don't exist. Use this to just generate all files initially + * and then manually modify them as necessary. */ + val forceGenerate: Boolean by option("-f", "--force-generate", help = "Force generating files if they don't exist") + .flag(default = false) + /** Whether to force updating files even if they exist. Use this to just update all files and manually * use version control to sort out what to actually update. */ - val forceUpdate: Boolean by option("-f", "--force-update", help = "Force updating files even if they exist") + val forceUpdate: Boolean by option("-F", "--force-update", help = "Force updating files even if they exist") .flag(default = false) @@ -95,13 +100,13 @@ object GenerateCommand: CliktCommand( private val meta: RepoMetadata, ) { fun generateReadme() { - val generate = meta.files.readme.generate + val generate = meta.files.readme.generate || forceGenerate val update = meta.files.readme.update || forceUpdate generate("README.md", generate, update) } fun generateLicense() { - val generate = meta.files.license.generate + val generate = meta.files.license.generate || forceGenerate val update = meta.files.license.update || forceUpdate if (meta.files.license.markdown) { if (update) repoDir.resolve("LICENSE").deleteIfExists() @@ -113,44 +118,44 @@ object GenerateCommand: CliktCommand( } fun generateContributing() { - val generate = meta.files.contributing.generate + val generate = meta.files.contributing.generate || forceGenerate val update = meta.files.contributing.update || forceUpdate generate("CONTRIBUTING.md", generate, update) } fun generateCodeOfConduct() { - val generate = meta.files.codeOfConduct.generate + val generate = meta.files.codeOfConduct.generate || forceGenerate val update = meta.files.codeOfConduct.update || forceUpdate generate("CODE_OF_CONDUCT.md", generate, update) } fun generateChangelog() { - val generate = meta.files.changelog.generate + val generate = meta.files.changelog.generate || forceGenerate val update = meta.files.changelog.update || forceUpdate generate("CHANGELOG.md", generate, update) } fun generateGitignore() { - val generate = meta.files.gitignore.generate + val generate = meta.files.gitignore.generate || forceGenerate val update = meta.files.gitignore.update || forceUpdate generate("gitignore", generate, update, path = ".gitignore") } fun generateGradleWrapper() { - val generate = meta.files.gradleWrapper.generate + val generate = meta.files.gradleWrapper.generate || forceGenerate val update = meta.files.gradleWrapper.update || forceUpdate generateGradleWrapper(generate, update) } fun generateGradleRootProject() { - val generate = meta.files.gradleRootProject.generate + val generate = meta.files.gradleRootProject.generate || forceGenerate val update = meta.files.gradleRootProject.update || forceUpdate generate("settings.gradle.kts", generate, update) generate("build.gradle.kts", generate, update) } fun generateGithubWorkflows() { - val generate = meta.files.githubWorkflows.generate + val generate = meta.files.githubWorkflows.generate || forceGenerate val update = meta.files.githubWorkflows.update || forceUpdate generate("github/workflows/build.yaml", generate, update, path = ".github/workflows/build.yaml") if (meta.files.githubWorkflows.buildDocs) { @@ -159,7 +164,7 @@ object GenerateCommand: CliktCommand( } fun generateGithubIssueTemplates() { - val generate = meta.files.githubIssueTemplates.generate + val generate = meta.files.githubIssueTemplates.generate || forceGenerate val update = meta.files.githubIssueTemplates.update || forceUpdate generate("github/ISSUE_TEMPLATE/config.yml", generate, update, path = ".github/ISSUE_TEMPLATE/config.yml") generate("github/ISSUE_TEMPLATE/20-report-a-bug.yml", generate, update, path = ".github/ISSUE_TEMPLATE/20-report-a-bug.yml") diff --git a/repoman/src/main/kotlin/org/metaborg/repoman/meta/RepoMetadata.kt b/repoman/src/main/kotlin/org/metaborg/repoman/meta/RepoMetadata.kt index 4c2667e..f3539b7 100644 --- a/repoman/src/main/kotlin/org/metaborg/repoman/meta/RepoMetadata.kt +++ b/repoman/src/main/kotlin/org/metaborg/repoman/meta/RepoMetadata.kt @@ -131,9 +131,9 @@ data class CodeOfConduct( @Serializable data class Changelog( /** Whether to generate the file. */ - val generate: Boolean = true, + val generate: Boolean = false, /** Whether to update the file. */ - val update: Boolean = false, + val update: Boolean = generate, ) /** Metadata for the .gitignore file. */ @@ -164,9 +164,9 @@ data class GradleWrapper( @Serializable data class GradleRootProject( /** Whether to generate the files. */ - val generate: Boolean = true, + val generate: Boolean = false, /** Whether to update the file. */ - val update: Boolean = false, + val update: Boolean = generate, /** The name of the root project. */ val rootProjectName: String? = null, /** Included builds. */ @@ -176,7 +176,7 @@ data class GradleRootProject( /** The version of the Metaborg Gradle convention to use. */ val conventionVersion: String = "latest.integration", /** Whether to create `publish` tasks that delegate to the included builds and subprojects. */ - val createPublishTasks: Boolean = false, + val createPublishTasks: Boolean = true, ) /** Metadata for the GitHub workflows. */ @@ -204,7 +204,7 @@ data class GithubWorkflows( @Serializable data class GithubIssueTemplates( /** Whether to generate the files. */ - val generate: Boolean = true, + val generate: Boolean = false, /** Whether to update the file. */ val update: Boolean = generate, /** Whether to automatically assign developers to issues. */ diff --git a/repoman/src/main/resources/templates/build.gradle.kts.kte b/repoman/src/main/resources/templates/build.gradle.kts.kte index e1c686f..d1559b3 100644 --- a/repoman/src/main/resources/templates/build.gradle.kts.kte +++ b/repoman/src/main/resources/templates/build.gradle.kts.kte @@ -15,6 +15,7 @@ import org.metaborg.convention.MavenPublishConventionExtension plugins { id("org.metaborg.convention.root-project") alias(libs.plugins.gitonium) + alias(libs.plugins.spoofax.gradle.langspec) apply false } @if(meta.files.gradleRootProject.createPublishTasks)