diff --git a/CHANGELOG.md b/CHANGELOG.md index 31c559f..a55859c 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/build.gradle.kts b/build.gradle.kts index 07fa8c6..85c1824 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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" - } } } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceBasePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceBasePlugin.kt deleted file mode 100644 index 341be36..0000000 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceBasePlugin.kt +++ /dev/null @@ -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 { - override fun apply(target: Project): Unit = target.run{ - registerKScienceExtension() - } -} \ No newline at end of file diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt index 0a19219..150c2ca 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceExtension.kt @@ -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() { diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt index aa1a822..6f150ac 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceJSPlugin.kt @@ -19,14 +19,8 @@ open class KScienceJSPlugin : Plugin { configure { explicitApiWarning() js(IR) { - browser { - webpackTask { - outputFileName = "main.bundle.js" - } - distribution { - directory = project.jsDistDirectory - } - } + browser() + nodejs() } sourceSets["main"].apply { languageSettings.applySettings() diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt index 85baece..7675142 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceMPPlugin.kt @@ -26,14 +26,8 @@ open class KScienceMPPlugin : Plugin { } js(IR) { - browser { - webpackTask { - outputFileName = "main.bundle.js" - } - distribution { - directory = project.jsDistDirectory - } - } + browser() + nodejs() } sourceSets.invoke { @@ -92,7 +86,7 @@ open class KScienceMPPlugin : Plugin { // } tasks.apply { - withType() { + withType { useJUnitPlatform() } diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt deleted file mode 100644 index bba5346..0000000 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceNodePlugin.kt +++ /dev/null @@ -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 { - override fun apply(target: Project) = target.run{ - pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { - configure { - js { - nodejs() - } - } - } - - pluginManager.withPlugin("org.jetbrains.kotlin.js") { - configure { - js { - nodejs() - } - } - } - } - -} \ No newline at end of file diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt new file mode 100644 index 0000000..acd7ed5 --- /dev/null +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt @@ -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() + var readmeStubPath: String = "docs/README-STUB.md" + val features = ArrayList() + + 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 = (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 { + override fun apply(target: Project): Unit = target.run { + apply() + 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() + } + + + 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 = 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() + ) + } + + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt index e45ea06..7f13c79 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KSciencePublishPlugin.kt @@ -11,9 +11,8 @@ import org.gradle.kotlin.dsl.withType open class KSciencePublishPlugin : Plugin { - override fun apply(project: Project): Unit = project.run{ + override fun apply(project: Project): Unit = project.run { plugins.apply("maven-publish") - registerKScienceExtension() afterEvaluate { val githubOrg: String = project.findProperty("githubOrg") as? String ?: "mipt-npm"