Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix crashes in the absence of a git repo. #2

Merged
merged 1 commit into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Before you submit a PR, make sure your tests are passing, and that the code is p
```
sbt prepare

sbt test
sbt testPlugin
```


Expand Down
8 changes: 8 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ inThisBuild(

ThisBuild / publishTo := sonatypePublishToBundle.value

addCommandAlias("testPlugin", "scripted; test")
addCommandAlias("prepare", "fix; fmt")
addCommandAlias("fmt", "all scalafmtSbt scalafmtAll")
addCommandAlias("fmtCheck", "all scalafmtSbtCheck scalafmtCheckAll")
Expand Down Expand Up @@ -66,6 +67,13 @@ lazy val zioSbtWebsite =
.in(file("zio-sbt-website"))
.settings(stdSettings("zio-sbt-website"))
.settings(buildInfoSettings("zio.sbt"))
.settings(
scriptedLaunchOpts := {
scriptedLaunchOpts.value ++
Seq("-Xmx1024M", "-Dplugin.version=" + version.value)
},
scriptedBufferLog := false
)
.enablePlugins(SbtPlugin)

lazy val docs = project
Expand Down
21 changes: 14 additions & 7 deletions zio-sbt-website/src/main/scala/zio/sbt/WebsitePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scala.sys.process.*

import mdoc.MdocPlugin
import mdoc.MdocPlugin.autoImport.*
import sbt.Keys.*
import sbt.Keys.{ streams, _ }
import sbt.*

object WebsitePlugin extends sbt.AutoPlugin {
Expand Down Expand Up @@ -43,15 +43,22 @@ object WebsitePlugin extends sbt.AutoPlugin {
libraryDependencies ++= docsDependencies.value,
mdocVariables ++= {
Map(
"VERSION" -> releaseVersion.getOrElse(version.value),
"RELEASE_VERSION" -> releaseVersion.getOrElse("NOT RELEASED YET"),
"VERSION" -> releaseVersion(sLog.value.warn(_)).getOrElse(version.value),
"RELEASE_VERSION" -> releaseVersion(sLog.value.warn(_)).getOrElse("NOT RELEASED YET"),
"SNAPSHOT_VERSION" -> version.value
)
}
)

private def releaseVersion: Option[String] =
"git tag --sort=committerdate".!!.split("\n").filter(_.startsWith("v")).lastOption.map(_.tail)
def releaseVersion(logger: String => Unit): Option[String] =
try "git tag --sort=committerdate".!!.split("\n").filter(_.startsWith("v")).lastOption.map(_.tail)
catch {
case _: Exception =>
logger(
s"Could not determine release version from git tags, will return 'None' instead. This is most likely a result of this project not having a git repo initialized. See previous log messages for more detail."
)
None
}

private def exit(exitCode: Int) = if (exitCode != 0) sys.exit(exitCode)

Expand Down Expand Up @@ -108,15 +115,15 @@ object WebsitePlugin extends sbt.AutoPlugin {

exit(Process(s"mv ${normalizedName.value}-website website", websiteDir.value.toFile).!)

exit(s"rm ${websiteDir.value.toString}/website/.git/ -rvf".!)
exit(s"rm -rvf ${websiteDir.value.toString}/website/.git/".!)
}

lazy val publishWebsiteTask: Def.Initialize[Task[Unit]] =
Def.task {
val _ = compileDocs.toTask("").value

val refinedNpmVersion = {
val v = releaseVersion.getOrElse(version.value)
val v = releaseVersion(streams.value.log.warn(_)).getOrElse(version.value)
if (v.endsWith("-SNAPSHOT")) v.replace("+", "--") else v
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lazy val root = (project in file("."))
.settings(
version := "0.1",
).enablePlugins(WebsitePlugin)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
id: index
title: "Introduction to ZIO SBT"
sidebar_label: "Introduction"
---

SBT Plugin for ZIO Projects.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@zio.dev/zio-sbt",
"description": "ZIO SBT Documentation",
"license": "Apache-2.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const sidebars = {
sidebar: [
'index'
]
};

module.exports = sidebars;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("dev.zio" % "zio-sbt-website" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Main {
def main(args: Array[String]): Unit = println("hello, zio")
}
8 changes: 8 additions & 0 deletions zio-sbt-website/src/sbt-test/zio-sbt-website/compileDocs/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
> clean
> compile
> compileDocs
$ exists target/website/docs
$ exists target/website/docs/index.md
$ exists target/website/docs/package.json
$ exists target/website/docs/sidebar.js

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lazy val root = (project in file("."))
.settings(
version := "0.1",
).enablePlugins(WebsitePlugin)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
id: index
title: "Introduction to ZIO SBT"
sidebar_label: "Introduction"
---

SBT Plugin for ZIO Projects.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@zio.dev/zio-sbt",
"description": "ZIO SBT Documentation",
"license": "Apache-2.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const sidebars = {
sidebar: [
'index'
]
};

module.exports = sidebars;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("dev.zio" % "zio-sbt-website" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Main {
def main(args: Array[String]): Unit = println("hello, zio")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
> clean
> installWebsite
$ exists target/website/src
$ exists target/website/static
$ exists target/website/LICENSE