Skip to content

Commit

Permalink
Add forceGenerate option
Browse files Browse the repository at this point in the history
  • Loading branch information
Virtlink committed Aug 1, 2024
1 parent 4f91452 commit bd26351
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
5 changes: 3 additions & 2 deletions repoman/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 16 additions & 11 deletions repoman/src/main/kotlin/org/metaborg/repoman/GenerateCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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()
Expand All @@ -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) {
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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. */
Expand All @@ -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. */
Expand Down Expand Up @@ -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. */
Expand Down
1 change: 1 addition & 0 deletions repoman/src/main/resources/templates/build.gradle.kts.kte
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bd26351

Please sign in to comment.