本文整理汇总了Scala中play.sbt.PlayRunHook类的典型用法代码示例。如果您正苦于以下问题:Scala PlayRunHook类的具体用法?Scala PlayRunHook怎么用?Scala PlayRunHook使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PlayRunHook类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: EmberRunner
//设置package包名称以及导入依赖的类
import java.io.File
import java.net.InetSocketAddress
import play.sbt.PlayRunHook
import sbt._
object EmberRunner {
def apply(logger: Logger,
baseDir: File,
port: Int = 4200): PlayRunHook = {
object EmberRunHook extends PlayRunHook {
var watchProcess: Option[Process] = None
override def beforeStarted(): Unit = {
if (baseDir.exists()) {
logger.info("Executing npm install")
val npm = Process(Seq("npm", "install"), baseDir).lines
npm.foreach(logger.info(_))
logger.info("Executing bower install")
val bower = Process(Seq("bower", "install"), baseDir).lines
bower.foreach(logger.info(_))
} else {
logger.info(s"Skipping npm and bower install. UI application directory ${baseDir.getAbsolutePath} not found.")
}
}
override def afterStarted(addr: InetSocketAddress): Unit = {
addr.getAddress.getHostAddress
val url = s"http://localhost:${addr.getPort}"
if (baseDir.exists()) {
logger.info(s"Starting ember server in development mode. Setting proxy to $url")
watchProcess = Some(Process(Seq("ember", "serve", "--proxy", url, "--port", port.toString), baseDir).run(logger))
} else {
logger.info(s"Skipping ember server start. UI application directory ${baseDir.getAbsolutePath} not found.")
}
}
override def afterStopped(): Unit = {
logger.info("Attempting to stop ember server")
watchProcess.foreach(_.destroy())
watchProcess = None
}
}
EmberRunHook
}
}
示例2: Webpack
//设置package包名称以及导入依赖的类
import java.net.InetSocketAddress
import play.sbt.PlayRunHook
import sbt._
object Webpack {
def apply(base: File): PlayRunHook = {
object WebpackHook extends PlayRunHook {
var process: Option[Process] = None
override def beforeStarted() = {
process = Option(
Process("webpack", base).run()
)
}
override def afterStarted(addr: InetSocketAddress) = {
process = Option(
Process("webpack --watch", base).run()
)
}
override def afterStopped() = {
process.foreach(_.destroy())
process = None
}
}
WebpackHook
}
}
示例3: HTMLValidation
//设置package包名称以及导入依赖的类
import play.sbt.PlayRunHook
import sbt._
object HTMLValidation {
def apply(base: File): PlayRunHook = {
object HTMLValidationProcess extends PlayRunHook {
var validationRun: Option[Process] = None
override def beforeStarted(): Unit = {
val env = "dev"
validationRun = Some(validationProcess(base, env).run)
}
override def afterStopped(): Unit = {
// Stop when play run stops
validationRun.map(p => p.destroy())
validationRun = None
}
}
HTMLValidationProcess
}
def command(base: File) = Command.command("w3c") { state =>
validationProcess(base) !;
state
}
def validationProcess(base: File, args: String*) = {
// have to use Process rather than fork because of NPE with get class loader in vnu tool
val log = ConsoleLogger()
log.info("Starting HTML Validation task...")
Process("java" :: "-jar" :: s"${base.getAbsolutePath}/project/tools/vnu.jar" :: "--skip-non-html" :: "--verbose" :: "--format" :: "text" :: "--html" :: "--errors-only" :: s"${base.getAbsolutePath}/target/html" :: ">" :: "out.txt" :: args.toList, base)
}
}
示例4: Grunt
//设置package包名称以及导入依赖的类
import play.sbt.PlayRunHook
import sbt._
object Grunt {
def apply(base: File): PlayRunHook = {
object GruntProcess extends PlayRunHook {
var gruntRun: Option[Process] = None
override def beforeStarted(): Unit = {
val env = "dev"
val log = ConsoleLogger()
log.info(s"run npm install... $env")
npmProcess(base, "install").!
log.info("Starting default Grunt task..")
gruntRun = Some(gruntProcess(base, env, "--verbose").run())
}
override def afterStopped(): Unit = {
// Stop grunt when play run stops
gruntRun.map(p => p.destroy())
gruntRun = None
}
}
GruntProcess
}
def gruntCommand(base: File) = Command.args("grunt", "<grunt-command>") { (state, args) =>
gruntProcess(base, args:_*) !;
state
}
def gruntProcess(base: File, args: String*) = Process("node" :: "node_modules/.bin/grunt" :: args.toList, base)
def npmProcess(base: File, args: String*) = Process("npm" :: args.toList, base)
}
示例5: Webpack
//设置package包名称以及导入依赖的类
import java.net.InetSocketAddress
import play.sbt.PlayRunHook
import sbt._
object Webpack {
def apply(base: File): PlayRunHook = {
object WebpackProcess extends PlayRunHook {
var process: Option[Process] = None
override def beforeStarted(): Unit = {
Process("npm install").!
}
override def afterStarted(addr: InetSocketAddress): Unit = {
process = Some(Process("./node_modules/.bin/webpack --progress -d --watch", base).run)
}
override def afterStopped(): Unit = {
process.map(p => p.destroy())
process = None
}
}
WebpackProcess
}
}
示例6: Grunt
//设置package包名称以及导入依赖的类
import play.sbt.PlayRunHook
import sbt._
import java.net.InetSocketAddress
object Grunt {
def apply(base: File): PlayRunHook = {
object GruntProcess extends PlayRunHook {
var process: Option[Process] = None
override def beforeStarted(): Unit = {
Process("grunt --force", base).run
}
override def afterStarted(addr: InetSocketAddress): Unit = {
process = Some(Process("grunt --force watch", base).run)
}
override def afterStopped(): Unit = {
process.map(p => p.destroy())
process = None
}
}
GruntProcess
}
}
示例7: WebpackServer
//设置package包名称以及导入依赖的类
import java.io.File
import java.net.InetSocketAddress
import play.sbt.PlayRunHook
import sbt._
object WebpackServer {
def apply(base: File): PlayRunHook = {
object WebpackServerScript extends PlayRunHook {
var process: Option[Process] = None // This is really ugly, how can I do this functionally?
override def afterStarted(address: InetSocketAddress): Unit = {
process = if (System.getProperty("os.name").toUpperCase().indexOf("WIN") >= 0)
Option(Process("cmd /c npm start", base).run)
else
Option(Process("npm start", base).run)
}
override def afterStopped(): Unit = {
process.foreach(p => { p.destroy() })
process = None
}
}
WebpackServerScript
}
}
示例8: Gulp
//设置package包名称以及导入依赖的类
import java.net.InetSocketAddress
import sbt._
import play.sbt.PlayRunHook
object Gulp {
def apply(base: File): PlayRunHook = {
object GulpProcess extends PlayRunHook {
var gulpRun: Option[Process] = None
override def beforeStarted(): Unit = {
val log = ConsoleLogger()
log.info("run npm install...")
npmProcess(base, "install").!
log.info("Starting default Gulp task..")
gulpRun = Some(gulpProcess(base, "default").run())
}
override def afterStopped(): Unit = {
// Stop gulp when play run stops
gulpRun.foreach(p => p.destroy())
gulpRun = None
}
}
GulpProcess
}
def gulpCommand(base: File) = Command.args("gulp", "<gulp-command>") { (state, args) =>
gulpProcess(base, args:_*) !;
state
}
def gulpProcess(base: File, args: String*): ProcessBuilder = {
if (sys.props("os.name").toLowerCase contains "windows") {
Process("cmd" :: "/c" :: "node_modules\\.bin\\gulp.cmd" :: args.toList, base)
}
else {
Process("node" :: "node_modules/.bin/gulp" :: args.toList, base)
}
}
def npmProcess(base: File, args: String*): ProcessBuilder = {
if (sys.props("os.name").toLowerCase contains "windows") {
Process("cmd" :: "/c" :: "npm" :: args.toList, base)
}
else {
Process("npm" :: args.toList, base)
}
}
}
示例9: UIBuild
//设置package包名称以及导入依赖的类
import java.net.InetSocketAddress
import play.sbt.PlayRunHook
import sbt._
object UIBuild {
def apply(base: File): PlayRunHook = {
object UIBuildHook extends PlayRunHook {
var process: Option[Process] = None
override def beforeStarted(): Unit = {
if (!(base / "ui" / "node_modules").exists()) Process("npm install", base / "ui").!
}
override def afterStarted(addr: InetSocketAddress): Unit = {
process = Option(
Process("npm run build -- --watch", base / "ui").run
)
}
override def afterStopped(): Unit = {
process.foreach(_.destroy())
process = None
}
}
UIBuildHook
}
}
示例10: Webpack
//设置package包名称以及导入依赖的类
import play.sbt.PlayRunHook
import sbt._
object Webpack {
def apply(base: File): PlayRunHook = {
object WebpackHook extends PlayRunHook {
var process: Option[Process] = None
override def beforeStarted() = {
println("Starting up....")
process = Option(
Process("webpack", base).run()
)
}
override def afterStarted(addr: java.net.InetSocketAddress) = {
println("afterStarted....")
process = Option(
Process("webpack --watch", base).run()
)
}
override def afterStopped() = {
println("afterStopped....")
process.foreach(_.destroy())
process = None
}
override def onError() : scala.Unit = {
println("Crap happened.......")
}
}
WebpackHook
}
}
示例11: UIBuild
//设置package包名称以及导入依赖的类
import java.net.InetSocketAddress
import play.sbt.PlayRunHook
import sbt._
object UIBuild {
def apply(base: File): PlayRunHook = {
object UIBuildHook extends PlayRunHook {
var process: Option[Process] = None
var npmInstall: String = "npm install"
var npmRun: String = "npm run build -- --watch"
// Windows requires npm commands prefixed with cmd /c
if (System.getProperty("os.name").toLowerCase().contains("win")){
npmInstall = "cmd /c" + npmInstall
npmRun = "cmd /c" + npmRun
}
override def beforeStarted(): Unit = {
if (!(base / "ui" / "node_modules").exists()) Process(npmInstall, base / "ui").!
}
override def afterStarted(addr: InetSocketAddress): Unit = {
process = Option(
Process(npmRun, base / "ui").run
)
}
override def afterStopped(): Unit = {
process.foreach(_.destroy())
process = None
}
}
UIBuildHook
}
}
示例12: Webpack
//设置package包名称以及导入依赖的类
import java.net.InetSocketAddress
import play.sbt.PlayRunHook
import sbt._
object Webpack {
def apply(base: File): PlayRunHook = {
object WebpackHook extends PlayRunHook {
var process: Option[Process] = None
override def beforeStarted() = {
process = Option(
Process("webpack", base).run()
)
}
override def afterStarted(addr: InetSocketAddress) = {
process = Option(
Process("webpack --watch", base).run()
)
}
override def afterStopped() = {
process.foreach(_.destroy())
process = None
}
}
WebpackHook
}
}