From 37a641887fe2a08e28274aa26feae5c48c674855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Tue, 29 Jun 2021 15:12:59 +0200 Subject: [PATCH] Update to typescript, rollup, lit --- .devcontainer/devcontainer.json | 34 +++++++++++++++++++++++++++++++++ .gitattributes | 2 +- .vscode/tasks.json | 32 +++++++++++++++++++++++++++++++ LICENSE.txt | 2 +- README.md | 11 +---------- package.json | 23 ++++++++++++---------- rollup.config.js | 24 +++++++++++++++++++++++ src/{main.js => main.ts} | 0 test/.env | 4 ++++ test/configuration.yaml | 11 +++++++++++ test/docker-compose.yml | 16 ++++++++++++++++ test/lovelace.yaml | 0 tsconfig.json | 10 ++++++++++ webpack.config.js | 10 ---------- 14 files changed, 147 insertions(+), 32 deletions(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .vscode/tasks.json create mode 100644 rollup.config.js rename src/{main.js => main.ts} (100%) create mode 100644 test/.env create mode 100644 test/configuration.yaml create mode 100644 test/docker-compose.yml create mode 100644 test/lovelace.yaml create mode 100644 tsconfig.json delete mode 100644 webpack.config.js diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..254e5f0 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": " Dev", + "image": "thomasloven/hass-custom-devcontainer", + "postCreateCommand": "sudo -E container setup-dev && npm add", + "containerEnv": { + "DEVCONTAINER": "1" + }, + "forwardPorts": [8123], + "mounts": [ + "source=${localWorkspaceFolder},target=/config/www/workspace,type=bind", + "source=${localWorkspaceFolder}/test,target=/config/test,type=bind", + "source=${localWorkspaceFolder}/test/configuration.yaml,target=/config/configuration.yaml,type=bind" + ], + "runArgs": ["--env-file", "${localWorkspaceFolder}/test/.env"], + "extensions": [ + "github.vscode-pull-request-github", + "esbenp.prettier-vscode", + "spmeesseman.vscode-taskexplorer" + ], + "settings": { + "files.eol": "\n", + "editor.tabSize": 2, + "editor.formatOnPaste": false, + "editor.formatOnSave": true, + "editor.formatOnType": true, + "[javascript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[typescript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "files.trimTrailingWhitespace": true + } + } \ No newline at end of file diff --git a/.gitattributes b/.gitattributes index 8cd2a1e..4744557 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,2 @@ -.js binary +.js binary package-lock.json.binary diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..aeabffc --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,32 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "npm: build", + "type": "npm", + "script": "build", + "problemMatcher": [] + }, + { + "label": "npm: watch", + "type": "npm", + "script": "watch", + "problemMatcher": [], + "presentation": { + "panel": "shared", + "group": "test" + } + }, + { + "label": "Run hass", + "type": "shell", + "command": "sudo container launch", + "problemMatcher": [], + "presentation": { + "panel": "shared", + "group": "test" + } + } + ] + } + \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt index 55b207d..cc7cc84 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Thomas Lovén +Copyright (c) 2021 Thomas Lovén Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 01556b8..cdc3dfb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ - -================= +# [![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/custom-components/hacs) @@ -7,14 +6,6 @@ For installation instructions [see this guide](https://github.com/thomasloven/hass-config/wiki/Lovelace-Plugins). -Install `` as a `module`. - -```yaml -resources: - - url: /local/.js - type: module -``` - ## Usage diff --git a/package.json b/package.json index 3cf0157..7ef04bb 100644 --- a/package.json +++ b/package.json @@ -4,22 +4,25 @@ "version": "1.0.0", "description": "", "scripts": { - "build": "webpack", - "watch": "webpack --watch --mode=development", + "build": "rollup -c", + "watch": "rollup -c --watch", "update-card-tools": "npm uninstall card-tools && npm install thomasloven/lovelace-card-tools" }, - "repository": { - "type": "git", - "url": "github.com:thomasloven/lovelace-" - }, - "keywords": [], "author": "Thomas Lovén", "license": "MIT", "devDependencies": { - "webpack": "^4.41.2", - "webpack-cli": "^3.3.10" + "@babel/core": "^7.13.1", + "@rollup/plugin-babel": "^5.3.0", + "@rollup/plugin-json": "^4.1.0", + "@rollup/plugin-node-resolve": "^11.2.0", + "rollup": "^2.39.0", + "rollup-plugin-terser": "^7.0.2", + "rollup-plugin-typescript2": "^0.30.0", + "typescript": "^4.1.5" }, "dependencies": { - "card-tools": "github:thomasloven/lovelace-card-tools" + "card-tools": "github:thomasloven/lovelace-card-tools", + "lit": "^2.0.0-rc.2", + "tslib": "^2.1.0" } } diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..79cd270 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,24 @@ +import nodeResolve from "@rollup/plugin-node-resolve"; +import json from "@rollup/plugin-json"; +import typescript from "rollup-plugin-typescript2"; +import { terser } from "rollup-plugin-terser"; +import babel from "@rollup/plugin-babel"; + +const dev = process.env.ROLLUP_WATCH; + +export default { + input: "src/main.ts", + output: { + file: ".js", + format: "es", + }, + plugins: [ + nodeResolve(), + json(), + typescript(), + babel({ + exclude: "node_modules/**", + }), + !dev && terser({ format: { comments: false } }), + ], +}; diff --git a/src/main.js b/src/main.ts similarity index 100% rename from src/main.js rename to src/main.ts diff --git a/test/.env b/test/.env new file mode 100644 index 0000000..7bfe784 --- /dev/null +++ b/test/.env @@ -0,0 +1,4 @@ +HASS_USERNAME=dev +HASS_PASSWORD=dev +LOVELACE_LOCAL_FILES=.js +LOVELACE_PLUGINS=thomasloven/lovelace-card-mod \ No newline at end of file diff --git a/test/configuration.yaml b/test/configuration.yaml new file mode 100644 index 0000000..643f28d --- /dev/null +++ b/test/configuration.yaml @@ -0,0 +1,11 @@ +default_config: + +demo: + +lovelace: + mode: storage + dashboards: + lovelace-yaml: + mode: yaml + title: yaml + filename: test/lovelace.yaml diff --git a/test/docker-compose.yml b/test/docker-compose.yml new file mode 100644 index 0000000..10dfa7b --- /dev/null +++ b/test/docker-compose.yml @@ -0,0 +1,16 @@ +version: "3.0" + +services: + test: + image: thomasloven/hass-custom-devcontainer + environment: + - HASS_USERNAME + - HASS_PASSWORD + - LOVELACE_LOCAL_FILES + - LOVELACE_PLUGINS + volumes: + - ./configuration.yaml:/config/configuration.yaml:ro + - .:/config/test:ro + - ..:/config/www/workspace + ports: + - 8125:8123 diff --git a/test/lovelace.yaml b/test/lovelace.yaml new file mode 100644 index 0000000..e69de29 diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..c16cac6 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "target": "es2017", + "moduleResolution": "node", + "resolveJsonModule": true, + "allowSyntheticDefaultImports": true, + "experimentalDecorators": true + } + } + \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js deleted file mode 100644 index 1040e78..0000000 --- a/webpack.config.js +++ /dev/null @@ -1,10 +0,0 @@ -const path = require('path'); - -module.exports = { - entry: './src/main.js', - mode: 'production', - output: { - filename: '.js', - path: path.resolve(__dirname) - } -};