mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-10 19:06:36 +00:00
Updates packages and clean gulp/ JS (#610)
This commit is contained in:
parent
a2612af6a9
commit
adac8e55d7
@ -13,8 +13,7 @@ async function bundledStreamFromHTML(path, bundlerOptions = {}) {
|
|||||||
const bundler = new Bundler(bundlerOptions);
|
const bundler = new Bundler(bundlerOptions);
|
||||||
const manifest = await bundler.generateManifest([path]);
|
const manifest = await bundler.generateManifest([path]);
|
||||||
const result = await bundler.bundle(manifest);
|
const result = await bundler.bundle(manifest);
|
||||||
return streamFromString(
|
return streamFromString(path, parse5.serialize(result.documents.get(path).ast));
|
||||||
path, parse5.serialize(result.documents.get(path).ast));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function analyze(root, paths) {
|
async function analyze(root, paths) {
|
||||||
|
@ -9,7 +9,7 @@ function streamFromString(filename, string) {
|
|||||||
cwd: '',
|
cwd: '',
|
||||||
base: '',
|
base: '',
|
||||||
path: filename,
|
path: filename,
|
||||||
contents: new Buffer(string)
|
contents: Buffer.from(string)
|
||||||
}));
|
}));
|
||||||
this.push(null);
|
this.push(null);
|
||||||
};
|
};
|
||||||
|
@ -41,8 +41,10 @@ function build(es6) {
|
|||||||
]);
|
]);
|
||||||
const project = new PolymerProject(polymerConfig);
|
const project = new PolymerProject(polymerConfig);
|
||||||
|
|
||||||
return mergeStream(minifyStream(project.sources(), es6),
|
return mergeStream(
|
||||||
minifyStream(project.dependencies(), es6))
|
minifyStream(project.sources(), es6),
|
||||||
|
minifyStream(project.dependencies(), es6)
|
||||||
|
)
|
||||||
.pipe(project.bundler({
|
.pipe(project.bundler({
|
||||||
strategy,
|
strategy,
|
||||||
strip: true,
|
strip: true,
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
const del = require('del');
|
const del = require('del');
|
||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
|
|
||||||
gulp.task('clean', () => {
|
gulp.task('clean', () => del(['build-es5', 'build', 'build-temp', 'build-translations']));
|
||||||
return del(['build-es5', 'build', 'build-temp', 'build-translations']);
|
|
||||||
});
|
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
const runSequence = require('run-sequence');
|
const runSequence = require('run-sequence');
|
||||||
|
|
||||||
gulp.task('default', () => {
|
gulp.task('default', () => runSequence.use(gulp)(
|
||||||
return runSequence.use(gulp)(
|
'clean',
|
||||||
'clean',
|
'build_es5',
|
||||||
'build_es5',
|
'build',
|
||||||
'build',
|
));
|
||||||
);
|
|
||||||
});
|
|
||||||
|
@ -66,12 +66,10 @@ function generateServiceWorker(es6) {
|
|||||||
const panelDir = path.resolve(rootDir, 'panels');
|
const panelDir = path.resolve(rootDir, 'panels');
|
||||||
|
|
||||||
if (DEV) {
|
if (DEV) {
|
||||||
genPromise = Promise.resolve(
|
genPromise = Promise.resolve(fs.readFileSync(path.resolve(__dirname, '../service-worker-dev.js.tmpl'), 'UTF-8'));
|
||||||
fs.readFileSync(path.resolve(__dirname, '../service-worker-dev.js.tmpl'), 'UTF-8'));
|
|
||||||
} else {
|
} else {
|
||||||
// Create fingerprinted versions of our dependencies.
|
// Create fingerprinted versions of our dependencies.
|
||||||
(es6 ? staticFingerprintedEs6 : staticFingerprintedEs5).forEach(
|
(es6 ? staticFingerprintedEs6 : staticFingerprintedEs5).forEach(fn => processStatic(fn, rootDir, es6 ? 'frontend_latest' : 'frontend_es5'));
|
||||||
fn => processStatic(fn, rootDir, es6? 'frontend_latest' : 'frontend_es5'));
|
|
||||||
staticFingerprinted.forEach(fn => processStatic(fn, baseRootDir, 'static'));
|
staticFingerprinted.forEach(fn => processStatic(fn, baseRootDir, 'static'));
|
||||||
|
|
||||||
panelsFingerprinted.forEach((panel) => {
|
panelsFingerprinted.forEach((panel) => {
|
||||||
|
@ -32,15 +32,13 @@ async function buildHassioPanel(es6) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const stream = await bundledStreamFromHTML(
|
const stream = await bundledStreamFromHTML('panels/hassio/hassio-main.html', {
|
||||||
'panels/hassio/hassio-main.html', {
|
strategy: stripImportsStrategy(toStrip)
|
||||||
strategy: stripImportsStrategy(toStrip)
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return minifyStream(stream, es6)
|
return minifyStream(stream, es6)
|
||||||
.pipe(rename('hassio-main.html'))
|
.pipe(rename('hassio-main.html'))
|
||||||
.pipe(gulp.dest('build-temp'));
|
.pipe(gulp.dest('build-temp'));
|
||||||
}
|
}
|
||||||
|
|
||||||
gulp.task('hassio-panel-es5', buildHassioPanel.bind(null, /* es6= */ false));
|
gulp.task('hassio-panel-es5', buildHassioPanel.bind(null, /* es6= */ false));
|
||||||
|
@ -3,42 +3,38 @@ const rollupEach = require('gulp-rollup-each');
|
|||||||
const rollupConfig = require('../../rollup.config');
|
const rollupConfig = require('../../rollup.config');
|
||||||
const rollupConfigEs6 = require('../../rollup.config-es6');
|
const rollupConfigEs6 = require('../../rollup.config-es6');
|
||||||
|
|
||||||
gulp.task('run_rollup_es5', () => {
|
gulp.task('run_rollup_es5', () => gulp.src([
|
||||||
return gulp.src([
|
'js/core.js',
|
||||||
'js/core.js',
|
'js/compatibility.js',
|
||||||
'js/compatibility.js',
|
'js/automation-editor/automation-editor.js',
|
||||||
'js/automation-editor/automation-editor.js',
|
'js/script-editor/script-editor.js',
|
||||||
'js/script-editor/script-editor.js',
|
'demo_data/demo_data.js',
|
||||||
'demo_data/demo_data.js',
|
])
|
||||||
])
|
|
||||||
.pipe(rollupEach(rollupConfig, rollupConfig))
|
.pipe(rollupEach(rollupConfig, rollupConfig))
|
||||||
.pipe(gulp.dest('build-temp'));
|
.pipe(gulp.dest('build-temp')));
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('run_rollup', () => {
|
gulp.task('run_rollup', () => gulp.src([
|
||||||
return gulp.src([
|
'js/core.js',
|
||||||
'js/core.js',
|
'js/automation-editor/automation-editor.js',
|
||||||
'js/automation-editor/automation-editor.js',
|
'js/script-editor/script-editor.js',
|
||||||
'js/script-editor/script-editor.js',
|
'demo_data/demo_data.js',
|
||||||
'demo_data/demo_data.js',
|
])
|
||||||
])
|
|
||||||
.pipe(rollupEach(rollupConfigEs6, rollupConfigEs6))
|
.pipe(rollupEach(rollupConfigEs6, rollupConfigEs6))
|
||||||
.pipe(gulp.dest('build-temp'));
|
.pipe(gulp.dest('build-temp')));
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('ru_all_es5', ['run_rollup_es5'], () => {
|
gulp.task('ru_all_es5', ['run_rollup_es5'], () => {
|
||||||
gulp.src([
|
gulp.src([
|
||||||
'build-temp/core.js',
|
'build-temp/core.js',
|
||||||
'build-temp/compatibility.js',
|
'build-temp/compatibility.js',
|
||||||
])
|
])
|
||||||
.pipe(gulp.dest('build-es5/'));
|
.pipe(gulp.dest('build-es5/'));
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('ru_all', ['run_rollup'], () => {
|
gulp.task('ru_all', ['run_rollup'], () => {
|
||||||
gulp.src([
|
gulp.src([
|
||||||
'build-temp/core.js',
|
'build-temp/core.js',
|
||||||
])
|
])
|
||||||
.pipe(gulp.dest('build/'));
|
.pipe(gulp.dest('build/'));
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('watch_ru_all', ['ru_all'], () => {
|
gulp.task('watch_ru_all', ['ru_all'], () => {
|
||||||
|
@ -13,11 +13,11 @@ const outDir = 'build-translations';
|
|||||||
|
|
||||||
const tasks = [];
|
const tasks = [];
|
||||||
|
|
||||||
function recursive_flatten (prefix, data) {
|
function recursiveFlatten(prefix, data) {
|
||||||
var output = {};
|
var output = {};
|
||||||
Object.keys(data).forEach(function (key) {
|
Object.keys(data).forEach(function (key) {
|
||||||
if (typeof(data[key]) === 'object') {
|
if (typeof (data[key]) === 'object') {
|
||||||
output = Object.assign({}, output, recursive_flatten(key + '.', data[key]));
|
output = Object.assign({}, output, recursiveFlatten(key + '.', data[key]));
|
||||||
} else {
|
} else {
|
||||||
output[prefix + key] = data[key];
|
output[prefix + key] = data[key];
|
||||||
}
|
}
|
||||||
@ -25,14 +25,14 @@ function recursive_flatten (prefix, data) {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function flatten (data) {
|
function flatten(data) {
|
||||||
return recursive_flatten('', data);
|
return recursiveFlatten('', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
var taskName = 'build-merged-translations';
|
let taskName = 'build-merged-translations';
|
||||||
gulp.task(taskName, function () {
|
gulp.task(taskName, function () {
|
||||||
return gulp.src(inDir + '/*.json')
|
return gulp.src(inDir + '/*.json')
|
||||||
.pipe(foreach(function(stream, file) {
|
.pipe(foreach(function (stream, file) {
|
||||||
// For each language generate a merged json file. It begins with en.json as
|
// For each language generate a merged json file. It begins with en.json as
|
||||||
// a failsafe for untranslated strings, and merges all parent tags into one
|
// a failsafe for untranslated strings, and merges all parent tags into one
|
||||||
// file for each specific subtag
|
// file for each specific subtag
|
||||||
@ -44,17 +44,17 @@ gulp.task(taskName, function () {
|
|||||||
src.push(inDir + '/' + lang + '.json');
|
src.push(inDir + '/' + lang + '.json');
|
||||||
}
|
}
|
||||||
return gulp.src(src)
|
return gulp.src(src)
|
||||||
.pipe(transform(function(data, file) {
|
.pipe(transform(function (data) {
|
||||||
// Polymer.AppLocalizeBehavior requires flattened json
|
// Polymer.AppLocalizeBehavior requires flattened json
|
||||||
return flatten(data);
|
return flatten(data);
|
||||||
}))
|
}))
|
||||||
.pipe(transform(function(data, file) {
|
.pipe(transform(function (data) {
|
||||||
const new_data = {};
|
const newData = {};
|
||||||
Object.entries(data).forEach(([key, value]) => {
|
Object.entries(data).forEach(([key, value]) => {
|
||||||
// Filter out empty strings or other falsey values before merging
|
// Filter out empty strings or other falsey values before merging
|
||||||
if (data[key]) new_data[key] = value;
|
if (data[key]) newData[key] = value;
|
||||||
});
|
});
|
||||||
return new_data;
|
return newData;
|
||||||
}))
|
}))
|
||||||
.pipe(merge({
|
.pipe(merge({
|
||||||
fileName: tr + '.json',
|
fileName: tr + '.json',
|
||||||
@ -65,11 +65,11 @@ gulp.task(taskName, function () {
|
|||||||
});
|
});
|
||||||
tasks.push(taskName);
|
tasks.push(taskName);
|
||||||
|
|
||||||
var taskName = 'build-translation-fingerprints';
|
taskName = 'build-translation-fingerprints';
|
||||||
gulp.task(taskName, ['build-merged-translations'], function() {
|
gulp.task(taskName, ['build-merged-translations'], function () {
|
||||||
return gulp.src(outDir + '/!(translationFingerprints).json')
|
return gulp.src(outDir + '/!(translationFingerprints).json')
|
||||||
.pipe(rename({
|
.pipe(rename({
|
||||||
extname: "",
|
extname: '',
|
||||||
}))
|
}))
|
||||||
.pipe(hash({
|
.pipe(hash({
|
||||||
algorithm: 'md5',
|
algorithm: 'md5',
|
||||||
@ -77,9 +77,9 @@ gulp.task(taskName, ['build-merged-translations'], function() {
|
|||||||
template: '<%= name %>-<%= hash %>.json',
|
template: '<%= name %>-<%= hash %>.json',
|
||||||
}))
|
}))
|
||||||
.pipe(hash.manifest('translationFingerprints.json'))
|
.pipe(hash.manifest('translationFingerprints.json'))
|
||||||
.pipe(transform(function(data, file) {
|
.pipe(transform(function (data) {
|
||||||
Object.keys(data).map(function(key, index) {
|
Object.keys(data).forEach((key) => {
|
||||||
data[key] = {fingerprint: data[key]};
|
data[key] = { fingerprint: data[key] };
|
||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
}))
|
}))
|
||||||
@ -87,25 +87,25 @@ gulp.task(taskName, ['build-merged-translations'], function() {
|
|||||||
});
|
});
|
||||||
tasks.push(taskName);
|
tasks.push(taskName);
|
||||||
|
|
||||||
var taskName = 'build-translations';
|
taskName = 'build-translations';
|
||||||
gulp.task(taskName, ['build-translation-fingerprints'], function() {
|
gulp.task(taskName, ['build-translation-fingerprints'], function () {
|
||||||
return gulp.src([
|
return gulp.src([
|
||||||
'src/translations/translationMetadata.json',
|
'src/translations/translationMetadata.json',
|
||||||
outDir + '/translationFingerprints.json',
|
outDir + '/translationFingerprints.json',
|
||||||
])
|
])
|
||||||
.pipe(merge({}))
|
.pipe(merge({}))
|
||||||
.pipe(transform(function(data, file) {
|
.pipe(transform(function (data) {
|
||||||
const new_data = {};
|
const newData = {};
|
||||||
Object.entries(data).forEach(([key, value]) => {
|
Object.entries(data).forEach(([key, value]) => {
|
||||||
// Filter out empty strings or other falsey values before merging
|
// Filter out empty strings or other falsey values before merging
|
||||||
if (data[key]['nativeName']) {
|
if (data[key].nativeName) {
|
||||||
new_data[key] = data[key];
|
newData[key] = data[key];
|
||||||
} else {
|
} else {
|
||||||
console.warn(`Skipping language ${key}. Native name was not translated.`);
|
console.warn(`Skipping language ${key}. Native name was not translated.`);
|
||||||
}
|
}
|
||||||
if (data[key]) new_data[key] = value;
|
if (data[key]) newData[key] = value;
|
||||||
});
|
});
|
||||||
return new_data;
|
return newData;
|
||||||
}))
|
}))
|
||||||
.pipe(insert.wrap('<script>\nwindow.translationMetadata = ', ';\n</script>'))
|
.pipe(insert.wrap('<script>\nwindow.translationMetadata = ', ';\n</script>'))
|
||||||
.pipe(rename('translationMetadata.html'))
|
.pipe(rename('translationMetadata.html'))
|
||||||
|
29
package.json
29
package.json
@ -26,17 +26,15 @@
|
|||||||
"babel-plugin-external-helpers": "^6.22.0",
|
"babel-plugin-external-helpers": "^6.22.0",
|
||||||
"babel-plugin-transform-object-rest-spread": "^6.26.0",
|
"babel-plugin-transform-object-rest-spread": "^6.26.0",
|
||||||
"babel-plugin-transform-react-jsx": "^6.24.1",
|
"babel-plugin-transform-react-jsx": "^6.24.1",
|
||||||
"babel-preset-babili": "^0.1.4",
|
|
||||||
"babel-preset-es2015": "^6.24.1",
|
"babel-preset-es2015": "^6.24.1",
|
||||||
"babel-preset-es2016": "^6.24.1",
|
|
||||||
"bower": "^1.8.2",
|
"bower": "^1.8.2",
|
||||||
"css-slam": "^2.0.2",
|
"css-slam": "^2.0.2",
|
||||||
"del": "^3.0.0",
|
"del": "^3.0.0",
|
||||||
"es6-object-assign": "^1.1.0",
|
"es6-object-assign": "^1.1.0",
|
||||||
"eslint": "^4.8.0",
|
"eslint": "^4.11.0",
|
||||||
"eslint-config-airbnb-base": "^12.0.2",
|
"eslint-config-airbnb-base": "^12.1.0",
|
||||||
"eslint-plugin-html": "^3.2.2",
|
"eslint-plugin-html": "^3.2.2",
|
||||||
"eslint-plugin-import": "^2.2.0",
|
"eslint-plugin-import": "^2.8.0",
|
||||||
"eslint-plugin-react": "^7.0.0",
|
"eslint-plugin-react": "^7.0.0",
|
||||||
"gulp": "^3.9.1",
|
"gulp": "^3.9.1",
|
||||||
"gulp-babel": "^7.0.0",
|
"gulp-babel": "^7.0.0",
|
||||||
@ -47,38 +45,37 @@
|
|||||||
"gulp-html-minifier": "^0.1.8",
|
"gulp-html-minifier": "^0.1.8",
|
||||||
"gulp-if": "^2.0.2",
|
"gulp-if": "^2.0.2",
|
||||||
"gulp-insert": "^0.5.0",
|
"gulp-insert": "^0.5.0",
|
||||||
"gulp-json-transform": "^0.4.2",
|
"gulp-json-transform": "^0.4.5",
|
||||||
"gulp-jsonminify": "^1.0.0",
|
"gulp-jsonminify": "^1.0.0",
|
||||||
"gulp-merge-json": "^1.0.0",
|
"gulp-merge-json": "^1.0.0",
|
||||||
"gulp-rename": "^1.2.2",
|
"gulp-rename": "^1.2.2",
|
||||||
"gulp-rollup-each": "^2.0.0",
|
"gulp-rollup-each": "^2.0.0",
|
||||||
"gulp-uglify": "^3.0.0",
|
"gulp-uglify": "^3.0.0",
|
||||||
"gulp-util": "^3.0.8",
|
"gulp-util": "^3.0.8",
|
||||||
"home-assistant-js-websocket": "^1.1.0",
|
"home-assistant-js-websocket": "^1.1.2",
|
||||||
"html-minifier": "^3.5.5",
|
"html-minifier": "^3.5.6",
|
||||||
"merge-stream": "^1.0.1",
|
"merge-stream": "^1.0.1",
|
||||||
"parse5": "^3.0.2",
|
"parse5": "^3.0.3",
|
||||||
"polymer-analyzer": "^2.3.0",
|
"polymer-analyzer": "^2.3.0",
|
||||||
"polymer-build": "^2.1.0",
|
"polymer-build": "^2.1.0",
|
||||||
"polymer-bundler": "^3.1.0",
|
"polymer-bundler": "^3.1.0",
|
||||||
"polymer-cli": "^1.5.6",
|
"polymer-cli": "^1.5.6",
|
||||||
"preact": "^8.2.5",
|
"preact": "^8.2.6",
|
||||||
"pump": "^1.0.2",
|
"pump": "^1.0.2",
|
||||||
"require-dir": "^0.3.2",
|
"require-dir": "^0.3.2",
|
||||||
"rollup": "^0.50.0",
|
"rollup": "^0.51.3",
|
||||||
"rollup-plugin-babel": "^3.0.2",
|
"rollup-plugin-babel": "^3.0.2",
|
||||||
"rollup-plugin-commonjs": "^8.2.1",
|
"rollup-plugin-commonjs": "^8.2.6",
|
||||||
"rollup-plugin-node-resolve": "^3.0.0",
|
"rollup-plugin-node-resolve": "^3.0.0",
|
||||||
"rollup-plugin-replace": "^2.0.0",
|
"rollup-plugin-replace": "^2.0.0",
|
||||||
"rollup-plugin-uglify": "^2.0.1",
|
"rollup-plugin-uglify": "^2.0.1",
|
||||||
"rollup-watch": "^4.3.1",
|
"rollup-watch": "^4.3.1",
|
||||||
"run-sequence": "^2.2.0",
|
"run-sequence": "^2.2.0",
|
||||||
"sw-precache": "^5.2.0",
|
"sw-precache": "^5.2.0",
|
||||||
"uglify-es": "^3.1.6",
|
"uglify-es": "^3.1.9",
|
||||||
"uglify-js": "^3.1.3",
|
"uglify-js": "^3.1.9"
|
||||||
"vulcanize": "^1.16.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"web-component-tester": "^6.3.0"
|
"web-component-tester": "^6.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
"panels/**/*"
|
"panels/**/*"
|
||||||
],
|
],
|
||||||
"lint": {
|
"lint": {
|
||||||
"rules": ["polymer-2-hybrid"]
|
"rules": ["polymer-2"]
|
||||||
},
|
},
|
||||||
"builds": [
|
"builds": [
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user