Skip to content

Commit 0b0e9b7

Browse files
committed
Fixed screenshot generation on Windows
1 parent 5728780 commit 0b0e9b7

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

tools/generate-screenshots.js

+14
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ examples = examples
2626
e.path
2727
.toLowerCase()
2828
.replace("public/src/", "public/screenshots/")
29+
.replace("public\\src\\", "public\\screenshots\\")
2930
.replace(/\.json/, "")
3031
.replace(/\.js/, "") + ".png",
3132
}));
3233

3334
let screenshots = [];
35+
3436
getScreenshots(screenshots, "./public/screenshots");
37+
3538
screenshots = screenshots.map((s) => s.toLowerCase());
3639

3740
const saveCanvas = async (page, example) => {
@@ -81,20 +84,31 @@ const saveCanvas = async (page, example) => {
8184
};
8285

8386
async function run() {
87+
88+
let missing = 0;
89+
8490
const browser = await puppeteer.launch({
8591
headless: true,
8692
});
8793

8894
const [page] = await browser.pages();
95+
8996
await page.setUserAgent(
9097
"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1"
9198
);
9299

93100
for (let example of examples.filter((e) => !screenshots.includes(e.path))) {
101+
94102
await saveCanvas(page, example);
103+
104+
missing++;
105+
95106
}
96107

108+
console.log(`Added ${missing} missing screenshots out of ${examples.length} examples`);
109+
97110
await browser.close();
111+
98112
server.close();
99113
}
100114

tools/utils.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,30 @@ const getExamples = (examples, path, depth = 0) => {
3434
};
3535

3636
const getScreenshots = (screenshots, path, depth = 0) => {
37+
3738
const files = fs.readdirSync(path);
39+
3840
if (depth > maxDepth) {
3941
return;
4042
}
43+
4144
for (let file of files) {
42-
const fileInfo = fs.statSync(p.resolve(path, file));
43-
if (fileInfo.isDirectory()) {
44-
getScreenshots(screenshots, p.resolve(path, file), depth + 1);
45+
46+
const loc = p.resolve(path, file);
47+
48+
const fileInfo = fs.statSync(loc);
49+
50+
if (fileInfo.isDirectory())
51+
{
52+
getScreenshots(screenshots, loc, depth + 1);
53+
}
54+
else
55+
{
56+
// console.log(loc);
57+
screenshots.push(loc);
4558
}
46-
screenshots.push(p.resolve(path, file));
4759
}
60+
4861
};
4962

5063
module.exports = {

0 commit comments

Comments
 (0)