zulip/tools/update-prod-static
Shubham Padia b3acaf8075 ui_init: Show unsupported browser warning on load.
We are using browserslist-useragent-regexp to build a regex to compare
our user agents against. This regex is generated and stored in
web/generated and is generated on every provision. This will remain
mostly unchanged since .browserlistrc is not a frequently modified file.
Still, we run it on every provision since we don't have a good mechanism
to detect changes in that list. We can look into that in a followup PR.

In terms of chosing the library, the regexp library is the current
recommendation browserslist github. Another library called
browserslist-useragent exists but it is not actively being worked upon
and is slower as well:
https://gist.github.com/dangreen/55c41072d8891efd3a772a4739d6cd9d

In terms of which browsers to flag as unsupported, we don't flag any
browsers that are not part of >=0 % query of browserslist. If they are
part of >= 0 %, but not part of `baseline widely available with
downstream`, we flag the browser as unsupported.

We also allow higher versions while generating the regex, so if our
regex is outdated a little bit, users with newer browsers don't get the
unsupported browser warning.
2026-01-12 16:34:54 -08:00

74 lines
1.9 KiB
Python
Executable File

#!/usr/bin/env python3
# Updates static files for production.
import os
import sys
# We need settings so we can figure out where the prod-static directory is.
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from scripts.lib.setup_path import setup_path
setup_path()
# check for the venv
from tools.lib import sanity_check
sanity_check.check_venv(__file__)
os.environ["DJANGO_SETTINGS_MODULE"] = "zproject.settings"
os.environ["ZULIP_COLLECTING_STATIC"] = "1"
from django.conf import settings
from scripts.lib.node_cache import setup_node_modules
from scripts.lib.zulip_tools import assert_not_running_as_root, run
assert_not_running_as_root()
os.chdir(settings.DEPLOY_ROOT)
# Install node packages
setup_node_modules(production=True)
# Build emoji
run(["./tools/setup/emoji/build_emoji"])
# Copy over static files from the zulip_bots and integrations packages
run(["./tools/setup/generate_bots_integrations_static_files.py"])
# Build pygments data
run(["./tools/setup/build_pygments_data"])
# Build time zone data
run(["./tools/setup/build_timezone_values"])
# Generate supported browser regex used during initial load
run(["node", "./tools/setup/build_supported_browser_regex.ts"])
# Generate landing page images of various sizes and formats if we will
# need them.
if settings.CORPORATE_ENABLED:
run(["./tools/setup/generate_landing_page_images.py"])
run(
[
"./tools/build-help-center",
"--no-relative-links",
"--out-dir",
"./dist_no_relative_links",
]
)
run(["./tools/build-help-center"])
# Create webpack bundle
run(["./tools/webpack", "--quiet"])
# Collect the files that we're going to serve; this creates prod-static/serve.
run(["./manage.py", "collectstatic", "-v0", "--noinput"])
# Compile translation strings to generate `.mo` files.
run(["./manage.py", "compilemessages", "-v0", "--ignore=*"])
# Needed if PRODUCTION
os.makedirs("prod-static", exist_ok=True)