A simple torch progressive web app (PWA) using the MediaDevices API. To be used on mobile as a torch utility app, because I am fed up with existing apps.
The app is available at https://gk-simple-torch.web.app/.
Once the app is loaded in a mobile browser supporting PWAs, you can install the app on the home screen for easier access. The app uses a ServiceWorker, so it can work offline (on supporting browsers).
The following npm scripts are available and can help during local development:
build
: Build the app (in dev mode; see below).build-prod
: Build the app (in production mode; see below).clean-up
: Remove the output directory.
(You shouldn't need to run this manually. It is run by other scripts as necessary.)dev
: Build (in dev mode), test and serve the app. Also, automatically reload and re-run tests whenever a file changes.
(Useful during development.)generate-icons
: Generates severalsimple-torch-<W>x<H>.png
icons (used as favicons and inmanifest.webmanifest
) based onsimple-torch.svg
. This needs to be manually run, when the logo (in SVG format) changes.serve-prod
: Build (in production mode) and serve the app.
(Unlikedev
this does not watch the files for changes.)
Building the app in production mode has the following differences:
- The
ENV.production
global JavaScript variable is set totrue
. - The ServiceWorker script (
sw.js
) is also built. - The ServiceWorker is registered at runtime (as a result of the above).
Important
Even if the app is built in dev mode, it may still be (temporarily) controlled by a previously installed ServiceWorker. To avoid surprises, the app is, by default, served on different ports based on the mode it is built in.
The following npm scripts are available and can help during testing:
lint
: Lint the app and tests source code (TypeScript) and helper scripts (JavaScript) and type-check the helper scripts.
(The source code is type-checked as part of the build process.)test
: Lint the code and run the automated tests (unit, end-to-end (e2e), web-app audits).test-unit
: Build the app and run the unit tests.test-e2e
: Build the app (in production mode) and run the end-to-end (e2e) tests.test-web-app
: Build the app (in production mode) and audit it for things like performance, accessibility, best practices, SEO, PWA-readiness, etc. It uses Lighthouse and webhint under the hood.
(You shouldn't need to run this manually. It is run by other scripts as necessary.)
Warning
Adding automated tests is still a work in progress.
Specifically, e2e tests are currently minimal 😱
The following npm scripts are available and can help with releasing/deploying a new version of the app:
deploy
: Build the app (in production mode) and deploy it to Firebase.
(You shouldn't need to run this manually. It is run as part of therelease
script.)release
: Cut a new version of the app and deploy it to production.
Things I want to (but won't necessarily) do:
- Add more e2e tests (and update documentation for the
test
script). - Consider adding snapshot/screenshot testing (different screen resolutions and states (torch on/off, muted/unmuted, etc.)).
- Add CI support.