Add Readme generator
This commit is contained in:
parent
25784a6916
commit
b8635df01c
19
CHANGELOG.md
19
CHANGELOG.md
@ -6,6 +6,25 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
### Added
|
||||
- Changelog plugin automatically applied to `project`
|
||||
- Feature matrix and Readme generation task for a `project` plugin
|
||||
|
||||
### Changed
|
||||
- Remove node plugin and make node binaries available by default
|
||||
- Use default webpack distribution path
|
||||
- `ru.mipt.npm.base` -> `ru.mipt.npm.project`
|
||||
- Move publishing out of general extension and apply it to project plugin instead.
|
||||
|
||||
### Deprecated
|
||||
|
||||
### Removed
|
||||
- Node plugin
|
||||
|
||||
### Fixed
|
||||
|
||||
### Security
|
||||
## [0.6.0]
|
||||
|
||||
### Added
|
||||
- Migrate to kotlin 1.4.0
|
||||
|
@ -6,7 +6,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "ru.mipt.npm"
|
||||
version = "0.6.0"
|
||||
version = "0.6.1"
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
@ -29,13 +29,14 @@ dependencies {
|
||||
implementation("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.14.4")
|
||||
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.4.0")
|
||||
implementation("org.jetbrains.dokka:dokka-base:1.4.0")
|
||||
implementation("org.jetbrains.intellij.plugins:gradle-changelog-plugin:0.5.0")
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
create("kscience.base"){
|
||||
id = "ru.mipt.npm.base"
|
||||
description = "The basic plugin that does not do anything but loading classpath, versions and extensions"
|
||||
create("kscience.project"){
|
||||
id = "ru.mipt.npm.project"
|
||||
description = "The root plugin for multimodule project infrastructure"
|
||||
implementationClass = "ru.mipt.npm.gradle.KScienceBasePlugin"
|
||||
}
|
||||
create("kscience.publish") {
|
||||
@ -67,12 +68,6 @@ gradlePlugin {
|
||||
description = "Additional native targets to be use alongside mpp"
|
||||
implementationClass = "ru.mipt.npm.gradle.KScienceNativePlugin"
|
||||
}
|
||||
|
||||
create("kscience.node") {
|
||||
id = "ru.mipt.npm.node"
|
||||
description = "NodeJS target for kotlin-mpp and kotlin-js"
|
||||
implementationClass = "ru.mipt.npm.gradle.KScienceNodePlugin"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,13 +0,0 @@
|
||||
package ru.mipt.npm.gradle
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
|
||||
/**
|
||||
* Apply extension and repositories
|
||||
*/
|
||||
open class KScienceBasePlugin : Plugin<Project> {
|
||||
override fun apply(target: Project): Unit = target.run{
|
||||
registerKScienceExtension()
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package ru.mipt.npm.gradle
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.*
|
||||
import org.gradle.kotlin.dsl.findByType
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
|
||||
@ -88,29 +88,6 @@ class KScienceExtension(val project: Project) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate publishing and configure it
|
||||
*/
|
||||
fun publish(block: Publishing.() -> Unit = {}) = Publishing().apply(block)
|
||||
|
||||
inner class Publishing {
|
||||
init {
|
||||
if (project.plugins.findPlugin(KSciencePublishPlugin::class) == null) {
|
||||
project.plugins.apply(KSciencePublishPlugin::class)
|
||||
}
|
||||
}
|
||||
|
||||
var githubOrg: String? by project.extra
|
||||
var githubProject: String? by project.extra
|
||||
var spaceRepo: String? by project.extra
|
||||
var spaceUser: String? by project.extra
|
||||
var spaceToken: String? by project.extra
|
||||
var bintrayOrg: String? by project.extra
|
||||
var bintrayUser: String? by project.extra
|
||||
var bintrayApiKey: String? by project.extra
|
||||
var bintrayRepo: String? by project.extra
|
||||
}
|
||||
}
|
||||
|
||||
internal fun Project.registerKScienceExtension() {
|
||||
|
@ -19,14 +19,8 @@ open class KScienceJSPlugin : Plugin<Project> {
|
||||
configure<KotlinJsProjectExtension> {
|
||||
explicitApiWarning()
|
||||
js(IR) {
|
||||
browser {
|
||||
webpackTask {
|
||||
outputFileName = "main.bundle.js"
|
||||
}
|
||||
distribution {
|
||||
directory = project.jsDistDirectory
|
||||
}
|
||||
}
|
||||
browser()
|
||||
nodejs()
|
||||
}
|
||||
sourceSets["main"].apply {
|
||||
languageSettings.applySettings()
|
||||
|
@ -26,14 +26,8 @@ open class KScienceMPPlugin : Plugin<Project> {
|
||||
}
|
||||
|
||||
js(IR) {
|
||||
browser {
|
||||
webpackTask {
|
||||
outputFileName = "main.bundle.js"
|
||||
}
|
||||
distribution {
|
||||
directory = project.jsDistDirectory
|
||||
}
|
||||
}
|
||||
browser()
|
||||
nodejs()
|
||||
}
|
||||
|
||||
sourceSets.invoke {
|
||||
@ -92,7 +86,7 @@ open class KScienceMPPlugin : Plugin<Project> {
|
||||
// }
|
||||
|
||||
tasks.apply {
|
||||
withType<Test>() {
|
||||
withType<Test> {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
|
@ -1,28 +0,0 @@
|
||||
package ru.mipt.npm.gradle
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
|
||||
class KScienceNodePlugin : Plugin<Project> {
|
||||
override fun apply(target: Project) = target.run{
|
||||
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
|
||||
configure<KotlinMultiplatformExtension> {
|
||||
js {
|
||||
nodejs()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pluginManager.withPlugin("org.jetbrains.kotlin.js") {
|
||||
configure<KotlinJsProjectExtension> {
|
||||
js {
|
||||
nodejs()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
133
src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt
Normal file
133
src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt
Normal file
@ -0,0 +1,133 @@
|
||||
package ru.mipt.npm.gradle
|
||||
|
||||
import groovy.text.SimpleTemplateEngine
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.apply
|
||||
import org.gradle.kotlin.dsl.extra
|
||||
import org.gradle.kotlin.dsl.findByType
|
||||
import org.gradle.kotlin.dsl.provideDelegate
|
||||
import org.jetbrains.changelog.ChangelogPlugin
|
||||
import kotlin.collections.component1
|
||||
import kotlin.collections.component2
|
||||
|
||||
class KSciencePublishingExtension(val project: Project) {
|
||||
var githubOrg: String? by project.extra
|
||||
var githubProject: String? by project.extra
|
||||
var spaceRepo: String? by project.extra
|
||||
var spaceUser: String? by project.extra
|
||||
var spaceToken: String? by project.extra
|
||||
var bintrayOrg: String? by project.extra
|
||||
var bintrayUser: String? by project.extra
|
||||
var bintrayApiKey: String? by project.extra
|
||||
var bintrayRepo: String? by project.extra
|
||||
}
|
||||
|
||||
class KScienceReadmeExtension(val project: Project) {
|
||||
val properties = HashMap<String, String>()
|
||||
var readmeStubPath: String = "docs/README-STUB.md"
|
||||
val features = ArrayList<Feature>()
|
||||
|
||||
data class Feature(val id: String, val ref: String, val description: String, val name: String = id)
|
||||
|
||||
|
||||
fun feature(id: String, ref: String, description: String, name: String = id) {
|
||||
features.add(Feature(id, ref, description, name))
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a markdown string listing features
|
||||
*/
|
||||
fun featuresString(itemPrefix: String = " - ", pathPrefix: String = "") = buildString {
|
||||
features.forEach {
|
||||
appendln("$itemPrefix[${it.id}]($pathPrefix${it.ref}) : ${it.description}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a readme string from the stub
|
||||
*/
|
||||
fun readmeString(): String? {
|
||||
val readmeStubFile = project.file(readmeStubPath)
|
||||
return if (readmeStubFile.exists()) {
|
||||
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 {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply extension and repositories
|
||||
*/
|
||||
open class KScienceProjectPlugin : Plugin<Project> {
|
||||
override fun apply(target: Project): Unit = target.run {
|
||||
apply<ChangelogPlugin>()
|
||||
val rootReadmeExtension = KScienceReadmeExtension(this)
|
||||
extensions.add("ksciencePublish", KSciencePublishingExtension(this))
|
||||
extensions.add("kscienceReadme", rootReadmeExtension)
|
||||
|
||||
//Add readme generators to individual subprojects
|
||||
subprojects {
|
||||
val readmeExtension = KScienceReadmeExtension(this)
|
||||
extensions.add("kscienceReadme", readmeExtension)
|
||||
tasks.create("generateReadme") {
|
||||
group = "documentation"
|
||||
description = "Generate a README file if stub is present"
|
||||
doLast {
|
||||
val readmeString = readmeExtension.readmeString()
|
||||
if (readmeString != null) {
|
||||
val readmeFile = file("README.md")
|
||||
readmeFile.writeText(readmeString)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.create("generateReadme") {
|
||||
group = "documentation"
|
||||
description = "Generate a README file and a feature matrix if stub is present"
|
||||
|
||||
doLast {
|
||||
val reader = groovy.json.JsonSlurper()
|
||||
val projects = subprojects.associate {
|
||||
it.name to it.extensions.findByType<KScienceReadmeExtension>()
|
||||
}
|
||||
|
||||
|
||||
val rootReadmeStub = project.file(rootReadmeExtension.readmeStubPath)
|
||||
if (rootReadmeStub.exists()) {
|
||||
|
||||
val modulesString = buildString {
|
||||
projects.entries.filter { !it.value?.features.isNullOrEmpty() }.forEach { (name, ext) ->
|
||||
appendln("### [$name]($name)")
|
||||
appendln(ext!!.featuresString(pathPrefix = "$name/"))
|
||||
}
|
||||
}
|
||||
|
||||
val rootReadmeProperties: Map<String, Any> = mapOf(
|
||||
"name" to project.name,
|
||||
"group" to project.group,
|
||||
"version" to project.version,
|
||||
"modulesString" to modulesString
|
||||
)
|
||||
|
||||
val readmeFile = project.file("README.md")
|
||||
readmeFile.writeText(
|
||||
SimpleTemplateEngine().createTemplate(rootReadmeStub).make(rootReadmeProperties).toString()
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -13,7 +13,6 @@ open class KSciencePublishPlugin : Plugin<Project> {
|
||||
|
||||
override fun apply(project: Project): Unit = project.run {
|
||||
plugins.apply("maven-publish")
|
||||
registerKScienceExtension()
|
||||
|
||||
afterEvaluate {
|
||||
val githubOrg: String = project.findProperty("githubOrg") as? String ?: "mipt-npm"
|
||||
|
Loading…
Reference in New Issue
Block a user