Last active
March 17, 2017 14:57
-
-
Save MichaelSitter/3cdc278bbd6e2227c0d8f8644be6ad06 to your computer and use it in GitHub Desktop.
Simple builder for Play run hooks: https://www.playframework.com/documentation/2.5.x/SBTCookbook#Hooking-into-Plays-dev-mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package build | |
import java.net.InetSocketAddress | |
import play.sbt.PlayRunHook | |
import sbt._ | |
object ProcessRunHookBuilder { | |
def apply( | |
base: File, | |
before: Option[String] = None, | |
after: Option[String] = None, | |
stopped: Option[String] = None, | |
error: Option[String] = None | |
): PlayRunHook = { | |
object ProcessRunHook extends PlayRunHook { | |
val processes: Seq[Option[Process]] = Nil | |
override def beforeStarted() = { | |
processes :+ before.map(Process(_).run()) | |
} | |
override def afterStarted(addr: InetSocketAddress) = { | |
processes :+ after.map(Process(_).run()) | |
} | |
override def afterStopped() = { | |
processes.map(_.map(_.destroy())) | |
stopped.map(Process(_).run()) | |
} | |
override def onError() = { | |
processes :+ error.map(c => Process(c).run()) | |
} | |
} | |
ProcessRunHook | |
} | |
} | |
// Enable in your build.sbt: | |
// import build.ProcessRunHookBuilder | |
// playRunHooks <+= baseDirectory.map(f => ProcessRunHookBuilder(f, Some("npm run start"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks good! Would you consider submitting a pull request to Play to add this to the documentation page? It should be at
https://github.com/playframework/playframework/edit/2.5.x/documentation/manual/working/commonGuide/build/SBTCookbook.md