diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000000..8576e20410 --- /dev/null +++ b/.babelrc @@ -0,0 +1,20 @@ +{ + "presets": [ + [ + "es2015", + { + "modules": false + } + ] + ], + "plugins": [ + "external-helpers", + "transform-object-rest-spread", + [ + "transform-react-jsx", + { + "pragma":"h" + } + ], + ] +} diff --git a/.eslintrc b/.eslintrc index be2414b93d..7f3d3a0e39 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,5 +1,16 @@ { "extends": "airbnb-base", + "parserOptions": { + "ecmaFeatures": { + "jsx": true, + "modules": true + } + }, + "settings": { + "react": { + "pragma": "h" + } + }, "globals": { "__DEV__": false, "__DEMO__": false, @@ -26,9 +37,24 @@ "no-continue": 0, "no-param-reassign": 0, "no-multi-assign": 0, - "radix": 0 + "radix": 0, + "import/prefer-default-export": 0, + "react/jsx-no-bind": [2, { "ignoreRefs": true }], + "react/jsx-no-duplicate-props": 2, + "react/self-closing-comp": 2, + "react/prefer-es6-class": 2, + "react/no-string-refs": 2, + "react/require-render-return": 2, + "react/no-find-dom-node": 2, + "react/no-is-mounted": 2, + "react/jsx-no-comment-textnodes": 2, + "react/jsx-curly-spacing": 2, + "react/jsx-no-undef": 2, + "react/jsx-uses-react": 2, + "react/jsx-uses-vars": 2 }, "plugins": [ - "html" + "html", + "react" ] } diff --git a/.travis.yml b/.travis.yml index 63a718cd3c..833305ab93 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ addons: packages: - google-chrome-stable script: + - npm run js_prod - npm run test - xvfb-run wct - if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then wct --plugin sauce; fi diff --git a/package.json b/package.json index f9eca700e9..dddb0d5f80 100644 --- a/package.json +++ b/package.json @@ -10,42 +10,49 @@ "clean": "rm -rf build/* build-temp/*", "js_dev": "node script/gen-service-worker.js && npm run watch_ru_all", "js_dev_demo": "BUILD_DEMO=1 npm run watch_ru_all", - "js_prod": "BUILD_DEV=0 npm run ru_all && script/optimize-js.js", + "js_prod": "BUILD_DEV=0 npm run ru_all", "js_demo": "BUILD_DEV=0 BUILD_DEMO=1 npm run ru_all", "frontend_html": "node script/vulcanize.js", "frontend_prod": "npm run js_prod && npm run frontend_html", "frontend_demo": "npm run js_demo && npm run frontend_html", - "ru_all": "npm run ru_core && npm run ru_compatibility && npm run ru_demo", + "ru_all": "npm run ru_automation && npm run ru_core && npm run ru_compatibility && npm run ru_demo", + "ru_automation": "rollup --config rollup/automation.js", "ru_core": "rollup --config rollup/core.js", "ru_compatibility": "rollup --config rollup/compatibility.js", "ru_demo": "rollup --config rollup/demo.js", - "watch_ru_all": "(npm run watch_ru_core & npm run watch_ru_compatibility & npm run watch_ru_demo) && wait", + "watch_ru_all": "(npm run watch_ru_automation & npm run watch_ru_core & npm run watch_ru_compatibility & npm run watch_ru_demo) && wait", + "watch_ru_automation": "rollup --config rollup/automation.js --watch --sourcemap inline", "watch_ru_core": "rollup --config rollup/core.js --watch --sourcemap inline", "watch_ru_compatibility": "rollup --config rollup/compatibility.js --watch --sourcemap inline", "watch_ru_demo": "rollup --config rollup/demo.js --watch --sourcemap inline", - "lint_js": "eslint src panels --ext html", + "lint_js": "eslint src panels preact-src --ext js,html", "lint_html": "ls -1 src/home-assistant.html panels/**/ha-panel-*.html | xargs polymer lint --input", "test": "npm run lint_js && npm run lint_html" }, "author": "Paulus Schoutsen (http://paulusschoutsen.nl)", "license": "Apache-2.0", "dependencies": { - "home-assistant-js-websocket": "^1.1.0" + "es6-object-assign": "^1.1.0", + "home-assistant-js-websocket": "^1.1.0", + "preact": "^8.1.0" }, "devDependencies": { + "babel-plugin-external-helpers": "^6.22.0", + "babel-plugin-transform-object-rest-spread": "^6.23.0", + "babel-plugin-transform-react-jsx": "^6.24.1", + "babel-preset-es2015": "^6.24.1", "bower": "^1.8.0", - "es6-object-assign": "^1.1.0", "eslint": "^3.19.0", "eslint-config-airbnb-base": "^11.1.3", "eslint-plugin-html": "^2.0.1", "eslint-plugin-import": "^2.2.0", + "eslint-plugin-react": "^7.0.0", "html-minifier": "^3.4.3", "hydrolysis": "^1.24.1", - "optimize-js": "^1.0.3", "polymer-cli": "^0.17.0", "polymer-lint": "^0.8.3", "rollup": "^0.41.6", - "rollup-plugin-buble": "^0.15.0", + "rollup-plugin-babel": "^2.7.1", "rollup-plugin-commonjs": "^8.0.2", "rollup-plugin-node-resolve": "^3.0.0", "rollup-plugin-replace": "^1.1.1", diff --git a/panels/automation/editor.js b/panels/automation/editor.js new file mode 100644 index 0000000000..16e13daf49 --- /dev/null +++ b/panels/automation/editor.js @@ -0,0 +1,10 @@ +import { h, render } from 'preact'; +import Automation from '../../preact-src/automation'; + +window.AutomationEditor = function (mountEl, props, mergeEl) { + return render(h(Automation, props), mountEl, mergeEl); +}; + +window.unmountPreact = function (mountEl, mergeEl) { + render(() => null, mountEl, mergeEl); +}; diff --git a/panels/automation/ha-automation-editor.html b/panels/automation/ha-automation-editor.html new file mode 100644 index 0000000000..3a05ded576 --- /dev/null +++ b/panels/automation/ha-automation-editor.html @@ -0,0 +1,214 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/automation/ha-automation-picker.html b/panels/automation/ha-automation-picker.html new file mode 100644 index 0000000000..961e89bd61 --- /dev/null +++ b/panels/automation/ha-automation-picker.html @@ -0,0 +1,116 @@ + + + + + + + + + + + + + diff --git a/panels/automation/ha-panel-automation.html b/panels/automation/ha-panel-automation.html new file mode 100644 index 0000000000..0cd4555cc2 --- /dev/null +++ b/panels/automation/ha-panel-automation.html @@ -0,0 +1,133 @@ + + + + + + + + + + + diff --git a/panels/hassio/ha-panel-hassio.html b/panels/hassio/ha-panel-hassio.html index bcb0efff10..ee03a303ee 100644 --- a/panels/hassio/ha-panel-hassio.html +++ b/panels/hassio/ha-panel-hassio.html @@ -7,12 +7,12 @@ -