Skip to content

Commit

Permalink
build:
Browse files Browse the repository at this point in the history
 - compile background and popup
 - moved manifest to src
 - added youtube-music to manual
 - package .crx
  • Loading branch information
lt-mayonesa committed Apr 4, 2019
1 parent 69b501e commit 59248c4
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 34 deletions.
1 change: 1 addition & 0 deletions .esdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"files": [
"./manual/how_to.md",
"./manual/youtube.md",
"./manual/youtube-music.md",
"./manual/netflix.md",
"./manual/soundcloud.md"
]
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ package-lock.json
docs
coverage
karma_html
dist
dist/**/*
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ addons:
update: true
packages:
- jq
chrome: stable

cache:
directories:
Expand All @@ -21,10 +22,10 @@ before_script:

script:
- karma start --single-run --browsers Firefox
- ./build.sh $TRAVIS_TAG

before_deploy:
- ./node_modules/.bin/esdoc
- ./build.sh $TRAVIS_TAG

deploy:
- provider: pages
Expand All @@ -36,7 +37,7 @@ deploy:
- provider: releases
api_key: $GITHUB_TOKEN
file_glob: true
file: browser-mpris2-*.zip
file: dist/*.*
skip_cleanup: true
on:
tags: true
67 changes: 51 additions & 16 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ function title() {
echo -e "\n${green}$1${fin}"
}

version=${1:-v666}
out="dist/"

if [[ ! -d ${out} ]]; then
mkdir ${out}
if [[ -d ${out} ]]; then
rm -r ${out}
fi

# BUILD EXTENSION
Expand All @@ -36,20 +37,30 @@ title "Step 3: Init Script"
npx google-closure-compiler --js='src/browser/init.js' --js_output_file="${extension}init.js" --language_out=${lang_out}
echo "Compiled src/browser/init.js into ${extension}init.js ✓"

title "Step 4: Background Script"
npx google-closure-compiler --js='background.js' --js_output_file="${extension}background.js" --language_out=${lang_out}
echo "Compiled background.js into ${extension}background.js ✓"
title "Step 4: Background Scripts"
for filename in src/browser/background/*.js; do
echo "↳ Compiling $filename"
name=$(basename ${filename})
npx google-closure-compiler --js="$filename" --js_output_file="${extension}background/$name" --language_out=${lang_out}
done
echo "Compiled background scripts into ${extension}background/ ✓"

title "Step 5: Manifest"
title "Step 5: Popup files"
for filename in src/browser/popup/*.js; do
echo "↳ Compiling $filename"
name=$(basename ${filename})
npx google-closure-compiler --js="$filename" --js_output_file="${extension}popup/$name" --language_out=${lang_out}
done
cp -v "src/browser/popup/popup.html" "${extension}popup/"
echo "Compiled popup files into ${extension}popup/ ✓"

title "Step 6: Manifest"
# replace version, first and last content script js with base.js and init.js respectively
cat manifest.json | \
cat "src/browser/manifest.json" | \
jq '.name = "browser-mpris2"' | \
jq '.version = "'$1'"' | \
jq '.content_scripts[0].js = ["base.js"]' | \
jq '.content_scripts[-1].js = ["init.js"]' \
jq '.version = "'${version/v/}'"' | \
> ${extension}manifest.json
# replace all instances of src/ with empty string
sed -i -e 's,src/,,g' ${extension}manifest.json
echo "Generated ${extension}manifest.json ✓"


Expand All @@ -61,14 +72,38 @@ title "Step 1: Copy source files"
cp -rv "src/native/" "$native"


title "REPLACE PACKAGE ID"
title "PACKAGE"

title "Step 1: Replace package id"
grep -lR org.mpris.browser_host.debug dist/ | xargs sed -i 's/org.mpris.browser_host.debug/org.mpris.browser_host/g'
echo "Replaced all occurrences of 'org.mpris.browser_host.debug' with 'org.mpris.browser_host'"
echo "Replaced all occurrences of 'org.mpris.browser_host.debug' with 'org.mpris.browser_host'"

# Compress extension and native to a release zip
title "Step 6: Zip Release"
zip -r "browser-mpris2-$1.zip" ${extension} ${native}
echo "Created release .zip for version $1"
title "Step 2: Zip Release"
cd dist
zip -r "browser-mpris2-$version.zip" "."
cd ..
echo "Created release .zip for version $version"

if [[ "$version" != "v666" ]]; then
title "Step 3: Package extension"
/opt/google/chrome/chrome --no-message-box --pack-extension=./dist/extension --pack-extension-key=./extension.pem
echo "Create release .crx for version $version"

# title "Step 4: Generate update .xml"
# echo "<?xml version='1.0' encoding='UTF-8'?>
#<gupdate xmlns='https://www.google.com/update2/response' protocol='2.0'>
# <app appid='mcakdldkgmlakhcpdmecedogacbagdba'>
# <updatecheck codebase='https://github.com/Lt-Mayonesa/browser-mpris2/releases/download/$version/browser-mpris2-$version.crx' version='"${version/v/}"' />
# </app>
#</gupdate>
#" > "${out}updates.xml";
#
# title "Step 5: Add updated URL"
# cat "${extension}manifest.json" | \
# jq '. + {update_url: "https://github.com/Lt-Mayonesa/browser-mpris2/releases/download/'${version}'/update.xml"}' \
# > ${extension}manifest.json
fi

title "DONE ✓"
exit 0;
28 changes: 28 additions & 0 deletions extension.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCjFq6n9C1wTilP
R5ujJiPbFaMj/+ujo+DOpO8QJMxt8c3U9JAAv+Zg0N8Vy9UVMMhMXliq6jH3mkYm
80uHCgHFZSJayQEKZSosKT30tiQZmUZZEgrJ0H/TjtsG7Jr4CtLk/0vQXNcNMFIr
g78u3hsBY8SHjuodzU+RPVJbYevoAeIid1yt59Rj/JbLpCNXvnmOfXFmrHGYV6fU
0sPV5UBb0fJ808oh+DErprJ0nQdIgyhrpdsZQ2w72uheClUFUiwEcT26uAYAF8Xb
m9KIFWBCshuC9y+3WqAGYG2FpeYJUs+wbRks1FGLRz/Xt/Op0B8VUqxTKgxwV8pI
rcGQdcSPAgMBAAECggEASwtaZe1dZUKKDrGAI+QedqbvsVaHSv7TKLNLUA3mxaaR
FK9OfhHPg/hI1uI61Cvk1wNI4KiwQmOKaUzlkadgpkDBvK2mXW6sp7J4kFypot/d
N4ouTawzzZj8HyULsBxm67mv3JqD2E1GWkCe3gWUvqB2Y/w2rWz2cnoZpfQaleBf
Ujzwn7dipBghzrN8L0X+HqyOnF0DmfzlI6NXMsqmYGZ6sR4I5DBcocup0FNcIvXE
PXuKETg9NOslnDlUhg/C4hdFmRUAYSFR8g+2t/AKM1/BYbEo0A0NEjQ8kURDrHK0
lij1ITSXjGYYmCqVOdPLtaLHr2vFjoxdUtDp3AVPUQKBgQDdfgZ6xVWnRofkRjxR
Peq+QTazWOIOC7NJdjYCk2zSilfaNHYMsDTe5OerlP5iKqZLoXiT1jbHSQZbwzQ/
jXhcDHmLZa5sp7QCqDqxakqJDldgVQkOsC4cIJPmxcoNH8xqtfCWK6YTCxmsu62v
sA4mO4ZdBYOQ65exALgld6kGMQKBgQC8f0poMgbTUW1/3TfQ7EcPfq1GY3/Lv4nG
ji5OJ8/VxT7U/2afrPakuZM2xNF8eP1AL5fZdlzzjB0wlaq8lrgFrhpghBZTDPM3
4jkGU/EZgB6a9a1acSGQNXdOhsV3aNCm8IP/ImRkxPfCJSbOfxYmL+cQhVa+u2y9
21PJKEUGvwKBgGREfOJvGstS3om0UfHlObNPClg+UHdTTKJg5SpdWtIk1ohtX1N3
ITgWH9pI5K/D5uwt+MvUGZA1uq8nuytZ+7aP3yX/rep6ML9TMN7H414QI/X0CNmh
X/5TsSCzQTiXwI4+Nt+EevX7/G95trLl3EHqiHTr3hdoz47NaI9tkBLBAoGAC6PU
pXCJaV065M11V+pvTO6mppUYXC2cxW0cQOlGdU3z3lVTMgMNTAjFpXkr8oLKKL+H
of8kKEn7t3dWjsTD4l3o9RLTChffoRDQMqrWVZvKyAjpxo774pranjfGU+ReFiD+
FbA7ANoE7rE6nz/Lz1nf6+4/+BE82tCDcQWSlaMCgYByWVJSSE6aiech4RIyEqaZ
XGf7stAkBOObYNo5JCEitLL1ovzeAvQ3ehF2rJENerKSpq7T8vbPTcN1zNjKwZN/
XySns6cyC7tK+ahccYYCKx9QC6Rnaez3lE2x2yn3mr+85WBpvotQRYDrDqRO7Ep6
gT3Aivf8NQmuE4wAXvNH2A==
-----END PRIVATE KEY-----
File renamed without changes.
File renamed without changes.
28 changes: 14 additions & 14 deletions manifest.json → src/browser/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"version": "0.2.1",
"browser_action": {
"default_title": "Browser MPRIS2",
"default_popup": "popup.html"
"default_popup": "popup/popup.html"
},
"background": {
"scripts": [
"background.js",
"updater.js"
"background/proxy.js",
"background/updater.js"
],
"persistent": false
},
Expand All @@ -20,12 +20,12 @@
"*://*/*"
],
"js": [
"src/browser/main/globals.js",
"src/browser/main/player.js",
"src/browser/main/carrier.js",
"src/browser/main/playback.js",
"src/browser/main/host.js",
"src/browser/main/page.js"
"main/globals.js",
"main/player.js",
"main/carrier.js",
"main/playback.js",
"main/host.js",
"main/page.js"
],
"run_at": "document_start",
"all_frames": true
Expand All @@ -36,7 +36,7 @@
"*://youtube.com/*"
],
"js": [
"src/providers/youtube.js"
"providers/youtube.js"
],
"run_at": "document_start",
"all_frames": true
Expand All @@ -46,7 +46,7 @@
"*://music.youtube.com/*"
],
"js": [
"src/browser/providers/youtube-music.js"
"providers/youtube-music.js"
],
"run_at": "document_start",
"all_frames": true
Expand All @@ -56,7 +56,7 @@
"*://soundcloud.com/*"
],
"js": [
"src/browser/providers/soundcloud.js"
"providers/soundcloud.js"
],
"run_at": "document_start",
"all_frames": true
Expand All @@ -67,7 +67,7 @@
"*://*.netflix.com/*"
],
"js": [
"src/browser/providers/netflix.js"
"providers/netflix.js"
],
"run_at": "document_start",
"all_frames": true
Expand All @@ -77,7 +77,7 @@
"*://*/*"
],
"js": [
"src/browser/init.js"
"init.js"
],
"run_at": "document_start",
"all_frames": true
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/native/chrome-mpris2
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def main():
player = active_players[tabid]
except KeyError:
# Many terrible things can happen to tabs; they can crash or be
# discarded. For these cases out background.js should still inform
# discarded. For these cases out proxy.js should still inform
# us. However it may be that that tab has already quit e.g. it may
# be in YouTube's main page when it crashes. In these cases we
# don't want to create a player just to immediately destroy it.
Expand Down

0 comments on commit 59248c4

Please sign in to comment.