diff --git a/core/src/main/scala/org/typelevel/sbt/TypelevelPlugin.scala b/core/src/main/scala/org/typelevel/sbt/TypelevelPlugin.scala index f4299afe..a9052102 100644 --- a/core/src/main/scala/org/typelevel/sbt/TypelevelPlugin.scala +++ b/core/src/main/scala/org/typelevel/sbt/TypelevelPlugin.scala @@ -22,6 +22,7 @@ import org.typelevel.sbt.gha.GitHubActionsPlugin import sbt._ import Keys._ +import TypelevelKernelPlugin.autoImport._ /** * The [[TypelevelPlugin]] brings together the [[TypelevelCiReleasePlugin]] and the @@ -44,7 +45,6 @@ object TypelevelPlugin extends AutoPlugin { "Convert compiler warnings into errors under CI builds (default: true)") } - import TypelevelKernelPlugin.mkCommand import TypelevelCiPlugin.autoImport._ import TypelevelSettingsPlugin.autoImport._ import TypelevelSonatypeCiReleasePlugin.autoImport._ @@ -76,52 +76,25 @@ object TypelevelPlugin extends AutoPlugin { scala <- githubWorkflowScalaVersions.value.filterNot(defaultScala.startsWith(_)) java <- githubWorkflowJavaVersions.value.tail // default java is head } yield MatrixExclude(Map("scala" -> scala, "java" -> java.render)) - } - ) ++ addPrePRCommandAlias ++ addTlPrePRBotHookCommandAlias - - // partially re-implemnents addCommandAlias - // this is so we can use the value of other settings to generate command - private def addPrePRCommandAlias: Seq[Setting[_]] = Seq( - GlobalScope / onLoad := { + }, + GlobalScope / tlCommandAliases ++= { val header = tlCiHeaderCheck.value val scalafmt = tlCiScalafmtCheck.value val scalafix = tlCiScalafixCheck.value - (GlobalScope / Keys.onLoad).value.compose { (state: State) => - val command = mkCommand( - List("project /", "githubWorkflowGenerate") ++ - List("+headerCreateAll").filter(_ => header) ++ - List("+scalafmtAll", "scalafmtSbt").filter(_ => scalafmt) ++ - List("+scalafixAll").filter(_ => scalafix) - ) - BasicCommands.addAlias(state, "prePR", command) - } - }, - GlobalScope / Keys.onUnload := { - (GlobalScope / Keys.onUnload) - .value - .compose((state: State) => BasicCommands.removeAlias(state, "prePR")) - } - ) + val prePR = List("project /", "githubWorkflowGenerate") ++ + List("+headerCreateAll").filter(_ => header) ++ + List("+scalafmtAll", "scalafmtSbt").filter(_ => scalafmt) ++ + List("+scalafixAll").filter(_ => scalafix) - private def addTlPrePRBotHookCommandAlias: Seq[Setting[_]] = Seq( - GlobalScope / onLoad := { - val header = tlCiHeaderCheck.value - val scalafmt = tlCiScalafmtCheck.value + val botHook = List("githubWorkflowGenerate") ++ + List("+headerCreateAll").filter(_ => header) ++ + List("+scalafmtAll", "scalafmtSbt").filter(_ => scalafmt) - (GlobalScope / Keys.onLoad).value.compose { (state: State) => - val command = mkCommand( - List("githubWorkflowGenerate") ++ - List("+headerCreateAll").filter(_ => header) ++ - List("+scalafmtAll", "scalafmtSbt").filter(_ => scalafmt) - ) - BasicCommands.addAlias(state, "tlPrePrBotHook", command) - } - }, - GlobalScope / Keys.onUnload := { - (GlobalScope / Keys.onUnload) - .value - .compose((state: State) => BasicCommands.removeAlias(state, "tlPrePrBotHook")) + Map( + "prePR" -> prePR, + "tlPrePrBotHook" -> botHook + ) } ) diff --git a/docs/customization.md b/docs/customization.md index 12cf2b9c..81df02f7 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -13,7 +13,7 @@ Instead of using the super-plugins, for finer-grained control you can always add `TypelevelKernelPlugin` - `tlIsScala3` (setting): `true`, if `scalaVersion` is 3.x. -- `tlReplaceCommandAlias` (method): Replace a `addCommandAlias` definition. +- `tlCommandAliases` (setting): Command aliases defined for this build. - `tlReleaseLocal` (command): Alias for `+publishLocal`. ### sbt-typelevel-versioning diff --git a/kernel/src/main/scala/org/typelevel/sbt/TypelevelKernelPlugin.scala b/kernel/src/main/scala/org/typelevel/sbt/TypelevelKernelPlugin.scala index 7380aa77..d203c604 100644 --- a/kernel/src/main/scala/org/typelevel/sbt/TypelevelKernelPlugin.scala +++ b/kernel/src/main/scala/org/typelevel/sbt/TypelevelKernelPlugin.scala @@ -39,6 +39,13 @@ object TypelevelKernelPlugin extends AutoPlugin { lazy val tlSkipIrrelevantScalas = settingKey[Boolean]( "Sets skip := true for compile/test/publish/etc. tasks on a project if the current scalaVersion is not in that project's crossScalaVersions (default: false)") + lazy val tlCommandAliases = settingKey[Map[String, List[String]]]( + "Command aliases defined for this build" + ) + + @deprecated( + "Use `tlCommandAliases` for a more composable command definition experience", + "0.6.1") def tlReplaceCommandAlias(name: String, contents: String): Seq[Setting[State => State]] = Seq(GlobalScope / onLoad ~= { (f: State => State) => f andThen { s: State => @@ -51,12 +58,27 @@ object TypelevelKernelPlugin extends AutoPlugin { import autoImport._ override def globalSettings = Seq( - Def.derive(tlIsScala3 := scalaVersion.value.startsWith("3.")) + Def.derive(tlIsScala3 := scalaVersion.value.startsWith("3.")), + tlCommandAliases := Map( + "tlReleaseLocal" -> List("reload", "project /", "+publishLocal") + ), + onLoad := { + val aliases = tlCommandAliases.value + onLoad.value.compose { (state: State) => + aliases.foldLeft(state) { + case (state, (alias, command)) => + BasicCommands.addAlias(state, alias, mkCommand(command)) + } + } + }, + onUnload := { + val aliases = tlCommandAliases.value.keys + onUnload.value.compose { (state: State) => + aliases.foldLeft(state) { (state, alias) => BasicCommands.removeAlias(state, alias) } + } + } ) - override def buildSettings = - addCommandAlias("tlReleaseLocal", mkCommand(List("reload", "project /", "+publishLocal"))) - override def projectSettings = Seq( ivyConfigurations += CompileTime, Compile / unmanagedClasspath ++= update.value.select(configurationFilter(CompileTime.name)) diff --git a/sonatype/src/main/scala/org/typelevel/sbt/TypelevelSonatypePlugin.scala b/sonatype/src/main/scala/org/typelevel/sbt/TypelevelSonatypePlugin.scala index dc9cb33d..d353c64b 100644 --- a/sonatype/src/main/scala/org/typelevel/sbt/TypelevelSonatypePlugin.scala +++ b/sonatype/src/main/scala/org/typelevel/sbt/TypelevelSonatypePlugin.scala @@ -22,7 +22,7 @@ import xerial.sbt.Sonatype import Keys._ import Sonatype.autoImport._ -import TypelevelKernelPlugin.mkCommand +import TypelevelKernelPlugin.autoImport._ object TypelevelSonatypePlugin extends AutoPlugin { @@ -37,19 +37,21 @@ object TypelevelSonatypePlugin extends AutoPlugin { import autoImport._ + override def globalSettings = Seq( + tlCommandAliases += { + "tlRelease" -> List( + "reload", + "project /", + "+mimaReportBinaryIssues", + "+publish", + "tlSonatypeBundleReleaseIfRelevant") + } + ) + override def buildSettings = Seq( tlSonatypeUseLegacyHost := false, autoAPIMappings := true - ) ++ addCommandAlias( - "tlRelease", - mkCommand( - List( - "reload", - "project /", - "+mimaReportBinaryIssues", - "+publish", - "tlSonatypeBundleReleaseIfRelevant")) ) override def projectSettings = Seq(