Remove rollup (#1179)

* Remove rollup

* Fix build

* Add copy webpack plugin

* Touch service worker

* Remove unused ha-config-js-.js
This commit is contained in:
Paulus Schoutsen 2018-05-16 07:54:29 -04:00 committed by GitHub
parent 5a16095270
commit 23a2a479a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 91 additions and 281 deletions

View File

@ -16,7 +16,7 @@ async function buildAuth(es6) {
const stream = gulp.src(path.resolve(config.polymer_dir, 'src/authorize.html'))
.pipe(replace([
['<!--EXTRA_SCRIPTS-->', es6 ? '' : es5Extra],
['/home-assistant-polymer/build/webpack/ha-authorize.js', `/${frontendPath}/authorize.js`],
['/home-assistant-polymer/hass_frontend/authorize.js', `/${frontendPath}/authorize.js`],
]));
return minifyStream(stream, /* es6= */ es6)

View File

@ -1,65 +0,0 @@
const gulp = require('gulp');
const filter = require('gulp-filter');
const { PolymerProject, } = require('polymer-build');
const {
composeStrategies,
generateShellMergeStrategy,
} = require('polymer-bundler');
const mergeStream = require('merge-stream');
const rename = require('gulp-rename');
const polymerConfig = require('../../polymer');
const minifyStream = require('../common/transform').minifyStream;
const {
stripImportsStrategy,
stripAllButEntrypointStrategy
} = require('../common/strategy');
function renamePanel(path) {
// Rename panels to be panels/* and not their subdir
if (path.basename.substr(0, 9) === 'ha-panel-' && path.extname === '.html') {
path.dirname = 'panels/';
}
// Rename frontend
if (path.dirname === 'src' && path.basename === 'home-assistant' &&
path.extname === '.html') {
path.dirname = '';
path.basename = 'frontend';
}
}
function build(es6) {
return;
const strategy = composeStrategies([
generateShellMergeStrategy(polymerConfig.shell),
stripImportsStrategy([
'bower_components/font-roboto/roboto.html',
'bower_components/paper-styles/color.html',
]),
stripAllButEntrypointStrategy('panels/hassio/ha-panel-hassio.html')
]);
const project = new PolymerProject(polymerConfig);
return mergeStream(
minifyStream(project.sources(), es6),
minifyStream(project.dependencies(), es6)
)
.pipe(project.bundler({
strategy,
strip: true,
sourcemaps: false,
stripComments: true,
inlineScripts: true,
inlineCss: true,
implicitStrip: true,
}))
.pipe(rename(renamePanel))
.pipe(filter(['**', '!src/entrypoint.html']))
.pipe(gulp.dest(es6 ? 'build' : 'build-es5'));
}
gulp.task('build_es5', ['ru_all', 'ru_all_es5', 'build-translations'], () => build(/* es6= */ false));
gulp.task('build_es6', ['ru_all', 'build-translations'], () => build(/* es6= */ true));
gulp.task('build', ['build_es5', 'build_es6']);

View File

@ -1,4 +0,0 @@
const del = require('del');
const gulp = require('gulp');
gulp.task('clean', () => del(['build-es5', 'build', 'build-temp-es5', 'build-temp', 'build-translations']));

View File

@ -1,7 +0,0 @@
const gulp = require('gulp');
const runSequence = require('run-sequence');
gulp.task('default', () => runSequence.use(gulp)(
'clean',
'build',
));

View File

@ -7,8 +7,8 @@ const md5 = require('../common/md5');
const { minifyStream } = require('../common/transform');
const buildReplaces = {
'/home-assistant-polymer/build/core.js': 'core.js',
'/home-assistant-polymer/build/webpack/app.js': 'app.js',
'/home-assistant-polymer/hass_frontend/core.js': 'core.js',
'/home-assistant-polymer/hass_frontend/app.js': 'app.js',
};
function generateIndex(es6) {

View File

@ -1,119 +0,0 @@
const fs = require('fs');
const gulp = require('gulp');
const rollupEach = require('gulp-rollup-each');
const commonjs = require('rollup-plugin-commonjs');
const nodeResolve = require('rollup-plugin-node-resolve');
const replace = require('rollup-plugin-replace');
const babel = require('rollup-plugin-babel');
const uglify = require('../common/gulp-uglify.js');
const DEV = !!JSON.parse(process.env.BUILD_DEV || 'true');
const DEMO = !!JSON.parse(process.env.BUILD_DEMO || 'false');
const version = fs.readFileSync('setup.py', 'utf8').match(/\d{8}[^']*/);
if (!version) {
throw Error('Version not found');
}
const VERSION = version[0];
function getRollupInputOptions(es6) {
const babelOpts = {
babelrc: false,
plugins: [
'external-helpers',
'transform-object-rest-spread',
[
'transform-react-jsx',
{
pragma: 'h'
}
],
]
};
if (!es6) {
babelOpts.presets = [
[
'env',
{
modules: false
}
]
];
}
return {
plugins: [
babel(babelOpts),
nodeResolve({
jsnext: true,
main: true,
}),
commonjs(),
replace({
values: {
__DEV__: JSON.stringify(DEV),
__DEMO__: JSON.stringify(DEMO),
__BUILD__: JSON.stringify(es6 ? 'latest' : 'es5'),
__VERSION__: JSON.stringify(VERSION),
},
}),
],
};
}
const rollupOutputOptions = {
format: 'iife',
exports: 'none',
};
gulp.task('run_rollup_es5', () => gulp.src([
'js/core.js',
'js/compatibility.js',
'demo_data/demo_data.js',
])
.pipe(rollupEach(getRollupInputOptions(/* es6= */ false), rollupOutputOptions))
.on('error', err => console.error(err.message))
.pipe(gulp.dest('build-temp-es5')));
gulp.task('run_rollup', () => gulp.src([
'js/core.js',
'js/util.js',
'demo_data/demo_data.js',
])
.pipe(rollupEach(getRollupInputOptions(/* es6= */ true), rollupOutputOptions))
.on('error', err => console.error(err.message))
.pipe(gulp.dest('build-temp')));
gulp.task('ru_all_es5', ['run_rollup_es5'], () => {
gulp.src([
'build-temp-es5/core.js',
'build-temp-es5/compatibility.js',
])
.pipe(uglify(/* es6= */ false, { sourceMap: false }))
.pipe(gulp.dest('build-es5/'));
});
gulp.task('ru_all', ['run_rollup'], () => {
gulp.src([
'build-temp/core.js',
])
.pipe(uglify(/* es6= */ true, { sourceMap: false }))
.pipe(gulp.dest('build/'));
});
gulp.task('watch_ru_all', ['ru_all'], () => {
gulp.watch([
'js/**/*.js',
'demo_data/**/*.js'
], ['ru_all']);
});
gulp.task('watch_ru_all_es5', ['ru_all_es5'], () => {
gulp.watch([
'js/**/*.js',
'demo_data/**/*.js'
], ['ru_all_es5']);
});

View File

@ -9,7 +9,7 @@
<link rel='apple-touch-icon' sizes='180x180'
href='/static/icons/favicon-apple-180x180.png'>
<link rel="mask-icon" href="/static/icons/mask-icon.svg" color="#3fbbf4">
<link rel='preload' href='/home-assistant-polymer/build/core.js' as='script'/>
<link rel='preload' href='/home-assistant-polymer/hass_frontend/core.js' as='script'/>
<link rel='preload' href='/static/fonts/roboto/Roboto-Regular.ttf' as='font' crossorigin />
<link rel='preload' href='/static/fonts/roboto/Roboto-Medium.ttf' as='font' crossorigin />
<meta name='apple-mobile-web-app-capable' content='yes'>
@ -100,10 +100,9 @@
});
} */
</script>
<!--<script src='/home-assistant-polymer/build/_demo_data_compiled.js'></script>-->
<!--EXTRA_SCRIPTS-->
<script src='/home-assistant-polymer/build/core.js'></script>
<script src='/home-assistant-polymer/build/webpack/app.js'></script>
<script src='/home-assistant-polymer/hass_frontend/core.js'></script>
<script src='/home-assistant-polymer/hass_frontend/app.js'></script>
<link rel='import' href='/home-assistant-polymer/hass_frontend/mdi.html' async>
{% for extra_url in extra_urls -%}
<link rel='import' href='{{ extra_url }}' async>

View File

@ -5,14 +5,10 @@ import refreshToken_ from './common/auth/refresh_token.js';
import parseQuery from './common/util/parse_query.js';
window.HAWS = HAWS;
window.HASS_DEMO = __DEMO__;
window.HASS_DEV = __DEV__;
window.HASS_BUILD = __BUILD__;
window.HASS_VERSION = __VERSION__;
const init = window.createHassConnection = function (password, accessToken) {
const proto = window.location.protocol === 'https:' ? 'wss' : 'ws';
const url = `${proto}://${window.location.host}/api/websocket?${window.HASS_BUILD}`;
const url = `${proto}://${window.location.host}/api/websocket?${__BUILD__}`;
const options = {
setupRetry: 10,
};
@ -94,7 +90,7 @@ window.addEventListener('error', (e) => {
const homeAssistant = document.querySelector('home-assistant');
if (homeAssistant && homeAssistant.hass && homeAssistant.hass.callService) {
homeAssistant.hass.callService('system_log', 'write', {
logger: `frontend.${window.HASS_DEV ? 'js_dev' : 'js'}.${window.HASS_BUILD}.${window.HASS_VERSION.replace('.', '')}`,
logger: `frontend.${__DEV__ ? 'js_dev' : 'js'}.${__BUILD__}.${__VERSION__.replace('.', '')}`,
message: `${e.filename}:${e.lineno}:${e.colno} ${e.message}`,
});
}

View File

@ -8,13 +8,8 @@
"version": "1.0.0",
"scripts": {
"clean": "rm -rf build/* build-temp/* build-es5/* build-temp-es5/* build-translations/*",
"gulp": "gulp",
"build": "BUILD_DEV=0 gulp && NODE_ENV=production webpack -p",
"build_demo": "BUILD_DEV=0 BUILD_DEMO=1 gulp",
"build": "script/build_frontend",
"dev": "npm run gulp ru_all gen-service-worker",
"dev-watch": "npm run gulp watch_ru_all gen-service-worker",
"dev-es5": "npm run gulp ru_all_es5 gen-service-worker-es5",
"dev-watch-es5": "npm run gulp watch_ru_all_es5 gen-service-worker-es5",
"lint_js": "eslint src panels js hassio test-mocha",
"lint_html": "polymer lint",
"mocha": "node_modules/.bin/mocha --opts test-mocha/mocha.opts",
@ -94,6 +89,7 @@
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-preset-env": "^1.6.1",
"chai": "^4.1.2",
"copy-webpack-plugin": "^4.5.1",
"css-slam": "^2.0.2",
"del": "^3.0.0",
"eslint": "^4.11.0",

View File

@ -23,7 +23,6 @@ import '../../../src/components/ha-markdown.js';
import '../../../src/components/ha-service-picker.js';
import '../../../src/layouts/ha-app-layout.js';
import '../../../src/util/hass-mixins.js';
import '../ha-config-js.js';
import '../ha-config-section.js';
import Automation from '../../../js/panel-config/automation.js';
import unmountPreact from '../../../js/common/preact/unmount.js';

View File

@ -1 +0,0 @@

View File

@ -21,7 +21,6 @@ import '../../../src/components/entity/ha-entity-picker.js';
import '../../../src/components/ha-combo-box.js';
import '../../../src/layouts/ha-app-layout.js';
import '../../../src/util/hass-mixins.js';
import '../ha-config-js.js';
import '../ha-config-section.js';
import Script from '../../../js/panel-config/script.js';
import unmountPreact from '../../../js/common/preact/unmount.js';

View File

@ -254,7 +254,7 @@ class HaPanelDevInfo extends PolymerElement {
jsVersion: {
type: String,
value: window.HASS_BUILD,
value: __BUILD__,
},
customUiList: {

View File

@ -31,7 +31,7 @@ class HaPanelHassio extends
iframeUrl: {
type: String,
value: window.HASS_DEV ?
value: __DEV__ ?
'/home-assistant-polymer/hassio/index.html' : '/api/hassio/app-es5/index.html',
}
};

View File

@ -55,7 +55,7 @@ class HaPanelMap extends window.hassMixins.LocalizeMixin(PolymerElement) {
super.connectedCallback();
var map = this._map = Leaflet.map(this.$.map);
var style = document.createElement('link');
style.setAttribute('href', window.HASS_DEV ?
style.setAttribute('href', __DEV__ ?
'/home-assistant-polymer/bower_components/leaflet/dist/leaflet.css' :
'/static/images/leaflet/leaflet.css');
style.setAttribute('rel', 'stylesheet');

View File

@ -9,46 +9,21 @@ cd "$(dirname "$0")/.."
OUTPUT_DIR=hass_frontend
OUTPUT_DIR_ES5=hass_frontend_es5
rm -rf $OUTPUT_DIR $OUTPUT_DIR_ES5
rm -rf $OUTPUT_DIR $OUTPUT_DIR_ES5 build-translations
cp -r public $OUTPUT_DIR
mkdir $OUTPUT_DIR_ES5
cp -r public/__init__.py $OUTPUT_DIR_ES5/
# Build frontend
BUILD_DEV=0 ./node_modules/.bin/gulp
BUILD_DEV=0 ./node_modules/.bin/gulp build-translations authorize authorize-es5
NODE_ENV=production webpack -p
BUILD_DEV=0 ./node_modules/.bin/gulp authorize authorize-es5
# Copy frontend to output
cp build/core.js $OUTPUT_DIR
cp build/webpack/* $OUTPUT_DIR
cp build-es5/core.js $OUTPUT_DIR_ES5
cp build-es5/webpack/* $OUTPUT_DIR_ES5
cp build-es5/compatibility.js $OUTPUT_DIR_ES5
# Translations
cp -r build-translations/output $OUTPUT_DIR/translations
# Local Roboto
cp -r node_modules/@polymer/font-roboto-local/fonts $OUTPUT_DIR
# Polyfill web components
cp node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js $OUTPUT_DIR
cp node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js $OUTPUT_DIR_ES5
# Icons
script/update_mdi.py
# Leaflet
mkdir $OUTPUT_DIR/images/leaflet
cp node_modules/leaflet/dist/leaflet.css $OUTPUT_DIR/images/leaflet
cp -r node_modules/leaflet/dist/images $OUTPUT_DIR/images/leaflet/
./node_modules/.bin/gulp compress
# Stub the service worker
touch build/service_worker.js
touch build-es5/service_worker.js
touch hass_frontend/service_worker.js
touch hass_frontend_es5/service_worker.js

View File

@ -21,6 +21,6 @@
addScript('/static/webcomponents-lite.js');
}
</script>
<script src="/home-assistant-polymer/build/webpack/ha-authorize.js"></script>
<script src="/home-assistant-polymer/hass_frontend/authorize.js"></script>
</body>
</html>

View File

@ -1,31 +1,6 @@
window.hassCallApi = function (host, auth, method, path, parameters) {
var url = host + '/api/' + path;
if (window.HASS_DEMO) {
var component = path.split('/', 1)[0];
var data;
switch (component) {
case 'bootstrap':
data = window.hassDemoData.bootstrap;
break;
case 'logbook':
data = window.hassDemoData.logbook;
break;
case 'history':
data = window.hassDemoData.stateHistory;
break;
default:
data = false;
}
return new Promise(function (resolve, reject) {
if (data) {
resolve(data);
} else {
reject(new Error('Request not allowed in demo mode.'));
}
});
}
return new Promise(function (resolve, reject) {
var req = new XMLHttpRequest();
req.open(method, url, true);

View File

@ -1,7 +1,16 @@
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const version = fs.readFileSync('setup.py', 'utf8').match(/\d{8}[^']*/);
if (!version) {
throw Error('Version not found');
}
const VERSION = version[0];
function createConfig(isProdBuild, latestBuild) {
let buildPath = latestBuild ? 'build/webpack/' : 'build-es5/webpack/';
let buildPath = latestBuild ? 'hass_frontend/' : 'hass_frontend_es5/';
let publicPath;
if (isProdBuild) {
@ -10,6 +19,12 @@ function createConfig(isProdBuild, latestBuild) {
publicPath = `/home-assistant-polymer/${buildPath}`;
}
const entry = {
app: './src/home-assistant.js',
authorize: './src/auth/ha-authorize.js',
core: './js/core.js',
};
const babelOptions = {
plugins: [
// Only support the syntax, Webpack will handle it.
@ -23,10 +38,30 @@ function createConfig(isProdBuild, latestBuild) {
],
};
if (!latestBuild) {
const plugins = [
new webpack.DefinePlugin({
__DEV__: JSON.stringify(!isProdBuild),
__BUILD__: JSON.stringify(latestBuild ? 'latest' : 'es5'),
__VERSION__: JSON.stringify(VERSION),
})
];
if (latestBuild) {
plugins.push(CopyWebpackPlugin([
{ from: 'build-translations/output', to: `translations` },
'node_modules/@polymer/font-roboto-local',
'node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js',
{ from: 'node_modules/leaflet/dist/leaflet.css', to: `images/leaflet/` },
{ from: 'node_modules/leaflet/dist/images', to: `images/leaflet/` },
]));
} else {
plugins.push(CopyWebpackPlugin([
'node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js',
]));
babelOptions.presets = [
['es2015', { modules: false }]
];
entry.compatibility = './js/compatibility.js';
}
const chunkFilename = isProdBuild ?
@ -34,10 +69,7 @@ function createConfig(isProdBuild, latestBuild) {
return {
mode: isProdBuild ? 'production' : 'development',
entry: {
app: './src/home-assistant.js',
authorize: './src/auth/ha-authorize.js'
},
entry,
module: {
rules: [
{
@ -49,6 +81,7 @@ function createConfig(isProdBuild, latestBuild) {
}
]
},
plugins,
output: {
filename: '[name].js',
chunkFilename: chunkFilename,

View File

@ -2660,7 +2660,7 @@ babel-plugin-syntax-jsx@^6.8.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946"
babel-plugin-syntax-object-rest-spread@^6.13.0, babel-plugin-syntax-object-rest-spread@^6.8.0:
babel-plugin-syntax-object-rest-spread@^6.8.0:
version "6.13.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz#fd6536f2bce13836ffa3a5458c4903a597bb3bf5"
@ -2917,7 +2917,7 @@ babel-plugin-transform-minify-booleans@^6.10.0-alpha.caaefb4c:
version "6.10.0-alpha.f95869d4"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-minify-booleans/-/babel-plugin-transform-minify-booleans-6.10.0-alpha.f95869d4.tgz#1deef69c22135038a91de1f5d13d759e3464c43c"
babel-plugin-transform-object-rest-spread@^6.22.0, babel-plugin-transform-object-rest-spread@^6.26.0:
babel-plugin-transform-object-rest-spread@^6.22.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.26.0.tgz#0f36692d50fef6b7e2d4b3ac1478137a963b7b06"
dependencies:
@ -4206,6 +4206,19 @@ copy-descriptor@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
copy-webpack-plugin@^4.5.1:
version "4.5.1"
resolved "https://registry.yarnpkg.com/copy-webpack-plugin/-/copy-webpack-plugin-4.5.1.tgz#fc4f68f4add837cc5e13d111b20715793225d29c"
dependencies:
cacache "^10.0.4"
find-cache-dir "^1.0.0"
globby "^7.1.1"
is-glob "^4.0.0"
loader-utils "^1.1.0"
minimatch "^3.0.4"
p-limit "^1.0.0"
serialize-javascript "^1.4.0"
core-js@^1.0.0:
version "1.2.7"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636"
@ -6027,6 +6040,17 @@ globby@^6.1.0:
pify "^2.0.0"
pinkie-promise "^2.0.0"
globby@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/globby/-/globby-7.1.1.tgz#fb2ccff9401f8600945dfada97440cca972b8680"
dependencies:
array-union "^1.0.1"
dir-glob "^2.0.0"
glob "^7.1.2"
ignore "^3.3.5"
pify "^3.0.0"
slash "^1.0.0"
globby@^8.0.0, globby@^8.0.1:
version "8.0.1"
resolved "https://registry.yarnpkg.com/globby/-/globby-8.0.1.tgz#b5ad48b8aa80b35b814fc1281ecc851f1d2b5b50"
@ -9033,6 +9057,12 @@ p-lazy@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/p-lazy/-/p-lazy-1.0.0.tgz#ec53c802f2ee3ac28f166cc82d0b2b02de27a835"
p-limit@^1.0.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.2.0.tgz#0e92b6bedcb59f022c13d0f1949dc82d15909f1c"
dependencies:
p-try "^1.0.0"
p-limit@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.1.0.tgz#b07ff2d9a5d88bec806035895a2bab66a27988bc"
@ -9063,6 +9093,10 @@ p-timeout@^2.0.1:
dependencies:
p-finally "^1.0.0"
p-try@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3"
package-json@^2.0.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/package-json/-/package-json-2.4.0.tgz#0d15bd67d1cbbddbb2ca222ff2edb86bcb31a8bb"