Skip to content

Commit

Permalink
Use sbt's built-in utils
Browse files Browse the repository at this point in the history
  • Loading branch information
olegstepura committed Dec 2, 2014
1 parent 4417a9f commit 6728ad3
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/main/scala/net/ground5hark/sbt/closure/SbtClosure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,6 @@ object SbtClosure extends AutoPlugin {
closure := closureCompile.value
)

object util {
def withoutExt(name: String): String = name.substring(0, name.lastIndexOf("."))
def relativePath(file: File, baseDir: File): String = {
import java.nio.file.Paths

val basePath = Paths.get(baseDir.getCanonicalPath)
val outputFilePath = Paths.get(file.getCanonicalPath)
basePath.relativize(outputFilePath).toString
}
}

private def invokeCompiler(src: File, target: File, flags: Seq[String]): Unit = {
val opts = Seq(s"--js=${src.getAbsolutePath}", s"--js_output_file=${target.getAbsolutePath}") ++
flags.filterNot(s => s.trim.startsWith("--js=") || s.trim.startsWith("--js_output_file="))
Expand All @@ -85,7 +74,7 @@ object SbtClosure extends AutoPlugin {
// Only do work on files which have been modified
val runCompiler = FileFunction.cached(streams.value.cacheDirectory / parentDir.value, FilesInfo.hash) { files =>
files.map { f =>
val outputFileSubPath = s"${util.withoutExt(compileMappings(f))}${suffix.value}"
val outputFileSubPath = IO.split(compileMappings(f))._1 + suffix.value
val outputFile = targetDir / outputFileSubPath
IO.createDirectory(outputFile.getParentFile)
streams.value.log.info(s"Closure compiler executing on file ${compileMappings(f)}")
Expand All @@ -95,7 +84,10 @@ object SbtClosure extends AutoPlugin {
}

val compiled = runCompiler(compileMappings.keySet).map { outputFile =>
(outputFile, util.relativePath(outputFile, targetDir))
val relativePath = IO.relativize(targetDir, outputFile).getOrElse {
sys.error(s"Cannot find $outputFile path relative to $targetDir")
}
(outputFile, relativePath)
}.toSeq

compiled ++ mappings.filter {
Expand Down

0 comments on commit 6728ad3

Please sign in to comment.