Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build configuration #64

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const main = async () => {
const pkg = readJson("./package.json");
const config = readJson("./config.json");
const entries = Object.keys(config.entries);
const { sizes, formats } = config.screenshot;

const publicUrl = pkg.targets.default.publicUrl;
const port = 1234;
Expand Down Expand Up @@ -88,7 +89,6 @@ const main = async () => {
return;
}
const page = await browser.newPage();
const screenSizes = [780, 338, 288];

const downloadAndSave = async (entry, size, format) => {
await page.locator("#graphic > iframe").waitFor("attached");
Expand All @@ -110,15 +110,17 @@ const main = async () => {
};

const shots = entries
.map((entry) => screenSizes.map((size) => ({ entry, size })))
.map((entry) => sizes.map((size) => ({ entry, size })))
.flat();

for await (const { entry, size } of shots) {
await page.goto(`${baseUrl}?width=${size}&entry=${entry}`, {
waitUntil: "networkidle",
});
await downloadAndSave(entry, size, "png");
await downloadAndSave(entry, size, "svg");

for await (const format of formats) {
await downloadAndSave(entry, size, format);
}
}
await browser.close();
await subscriber.unsubscribe();
Expand Down
4 changes: 4 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,9 @@
"key": "",
"build": "./dist",
"profile": "sink"
},
"screenshot": {
"sizes": [780, 338, 288],
"formats": ["svg"]
}
}