diff options
author | Adam <897017+aSemy@users.noreply.github.com> | 2023-05-25 23:19:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-26 00:19:27 +0200 |
commit | f182a0add34876f74c47100e604f79f46c4ddca2 (patch) | |
tree | ab13fdef2c3ae4b807aa5defbff39bb89c3ec2b0 /plugins/base | |
parent | f55e22d5fe3f9121b7ed81d0c3f8c6a094dff45c (diff) | |
download | dokka-f182a0add34876f74c47100e604f79f46c4ddca2.tar.gz dokka-f182a0add34876f74c47100e604f79f46c4ddca2.tar.bz2 dokka-f182a0add34876f74c47100e604f79f46c4ddca2.zip |
Improve copying base-frontend files between subprojects (#2970)
Diffstat (limited to 'plugins/base')
-rw-r--r-- | plugins/base/.gitignore | 7 | ||||
-rw-r--r-- | plugins/base/build.gradle.kts | 50 | ||||
-rw-r--r-- | plugins/base/frontend/build.gradle.kts | 43 |
3 files changed, 54 insertions, 46 deletions
diff --git a/plugins/base/.gitignore b/plugins/base/.gitignore deleted file mode 100644 index 11d1825b..00000000 --- a/plugins/base/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -src/main/resources/dokka/scripts/main.js -src/main/resources/dokka/scripts/main.css -src/main/resources/dokka/scripts/main.js.map -src/main/resources/dokka/scripts/highlight-* -src/main/resources/dokka/scripts/vendors~* -search-component/dist/ -/src/main/resources/dokka/styles/main.css diff --git a/plugins/base/build.gradle.kts b/plugins/base/build.gradle.kts index 98a929ae..b6ba2917 100644 --- a/plugins/base/build.gradle.kts +++ b/plugins/base/build.gradle.kts @@ -3,6 +3,7 @@ import org.jetbrains.registerDokkaArtifactPublication plugins { id("org.jetbrains.conventions.kotlin-jvm") id("org.jetbrains.conventions.maven-publish") + id("org.jetbrains.conventions.dokka-html-frontend-files") } dependencies { @@ -33,45 +34,40 @@ dependencies { testImplementation(projects.core.testApi) testImplementation(platform(libs.junit.bom)) testImplementation(libs.junit.jupiter) + + dokkaHtmlFrontendFiles(projects.plugins.base.frontend) { + because("fetch frontend files from subproject :plugins:base:frontend") + } } -val projectDistDir = project(":plugins:base:frontend").file("dist") -val generateFrontendFiles = tasks.getByPath(":plugins:base:frontend:generateFrontendFiles") +// access the frontend files via the dependency on :plugins:base:frontend +val dokkaHtmlFrontendFiles: Provider<FileCollection> = + configurations.dokkaHtmlFrontendFiles.map { frontendFiles -> + frontendFiles.incoming.artifacts.artifactFiles + } + +val preparedokkaHtmlFrontendFiles by tasks.registering(Sync::class) { + description = "copy Dokka Base frontend files into the resources directory" -val copyJsFiles by tasks.registering(Copy::class) { - from(projectDistDir) { + from(dokkaHtmlFrontendFiles) { include("*.js") + into("dokka/scripts") } - dependsOn(generateFrontendFiles) - destinationDir = - File(sourceSets.main.get().resources.sourceDirectories.singleFile, "dokka/scripts") -} -val copyCssFiles by tasks.registering(Copy::class) { - from(projectDistDir) { + from(dokkaHtmlFrontendFiles) { include("*.css") + into("dokka/styles") } - dependsOn(generateFrontendFiles) - destinationDir = - File(sourceSets.main.get().resources.sourceDirectories.singleFile, "dokka/styles") -} -val copyFrontend by tasks.registering { - dependsOn(copyJsFiles, copyCssFiles) + into(layout.buildDirectory.dir("generated/src/main/resources")) } -tasks { - processResources { - dependsOn(copyFrontend) - } - - sourcesJar { - dependsOn(processResources) - } +sourceSets.main { + resources.srcDir(preparedokkaHtmlFrontendFiles.map { it.destinationDir }) +} - test { - maxHeapSize = "4G" - } +tasks.test { + maxHeapSize = "4G" } registerDokkaArtifactPublication("dokkaBase") { diff --git a/plugins/base/frontend/build.gradle.kts b/plugins/base/frontend/build.gradle.kts index cadf3fae..2d8bbb7f 100644 --- a/plugins/base/frontend/build.gradle.kts +++ b/plugins/base/frontend/build.gradle.kts @@ -1,6 +1,10 @@ +import com.github.gradle.node.npm.task.NpmTask +import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs + +@Suppress("DSL_SCOPE_VIOLATION") // fixed in Gradle 8.1 https://github.com/gradle/gradle/pull/23639 plugins { - base - id("com.github.node-gradle.node") version "3.2.1" + id("org.jetbrains.conventions.dokka-html-frontend-files") + alias(libs.plugins.gradleNode) } node { @@ -11,19 +15,34 @@ node { distBaseUrl.set(null as String?) // Strange cast to avoid overload ambiguity } -val npmRunBuild = tasks.getByName("npm_run_build") { - inputs.dir(file("src/main")) - inputs.files(file("package.json"), file("webpack.config.js")) - outputs.dir(file("dist/")) +val distributionDirectory = layout.projectDirectory.dir("dist") + +val npmRunBuild by tasks.registering(NpmTask::class) { + dependsOn(tasks.npmInstall) + + npmCommand.set(parseSpaceSeparatedArgs("run build")) + + inputs.dir("src/main") + inputs.files( + "package.json", + "webpack.config.js", + ) + + outputs.dir(distributionDirectory) outputs.cacheIf { true } } -task("generateFrontendFiles") { - dependsOn(npmRunBuild) +configurations.dokkaHtmlFrontendFilesElements.configure { + outgoing { + artifact(distributionDirectory) { + builtBy(npmRunBuild) + } + } } -tasks { - clean { - delete(file("node_modules"), file("dist")) - } +tasks.clean { + delete( + file("node_modules"), + file("dist"), + ) } |