Skip to content

Commit

Permalink
do not build the service worker if the file is empty #104
Browse files Browse the repository at this point in the history
  • Loading branch information
tbela99 committed Oct 15, 2020
1 parent 871c11e commit 535adf9
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 22 deletions.
27 changes: 17 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,29 @@ VER=$(git rev-parse --short HEAD)
cd $DIR
#
#
# build config files
# process es6+ deps
node rollup.config.js
# minify
node terser.config.js
#
cat worker/dist/serviceworker.js | sed "s/build-date/$DATE/g" | sed "s/build-id/$VER/g" > worker/dist/serviceworker.js
sed -i "s/build-date/$DATE/g" worker/dist/serviceworker.js && sed -i "s/build-id/$VER/g" worker/dist/serviceworker.js
#
./node_modules/terser/bin/terser --warn --comments all --beautify beautify=true,preamble='"/* do not edit! */"' --ecma=8\
-- worker/src/browser.js | sed "s/build-date/$DATE/g" | sed "s/build-id/$VER/g" > worker/dist/browser.js
if [ ! -s worker/dist/serviceworker.js ]; then

echo -e '\e[31mbuild failed\e[0m'
exit 1
fi
#
./node_modules/terser/bin/terser --warn --comments all --beautify beautify=true,preamble='"/* do not edit! */"' --ecma=8\
-- worker/src/browser.administrator.js | sed "s/build-date/$DATE/g" | sed "s/build-id/$VER/g" > worker/dist/browser.administrator.js
# shellcheck disable=SC2002
sed -i "s/build-date/$DATE/g" worker/src/browser.js && sed -i "s/build-id/$VER/g" worker/dist/browser.js
#
./node_modules/terser/bin/terser --warn --comments all --beautify beautify=true,preamble='"/* do not edit! */"' --ecma=8\
-- worker/src/browser.sync.js | sed "s/build-date/$DATE/g" | sed "s/build-id/$VER/g" > worker/dist/browser.sync.js
sed -i "s/build-date/$DATE/g" worker/src/browser.administrator.js && sed -i "s/build-id/$VER/g" worker/dist/browser.administrator.js
#
./node_modules/terser/bin/terser --warn --comments all --beautify beautify=true,preamble='"/* do not edit! */"' --ecma=8\
-- worker/src/browser.uninstall.js | sed "s/build-date/$DATE/g" | sed "s/build-id/$VER/g" > worker/dist/browser.uninstall.js
sed -i "s/build-date/$DATE/g" worker/src/browser.sync.js && sed -i "s/build-id/$VER/g" worker/dist/browser.sync.js
#
node terser.config.js
sed -i "s/build-date/$DATE/g" worker/src/browser.uninstall.js && sed -i "s/build-id/$VER/g" worker/dist/browser.uninstall.js
#
# node terser.config.js
#
sha1sum worker/dist/serviceworker.js | awk '{print $1;}' | tee ./worker_version
2 changes: 2 additions & 0 deletions config/terser/terser.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ for (let name in config) {
name,
error
});

throw error;
}
})(config[name], name);
}
2 changes: 2 additions & 0 deletions terser.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@
name,
error
});

throw error;
}
})(config[name], name);
}
Expand Down
4 changes: 4 additions & 0 deletions worker/dist/browser.administrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
* @license MIT License
*/
// @ts-check
<<<<<<< Updated upstream
// build a484bf1 2020-09-20 11:24:40-04:00
=======
// build 10d7737 2020-10-14 17:55:11-04:00
>>>>>>> Stashed changes
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("{scope}worker{debug}.js", {
scope: "{scope}"
Expand Down
2 changes: 1 addition & 1 deletion worker/dist/browser.administrator.min.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"serviceWorker"in navigator&&navigator.serviceWorker.register("{scope}worker{debug}.js",{scope:"{scope}"}).catch((function(e){console.error("😭",e)}));
undefined
4 changes: 4 additions & 0 deletions worker/dist/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
* @license MIT License
*/
// @ts-check
<<<<<<< Updated upstream
// build a484bf1 2020-09-20 11:24:40-04:00
=======
// build 10d7737 2020-10-14 17:55:11-04:00
>>>>>>> Stashed changes
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("{scope}worker{debug}.js", {
scope: "{scope}"
Expand Down
2 changes: 1 addition & 1 deletion worker/dist/browser.min.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
if("serviceWorker"in navigator&&(navigator.serviceWorker.register("{scope}worker{debug}.js",{scope:"{scope}"}).catch((function(e){console.error("😭",e)})),"onbeforeinstallprompt"in window)){let e,t;const a='<div class="pwa-app-install pwa-app-install-bottom"><div class="alert alert-success"><div class=alert-body><button type=button class=close data-dismiss=alert aria-label=Close><span aria-hidden=true>&times;</span></button>Click <a href=# data-action=install-pwa-app>here</a> to make this site available offline.',clickHandler=function(a){a.preventDefault(),a.stopPropagation(),e.prompt(),t.removeEventListener("click",clickHandler,!1),t=null,e.userChoice.then((function(e){}),(function(e){console.error("😭",e)}))},createButton=function(){document.body.insertAdjacentHTML("beforeend",a),t=document.querySelector("a[data-action=install-pwa-app]"),t.addEventListener("click",clickHandler,!1)};window.addEventListener("beforeinstallprompt",(function(t){e=t,t.preventDefault(),createButton()}))}
undefined
4 changes: 4 additions & 0 deletions worker/dist/browser.uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
* @license MIT License
*/
// @ts-check
<<<<<<< Updated upstream
// build a484bf1 2020-09-20 11:24:40-04:00
=======
// build 10d7737 2020-10-14 17:55:11-04:00
>>>>>>> Stashed changes
if ("serviceWorker" in navigator && navigator.serviceWorker.controller) {
navigator.serviceWorker.getRegistration().then((function(registration) {
registration.unregister().then((function(result) {
Expand Down
2 changes: 1 addition & 1 deletion worker/dist/browser.uninstall.min.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"serviceWorker"in navigator&&navigator.serviceWorker.controller&&navigator.serviceWorker.getRegistration().then((function(r){r.unregister().then((function(r){}))}));
undefined
6 changes: 3 additions & 3 deletions worker/dist/serviceworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,14 +881,14 @@
* service worker build id
*/
buildid: {
value: "a484bf1",
value: "871c11e",
enumerable: true
},
/**
* service worker buid date
*/
builddate: {
value: "2020-09-20 11:24:40-04:00",
value: "2020-10-14 21:30:28-04:00",
enumerable: true
},
/**
Expand Down Expand Up @@ -1661,7 +1661,7 @@

if (!event.url || (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin')) {

return fetch(event.request);
return;
}

let response;
Expand Down
2 changes: 1 addition & 1 deletion worker/dist/serviceworker.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion worker/src/browser.administrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// @ts-check

// build build-id build-date
// build build-id 2020-10-14 21:09:16-04:00

if ("serviceWorker" in navigator) {
navigator.serviceWorker.
Expand Down
2 changes: 1 addition & 1 deletion worker/src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// @ts-check

// build build-id build-date
// build build-id 2020-10-14 21:09:16-04:00

if ("serviceWorker" in navigator) {
navigator.serviceWorker.
Expand Down
2 changes: 1 addition & 1 deletion worker/src/browser.uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
// @ts-check

// build build-id build-date
// build build-id 2020-10-14 21:09:16-04:00

if ("serviceWorker" in navigator && navigator.serviceWorker.controller) {
navigator.serviceWorker.getRegistration().then(function (registration) {
Expand Down
2 changes: 1 addition & 1 deletion worker/src/service/sw.service.fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ self.addEventListener("fetch", (event) => {

if (!event.url || (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin')) {

return fetch(event.request);
return;
}

let response;
Expand Down
2 changes: 1 addition & 1 deletion worker_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cde1d7edd1e8fb2e1cf5f1855bebd34b58b142e0
acc113672222df687cf6060cf858c6e590e638a8

0 comments on commit 535adf9

Please sign in to comment.