/simple-torch

A simple torch PWA using the `MediaDevices` API.

Primary LanguageTypeScriptThe UnlicenseUnlicense

Simple Torch

Description

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.

Usage

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).

Contributing

Local development

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 several simple-torch-<W>x<H>.png icons (used as favicons and in manifest.webmanifest) based on simple-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.
    (Unlike dev this does not watch the files for changes.)

Building the app in production mode has the following differences:

  1. The ENV.production global JavaScript variable is set to true.
  2. The ServiceWorker script (sw.js) is also built.
  3. 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.

Testing

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 😱

Releasing/Deploying

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 the release script.)
  • release: Cut a new version of the app and deploy it to production.

TODO

Things I want to (but won't necessarily) do: