[orx-git-archiver-gradle] Add Gradle plugin for GitArchiver

This commit is contained in:
Edwin Jakobs
2021-11-23 10:09:10 +01:00
parent 5abdbd4572
commit bce724a73b
4 changed files with 86 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
# orx-git-archive-gradle
A Gradle plugin that turns a git history and `screenshots` directory into a markdown file.
## Usage
`openrndr-template` uses this plugin by default. All you need to do is use [orx-git-archiver](../orx-git-archiver) such
that screenshots will have the Git commit id in their filename.

View File

@@ -0,0 +1,17 @@
plugins {
kotlin("jvm")
`java-gradle-plugin`
}
dependencies {
implementation(project(":orx-jvm:orx-git-archiver"))
}
gradlePlugin {
plugins {
create("gitArchiveToMarkdown") {
id = "org.openrndr.extra.gitarchiver.tomarkdown"
implementationClass = "org.openrndr.extra.gitarchiver.GitArchiveToMarkdown"
}
}
}

View File

@@ -0,0 +1,59 @@
package org.openrndr.extra.gitarchiver
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*
import org.gradle.work.InputChanges
import java.io.File
import javax.inject.Inject
abstract class GitArchiveToMarkdown @Inject constructor() : DefaultTask() {
@get:OutputDirectory
abstract val outputDir: DirectoryProperty
@get:InputDirectory
abstract val gitDir: DirectoryProperty
@get:InputDirectory
abstract val screenshotsDir: DirectoryProperty
@get:Input
abstract val historySize: Property<Int>
@TaskAction
fun execute(inputChanges: InputChanges) {
val parent = outputDir.asFile.get()
val git = GitProvider.create()
val references = git.logReferences(historySize.get())
val text = references.map { reference ->
val screenshots = screenshotsDir.asFile.get().listFiles().filter { file ->
file.extension == "png" && file.name.contains(reference)
}
println(screenshots)
screenshots.forEach {
it.copyTo(File(outputDir.asFile.get(), it.name))
}
val screenShotsMD = screenshots.map {
"![${it.nameWithoutExtension}](${it.name})"
}.joinToString("\n")
"""# $reference
|$screenShotsMD
|```
|${git.show(reference)}}
|```
""".trimMargin()
}.joinToString("\n")
File(parent, "README.md").writeText(text)
}
init {
outputDir.set(File("build/git-archive-markdown"))
gitDir.set(File(".git"))
screenshotsDir.set(File("screenshots"))
historySize.set(20)
}
}

View File

@@ -13,6 +13,7 @@ include 'openrndr-demos',
'orx-filter-extension',
'orx-fx',
'orx-jvm:orx-git-archiver',
'orx-jvm:orx-git-archiver-gradle',
'orx-glslify',
'orx-gradient-descent',
'orx-integral-image',