Skip to content

Commit 417d8e7

Browse files
authored
Consolidate frontend (#468)
* Consolidate frontend * Remove no longer needed cd * Get Roboto from bower_components * Remove external dependency from update_mdi.py * Copy leaflet assets on build time * Tweak Dockerfile * Create Python package * Set zip_safe to False * Update build scripts * Version bump to 20171021.0 * Fix service worker * Version bump to 20171021.2 * Update docker ignore * Tweak Dockerfile thanks to Adam
1 parent cbc4475 commit 417d8e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3084
-11
lines changed

.dockerignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
bower_components
3+
hass_frontend
4+
build
5+
build-temp
6+
.git

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,18 @@ node_modules/*
44
bower_components/*
55
npm-debug.log
66
.DS_Store
7+
hass_frontend/*
8+
9+
# Python stuff
10+
*.py[cod]
11+
*.egg
12+
*.egg-info
13+
14+
# venv stuff
15+
pyvenv.cfg
16+
pip-selfcheck.json
17+
venv
18+
.venv
19+
lib
20+
bin
21+
dist

Dockerfile

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM node:8.2.1-alpine
2+
3+
# install yarn
4+
ENV PATH /root/.yarn/bin:$PATH
5+
6+
RUN apk update \
7+
&& apk add curl bash binutils tar git python3 \
8+
&& rm -rf /var/cache/apk/* \
9+
&& /bin/bash \
10+
&& touch ~/.bashrc \
11+
&& curl -o- -L https://yarnpkg.com/install.sh | bash
12+
13+
RUN mkdir -p /frontend
14+
WORKDIR /frontend
15+
16+
ENV NODE_ENV production
17+
18+
COPY package.json ./
19+
RUN yarn
20+
21+
COPY bower.json ./
22+
RUN ./node_modules/.bin/bower install --allow-root
23+
24+
COPY . .
25+
CMD [ "/bin/bash", "./script/build_frontend" ]

MANIFEST.in

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include README.md
2+
include LICENSE.md
3+
graft hass_frontend
4+
recursive-exclude * *.py[co]

gulp/tasks/gen-service-worker.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const config = require('../config');
2323

2424
const DEV = !!JSON.parse(process.env.BUILD_DEV || 'true');
2525

26-
var rootDir = '..';
26+
var rootDir = 'hass_frontend';
2727
var panelDir = path.resolve(rootDir, 'panels');
2828

2929
var dynamicUrlToDependencies = {
@@ -44,8 +44,8 @@ var staticFingerprinted = [
4444
// These panels will always be registered inside HA and thus can
4545
// be safely assumed to be able to preload.
4646
var panelsFingerprinted = [
47-
'map', 'dev-event', 'dev-info', 'dev-service', 'dev-state', 'dev-template',
48-
'dev-mqtt',
47+
'dev-event', 'dev-info', 'dev-service', 'dev-state', 'dev-template',
48+
'dev-mqtt', 'kiosk',
4949
];
5050

5151
function md5(filename) {
@@ -71,7 +71,7 @@ gulp.task('gen-service-worker', () => {
7171
panelsFingerprinted.forEach(panel => {
7272
var fpath = panelDir + '/ha-panel-' + panel + '.html';
7373
var hash = md5(fpath);
74-
var url = '/frontend/panels/' + panel + '-' + hash + '.html';
74+
var url = '/static/panels/ha-panel-' + panel + '-' + hash + '.html';
7575
dynamicUrlToDependencies[url] = [fpath];
7676
});
7777

@@ -89,9 +89,11 @@ gulp.task('gen-service-worker', () => {
8989
rootDir + '/fonts/roboto/Roboto-Bold.ttf',
9090
rootDir + '/images/card_media_player_bg.png',
9191
],
92-
stripPrefix: '..',
92+
stripPrefix: 'hass_frontend',
9393
replacePrefix: 'static',
9494
verbose: true,
95+
// Allow our users to refresh to get latest version.
96+
clientsClaim: true,
9597
};
9698

9799
genPromise = swPrecache.generate(options);

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
"author": "Paulus Schoutsen <Paulus@PaulusSchoutsen.nl> (http://paulusschoutsen.nl)",
2121
"license": "Apache-2.0",
2222
"dependencies": {
23-
"es6-object-assign": "^1.1.0",
24-
"home-assistant-js-websocket": "^1.1.0",
25-
"preact": "^8.2.5"
26-
},
27-
"devDependencies": {
2823
"babel-core": "^6.26.0",
2924
"babel-plugin-external-helpers": "^6.22.0",
3025
"babel-plugin-transform-object-rest-spread": "^6.26.0",
@@ -34,6 +29,7 @@
3429
"bower": "^1.8.2",
3530
"css-slam": "^2.0.2",
3631
"del": "^3.0.0",
32+
"es6-object-assign": "^1.1.0",
3733
"eslint": "^4.8.0",
3834
"eslint-config-airbnb-base": "^12.0.2",
3935
"eslint-plugin-html": "^3.2.2",
@@ -49,13 +45,15 @@
4945
"gulp-rollup-each": "^2.0.0",
5046
"gulp-uglify": "^3.0.0",
5147
"gulp-util": "^3.0.8",
48+
"home-assistant-js-websocket": "^1.1.0",
5249
"html-minifier": "^3.5.5",
5350
"merge-stream": "^1.0.1",
5451
"parse5": "^3.0.2",
5552
"polymer-analyzer": "^2.3.0",
5653
"polymer-build": "^2.1.0",
5754
"polymer-bundler": "^3.1.0",
5855
"polymer-cli": "^1.5.6",
56+
"preact": "^8.2.5",
5957
"require-dir": "^0.3.2",
6058
"rollup": "^0.50.0",
6159
"rollup-plugin-babel": "^3.0.2",
@@ -67,7 +65,9 @@
6765
"run-sequence": "^2.2.0",
6866
"sw-precache": "^5.2.0",
6967
"uglify-js": "^3.1.3",
70-
"vulcanize": "^1.16.0",
68+
"vulcanize": "^1.16.0"
69+
},
70+
"devDependencies": {
7171
"web-component-tester": "^6.3.0"
7272
}
7373
}

public/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""AUTO-GENERATED. DO NOT MODIFY"""
2+
import os
3+
4+
5+
def where():
6+
"""Return path to the frontend."""
7+
return os.path.dirname(__file__)
8+

public/icons/favicon-1024x1024.png

93 KB

public/icons/favicon-192x192.png

15.3 KB

public/icons/favicon-384x384.png

19.4 KB

public/icons/favicon-512x512.png

43.7 KB
14.9 KB

public/icons/favicon.ico

17.5 KB
Binary file not shown.

public/icons/home-assistant-icon.svg

+2,814

public/icons/tile-win-150x150.png

10.4 KB

public/icons/tile-win-310x150.png

9.23 KB

public/icons/tile-win-310x310.png

21.7 KB

public/icons/tile-win-70x70.png

4.9 KB
1.51 KB
30.4 KB

public/images/config_fitbit_app.png

45.6 KB

public/images/config_icloud.png

167 KB

public/images/config_insteon.png

30.1 KB

public/images/config_philips_hue.jpg

8.77 KB

public/images/config_webos.png

22.3 KB

public/images/config_wink.png

7.98 KB
+1

public/images/darksky/weather-fog.svg

+1
+1
+1
+1
+1
+1
+1

public/images/logo_automatic.png

6.1 KB

public/images/logo_axis.png

2.79 KB

public/images/logo_philips_hue.png

16.7 KB
18.2 KB

public/images/notification-badge.png

2.89 KB

public/images/smart-tv.png

3.17 KB

public/robots.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
User-agent: *
2+
Disallow: /

script/bootstrap

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
# Resolve all frontend dependencies that the application requires to develop.
3+
4+
# Stop on errors
5+
set -e
6+
7+
cd "$(dirname "$0")/.."
8+
9+
# Install node modules
10+
yarn install
11+
12+
# Install bower web components. Allow to download the components as root since the user in docker is root.
13+
./node_modules/.bin/bower install --allow-root
14+
15+
# Build files that need to be generated to run development mode
16+
yarn dev

script/build_frontend

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/sh
2+
# Builds the frontend for production
3+
4+
# Stop on errors
5+
set -e
6+
7+
cd "$(dirname "$0")/.."
8+
9+
OUTPUT_DIR=hass_frontend
10+
11+
rm -rf $OUTPUT_DIR
12+
cp -r public $OUTPUT_DIR
13+
14+
# Build frontend
15+
BUILD_DEV=0 ./node_modules/.bin/gulp
16+
17+
# Entry points
18+
cp build/*.js build/*.html $OUTPUT_DIR
19+
20+
# Panels
21+
mkdir $OUTPUT_DIR/panels
22+
cp build/panels/*.html $OUTPUT_DIR/panels
23+
24+
# Local Roboto
25+
cp -r bower_components/font-roboto-local/fonts $OUTPUT_DIR
26+
27+
# Polyfill web components
28+
cp bower_components/webcomponentsjs/webcomponents-lite.js $OUTPUT_DIR
29+
cp bower_components/webcomponentsjs/custom-elements-es5-adapter.js $OUTPUT_DIR
30+
31+
# Icons
32+
script/update_mdi.py
33+
34+
# Leaflet
35+
mkdir $OUTPUT_DIR/images/leaflet
36+
cp bower_components/leaflet/dist/leaflet.css $OUTPUT_DIR/images/leaflet
37+
cp -r bower_components/leaflet/dist/images $OUTPUT_DIR/images/leaflet/
38+
39+
# Generate service worker
40+
BUILD_DEV=0 ./node_modules/.bin/gulp gen-service-worker
41+
cp build/service_worker.js $OUTPUT_DIR
42+
43+
44+
# GZIP frontend
45+
cd $OUTPUT_DIR
46+
gzip -f -n -k -9 *.html *.js ./panels/*.html ./fonts/roboto/*.ttf ./fonts/robotomono/*.ttf
47+
cd ..
48+
49+
# Generate the __init__ file
50+
echo "VERSION = '`git rev-parse HEAD`'" >> $OUTPUT_DIR/__init__.py
51+
echo "CREATED_AT = `date +%s`" >> $OUTPUT_DIR/__init__.py
52+
53+
# Generate the MD5 hash of the new frontend
54+
script/fingerprint_frontend.py

script/fingerprint_frontend.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
"""Generate a file with all md5 hashes of the assets."""
3+
4+
from collections import OrderedDict
5+
import glob
6+
import hashlib
7+
import json
8+
9+
fingerprint_file = './hass_frontend/__init__.py'
10+
base_dir = 'hass_frontend/'
11+
12+
13+
def fingerprint():
14+
"""Fingerprint the frontend files."""
15+
files = (glob.glob(base_dir + '**/*.html') +
16+
glob.glob(base_dir + '*.html') +
17+
glob.glob(base_dir + 'core.js') +
18+
glob.glob(base_dir + 'compatibility.js'))
19+
20+
md5s = OrderedDict()
21+
22+
for fil in sorted(files):
23+
name = fil[len(base_dir):]
24+
with open(fil) as fp:
25+
md5 = hashlib.md5(fp.read().encode('utf-8')).hexdigest()
26+
md5s[name] = md5
27+
28+
template = "FINGERPRINTS = {}\n"
29+
result = template.format(json.dumps(md5s, indent=4))
30+
31+
with open(fingerprint_file, 'at') as fp:
32+
fp.write(result)
33+
34+
35+
if __name__ == '__main__':
36+
fingerprint()

script/release

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
# Pushes a new version to PyPi.
3+
4+
cd "$(dirname "$0")/.."
5+
6+
python3 setup.py sdist upload

script/update_mdi.py

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python3
2+
"""Download the latest Polymer v1 iconset for materialdesignicons.com."""
3+
import os
4+
import re
5+
import sys
6+
import urllib.request
7+
8+
GETTING_STARTED_URL = ('https://raw.githubusercontent.com/Templarian/'
9+
'MaterialDesign/master/site/getting-started.savvy')
10+
DOWNLOAD_LINK = re.compile(r'(/api/download/polymer/v1/([A-Z0-9-]{36}))')
11+
START_ICONSET = '<iron-iconset-svg'
12+
13+
OUTPUT_BASE = 'hass_frontend'
14+
ICONSET_OUTPUT = os.path.join(OUTPUT_BASE, 'mdi.html')
15+
16+
17+
def get_text(url):
18+
with urllib.request.urlopen(url) as f:
19+
return f.read().decode('utf-8')
20+
21+
22+
def get_remote_version():
23+
"""Get current version and download link."""
24+
gs_page = get_text(GETTING_STARTED_URL)
25+
26+
mdi_download = re.search(DOWNLOAD_LINK, gs_page)
27+
28+
if not mdi_download:
29+
print("Unable to find download link")
30+
sys.exit()
31+
32+
return 'https://materialdesignicons.com' + mdi_download.group(1)
33+
34+
35+
def clean_component(source):
36+
"""Clean component."""
37+
return source[source.index(START_ICONSET):]
38+
39+
40+
def write_component(source):
41+
"""Write component."""
42+
with open(ICONSET_OUTPUT, 'w') as outp:
43+
print('Writing icons to', ICONSET_OUTPUT)
44+
outp.write(source)
45+
46+
47+
def main():
48+
"""Main section of the script."""
49+
# All scripts should have their current work dir set to project root
50+
if os.path.basename(os.getcwd()) == 'script':
51+
os.chdir('..')
52+
53+
print("materialdesignicons.com icon updater")
54+
55+
remote_url = get_remote_version()
56+
source = clean_component(get_text(remote_url))
57+
write_component(source)
58+
59+
print('Updated to latest version')
60+
61+
62+
if __name__ == '__main__':
63+
main()

setup.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(name='home-assistant-frontend',
4+
version='20171021.2',
5+
description='The Home Assistant frontend',
6+
url='https://github.com/home-assistant/home-assistant-polymer',
7+
author='Paulus Schoutsen',
8+
author_email='Paulus@PaulusSchoutsen.nl',
9+
license='Apache License 2.0',
10+
packages=find_packages(include=['hass_frontend', 'hass_frontend.*']),
11+
include_package_data=True,
12+
zip_safe=False)

0 commit comments

Comments
 (0)