Skip to content

Commit 20c0228

Browse files
authored
Add workload resources.txt (#554)
For supporting service workers in PR #540 we need an explicit list of resources for each workload so we can preload them. This adds a common resources/shared/generate-resources.mjs helper that is used in all build scripts to generate a list of all files in the respective dist/ output folder.
1 parent d580bee commit 20c0228

60 files changed

Lines changed: 1625 additions & 8 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import fs from "fs";
2+
import path from "path";
3+
4+
function walkDir(dir, fileList = []) {
5+
const files = fs.readdirSync(dir);
6+
for (const file of files) {
7+
const filePath = path.join(dir, file);
8+
if (fs.statSync(filePath).isDirectory())
9+
walkDir(filePath, fileList);
10+
else
11+
fileList.push(filePath);
12+
}
13+
return fileList;
14+
}
15+
16+
export function generateResourcesFile(distPath) {
17+
if (!fs.existsSync(distPath)) {
18+
console.warn(`Directory ${distPath} does not exist, skipping resources.txt generation.`);
19+
return;
20+
}
21+
const absoluteDist = path.resolve(distPath);
22+
const files = walkDir(absoluteDist);
23+
const relativePaths = files.map((f) => path.relative(absoluteDist, f)).filter((f) => f !== "resources.txt");
24+
fs.writeFileSync(path.join(absoluteDist, "resources.txt"), `${relativePaths.join("\n")}\n`, "utf8");
25+
console.log(`Generated resources.txt at ${distPath}`);
26+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
index.html
2+
libs/dexie.mjs
3+
src/components/todo-app/todo-app.component.js
4+
src/components/todo-app/todo-app.template.js
5+
src/components/todo-bottombar/todo-bottombar.component.js
6+
src/components/todo-bottombar/todo-bottombar.template.js
7+
src/components/todo-item/todo-item.component.js
8+
src/components/todo-item/todo-item.template.js
9+
src/components/todo-list/todo-list.component.js
10+
src/components/todo-list/todo-list.template.js
11+
src/components/todo-topbar/todo-topbar.component.js
12+
src/components/todo-topbar/todo-topbar.template.js
13+
src/hooks/useDoubleClick.js
14+
src/hooks/useKeyListener.js
15+
src/hooks/useRouter.js
16+
src/index.mjs
17+
src/speedometer-utils/benchmark.mjs
18+
src/speedometer-utils/helpers.mjs
19+
src/speedometer-utils/params.mjs
20+
src/speedometer-utils/test-invoker.mjs
21+
src/speedometer-utils/test-runner.mjs
22+
src/speedometer-utils/todomvc-utils.mjs
23+
src/speedometer-utils/translations.mjs
24+
src/storage/base-storage-manager.js
25+
src/storage/dexieDB-manager.js
26+
src/storage/indexedDB-manager.js
27+
src/storage/storage-factory.js
28+
src/utils/nanoid.js
29+
src/workload-test.mjs
30+
styles/app.constructable.js
31+
styles/bottombar.constructable.js
32+
styles/footer.css
33+
styles/global.constructable.js
34+
styles/global.css
35+
styles/header.css
36+
styles/main.constructable.js
37+
styles/todo-item.constructable.js
38+
styles/todo-list.constructable.js
39+
styles/topbar.constructable.js

suites-experimental/javascript-wc-indexeddb/scripts/build.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import path from "path";
2+
import { generateResourcesFile } from "../../../resources/shared/generate-resources.mjs";
13
import fs from "fs/promises";
24
import { dirname } from "path";
35

@@ -97,7 +99,7 @@ const filesToMove = [
9799
{ src: "node_modules/todomvc-css/dist/todo-list.constructable.js", dest: "./dist/styles/todo-list.constructable.js" },
98100
{ src: "node_modules/todomvc-css/dist/todo-item.constructable.js", dest: "./dist/styles/todo-item.constructable.js" },
99101
{ src: "node_modules/dexie/dist/modern/dexie.mjs", dest: "./dist/libs/dexie.mjs" },
100-
{ src: "node_modules/speedometer-utils/step-scheduler.mjs", dest: "./dist/src/speedometer-utils/test-invoker.mjs" },
102+
{ src: "node_modules/speedometer-utils/step-scheduler.mjs", dest: "./dist/src/speedometer-utils/step-scheduler.mjs" },
101103
{ src: "node_modules/speedometer-utils/step-runner.mjs", dest: "./dist/src/speedometer-utils/step-runner.mjs" },
102104
{ src: "node_modules/speedometer-utils/params.mjs", dest: "./dist/src/speedometer-utils/params.mjs" },
103105
{ src: "src/speedometer-utils/benchmark.mjs", dest: "./dist/src/speedometer-utils/benchmark.mjs" },
@@ -164,4 +166,5 @@ const build = async () => {
164166
console.log("Done with building!");
165167
};
166168

167-
build();
169+
await build();
170+
await generateResourcesFile(path.join(import.meta.dirname, "../dist"));
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
app.js
2+
index.html
3+
public/images/5-healthy-smoothie.webp
4+
public/images/beef-stroganoff.webp
5+
public/images/beef-tacos.webp
6+
public/images/best-comfort-food.webp
7+
public/images/bread-at-home.webp
8+
public/images/caesar-salad.webp
9+
public/images/chicken-alfredo.webp
10+
public/images/chocolate-cake.webp
11+
public/images/chocolate-chip-cookies.webp
12+
public/images/fruit-salad.webp
13+
public/images/garlic-bread.webp
14+
public/images/gluten-free-baking.webp
15+
public/images/greek-salad.webp
16+
public/images/homemade-pizza.webp
17+
public/images/icons-outline.webp
18+
public/images/lemon-drizzle-cake.webp
19+
public/images/low-carb-desserts.webp
20+
public/images/margherita-pizza.webp
21+
public/images/mastering-art-of-french-cooking.webp
22+
public/images/meal-prepping.webp
23+
public/images/mediterranean-cuisine.webp
24+
public/images/pancakes.webp
25+
public/images/plant-based-protein.webp
26+
public/images/quinoa-stuffed-peppers.webp
27+
public/images/ramen-noodles.webp
28+
public/images/seasonal-salads.webp
29+
public/images/shrimp-paella.webp
30+
public/images/spaghetti-carbonara.webp
31+
public/images/superfoods-you-should-include.webp
32+
public/images/sushi-platter.webp
33+
public/images/thai-green-curry.webp
34+
public/images/tomato-soup.webp
35+
public/images/vegan-burger.webp
36+
public/images/vegan-desserts.webp
37+
public/images/vegetable-stir-fry.webp
38+
public/images/vegetarian-stir-fry.webp
39+
public/images/week-night-dinners.webp

suites-experimental/suites.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const ExperimentalSuites = freezeSuites([
77
{
88
name: "TodoMVC-LocalStorage",
99
url: "suites-experimental/todomvc-localstorage/dist/index.html",
10+
resources: "suites-experimental/todomvc-localstorage/dist/resources.txt",
1011
tags: ["todomvc", "experimental"],
1112
async prepare(page) {
1213
(await page.waitForElement(".new-todo")).focus();
@@ -36,6 +37,7 @@ export const ExperimentalSuites = freezeSuites([
3637
{
3738
name: "TodoMVC-Emoji",
3839
url: "suites/todomvc/vanilla-examples/javascript-web-components/dist/index.html",
40+
resources: "suites/todomvc/vanilla-examples/javascript-web-components/dist/resources.txt",
3941
tags: ["todomvc", "experimental"],
4042
async prepare(page) {
4143
await page.waitForElement("todo-app");
@@ -68,6 +70,7 @@ export const ExperimentalSuites = freezeSuites([
6870
{
6971
name: "TodoMVC-WebComponents-PostMessage",
7072
url: "suites/todomvc/vanilla-examples/javascript-web-components/dist/index.html",
73+
resources: "suites/todomvc/vanilla-examples/javascript-web-components/dist/resources.txt",
7174
tags: ["experimental", "todomvc", "webcomponents"],
7275
async prepare() {},
7376
type: "remote",
@@ -78,6 +81,7 @@ export const ExperimentalSuites = freezeSuites([
7881
{
7982
name: "TodoMVC-Jaspr-Dart2JS-O4",
8083
url: "suites-experimental/todomvc-dart-jaspr/dist/out-dart2js-O4/index.html",
84+
resources: "suites-experimental/todomvc-dart-jaspr/dist/out-dart2js-O4/resources.txt",
8185
tags: ["todomvc", "experimental"],
8286
async prepare(page) {
8387
(await page.waitForElement(".new-todo")).focus();
@@ -106,6 +110,7 @@ export const ExperimentalSuites = freezeSuites([
106110
{
107111
name: "TodoMVC-Jaspr-Dart2Wasm-O2",
108112
url: "suites-experimental/todomvc-dart-jaspr/dist/out-dart2wasm-O2/index.html",
113+
resources: "suites-experimental/todomvc-dart-jaspr/dist/out-dart2wasm-O2/resources.txt",
109114
tags: ["todomvc", "experimental"],
110115
disabled: true,
111116
async prepare(page) {
@@ -135,6 +140,7 @@ export const ExperimentalSuites = freezeSuites([
135140
{
136141
name: "NewsSite-PostMessage",
137142
url: "suites/newssite/news-next/dist/index.html",
143+
resources: "suites/newssite/news-next/dist/resources.txt",
138144
tags: ["experimental", "newssite", "language"],
139145
async prepare() {},
140146
type: "remote",
@@ -145,6 +151,7 @@ export const ExperimentalSuites = freezeSuites([
145151
{
146152
name: "TodoMVC-WebComponents-IndexedDB",
147153
url: "suites-experimental/javascript-wc-indexeddb/dist/index.html?useAsyncSteps=true&storageType=vanilla",
154+
resources: "suites-experimental/javascript-wc-indexeddb/dist/resources.txt",
148155
tags: ["todomvc", "webcomponents", "experimental"],
149156
async prepare() {},
150157
type: "remote",
@@ -155,6 +162,7 @@ export const ExperimentalSuites = freezeSuites([
155162
{
156163
name: "TodoMVC-WebComponents-DexieJS",
157164
url: "suites-experimental/javascript-wc-indexeddb/dist/index.html?useAsyncSteps=true&storageType=dexie",
165+
resources: "suites-experimental/javascript-wc-indexeddb/dist/resources.txt",
158166
tags: ["todomvc", "webcomponents", "experimental"],
159167
async prepare() {},
160168
type: "remote",
@@ -165,6 +173,7 @@ export const ExperimentalSuites = freezeSuites([
165173
{
166174
name: "Responsive-Design",
167175
url: "suites-experimental/responsive-design/dist/index.html",
176+
resources: "suites-experimental/responsive-design/dist/resources.txt",
168177
tags: ["responsive-design", "webcomponents", "experimental"],
169178
type: "async",
170179
async prepare(page) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
base.css
2+
favicon.ico
3+
index.css
4+
index.html
5+
main.dart.js
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
base.css
2+
favicon.ico
3+
index.css
4+
index.html
5+
main.dart.js
6+
main.mjs
7+
main.wasm
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
app.js
2+
base.css
3+
controller.js
4+
helpers.js
5+
index.css
6+
index.html
7+
model.js
8+
store.js
9+
template.js
10+
view.js

suites-experimental/todomvc-localstorage/scripts/build.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { generateResourcesFile } from "../../../resources/shared/generate-resources.mjs";
12
import fs from "fs/promises";
23
import path from "path";
34

@@ -53,4 +54,5 @@ const build = async () => {
5354
console.log("done!!");
5455
};
5556

56-
build();
57+
await build();
58+
await generateResourcesFile(path.join(import.meta.dirname, "../dist"));
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
app.js
2+
controller.js
3+
helpers.js
4+
model.js
5+
store.js
6+
template.js
7+
view.js

0 commit comments

Comments
 (0)