Skip to content

Commit

Permalink
Make the play routes compiler compatible with rules_scala_annex workers
Browse files Browse the repository at this point in the history
  • Loading branch information
jjudd committed Jul 26, 2024
1 parent c22391c commit 04aaf3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions play-routes-compiler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ scala_library(
tags = ["maven_coordinates=com.lucidchart:" + artifact_id + ":{pom_version}"],
visibility = ["//visibility:public"],
deps = [
"@rules_scala_annex//src/main/scala/higherkindness/rules_scala/common/worker",
"@play_routes_compiler_cli_maven//:com_github_scopt_scopt_3",
"@play_routes_compiler_cli_maven//:org_playframework_play_routes_compiler_3",
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package rulesplayroutes.routes

import java.io.File
import higherkindness.rules_scala.common.worker.WorkerMain
import java.io.{File, PrintStream}
import java.nio.file.{Files, Paths}
import play.routes.compiler._
import play.routes.compiler.RoutesCompiler.RoutesCompilerTask
import scala.jdk.CollectionConverters._
import scala.io.Source
import scala.Console._
import scopt.OptionParser

object CommandLinePlayRoutesCompiler {
object CommandLinePlayRoutesCompiler extends WorkerMain[Unit] {

case class Config(
sources: Seq[File] = Seq.empty[File],
Expand All @@ -20,7 +22,7 @@ object CommandLinePlayRoutesCompiler {
generateForwardsRouter: Boolean = true
)

val parser = new scopt.OptionParser[Config]("scopt") {
val parser = new OptionParser[Config]("scopt") {
head("Command Line Play Routes Compiler", "0.1")

arg[File]("<outputDirectory>").required().action { (value, config) =>
Expand Down Expand Up @@ -76,7 +78,7 @@ object CommandLinePlayRoutesCompiler {
/**
* Do Play Routes compilation and return true if things succeeded, otherwise return false.
*/
def doCompile(config: Config): Boolean = {
def compilePlayRoutes(config: Config): Boolean = {
config.sources.forall { file =>
RoutesCompiler.compile(
RoutesCompilerTask(
Expand All @@ -102,9 +104,11 @@ object CommandLinePlayRoutesCompiler {
}
}

def main(args: Array[String]): Unit = {
override def init(args: Option[Array[String]]): Unit = ()

protected def work(ctx: Unit, args: Array[String], out: PrintStream): Unit = {
val isSuccess = parser.parse(args, Config())
.map(doCompile)
.map(compilePlayRoutes)
.getOrElse(false)

if (isSuccess) {
Expand Down

0 comments on commit 04aaf3d

Please sign in to comment.