Skip to content

Commit

Permalink
Add minimal working plugin setup
Browse files Browse the repository at this point in the history
  • Loading branch information
valencik committed Dec 1, 2023
1 parent 2cd6c3f commit 5961d64
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ jobs:

- name: Make target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: mkdir -p laikaIO/.jvm/target core/.js/target jsinterop/.js/target core/.jvm/target project/target
run: mkdir -p sbt/target laikaIO/.jvm/target core/.js/target jsinterop/.js/target core/.jvm/target project/target

- name: Compress target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: tar cf targets.tar laikaIO/.jvm/target core/.js/target jsinterop/.js/target core/.jvm/target project/target
run: tar cf targets.tar sbt/target laikaIO/.jvm/target core/.js/target jsinterop/.js/target core/.jvm/target project/target

- name: Upload target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
Expand Down
13 changes: 13 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ lazy val root =
core,
laikaIO,
jsInterop,
plugin,
web,
searchdocsCore,
searchdocsIO,
Expand Down Expand Up @@ -108,6 +109,18 @@ lazy val jsInterop = crossProject(JSPlatform)
),
)

lazy val plugin =
project
.in(file("sbt"))
.dependsOn(core.jvm, laikaIO.jvm)
.enablePlugins(SbtPlugin)
.settings(
name := "protosearch-sbt",
sbtPlugin := true,
crossScalaVersions := Seq(Scala212),
addSbtPlugin("org.typelevel" % "laika-sbt" % laikaV),
)

lazy val searchdocsCore = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Pure)
.in(file("searchdocs"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2022 CozyDev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package pink.cozydev.protosearch.sbt

import sbt.*
import sbt.Keys.*
import laika.sbt.LaikaPlugin
import laika.sbt.LaikaPlugin.autoImport._

object ProtosearchPlugin extends AutoPlugin {

override val trigger = allRequirements

override def requires = plugins.JvmPlugin && LaikaPlugin

object autoImport {
val protosearchGenerateIndex = taskKey[Set[File]]("Generate Protosearch Index files")
val protosearchIndexTarget = settingKey[String]("The target directory for index files")
}

import autoImport._

override lazy val projectSettings: Seq[Setting[_]] = Seq(
protosearchIndexTarget := ((Laika / target).value / "index").toString(),
protosearchGenerateIndex := Tasks.protosearchGenerateIndex.value,
)
}
50 changes: 50 additions & 0 deletions sbt/src/main/scala/pink/cozydev/protosearch/Tasks.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2022 CozyDev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package pink.cozydev.protosearch.sbt

import cats.effect.IO
import cats.effect.unsafe.implicits.global
import pink.cozydev.protosearch.analysis.DocsDirectory
import sbt.*
import laika.io.model.FilePath

object Tasks {
import Def.*
import laika.sbt.LaikaPlugin.autoImport._
import pink.cozydev.protosearch.sbt.ProtosearchPlugin.autoImport._

val protosearchGenerateIndex: Initialize[Task[Set[File]]] = task {
val userConfig = (Compile / laikaConfig).value
val targetDir = protosearchIndexTarget.value

val parser = laika.sbt.Settings.parser.value
val tree = parser.use(_.fromInput(laikaInputs.value.delegate).parse).unsafeRunSync()
DocsDirectory.plaintextRenderer
.use(
_.from(tree)
.toDirectory(FilePath.parse(targetDir))(userConfig.encoding)
.render
)
.unsafeRunSync()

val msg = IO.println(s"rendered to ${targetDir}")

msg.unsafeRunSync()
Set.empty
}

}

0 comments on commit 5961d64

Please sign in to comment.