Skip to content

Commit

Permalink
Add build using polymer-build
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Jul 17, 2017
1 parent 2453d6f commit 95f5a88
Show file tree
Hide file tree
Showing 6 changed files with 1,906 additions and 832 deletions.
86 changes: 86 additions & 0 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
'use strict';

import del from 'del';
import filter from 'gulp-filter';
import gulp from 'gulp';
import rollupEach from 'gulp-rollup-each';
import gulpif from 'gulp-if';
import { gulp as cssSlam } from 'css-slam';
import htmlMinifier from 'gulp-html-minifier';
import { PolymerProject, HtmlSplitter } from 'polymer-build';
import mergeStream from 'merge-stream';
import babel from 'gulp-babel';
import rename from 'gulp-rename';

import rollupConfig from './rollup.config';
import polymerConfig from './polymer';

gulp.task('run_rollup', () => {
return gulp.src([
Expand All @@ -29,3 +40,78 @@ gulp.task('watch_ru_all', ['ru_all'], () => {
'demo_data/**/*.js'
], ['ru_all']);
});

function minifyStream(stream) {
const sourcesHtmlSplitter = new HtmlSplitter();
return stream
.pipe(sourcesHtmlSplitter.split())
.pipe(gulpif(/\.js$/, babel({
presets: ['babili'], // 'es2015'
// plugins: ['external-helpers']
})))
.pipe(gulpif(/\.css$/, cssSlam()))
.pipe(gulpif(/\.html$/, cssSlam()))
.pipe(gulpif(/\.html$/, htmlMinifier({
collapseWhitespace: true,
removeComments: true
})))
.pipe(sourcesHtmlSplitter.rejoin());
}

gulp.task('clean', () => {
return del(['build', 'build-temp']);
});

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/';
}

if (path.dirname === 'src' && path.basename === 'home-assistant' &&
path.extname === '.html') {
path.dirname = '';
path.basename = 'frontend';
}
}

gulp.task('build', ['clean', 'ru_all'], () => {
const project = new PolymerProject(polymerConfig);
mergeStream(minifyStream(project.sources()),
minifyStream(project.dependencies()))
.pipe(project.bundler({
// TODO this doesn't work yet
stripExcludes: [
'bower_components/font-roboto/roboto.html',
'bower_components/paper-styles/color.html',
// The Hass.io panel will be loaded on demand from supervisor
'panels/hassio/hassio-main.html'
],
strip: true,
sourcemaps: false,
stripComments: true,
inlineScripts: true,
inlineCss: true,
implicitStrip: true,
}))
.pipe(rename(renamePanel))
.pipe(filter(['**', '!src/entrypoint.html']))
.pipe(gulp.dest('build/'));
});

/*
TODO
Add build for Hass.io panel.
Target: './build-temp/hassio-main.html',
stripExcludes: [
'bower_components/font-roboto/roboto.html',
'bower_components/paper-styles/color.html',
'bower_components/polymer/polymer.html',
'bower_components/iron-meta/iron-meta.html',
]
*/
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,28 @@
"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-babili": "^0.1.4",
"babel-preset-es2015": "^6.24.1",
"bower": "^1.8.0",
"css-slam": "^1.2.1",
"del": "^3.0.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",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-filter": "^5.0.0",
"gulp-html-minifier": "^0.1.8",
"gulp-if": "^2.0.2",
"gulp-rename": "^1.2.2",
"gulp-rollup-each": "^1.0.2",
"html-minifier": "^3.4.3",
"hydrolysis": "^1.24.1",
"polymer-cli": "^0.17.0",
"merge-stream": "^1.0.1",
"polymer-build": "^1.6.0",
"polymer-cli": "^1.3.1",
"polymer-lint": "^0.8.3",
"rollup": "^0.41.6",
"rollup-plugin-babel": "^2.7.1",
Expand Down
13 changes: 0 additions & 13 deletions panels/hassio/todo.md

This file was deleted.

7 changes: 2 additions & 5 deletions polymer.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"entrypoint": "src/entrypoint.html",
"shell": "src/home-assistant.html",
"fragments": [
"panels/automation/ha-panel-automation.html",
Expand All @@ -19,11 +20,7 @@
],
"sources": [
"src/**/*",
"panels/**/*",
"bower.json"
],
"extraDependencies": [
"bower_components/webcomponentsjs/*"
"panels/**/*"
],
"lint": {
"rules": ["polymer-2-hybrid"]
Expand Down
1 change: 1 addition & 0 deletions src/entrypoint.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!--unused, but required for polymer-build-->

0 comments on commit 95f5a88

Please sign in to comment.