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