Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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")))
@wsargent

This comment has been minimized.

Copy link

commented Mar 17, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.