Setup a Remark plugin to replace [detekt_version] with the current version on website (#5001)

This commit is contained in:
Nicola Corti
2022-06-27 21:44:41 +01:00
committed by GitHub
parent c8eb24c04b
commit 5ff82e1131
11 changed files with 25 additions and 43 deletions

View File

@@ -66,9 +66,9 @@ tasks {
register("incrementMajor") { doLast { updateVersion { it.nextMajor() } } } register("incrementMajor") { doLast { updateVersion { it.nextMajor() } } }
register<UpdateVersionInFileTask>("applyDocVersion") { register<UpdateVersionInFileTask>("applyDocVersion") {
fileToUpdate.set(file("${rootProject.rootDir}/website/docusaurus.config.js")) fileToUpdate.set(file("${rootProject.rootDir}/website/src/remark/detektVersionReplace.js"))
linePartToFind.set(" detektVersion:") linePartToFind.set("const detektVersion = ")
lineTransformation.set(" detektVersion: '${Versions.DETEKT}'") lineTransformation.set("const detektVersion = \"${Versions.DETEKT}\";")
} }
} }

View File

@@ -1,5 +0,0 @@
import DetektVersion from "./_detekt-version.jsx";
:::info
The latest released version of Detekt is **<DetektVersion/>**
:::

View File

@@ -1,8 +0,0 @@
import React from "react";
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
const DetektVersion = () => (
<span>{useDocusaurusContext().siteConfig.customFields.detektVersion}</span>
);
export default DetektVersion

View File

@@ -8,7 +8,6 @@ summary:
sidebar_position: 1 sidebar_position: 1
--- ---
import DetektVersionBanner from "../_detekt-version-banner.mdx";
import CliOptions from "./_cli-options.md"; import CliOptions from "./_cli-options.md";
## Install the cli ## Install the cli
@@ -31,8 +30,6 @@ detekt [options]
### Any OS: ### Any OS:
<DetektVersionBanner />
```sh ```sh
curl -sSLO https://github.com/detekt/detekt/releases/download/v[detekt_version]/detekt-cli-[detekt_version].zip curl -sSLO https://github.com/detekt/detekt/releases/download/v[detekt_version]/detekt-cli-[detekt_version].zip
unzip detekt-cli-[detekt_version].zip unzip detekt-cli-[detekt_version].zip

View File

@@ -8,8 +8,6 @@ summary:
sidebar_position: 2 sidebar_position: 2
--- ---
import DetektVersionBanner from "../\_detekt-version-banner.mdx";
Detekt requires **Gradle 6.1** or higher. We, however, recommend using the version of Gradle that is [listed in this table](/docs/introduction/compatibility). Detekt requires **Gradle 6.1** or higher. We, however, recommend using the version of Gradle that is [listed in this table](/docs/introduction/compatibility).
## <a name="tasks">Available plugin tasks</a> ## <a name="tasks">Available plugin tasks</a>
@@ -64,8 +62,6 @@ Using the plugins DSL:
#### Groovy DSL #### Groovy DSL
<DetektVersionBanner/>
```groovy ```groovy
plugins { plugins {
id "io.gitlab.arturbosch.detekt" version "[detekt_version]" id "io.gitlab.arturbosch.detekt" version "[detekt_version]"

View File

@@ -8,13 +8,9 @@ summary:
sidebar_position: 3 sidebar_position: 3
--- ---
import DetektVersionBanner from "../\_detekt-version-banner.mdx";
1. Add following lines to your build.gradle file. 1. Add following lines to your build.gradle file.
2. Run `gradle detekt` 2. Run `gradle detekt`
<DetektVersionBanner/>
###### Groovy DSL ###### Groovy DSL
```groovy ```groovy
repositories { repositories {

View File

@@ -8,13 +8,9 @@ summary:
sidebar_position: 4 sidebar_position: 4
--- ---
import DetektVersionBanner from "../\_detekt-version-banner.mdx";
1. Add following lines to your pom.xml. 1. Add following lines to your pom.xml.
2. Run `mvn verify` (when using the verify phase as we are doing here) 2. Run `mvn verify` (when using the verify phase as we are doing here)
<DetektVersionBanner/>
```xml ```xml
<build> <build>
<plugins> <plugins>

View File

@@ -5,8 +5,6 @@ sidebar_position: 1
summary: summary:
--- ---
import DetektVersionBanner from "./\_detekt-version-banner.mdx";
![detekt logo](/img/logo.svg "detekt logo") ![detekt logo](/img/logo.svg "detekt logo")
![detekt in action](/img/tutorial/detekt_in_action.png "detekt in action") ![detekt in action](/img/tutorial/detekt_in_action.png "detekt in action")
@@ -26,8 +24,6 @@ import DetektVersionBanner from "./\_detekt-version-banner.mdx";
Apply the following configuration to your Gradle project build file: Apply the following configuration to your Gradle project build file:
<DetektVersionBanner/>
```kotlin ```kotlin
plugins { plugins {
id("io.gitlab.arturbosch.detekt").version("[detekt_version]") id("io.gitlab.arturbosch.detekt").version("[detekt_version]")

View File

@@ -5,8 +5,6 @@ keywords: [extensions, rulesets]
sidebar_position: 9 sidebar_position: 9
--- ---
import DetektVersionBanner from "../\_detekt-version-banner.mdx";
The following page describes how to extend detekt and how to customize it to your domain-specific needs. The following page describes how to extend detekt and how to customize it to your domain-specific needs.
The associated **code samples** to this guide can be found in the package [detekt/detekt-sample-extensions](https://github.com/detekt/detekt/tree/main/detekt-sample-extensions). The associated **code samples** to this guide can be found in the package [detekt/detekt-sample-extensions](https://github.com/detekt/detekt/tree/main/detekt-sample-extensions).
@@ -221,11 +219,9 @@ To enable it, we add the published dependency to `detekt` via the `detektPlugins
###### Gradle (Kotlin/Groovy DSL) ###### Gradle (Kotlin/Groovy DSL)
<DetektVersionBanner/>
```kotlin ```kotlin
dependencies { dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:{{ site.detekt_version }}") detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:[detekt_version]")
} }
``` ```

View File

@@ -3,6 +3,7 @@
const lightCodeTheme = require('prism-react-renderer/themes/github'); const lightCodeTheme = require('prism-react-renderer/themes/github');
const darkCodeTheme = require('prism-react-renderer/themes/dracula'); const darkCodeTheme = require('prism-react-renderer/themes/dracula');
const detektVersionReplace = require('./src/remark/detektVersionReplace');
/** @type {import('@docusaurus/types').Config} */ /** @type {import('@docusaurus/types').Config} */
const config = { const config = {
@@ -25,6 +26,7 @@ const config = {
docs: { docs: {
sidebarPath: require.resolve('./sidebars.js'), sidebarPath: require.resolve('./sidebars.js'),
editUrl: 'https://github.com/detekt/detekt/edit/main/website/', editUrl: 'https://github.com/detekt/detekt/edit/main/website/',
remarkPlugins: [detektVersionReplace],
}, },
blog: { blog: {
showReadingTime: true, showReadingTime: true,
@@ -179,9 +181,6 @@ const config = {
}, },
}), }),
customFields: {
detektVersion: '1.21.0-RC1'
},
}; };
module.exports = config; module.exports = config;

View File

@@ -0,0 +1,19 @@
const visit = require("unist-util-visit");
// Remark plugin that is replacing the [detekt_version] with the latest
// released version. Please note that this field is updated automatically
// by the `:detekt-generator:generateDocumentation` task.
const detektVersion = "1.21.0-RC1";
const plugin = (options) => {
const transformer = async (ast) => {
visit(ast, "code", (node) => {
if (node.value.includes("[detekt_version]")) {
node.value = node.value.replace("[detekt_version]", detektVersion);
}
});
};
return transformer;
};
module.exports = plugin;