mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-10 03:19:44 +00:00
Pre-construct frontend index.html (#609)
* Pre-construct frontend index.html * Only preload things that matter * Fix entry point in dev mode * Template Service worker url * Update referenced service worker
This commit is contained in:
@@ -7,28 +7,26 @@ import hashlib
|
||||
import json
|
||||
import argparse
|
||||
from os import path
|
||||
import re
|
||||
|
||||
parser = argparse.ArgumentParser(description='Generate fingerprints of frontend files.')
|
||||
parser.add_argument('--base_dir', type=str, help='Base dir to look for files.', default='hass_frontend')
|
||||
args = parser.parse_args()
|
||||
base_dir = args.base_dir + '/'
|
||||
fingerprint_file = path.join(base_dir, '__init__.py')
|
||||
panel_match = re.compile(r'ha-panel-((\w|-)+)\.html')
|
||||
|
||||
|
||||
def fingerprint():
|
||||
"""Fingerprint the frontend files."""
|
||||
files = (glob.glob(base_dir + '**/*.html') +
|
||||
glob.glob(base_dir + '*.html') +
|
||||
glob.glob(base_dir + 'core.js') +
|
||||
glob.glob(base_dir + 'compatibility.js'))
|
||||
|
||||
"""Fingerprint the panels."""
|
||||
files = glob.glob(base_dir + 'panels/*.html')
|
||||
md5s = OrderedDict()
|
||||
|
||||
for fil in sorted(files):
|
||||
name = fil[len(base_dir):]
|
||||
panel = panel_match.search(fil).groups(0)[0]
|
||||
with open(fil) as fp:
|
||||
md5 = hashlib.md5(fp.read().encode('utf-8')).hexdigest()
|
||||
md5s[name] = md5
|
||||
md5s[panel] = md5
|
||||
|
||||
template = "FINGERPRINTS = {}\n"
|
||||
result = template.format(json.dumps(md5s, indent=4))
|
||||
|
||||
Reference in New Issue
Block a user