mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-08 18:06:36 +00:00
Use Gulp to index demos (#6203)
This commit is contained in:
parent
7bbecfde2b
commit
c53fd0d1e1
6
.github/workflows/ci.yaml
vendored
6
.github/workflows/ci.yaml
vendored
@ -34,10 +34,8 @@ jobs:
|
|||||||
run: yarn install
|
run: yarn install
|
||||||
env:
|
env:
|
||||||
CI: true
|
CI: true
|
||||||
- name: Build icons
|
- name: Build resources
|
||||||
run: ./node_modules/.bin/gulp gen-icons-json
|
run: ./node_modules/.bin/gulp gen-icons-json build-translations gather-gallery-demos
|
||||||
- name: Build translations
|
|
||||||
run: ./node_modules/.bin/gulp build-translations
|
|
||||||
- name: Run eslint
|
- name: Run eslint
|
||||||
run: ./node_modules/.bin/eslint '{**/src,src}/**/*.{js,ts,html}' --ignore-path .gitignore
|
run: ./node_modules/.bin/eslint '{**/src,src}/**/*.{js,ts,html}' --ignore-path .gitignore
|
||||||
- name: Run tsc
|
- name: Run tsc
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
// Run demo develop mode
|
// Run demo develop mode
|
||||||
const gulp = require("gulp");
|
const gulp = require("gulp");
|
||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
const env = require("../env");
|
const env = require("../env");
|
||||||
|
const paths = require("../paths");
|
||||||
|
|
||||||
require("./clean.js");
|
require("./clean.js");
|
||||||
require("./translations.js");
|
require("./translations.js");
|
||||||
@ -12,6 +15,31 @@ require("./service-worker.js");
|
|||||||
require("./entry-html.js");
|
require("./entry-html.js");
|
||||||
require("./rollup.js");
|
require("./rollup.js");
|
||||||
|
|
||||||
|
gulp.task("gather-gallery-demos", async function gatherDemos() {
|
||||||
|
const files = await fs.promises.readdir(
|
||||||
|
path.resolve(paths.gallery_dir, "src/demos")
|
||||||
|
);
|
||||||
|
|
||||||
|
let content = "export const DEMOS = {\n";
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
const demoId = path.basename(file, ".ts");
|
||||||
|
const demoPath = "../src/demos/" + demoId;
|
||||||
|
content += ` "${demoId}": () => import("${demoPath}"),\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
content += "};";
|
||||||
|
|
||||||
|
const galleryBuild = path.resolve(paths.gallery_dir, "build");
|
||||||
|
|
||||||
|
fs.mkdirSync(galleryBuild, { recursive: true });
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.resolve(galleryBuild, "import-demos.ts"),
|
||||||
|
content,
|
||||||
|
"utf-8"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
gulp.task(
|
gulp.task(
|
||||||
"develop-gallery",
|
"develop-gallery",
|
||||||
gulp.series(
|
gulp.series(
|
||||||
@ -20,7 +48,11 @@ gulp.task(
|
|||||||
},
|
},
|
||||||
"clean-gallery",
|
"clean-gallery",
|
||||||
"translations-enable-merge-backend",
|
"translations-enable-merge-backend",
|
||||||
gulp.parallel("gen-icons-json", "build-translations"),
|
gulp.parallel(
|
||||||
|
"gen-icons-json",
|
||||||
|
"build-translations",
|
||||||
|
"gather-gallery-demos"
|
||||||
|
),
|
||||||
"copy-static-gallery",
|
"copy-static-gallery",
|
||||||
"gen-index-gallery-dev",
|
"gen-index-gallery-dev",
|
||||||
env.useRollup() ? "rollup-dev-server-gallery" : "webpack-dev-server-gallery"
|
env.useRollup() ? "rollup-dev-server-gallery" : "webpack-dev-server-gallery"
|
||||||
@ -35,7 +67,11 @@ gulp.task(
|
|||||||
},
|
},
|
||||||
"clean-gallery",
|
"clean-gallery",
|
||||||
"translations-enable-merge-backend",
|
"translations-enable-merge-backend",
|
||||||
gulp.parallel("gen-icons-json", "build-translations"),
|
gulp.parallel(
|
||||||
|
"gen-icons-json",
|
||||||
|
"build-translations",
|
||||||
|
"gather-gallery-demos"
|
||||||
|
),
|
||||||
"copy-static-gallery",
|
"copy-static-gallery",
|
||||||
env.useRollup() ? "rollup-prod-gallery" : "webpack-prod-gallery",
|
env.useRollup() ? "rollup-prod-gallery" : "webpack-prod-gallery",
|
||||||
"gen-index-gallery-prod"
|
"gen-index-gallery-prod"
|
||||||
|
@ -11,9 +11,7 @@ import { PolymerElement } from "@polymer/polymer/polymer-element";
|
|||||||
import "../../src/components/ha-card";
|
import "../../src/components/ha-card";
|
||||||
import "../../src/managers/notification-manager";
|
import "../../src/managers/notification-manager";
|
||||||
import "../../src/styles/polymer-ha-style";
|
import "../../src/styles/polymer-ha-style";
|
||||||
|
import { DEMOS } from "../build/import-demos";
|
||||||
// eslint-disable-next-line no-undef
|
|
||||||
const DEMOS = require.context("./demos", true, /^(.*\.(ts$))[^.]*$/im);
|
|
||||||
|
|
||||||
const fixPath = (path) => path.substr(2, path.length - 5);
|
const fixPath = (path) => path.substr(2, path.length - 5);
|
||||||
|
|
||||||
@ -163,7 +161,7 @@ class HaGallery extends PolymerElement {
|
|||||||
},
|
},
|
||||||
_demos: {
|
_demos: {
|
||||||
type: Array,
|
type: Array,
|
||||||
value: DEMOS.keys().map(fixPath),
|
value: Object.keys(DEMOS),
|
||||||
},
|
},
|
||||||
_lovelaceDemos: {
|
_lovelaceDemos: {
|
||||||
type: Array,
|
type: Array,
|
||||||
@ -210,7 +208,7 @@ class HaGallery extends PolymerElement {
|
|||||||
while (root.lastChild) root.removeChild(root.lastChild);
|
while (root.lastChild) root.removeChild(root.lastChild);
|
||||||
|
|
||||||
if (demo) {
|
if (demo) {
|
||||||
DEMOS(`./${demo}.ts`);
|
DEMOS[demo]();
|
||||||
const el = document.createElement(demo);
|
const el = document.createElement(demo);
|
||||||
root.appendChild(el);
|
root.appendChild(el);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user