From 33eb674d37924a677afa936877d38a2f395c6460 Mon Sep 17 00:00:00 2001 From: Niklas Fiekas Date: Tue, 17 Sep 2019 19:59:50 +0200 Subject: [PATCH] build service worker from ui module --- package.json | 1 + ui/build | 2 +- ui/serviceWorker/gulpfile.js | 3 +++ ui/serviceWorker/package.json | 19 +++++++++++++++++++ .../serviceWorker/src/main.ts | 4 ++-- ui/serviceWorker/tsconfig.json | 8 ++++++++ ui/site/src/main.js | 2 +- 7 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 ui/serviceWorker/gulpfile.js create mode 100644 ui/serviceWorker/package.json rename public/javascripts/service-worker.js => ui/serviceWorker/src/main.ts (92%) create mode 100644 ui/serviceWorker/tsconfig.json diff --git a/package.json b/package.json index 2dd0f4e93c..d610531d36 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "ui/notify", "ui/puzzle", "ui/round", + "ui/serviceWorker", "ui/simul", "ui/site", "ui/tournament", diff --git a/ui/build b/ui/build index 3bf3f4a90b..40851f439c 100755 --- a/ui/build +++ b/ui/build @@ -13,7 +13,7 @@ mkdir -p public/compiled ts_apps1="common chess" ts_apps2="ceval game tree chat nvui" -apps="site chat cli challenge notify learn insight editor puzzle round analyse lobby tournament tournamentSchedule tournamentCalendar simul dasher speech palantir" +apps="site chat cli challenge notify learn insight editor puzzle round analyse lobby tournament tournamentSchedule tournamentCalendar simul dasher speech palantir serviceWorker" if [ $mode == "upgrade" ]; then yarn upgrade --non-interactive diff --git a/ui/serviceWorker/gulpfile.js b/ui/serviceWorker/gulpfile.js new file mode 100644 index 0000000000..59d785447d --- /dev/null +++ b/ui/serviceWorker/gulpfile.js @@ -0,0 +1,3 @@ +const lilaGulp = require('../gulp/tsProject.js'); + +lilaGulp(undefined, 'lichess.serviceWorker', __dirname); diff --git a/ui/serviceWorker/package.json b/ui/serviceWorker/package.json new file mode 100644 index 0000000000..d5dbd00454 --- /dev/null +++ b/ui/serviceWorker/package.json @@ -0,0 +1,19 @@ +{ + "name": "serviceWorker", + "version": "1.0.0", + "description": "lichess.org service worker", + "author": "Thibault Duplessis", + "license": "AGPL-3.0", + "devDependencies": { + "browserify": "^16", + "fancy-log": "^1", + "gulp": "^4", + "gulp-size": "^3", + "gulp-terser": "^1", + "tsify": "^4", + "typescript": "^3", + "vinyl-source-stream": "^2", + "vinyl-buffer": "^1", + "watchify": "^3" + } +} diff --git a/public/javascripts/service-worker.js b/ui/serviceWorker/src/main.ts similarity index 92% rename from public/javascripts/service-worker.js rename to ui/serviceWorker/src/main.ts index bc67c5b5f7..aa50530f29 100644 --- a/public/javascripts/service-worker.js +++ b/ui/serviceWorker/src/main.ts @@ -1,4 +1,4 @@ -self.addEventListener('push', event => { +self.addEventListener('push', (event: any) => { const data = event.data.json(); return self.registration.showNotification(data.title, { badge: 'https://lichess1.org/assets/images/logo.256.png', @@ -10,7 +10,7 @@ self.addEventListener('push', event => { }); }); -self.addEventListener('notificationclick', event => { +self.addEventListener('notificationclick', (event: any) => { event.waitUntil(self.registration.getNotifications().then(notifications => { notifications.forEach(notification => notification.close()); return self.clients.matchAll({ diff --git a/ui/serviceWorker/tsconfig.json b/ui/serviceWorker/tsconfig.json new file mode 100644 index 0000000000..c59ea75bde --- /dev/null +++ b/ui/serviceWorker/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../tsconfig.base.json", + "include": ["src/*.ts"], + "lib": ["ES6"], + "compilerOptions": { + "noImplicitAny": false + } +} diff --git a/ui/site/src/main.js b/ui/site/src/main.js index a209894db7..124f4e50e6 100644 --- a/ui/site/src/main.js +++ b/ui/site/src/main.js @@ -978,7 +978,7 @@ //////////////////// if ('serviceWorker' in navigator && 'Notification' in window && 'PushManager' in window) { - const workerUrl = lichess.assetUrl('javascripts/service-worker.js', {noVersion: true, sameDomain: true}); + const workerUrl = lichess.assetUrl(lichess.compiledScript('serviceWorker'), {noVersion: true, sameDomain: true}); navigator.serviceWorker.register(workerUrl, {scope: '/'}); }