Use webpack

This change adds webpack as the main tool used while developing the
extension. The extension has been minimally refactored so it works with
webpack, with the intention of refactoring it even further in follow-up
CLs in order to improve the file/folder structure of the project and its
readibility.

Bug: translateselectedtext:5
Change-Id: I89d7422e38fdaf46661c96527c51aa4436ad8056
diff --git a/tools/i18n/bump-translations.bash b/tools/i18n/bump-translations.bash
index 5de175c..55f4dd7 100644
--- a/tools/i18n/bump-translations.bash
+++ b/tools/i18n/bump-translations.bash
@@ -17,10 +17,10 @@
 
 # Generate i18n credits file
 go run generate-i18n-credits.go
-git add ../../src/json/i18n-credits.json
+git add ../../src/static/json/i18n-credits.json
 
 # Delete empty translations
-cd ../../src/_locales
+cd ../../src/static/_locales
 for lang in *; do
   if [[ "$lang" == "README.md" ]]; then
     continue
diff --git a/tools/i18n/crowdin.template.yml b/tools/i18n/crowdin.template.yml
index 3589ec3..9186c2a 100644
--- a/tools/i18n/crowdin.template.yml
+++ b/tools/i18n/crowdin.template.yml
@@ -11,10 +11,10 @@
 files: [
  {
   # Source files filter
-  "source" : "src/_locales/en/messages.json",
+  "source" : "src/static/_locales/en/messages.json",
 
   # Where translations will be placed
-  "translation" : "src/_locales/%osx_locale%/%original_file_name%",
+  "translation" : "src/static/_locales/%osx_locale%/%original_file_name%",
 
   # Files or directories for ignore
   "ignore" : ["OWNERS"],
diff --git a/tools/i18n/generate-i18n-credits.go b/tools/i18n/generate-i18n-credits.go
index 0d75842..e37d419 100644
--- a/tools/i18n/generate-i18n-credits.go
+++ b/tools/i18n/generate-i18n-credits.go
@@ -21,7 +21,7 @@
 const checkAttempts = 5
 const checkWaitTime = 2 * time.Second
 const baseApiURL = "https://api.crowdin.com/api/v2/"
-const i18nCreditsFile = "../../src/json/i18n-credits.json"
+const i18nCreditsFile = "../../src/static/json/i18n-credits.json"
 
 // Contributors who have sent translations before the Crowdin instance
 // was set up:
diff --git a/tools/release.bash b/tools/release.bash
new file mode 100644
index 0000000..b838100
--- /dev/null
+++ b/tools/release.bash
@@ -0,0 +1,108 @@
+#!/bin/bash
+#
+# Generate release files (ZIP archives of the extension source code).
+#
+# Precondition: webpack has already built the extension.
+
+# Prints help text
+function usage() {
+  cat <<END
+
+  Usage: $progname [--channel CHANNEL --browser BROWSER]
+
+  optional arguments:
+    -h, --help     show this help message and exit
+    -c, --channel  indicates the channel of the release. Can be "beta"
+                   or "stable". Defaults to "stable".
+    -b, --browser  indicates the target browser for the release. As of
+                   now it can only be "chromium", which is also the
+                   default value.
+    -f, --fast     indicates that the release shouldn't generate the
+                   i18n credits JSON file.
+
+END
+}
+
+# Updates manifest.json field
+function set_manifest_field() {
+  sed -i -E "s/\"$1\": \"[^\"]*\"/\"$1\": \"$2\"/" dist/$browser/manifest.json
+}
+
+# Get options
+opts=$(getopt -l "help,channel:,browser:,fast" -o "hc:b:f" -n "$progname" -- "$@")
+eval set -- "$opts"
+
+channel=stable
+browser=chromium
+fast=0
+
+while true; do
+  case "$1" in
+    -h | --help)
+      usage
+      exit
+      ;;
+    -c | --channel)
+      channel="$2"
+      shift 2
+      ;;
+    -b | --browser)
+      browser="$2"
+      shift 2
+      ;;
+    -f | --fast)
+      fast=1
+      shift
+      ;;
+    *) break ;;
+  esac
+done
+
+if [[ $channel != "stable" && $channel != "beta" ]]; then
+  echo "channel parameter value is incorrect." >&2
+  usage
+  exit
+fi
+
+if [[ $browser != "chromium" ]]; then
+  echo "browser parameter value is incorrect." >&2
+  usage
+  exit
+fi
+
+echo "Started building release..."
+
+# Generate the credits for the translators if applicable
+if [[ $fast == 0 ]]; then
+  bash generatei18nCredits.bash
+fi
+
+# This is the version name which git gives us
+version=$(git describe --always --tags --dirty)
+
+# If the version name contains a hyphen then it isn't a release
+# version. This is also the case if it doesn't start with a "v".
+if [[ $version == *"-"* || $version != "v"* ]]; then
+  # As it isn't a release version, setting version number to 0 so it
+  # cannot be uploaded to the Chrome Web Store
+  set_manifest_field "version" "0"
+  set_manifest_field "version_name" "$version-$channel"
+else
+  # It is a release version, set the version fields accordingly.
+  set_manifest_field "version" "${version:1}"
+  set_manifest_field "version_name" "${version:1}-$channel"
+fi
+
+if [[ $channel == "beta" ]]; then
+  # Change manifest.json to label the release as beta
+  set_manifest_field "name" "__MSG_appBetaName__"
+fi
+
+# Create ZIP file for upload to the Chrome Web Store
+mkdir -p out
+rm -rf out/translateselectedtext-$version-$browser-$channel.zip
+(cd dist/$browser &&
+  zip -rq ../../out/translateselectedtext-$version-$browser-$channel.zip * \
+  -x "*/.git*" -x "*/\.DS_Store" -x "*/OWNERS")
+
+echo "Done!"