Skip to content

Commit

Permalink
Update template
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexITC committed Nov 8, 2020
1 parent 0c9953e commit d9dd23c
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 113 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ target/
project/target/
.idea/

.bsp/
3 changes: 3 additions & 0 deletions .sbtopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-J-Xmx4G
-J-XX:MaxMetaspaceSize=4G
-J-XX:+CMSClassUnloadingEnabled
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ It's pretty simple to get started, just follow these steps:
- Move to the cloned repo: `cd chrome-scalajs-template`
- Add your brand: `./customize.sh com.alexitc.chrome com/alexitc/chrome` (replace the arguments with your desired base package, ignore the `sed` related warnings).
- Edit the [build.sbt](build.sbt) to add the desired details for your app.
- Edit the [AppManifest.scala](project/AppManifest.scala) to define your app manifest.
- Edit the [app resources](src/main/resources) to the ones for your app.
- Commit your changes and continue to the next section for building the app, also, start looking on the [Firefox guide](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions) or the [Chrome guide](https://developer.chrome.com/extensions/devguide) for developing extensions.
- Running `sbt chromePackage` on this project is enough to get your extension packaged.

## Development
- Running `sbt ~chromeUnpackedFast` will build the app each time it detects changes on the code, it also disables js optimizations which result in faster builds (placing the build at `target/chrome/unpacked-fast`).
- Running `sbt "~chromeUnpackedFast"` will build the app each time it detects changes on the code, it also disables js optimizations which result in faster builds (placing the build at `target/chrome/unpacked-fast`).
- Be sure to integrate scalafmt on your IntelliJ to format the source code on save (see https://scalameta.org/scalafmt/docs/installation.html#intellij).

## Release
Expand Down
185 changes: 77 additions & 108 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,120 +1,89 @@
import chrome._
import chrome.permissions.Permission
import chrome.permissions.Permission.API
import com.alexitc.{Chrome, ChromeSbtPlugin}

resolvers += Resolver.sonatypeRepo("releases")
resolvers += Resolver.bintrayRepo("oyvindberg", "ScalablyTyped")
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

name := "chrome-scalajs-template" // TODO: REPLACE ME
version := "1.0.0"
scalaVersion := "2.12.10"
scalacOptions ++= Seq(
"-language:implicitConversions",
"-language:existentials",
"-Xlint",
"-deprecation",
//"-Xfatal-warnings",
"-feature"
)

enablePlugins(ChromeSbtPlugin, BuildInfoPlugin, ScalaJSBundlerPlugin, ScalablyTypedConverterPlugin)
import com.alexitc.ChromeSbtPlugin

lazy val appName = "chrome-scalajs-template" // TODO: REPLACE ME
lazy val isProductionBuild = sys.env.getOrElse("PROD", "false") == "true"

// build-info
buildInfoPackage := "com.alexitc"
buildInfoKeys := Seq[BuildInfoKey](name)
buildInfoKeys ++= Seq[BuildInfoKey](
"production" -> (sys.env.getOrElse("PROD", "false") == "true")
)

// NOTE: source maps are disabled to avoid a file not found error which occurs when using the current
// webpack settings.
scalaJSLinkerConfig := scalaJSLinkerConfig.value.withSourceMap(false)
version in webpack := "4.8.1"

webpackConfigFile := {
val file = if (isProductionBuild) "production.webpack.config.js" else "dev.webpack.config.js"
Some(baseDirectory.value / file)
}

// scala-js-chrome
scalaJSLinkerConfig := scalaJSLinkerConfig.value.withRelativizeSourceMapBase(
Some((Compile / fastOptJS / artifactPath).value.toURI)
)
skip in packageJSDependencies := false

webpackBundlingMode := BundlingMode.Application

fastOptJsLib := (webpack in (Compile, fastOptJS)).value.head
fullOptJsLib := (webpack in (Compile, fullOptJS)).value.head

webpackBundlingMode := BundlingMode.LibraryAndApplication()
val circe = "0.13.0"

// 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 (Compile, fastOptJS)).value / "main.js"
lazy val baseSettings: Project => Project = {
_.enablePlugins(ScalaJSPlugin)
.settings(
name := appName,
version := "1.0.0",
scalaVersion := "2.13.3",
scalacOptions ++= Seq(
"-language:implicitConversions",
"-language:existentials",
"-Xlint",
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-encoding",
"utf-8", // Specify character encoding used by source files.
"-explaintypes", // Explain type errors in more detail.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-unchecked" // Enable additional warnings where generated code depends on assumptions.
),
scalacOptions += "-Ymacro-annotations",
requireJsDomEnv in Test := true
)
}

artifactPath in (Compile, fullOptJS) := {
(crossTarget in (Compile, fullOptJS)).value / "main.js"
lazy val bundlerSettings: Project => Project = {
_.enablePlugins(ScalaJSBundlerPlugin)
.settings(
// NOTE: source maps are disabled to avoid a file not found error which occurs when using the current
// webpack settings.
scalaJSLinkerConfig := scalaJSLinkerConfig.value.withSourceMap(false),
version in webpack := "4.8.1",
webpackConfigFile := {
val file = if (isProductionBuild) "production.webpack.config.js" else "dev.webpack.config.js"
Some(baseDirectory.value / file)
},
// scala-js-chrome
scalaJSLinkerConfig := scalaJSLinkerConfig.value.withRelativizeSourceMapBase(
Some((Compile / fastOptJS / artifactPath).value.toURI)
),
skip in packageJSDependencies := false,
webpackBundlingMode := BundlingMode.Application,
fastOptJsLib := (webpack in (Compile, fastOptJS)).value.head,
fullOptJsLib := (webpack in (Compile, fullOptJS)).value.head,
webpackBundlingMode := BundlingMode.LibraryAndApplication(),
// 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 (Compile, fastOptJS)).value / "main.js"
},
artifactPath in (Compile, fullOptJS) := {
(crossTarget in (Compile, fullOptJS)).value / "main.js"
}
)
}

chromeManifest := new ExtensionManifest {
override val name = "__MSG_extensionName__" // NOTE: i18n on the manifest is not supported on firefox
override val version = Keys.version.value

override val description = Some(
"TO BE UPDATED" // TODO: REPLACE ME
)
override val icons = Chrome.icons("icons", "app.png", Set(48, 96, 128))

// TODO: REPLACE ME, use only the minimum required permissions
override val permissions = Set[Permission](
API.Storage,
API.Notifications,
API.Alarms
)

override val defaultLocale: Option[String] = Some("en")

// TODO: REPLACE ME
override val browserAction: Option[BrowserAction] =
Some(BrowserAction(icons, Some("TO BE DEFINED - POPUP TITLE"), Some("popup.html")))

// scripts used on all modules
val commonScripts = List("scripts/common.js", "main-bundle.js")

override val background = Background(
scripts = commonScripts ::: List("scripts/background-script.js")
)

override val contentScripts: List[ContentScript] = List(
ContentScript(
matches = List(
"https://github.com/*" // TODO: REPLACE ME
lazy val buildInfoSettings: Project => Project = {
_.enablePlugins(BuildInfoPlugin)
.settings(
buildInfoPackage := "com.alexitc",
buildInfoKeys := Seq[BuildInfoKey](name),
buildInfoKeys ++= Seq[BuildInfoKey](
"production" -> isProductionBuild
),
css = List("css/active-tab.css"),
js = commonScripts ::: List("scripts/active-tab-script.js")
buildInfoUsePackageAsPath := true
)
)

override val webAccessibleResources = List("icons/*")
}

val circe = "0.13.0"

libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "1.1.0"
libraryDependencies += "com.alexitc" %%% "scala-js-chrome" % "0.7.0"

libraryDependencies += "io.circe" %%% "circe-core" % circe
libraryDependencies += "io.circe" %%% "circe-generic" % circe
libraryDependencies += "io.circe" %%% "circe-parser" % circe

// js dependencies, adding typescript type definitions gets them a Scala facade
npmDependencies in Compile ++= Seq(
"sweetalert" -> "2.1.2"
)
lazy val root = (project in file("."))
.enablePlugins(ChromeSbtPlugin, ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, buildInfoSettings)
.settings(
chromeManifest := AppManifest.generate(appName, Keys.version.value),
// js dependencies, adding typescript type definitions gets them a Scala facade
Compile / npmDependencies ++= Seq(
"sweetalert" -> "2.1.2"
),
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "1.1.0",
"com.alexitc" %%% "scala-js-chrome" % "0.7.0",
"io.circe" %%% "circe-core" % circe,
"io.circe" %%% "circe-generic" % circe,
"io.circe" %%% "circe-parser" % circe
)
)
51 changes: 51 additions & 0 deletions project/AppManifest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import chrome.permissions.Permission
import chrome.permissions.Permission.API
import chrome.{Background, BrowserAction, ContentScript, ExtensionManifest}
import com.alexitc.Chrome

object AppManifest {

def generate(appName: String, appVersion: String): ExtensionManifest = {
new ExtensionManifest {
override val name = appName
override val version = appVersion

override val description = Some(
"TO BE UPDATED" // TODO: REPLACE ME
)
override val icons = Chrome.icons("icons", "app.png", Set(48, 96, 128))

// TODO: REPLACE ME, use only the minimum required permissions
override val permissions = Set[Permission](
API.Storage,
API.Notifications,
API.Alarms
)

override val defaultLocale: Option[String] = Some("en")

// TODO: REPLACE ME
override val browserAction: Option[BrowserAction] =
Some(BrowserAction(icons, Some("TO BE DEFINED - POPUP TITLE"), Some("popup.html")))

// scripts used on all modules
val commonScripts = List("scripts/common.js", "main-bundle.js")

override val background = Background(
scripts = commonScripts ::: List("scripts/background-script.js")
)

override val contentScripts: List[ContentScript] = List(
ContentScript(
matches = List(
"https://github.com/*" // TODO: REPLACE ME
),
css = List("css/active-tab.css"),
js = commonScripts ::: List("scripts/active-tab-script.js")
)
)

override val webAccessibleResources = List("icons/*")
}
}
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.3.13
sbt.version=1.4.1
5 changes: 2 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
resolvers += Resolver.bintrayRepo("oyvindberg", "converter")
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

addSbtPlugin("org.scalablytyped.converter" % "sbt-converter" % "1.0.0-beta12")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.3.0")
addSbtPlugin("org.scalablytyped.converter" % "sbt-converter" % "1.0.0-beta28")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.1.0")
addSbtPlugin("com.alexitc" % "sbt-chrome-plugin" % "0.7.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.18.0")
Expand Down

0 comments on commit d9dd23c

Please sign in to comment.