Update frontend dev instructions

This commit is contained in:
Paulus Schoutsen 2017-10-31 22:32:59 -07:00
parent cf5126f332
commit 68ee2ccb70

View File

@ -9,7 +9,7 @@ sharing: true
footer: true
---
Home Assistant is built on top of the [Polymer](https://www.polymer-project.org/) webcomponents framework. Polymer allows building encapsulated custom HTML elements. [Home-Assistant-Polymer source code on GitHub.](https://github.com/home-assistant/home-assistant-polymer)
Home Assistant is built on top of the [Polymer](https://www.polymer-project.org/) webcomponents framework. Polymer allows building encapsulated custom HTML elements. [Home-Assistant-Polymer source code on GitHub.][hass-polymer]
<p class='note warning'>
Do not use development mode in production. Home Assistant uses aggressive caching to improve the mobile experience. This is disabled during development so that you do not have to restart the server in between changes.
@ -17,70 +17,81 @@ Do not use development mode in production. Home Assistant uses aggressive cachin
## {% linkable_title Setting up the environment %}
Home Assistant will by default serve the compiled version of the frontend. As everything is compiled into the file `frontend.html` you do not want to work with the compiled version but with the separate files during development. To enable development mode for Home Assistant, update your `configuration.yaml` to have these lines:
<p class='note'>
All commands below need to be run from inside the home-assistant-polymer repository.
</p>
Home Assistant will by default serve the compiled version of the frontend from the hass_frontend Python package. For development you want to work with the unbundled source files which are in the home-assistant-polymer repository.
First step is to configure Home Assistant to use the development mode for the frontend. Do this by updating the frontend config in your `configuration.yaml` and set the path to the polymer repo:
```yaml
http:
development: 1
frontend:
development_repo: ../home-assistant-polymer
```
Node.js is required to setup the frontend development environment. The preferred method of installing node.js is [nvm](https://github.com/creationix/nvm). Install nvm using the instructions in the [README](https://github.com/creationix/nvm#install-script), and install the correct node.js by running the following command from the `home-assistant` directory:
Next step is to git clone the [home-assistant-polymer repository][hass-polymer]. You can place the repository anywhere on your system but to keep these instructions simple we're cloning the home-assistant-polymer repository as a sibling to the Home Assistant repo.
```bash
$ git submodule update --init
$ nvm install $(<homeassistant/components/frontend/www_static/home-assistant-polymer/.nvmrc)
$ git clone https://github.com/home-assistant/home-assistant-polymer.git
$ cd home-assistant-polymer
```
After cloning, your folder structure should look like this:
```text
/home-assistant
/home-assistant-polymer
```
Node.js is required to build the frontend. The preferred method of installing node.js is with [nvm](https://github.com/creationix/nvm). Install nvm using the instructions in the [README](https://github.com/creationix/nvm#install-script), and install the correct node.js by running the following command:
```bash
$ nvm install
```
[Yarn](https://yarnpkg.com/en/) is used as the package manager for node modules. [Install yarn using the instructions here.](https://yarnpkg.com/en/docs/install)
Next, development dependencies need to be installed to bootstrap the frontend development environment by running from the `home-assistant` directory:
Next, development dependencies need to be installed to bootstrap the frontend development environment. First activate the right Node version and then download all the needed modules and do a first build:
```bash
$ script/bootstrap_frontend
$ nvm use
$ script/bootstrap
```
This script will use yarn and bower to install all the necessary dependencies necessary for development in
This script will use yarn and bower to install all the necessary dependencies necessary for development and do an initial build.
`home-assistant/homeassistant/components/frontend/www_static/home-assistant-polymer`.
### {% linkable_title Creating pull requests %}
If you're planning on issuing a PR back to the Home Assistant codebase you need to fork the polymer project and add your fork as a remote.
If you're planning on issuing a PR back to the Home Assistant codebase you need to fork the polymer project and add your fork as a remote to the Home Assistant Polymer repo.
```bash
$ cd homeassistant/components/frontend/www_static/home-assistant-polymer
$ git remote add <remote name> <github URL to your fork>
```
When you've made your changes and are ready to push them change to the working directory for the polymer project and then push your changes
``` bash
$ cd homeassistant/components/frontend/www_static/home-assistant-polymer
$ git add -A
$ git commit -m "Added new feature X"
$ git push -u <remote name> HEAD
```
## {% linkable_title Development %}
While you are developing, you need to have Rollup running to have changes you make to the JavaScript app-core made available.
While you are developing, you need to have gulp running to watch the source files for changes and build when necessary.
```bash
$ cd homeassistant/components/frontend/www_static/home-assistant-polymer
$ yarn run dev
$ yarn run dev-watch
```
The source code for the frontend can be found in two different directories:
- UI: `homeassistant/components/frontend/www_static/home-assistant-polymer/src/`
- Panels: `homeassistant/components/frontend/www_static/home-assistant-polymer/panels/`
- UI: `/home-assistant-polymer/src/`
- Panels: `/home-assistant-polymer/panels/`
# {% linkable_title Building the Polymer frontend %}
Building a new version of the frontend is as simple as running `script/build_frontend`. This fires off the following commands:
Building a new version of the frontend is as simple as running `script/build_frontend`.
* **home-assistant-polymer**: Install NPM dependencies.
* **home-assistant-polymer**: start frontend build.
* Compile all used JavaScript.
* Install Bower dependencies.
* Vulcanize and minify the core and panel sources to build dir.
* Copy the webcomponents polyfill `webcomponents-lite.min.js` from **home-assistant-polymer** to `components/frontend/www_static/webcomponents-lite.min.js`.
* Copy the final frontend build `frontend.html` and panel sources from **home-assistant-polymer** to `components/frontend/www_static/frontend/`.
* Generate MD5 hashes of core and panel sources.
* Create gzip versions of all the sources.
[hass-polymer]: https://github.com/home-assistant/home-assistant-polymer