diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000000..94218355ff --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,13 @@ +# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.148.1/containers/python-3/.devcontainer/base.Dockerfile +FROM mcr.microsoft.com/vscode/devcontainers/python:0-3.9 + +ENV \ + DEBIAN_FRONTEND=noninteractive \ + DEVCONTAINER=true \ + PATH=$PATH:./node_modules/.bin + +# Install nvm +COPY .nvmrc /tmp/.nvmrc +RUN \ + su vscode -c \ + "source /usr/local/share/nvm/nvm.sh && nvm install $(cat /tmp/.nvmrc) 2>&1" \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..78d39cd415 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,31 @@ +{ + "name": "Home Assistant Frontend", + "build": { + "dockerfile": "Dockerfile", + "context": ".." + }, + "appPort": 8123, + "context": "..", + "postCreateCommand": "script/bootstrap", + "extensions": [ + "github.vscode-pull-request-github", + "dbaeumer.vscode-eslint", + "ms-vscode.vscode-typescript-tslint-plugin", + "esbenp.prettier-vscode", + "bierner.lit-html", + "runem.lit-plugin", + "ms-python.vscode-pylance" + ], + "settings": { + "terminal.integrated.shell.linux": "/bin/bash", + "files.eol": "\n", + "editor.tabSize": 2, + "editor.formatOnPaste": false, + "editor.formatOnSave": true, + "editor.formatOnType": true, + "[typescript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "files.trimTrailingWhitespace": true + } +} diff --git a/.gitignore b/.gitignore index af590a8ade..74fe1c8f92 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,6 @@ yarn-error.log #asdf .tool-versions + +# Home Assistant config +config \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index d23faf6995..c6868baeb0 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -37,6 +37,37 @@ "instanceLimit": 1 } }, + { + "label": "Develop Supervisor panel", + "type": "gulp", + "task": "develop-hassio", + "problemMatcher": { + "owner": "ha-build", + "source": "ha-build", + "fileLocation": "absolute", + "severity": "error", + "pattern": [ + { + "regexp": "(SyntaxError): (.+): (.+) \\((\\d+):(\\d+)\\)", + "severity": 1, + "file": 2, + "message": 3, + "line": 4, + "column": 5 + } + ], + "background": { + "activeOnStart": true, + "beginsPattern": "Changes detected. Starting compilation", + "endsPattern": "Build done @" + } + }, + "isBackground": true, + "group": "build", + "runOptions": { + "instanceLimit": 1 + } + }, { "label": "Develop Gallery", "type": "gulp", @@ -133,5 +164,45 @@ "instanceLimit": 1 } }, + { + "label": "Run HA Core in devcontainer", + "type": "shell", + "command": "script/core", + "isBackground": true, + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [], + "runOptions": { + "instanceLimit": 1 + } + }, + { + "label": "Run HA Core for Supervisor in devcontainer", + "type": "shell", + "command": "HASSIO=${input:supervisorHost} HASSIO_TOKEN=${input:supervisorToken} script/core", + "isBackground": true, + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [], + "runOptions": { + "instanceLimit": 1 + } + } + ], + "inputs": [ + { + "id": "supervisorHost", + "type": "promptString", + "description": "The IP of the Supervisor host running the Remote API proxy add-on" + }, + { + "id": "supervisorToken", + "type": "promptString", + "description": "The token for the Remote API proxy add-on" + } ] } diff --git a/script/core b/script/core new file mode 100755 index 0000000000..7f45620af3 --- /dev/null +++ b/script/core @@ -0,0 +1,55 @@ +#!/bin/sh +# Helper to start Home Assistant Core inside the devcontainer + +# Stop on errors +set -e + +if [ -z "${DEVCONTAINER}" ]; then + echo "This task should only run inside a devcontainer, for local install HA Core in a venv." + exit 1 +fi + +if [ ! -z "${CODESPACES}" ]; then + WORKSPACE="/root/workspace/frontend" +else + WORKSPACE="/workspaces/frontend" +fi + +if [ -z $(which hass) ]; then + echo "Installing Home Asstant core from dev." + python3 -m pip install --upgrade \ + colorlog \ + git+git://github.com/home-assistant/home-assistant.git@dev +fi + +if [ ! -d "${WORKSPACE}/config" ]; then + echo "Creating default configuration." + mkdir -p "${WORKSPACE}/config"; + hass --script ensure_config -c config + echo "demo: + +logger: + default: info + logs: + homeassistant.components.frontend: debug +" >> "${WORKSPACE}/config/configuration.yaml" + + if [ ! -z "${HASSIO}" ]; then + echo " +# frontend: +# development_repo: ${WORKSPACE} + +hassio: + development_repo: ${WORKSPACE}" >> "${WORKSPACE}/config/configuration.yaml" + else + echo " +frontend: + development_repo: ${WORKSPACE} + +# hassio: +# development_repo: ${WORKSPACE}" >> "${WORKSPACE}/config/configuration.yaml" + fi + +fi + +hass -c "${WORKSPACE}/config"