Readme template update
This commit is contained in:
parent
b8635df01c
commit
981687ee5e
@ -2,7 +2,7 @@ plugins {
|
|||||||
`java-gradle-plugin`
|
`java-gradle-plugin`
|
||||||
`kotlin-dsl`
|
`kotlin-dsl`
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
id("org.jetbrains.changelog") version "0.4.0"
|
id("org.jetbrains.changelog") version "0.5.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "ru.mipt.npm"
|
group = "ru.mipt.npm"
|
||||||
@ -37,7 +37,7 @@ gradlePlugin {
|
|||||||
create("kscience.project"){
|
create("kscience.project"){
|
||||||
id = "ru.mipt.npm.project"
|
id = "ru.mipt.npm.project"
|
||||||
description = "The root plugin for multimodule project infrastructure"
|
description = "The root plugin for multimodule project infrastructure"
|
||||||
implementationClass = "ru.mipt.npm.gradle.KScienceBasePlugin"
|
implementationClass = "ru.mipt.npm.gradle.KScienceProjectPlugin"
|
||||||
}
|
}
|
||||||
create("kscience.publish") {
|
create("kscience.publish") {
|
||||||
id = "ru.mipt.npm.publish"
|
id = "ru.mipt.npm.publish"
|
||||||
|
@ -8,8 +8,10 @@ import org.gradle.kotlin.dsl.extra
|
|||||||
import org.gradle.kotlin.dsl.findByType
|
import org.gradle.kotlin.dsl.findByType
|
||||||
import org.gradle.kotlin.dsl.provideDelegate
|
import org.gradle.kotlin.dsl.provideDelegate
|
||||||
import org.jetbrains.changelog.ChangelogPlugin
|
import org.jetbrains.changelog.ChangelogPlugin
|
||||||
|
import java.io.File
|
||||||
import kotlin.collections.component1
|
import kotlin.collections.component1
|
||||||
import kotlin.collections.component2
|
import kotlin.collections.component2
|
||||||
|
import kotlin.reflect.KFunction
|
||||||
|
|
||||||
class KSciencePublishingExtension(val project: Project) {
|
class KSciencePublishingExtension(val project: Project) {
|
||||||
var githubOrg: String? by project.extra
|
var githubOrg: String? by project.extra
|
||||||
@ -23,18 +25,54 @@ class KSciencePublishingExtension(val project: Project) {
|
|||||||
var bintrayRepo: String? by project.extra
|
var bintrayRepo: String? by project.extra
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class Maturity {
|
||||||
|
PROTOTYPE,
|
||||||
|
EXPERIMENTAL,
|
||||||
|
DEVELOPMENT,
|
||||||
|
PRODUCTION
|
||||||
|
}
|
||||||
|
|
||||||
class KScienceReadmeExtension(val project: Project) {
|
class KScienceReadmeExtension(val project: Project) {
|
||||||
val properties = HashMap<String, String>()
|
var description: String = ""
|
||||||
var readmeStubPath: String = "docs/README-STUB.md"
|
var maturity: Maturity = Maturity.EXPERIMENTAL
|
||||||
val features = ArrayList<Feature>()
|
|
||||||
|
var readmeTemplate: File = project.file("docs/README-TEMPLATE.md")//"docs/README-TEMPLATE.md"
|
||||||
|
|
||||||
data class Feature(val id: String, val ref: String, val description: String, val name: String = id)
|
data class Feature(val id: String, val ref: String, val description: String, val name: String = id)
|
||||||
|
|
||||||
|
val features = ArrayList<Feature>()
|
||||||
|
|
||||||
fun feature(id: String, ref: String, description: String, name: String = id) {
|
fun feature(id: String, ref: String, description: String, name: String = id) {
|
||||||
features.add(Feature(id, ref, description, name))
|
features.add(Feature(id, ref, description, name))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val properties: MutableMap<String, Any?> = mutableMapOf(
|
||||||
|
"name" to project.name,
|
||||||
|
"group" to project.group,
|
||||||
|
"version" to project.version,
|
||||||
|
"features" to featuresString()
|
||||||
|
)
|
||||||
|
|
||||||
|
private val actualizedProperties get() = properties.mapValues {(_,value)->
|
||||||
|
if(value is KFunction<*>){
|
||||||
|
value.call()
|
||||||
|
} else {
|
||||||
|
value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun property(key: String, value: Any?) {
|
||||||
|
properties[key] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
fun propertyByTemplate(key: String, template: String){
|
||||||
|
properties[key] = SimpleTemplateEngine().createTemplate(template).make(actualizedProperties).toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun propertyByTemplate(key: String, template: File){
|
||||||
|
properties[key] = SimpleTemplateEngine().createTemplate(template).make(actualizedProperties).toString()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a markdown string listing features
|
* Generate a markdown string listing features
|
||||||
*/
|
*/
|
||||||
@ -48,18 +86,8 @@ class KScienceReadmeExtension(val project: Project) {
|
|||||||
* Generate a readme string from the stub
|
* Generate a readme string from the stub
|
||||||
*/
|
*/
|
||||||
fun readmeString(): String? {
|
fun readmeString(): String? {
|
||||||
val readmeStubFile = project.file(readmeStubPath)
|
return if (readmeTemplate.exists()) {
|
||||||
return if (readmeStubFile.exists()) {
|
SimpleTemplateEngine().createTemplate(readmeTemplate).make(actualizedProperties).toString()
|
||||||
buildString {
|
|
||||||
|
|
||||||
val readmeProperties: Map<String, Any?> = (properties + mapOf(
|
|
||||||
"name" to project.name,
|
|
||||||
"group" to project.group,
|
|
||||||
"version" to project.version,
|
|
||||||
"features" to featuresString()
|
|
||||||
)).withDefault { null }
|
|
||||||
SimpleTemplateEngine().createTemplate(readmeStubFile).make(properties).toString()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
@ -74,19 +102,19 @@ open class KScienceProjectPlugin : Plugin<Project> {
|
|||||||
apply<ChangelogPlugin>()
|
apply<ChangelogPlugin>()
|
||||||
val rootReadmeExtension = KScienceReadmeExtension(this)
|
val rootReadmeExtension = KScienceReadmeExtension(this)
|
||||||
extensions.add("ksciencePublish", KSciencePublishingExtension(this))
|
extensions.add("ksciencePublish", KSciencePublishingExtension(this))
|
||||||
extensions.add("kscienceReadme", rootReadmeExtension)
|
extensions.add("readme", rootReadmeExtension)
|
||||||
|
|
||||||
//Add readme generators to individual subprojects
|
//Add readme generators to individual subprojects
|
||||||
subprojects {
|
subprojects {
|
||||||
val readmeExtension = KScienceReadmeExtension(this)
|
val readmeExtension = KScienceReadmeExtension(this)
|
||||||
extensions.add("kscienceReadme", readmeExtension)
|
extensions.add("readme", readmeExtension)
|
||||||
tasks.create("generateReadme") {
|
tasks.create("generateReadme") {
|
||||||
group = "documentation"
|
group = "documentation"
|
||||||
description = "Generate a README file if stub is present"
|
description = "Generate a README file if stub is present"
|
||||||
doLast {
|
doLast {
|
||||||
val readmeString = readmeExtension.readmeString()
|
val readmeString = readmeExtension.readmeString()
|
||||||
if (readmeString != null) {
|
if (readmeString != null) {
|
||||||
val readmeFile = file("README.md")
|
val readmeFile = this@subprojects.file("README.md")
|
||||||
readmeFile.writeText(readmeString)
|
readmeFile.writeText(readmeString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,27 +131,30 @@ open class KScienceProjectPlugin : Plugin<Project> {
|
|||||||
it.name to it.extensions.findByType<KScienceReadmeExtension>()
|
it.name to it.extensions.findByType<KScienceReadmeExtension>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rootReadmeExtension.readmeTemplate.exists()) {
|
||||||
val rootReadmeStub = project.file(rootReadmeExtension.readmeStubPath)
|
|
||||||
if (rootReadmeStub.exists()) {
|
|
||||||
|
|
||||||
val modulesString = buildString {
|
val modulesString = buildString {
|
||||||
projects.entries.filter { !it.value?.features.isNullOrEmpty() }.forEach { (name, ext) ->
|
projects.entries.forEach { (name, ext) ->
|
||||||
appendln("### [$name]($name)")
|
appendln("### [$name]($name)")
|
||||||
appendln(ext!!.featuresString(pathPrefix = "$name/"))
|
if (ext != null) {
|
||||||
|
appendln(ext.description)
|
||||||
|
appendln("**Maturity**: ${ext.maturity}")
|
||||||
|
appendln("#### Features:")
|
||||||
|
appendln(ext.featuresString(pathPrefix = "$name/"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val rootReadmeProperties: Map<String, Any> = mapOf(
|
val rootReadmeProperties: Map<String, Any?> = mapOf(
|
||||||
"name" to project.name,
|
"name" to project.name,
|
||||||
"group" to project.group,
|
"group" to project.group,
|
||||||
"version" to project.version,
|
"version" to project.version,
|
||||||
"modulesString" to modulesString
|
"modules" to modulesString
|
||||||
)
|
)
|
||||||
|
|
||||||
val readmeFile = project.file("README.md")
|
val readmeFile = project.file("README.md")
|
||||||
readmeFile.writeText(
|
readmeFile.writeText(
|
||||||
SimpleTemplateEngine().createTemplate(rootReadmeStub).make(rootReadmeProperties).toString()
|
SimpleTemplateEngine().createTemplate(rootReadmeExtension.readmeTemplate).make(rootReadmeProperties).toString()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user