这就是这种情况;我有一个与激活程序集成的播放应用程序。为了运行我的Grunt任务,我将Grunt.scala添加到了我的项目中
import java.net.InetSocketAddress
import play.sbt.PlayRunHook
import sbt._
object Grunt {
def apply(base: File): PlayRunHook = {
object GruntProcess extends PlayRunHook {
var process: Option[Process] = None
def osCommand(command: String): String = {
System.getProperty("os.name").toLowerCase().startsWith("win") match{
case true => s"cmd.exe /c $command"
case false => command
}
}
override def beforeStarted(): Unit = {
Process(osCommand("grunt dist"), base).run
}
override def afterStarted(addr: InetSocketAddress): Unit = {
process = Some(Process(osCommand("grunt watch"), base).run)
}
override def afterStopped(): Unit = {
process.map(p => p.destroy())
process = None
}
}
GruntProcess
}
}
然后将以下行添加到我的build.sbt中:
PlayKeys.playRunHooks += Grunt(baseDirectory.value)
基本上遵循Play的文档。所以现在为了运行我的项目,我使用以下激活器命令:
activator -Dsbt.log.noformat=true clean dist universal:packageZipTarball
问题是如何从scala类访问“ dist”命令行参数。我想使用该参数来确定我应该运行哪个Grunt任务(dist,test等)。
答案 0 :(得分:0)
我发现this回购中的SBT文件很有教育意义。基本上可以从SBT文件(不是scala挂钩)处理不同的环境,如该文件底部所示:
....
// Execute frontend prod build task prior to play dist execution.
dist := (dist dependsOn `ui-prod-build`).value
// Execute frontend prod build task prior to play stage execution.
stage := (stage dependsOn `ui-prod-build`).value
....