diff --git a/examples/build.sbt b/examples/build.sbt index 9a944ee..205edff 100644 --- a/examples/build.sbt +++ b/examples/build.sbt @@ -26,12 +26,28 @@ lazy val exampleApp = project.in(file("app")) scalaJSUseMainModuleInitializer in Test := false, relativeSourceMaps := true, skip in packageJSDependencies := false, + + // you can customize and have a static output name for lib and dependencies + // instead of having the default files names like app-fastopt.js, ... + artifactPath in (Compile, fastOptJS) := { + (crossTarget in fastOptJS).value / "main.js" + }, + artifactPath in (Compile, fullOptJS) := { + (crossTarget in fullOptJS).value / "main.js" + }, + artifactPath in (Compile, packageJSDependencies) := { + (crossTarget in packageJSDependencies).value / "dependencies.js" + }, + artifactPath in (Compile, packageMinifiedJSDependencies) := { + (crossTarget in packageMinifiedJSDependencies).value / "dependencies.js" + }, + chromeManifest := new AppManifest { val name = Keys.name.value val version = Keys.version.value val app = App( background = Background( - scripts = Chrome.defaultScripts + scripts = List("main.js", "dependencies.js") ) ) override val defaultLocale = Some("en") @@ -71,9 +87,25 @@ lazy val extension = project.in(file("extension")) scalaJSUseMainModuleInitializer in Test := false, relativeSourceMaps := true, skip in packageJSDependencies := false, + + // you can customize and have a static output name for lib and dependencies + // instead of having the default files names like extension-fastopt.js, ... + artifactPath in (Compile, fastOptJS) := { + (crossTarget in fastOptJS).value / "main.js" + }, + artifactPath in (Compile, fullOptJS) := { + (crossTarget in fullOptJS).value / "main.js" + }, + artifactPath in (Compile, packageJSDependencies) := { + (crossTarget in packageJSDependencies).value / "dependencies.js" + }, + artifactPath in (Compile, packageMinifiedJSDependencies) := { + (crossTarget in packageMinifiedJSDependencies).value / "dependencies.js" + }, + chromeManifest := new ExtensionManifest { val background = Background( - scripts = Chrome.defaultScripts + scripts = List("main.js", "dependencies.js") ) val name = Keys.name.value val version = Keys.version.value diff --git a/sbt-plugin/src/main/scala/net/lullabyte/Chrome.scala b/sbt-plugin/src/main/scala/net/lullabyte/Chrome.scala index b22ad9a..f743e43 100644 --- a/sbt-plugin/src/main/scala/net/lullabyte/Chrome.scala +++ b/sbt-plugin/src/main/scala/net/lullabyte/Chrome.scala @@ -7,9 +7,7 @@ import sbt._ object Chrome { - val mainFileName = "main.js" - val dependenciesFileName = "dependencies.js" - val defaultScripts = List(dependenciesFileName, mainFileName) + val manifestFileName = "manifest.json" def i18n(msg: String): String = s"__MSG_${msg}__" @@ -20,16 +18,34 @@ object Chrome { } def buildUnpackedDirectory(unpacked: File)(manifest: File, jsLib: File, - jsDeps: File, resources: Seq[File]): File = { + jsDeps: File, resources: Seq[File]): File = { + + val libsAndDependencies = List( + jsLib -> unpacked / jsLib.getName, + jsDeps -> unpacked / jsDeps.getName + ) + + val sourceMaps = List(jsLib, jsDeps) map { sourceFile => + val fileName = sourceFile.getName + ".map" + val originalSourceMap = sourceFile.getParentFile / fileName + originalSourceMap -> unpacked / fileName + } filter (_._1.exists()) + + val chromeSpecific = List( + manifest -> unpacked / manifestFileName + ) + IO.createDirectory(unpacked) + resources.foreach { resource => IO.copyDirectory(resource, unpacked, overwrite = true, preserveLastModified = true) } - IO.copy(List( - (jsLib, unpacked / mainFileName), - (jsDeps, unpacked / dependenciesFileName), - (manifest, unpacked / "manifest.json") - ), overwrite = true, preserveLastModified = true, preserveExecutable = true) + + IO.copy( + libsAndDependencies ::: sourceMaps ::: chromeSpecific, + overwrite = true, preserveLastModified = true, preserveExecutable = true + ) + unpacked } diff --git a/sbt-plugin/src/main/scala/net/lullabyte/ChromeSbtPlugin.scala b/sbt-plugin/src/main/scala/net/lullabyte/ChromeSbtPlugin.scala index f74555b..0d7c65d 100644 --- a/sbt-plugin/src/main/scala/net/lullabyte/ChromeSbtPlugin.scala +++ b/sbt-plugin/src/main/scala/net/lullabyte/ChromeSbtPlugin.scala @@ -20,11 +20,12 @@ object ChromeSbtPlugin extends AutoPlugin { val fullOptJsLib = TaskKey[Attributed[File]]("fullOptJsLib") val fastOptJsLib = TaskKey[Attributed[File]]("fastOptJsLib") + private val chromeDir = "chrome" lazy val baseSettings: Seq[Def.Setting[_]] = Seq( fastOptJsLib := (fastOptJS in Compile).value, chromeUnpackedFast := { - Chrome.buildUnpackedDirectory(target.value / "chrome" / "unpacked-fast")( + Chrome.buildUnpackedDirectory(target.value / chromeDir / "unpacked-fast")( (chromeGenerateManifest in Compile).value, fastOptJsLib.value.data, (packageJSDependencies in Compile).value, @@ -33,7 +34,7 @@ object ChromeSbtPlugin extends AutoPlugin { }, fullOptJsLib := (fullOptJS in Compile).value, chromeUnpackedOpt := { - Chrome.buildUnpackedDirectory(target.value / "chrome" / "unpacked-opt")( + Chrome.buildUnpackedDirectory(target.value / chromeDir / "unpacked-opt")( (chromeGenerateManifest in Compile).value, fullOptJsLib.value.data, (packageMinifiedJSDependencies in Compile).value, @@ -41,7 +42,7 @@ object ChromeSbtPlugin extends AutoPlugin { ) }, chromePackage := { - val out = target.value / "chrome" + val out = target.value / chromeDir val chromeAppDir = chromeUnpackedOpt.value val zipFile = new File(out, s"${name.value}.zip") val excludeFileNames = Set( @@ -52,7 +53,7 @@ object ChromeSbtPlugin extends AutoPlugin { zipFile }, chromeGenerateManifest := { - Chrome.generateManifest(target.value / "chrome" / "generated_manifest.json")( + Chrome.generateManifest(target.value / chromeDir / "generated_manifest.json")( (chromeManifest in Compile).value ) }