Consolidate frontend (#9915)

* Consolidate frontend

* Remove home-assistant-polymer submodule

* Convert to using a pypi package for frontend

* fix release script

* Lint

* Remove unused file

* Remove frontend related scripts

* Move hass_frontend to frontend REQUIREMENTS

* Fix tests

* lint

* Address comments

* Lint + fix tests in py34

* Fix py34 tests again

* fix typo
This commit is contained in:
Paulus Schoutsen 2017-10-24 19:36:27 -07:00 committed by GitHub
parent 29fb65b224
commit 2bdad5388b
169 changed files with 372 additions and 5396 deletions

View file

@ -5,10 +5,6 @@
set -e
cd "$(dirname "$0")/.."
script/bootstrap_server
if command -v yarn >/dev/null ; then
script/bootstrap_frontend
else
echo "Frontend development not possible without Node/yarn"
fi
echo "Installing test dependencies..."
python3 -m pip install tox colorlog

View file

@ -1,23 +0,0 @@
#!/bin/sh
# Resolve all frontend dependencies that the application requires to develop.
# Stop on errors
set -e
cd "$(dirname "$0")/.."
echo "Bootstrapping frontend..."
git submodule update --init
cd homeassistant/components/frontend/www_static/home-assistant-polymer
# Install node modules
yarn install
# Install bower web components. Allow to download the components as root since the user in docker is root.
./node_modules/.bin/bower install --allow-root
# Build files that need to be generated to run development mode
yarn dev
cd ../../../../..

View file

@ -1,10 +0,0 @@
#!/bin/sh
# Resolve all server dependencies that the application requires to develop.
# Stop on errors
set -e
cd "$(dirname "$0")/.."
echo "Installing test dependencies..."
python3 -m pip install tox colorlog

View file

@ -1,34 +0,0 @@
#!/bin/sh
# Builds the frontend for production
# Stop on errors
set -e
cd "$(dirname "$0")/.."
# Clean up
rm -rf homeassistant/components/frontend/www_static/core.js* \
homeassistant/components/frontend/www_static/compatibility.js* \
homeassistant/components/frontend/www_static/frontend.html* \
homeassistant/components/frontend/www_static/webcomponents-lite.js* \
homeassistant/components/frontend/www_static/custom-elements-es5-adapter.js* \
homeassistant/components/frontend/www_static/panels
cd homeassistant/components/frontend/www_static/home-assistant-polymer
# Build frontend
BUILD_DEV=0 ./node_modules/.bin/gulp
cp bower_components/webcomponentsjs/webcomponents-lite.js ..
cp bower_components/webcomponentsjs/custom-elements-es5-adapter.js ..
cp build/*.js build/*.html ..
mkdir ../panels
cp build/panels/*.html ../panels
BUILD_DEV=0 ./node_modules/.bin/gulp gen-service-worker
cp build/service_worker.js ..
cd ..
# Pack frontend
gzip -f -n -k -9 *.html *.js ./panels/*.html
cd ../../../..
# Generate the MD5 hash of the new frontend
script/fingerprint_frontend.py

View file

@ -1,40 +0,0 @@
#!/usr/bin/env python3
"""Generate a file with all md5 hashes of the assets."""
from collections import OrderedDict
import glob
import hashlib
import json
fingerprint_file = 'homeassistant/components/frontend/version.py'
base_dir = 'homeassistant/components/frontend/www_static/'
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'))
md5s = OrderedDict()
for fil in sorted(files):
name = fil[len(base_dir):]
with open(fil) as fp:
md5 = hashlib.md5(fp.read().encode('utf-8')).hexdigest()
md5s[name] = md5
template = """\"\"\"DO NOT MODIFY. Auto-generated by script/fingerprint_frontend.\"\"\"
FINGERPRINTS = {}
"""
result = template.format(json.dumps(md5s, indent=4))
with open(fingerprint_file, 'w') as fp:
fp.write(result)
if __name__ == '__main__':
fingerprint()

View file

@ -50,6 +50,7 @@ TEST_REQUIREMENTS = (
'haversine',
'hbmqtt',
'holidays',
'home-assistant-frontend',
'influxdb',
'libpurecoollink',
'libsoundtouch',

View file

@ -1,68 +0,0 @@
#!/usr/bin/env python3
"""Download the latest Polymer v1 iconset for materialdesignicons.com."""
import gzip
import os
import re
import requests
import sys
from fingerprint_frontend import fingerprint
GETTING_STARTED_URL = ('https://raw.githubusercontent.com/Templarian/'
'MaterialDesign/master/site/getting-started.savvy')
DOWNLOAD_LINK = re.compile(r'(/api/download/polymer/v1/([A-Z0-9-]{36}))')
START_ICONSET = '<iron-iconset-svg'
OUTPUT_BASE = os.path.join('homeassistant', 'components', 'frontend')
ICONSET_OUTPUT = os.path.join(OUTPUT_BASE, 'www_static', 'mdi.html')
ICONSET_OUTPUT_GZ = os.path.join(OUTPUT_BASE, 'www_static', 'mdi.html.gz')
def get_remote_version():
"""Get current version and download link."""
gs_page = requests.get(GETTING_STARTED_URL).text
mdi_download = re.search(DOWNLOAD_LINK, gs_page)
if not mdi_download:
print("Unable to find download link")
sys.exit()
return 'https://materialdesignicons.com' + mdi_download.group(1)
def clean_component(source):
"""Clean component."""
return source[source.index(START_ICONSET):]
def write_component(source):
"""Write component."""
with open(ICONSET_OUTPUT, 'w') as outp:
print('Writing icons to', ICONSET_OUTPUT)
outp.write(source)
with gzip.open(ICONSET_OUTPUT_GZ, 'wb') as outp:
print('Writing icons gz to', ICONSET_OUTPUT_GZ)
outp.write(source.encode('utf-8'))
def main():
"""Main section of the script."""
# All scripts should have their current work dir set to project root
if os.path.basename(os.getcwd()) == 'script':
os.chdir('..')
print("materialdesignicons.com icon updater")
remote_url = get_remote_version()
source = clean_component(requests.get(remote_url).text)
write_component(source)
fingerprint()
print('Updated to latest version')
if __name__ == '__main__':
main()