@rettangoli/vt 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cli/generate.js +13 -3
- package/src/cli/report.js +3 -4
- package/src/common.js +14 -4
package/package.json
CHANGED
package/src/cli/generate.js
CHANGED
|
@@ -74,7 +74,7 @@ async function main(options) {
|
|
|
74
74
|
templateConfig,
|
|
75
75
|
);
|
|
76
76
|
|
|
77
|
-
// Generate overview page
|
|
77
|
+
// Generate overview page (includes all files, skipped or not)
|
|
78
78
|
generateOverview(
|
|
79
79
|
generatedFiles,
|
|
80
80
|
indexTemplatePath,
|
|
@@ -82,12 +82,22 @@ async function main(options) {
|
|
|
82
82
|
configData,
|
|
83
83
|
);
|
|
84
84
|
|
|
85
|
-
// Take screenshots
|
|
85
|
+
// Take screenshots (only for non-skipped files)
|
|
86
86
|
if (!skipScreenshots) {
|
|
87
|
+
// Filter out files with skipScreenshot: true in frontmatter
|
|
88
|
+
const filesToScreenshot = generatedFiles.filter(
|
|
89
|
+
(file) => !file.frontMatter?.skipScreenshot
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const skippedCount = generatedFiles.length - filesToScreenshot.length;
|
|
93
|
+
if (skippedCount > 0) {
|
|
94
|
+
console.log(`Skipping screenshots for ${skippedCount} files`);
|
|
95
|
+
}
|
|
96
|
+
|
|
87
97
|
const server = configUrl ? null : startWebServer(siteOutputPath, vtPath, port);
|
|
88
98
|
try {
|
|
89
99
|
await takeScreenshots(
|
|
90
|
-
|
|
100
|
+
filesToScreenshot,
|
|
91
101
|
`http://localhost:${port}`,
|
|
92
102
|
candidatePath,
|
|
93
103
|
24,
|
package/src/cli/report.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import crypto from "crypto";
|
|
4
|
-
import sharp from "sharp";
|
|
5
4
|
import { Liquid } from "liquidjs";
|
|
6
5
|
import { cp } from "node:fs/promises";
|
|
7
6
|
|
|
@@ -227,19 +226,19 @@ async function main(options = {}) {
|
|
|
227
226
|
};
|
|
228
227
|
console.log(JSON.stringify(logData, null, 2));
|
|
229
228
|
});
|
|
230
|
-
|
|
229
|
+
|
|
231
230
|
// Summary at the end
|
|
232
231
|
console.log(`\nSummary:`);
|
|
233
232
|
console.log(`Total images: ${results.length}`);
|
|
234
233
|
console.log(`Mismatched images: ${mismatchingItems.length}`);
|
|
235
|
-
|
|
234
|
+
|
|
236
235
|
// Generate HTML report
|
|
237
236
|
await generateReport({
|
|
238
237
|
results: mismatchingItems,
|
|
239
238
|
templatePath,
|
|
240
239
|
outputPath,
|
|
241
240
|
});
|
|
242
|
-
if(mismatchingItems.length > 0){
|
|
241
|
+
if(mismatchingItems.length > 0){
|
|
243
242
|
console.error("Error: there are more than 0 mismatching item.")
|
|
244
243
|
process.exit(1);
|
|
245
244
|
}
|
package/src/common.js
CHANGED
|
@@ -284,13 +284,23 @@ async function takeScreenshots(
|
|
|
284
284
|
// Create a new context and page for each file (for parallelism)
|
|
285
285
|
const context = await browser.newContext();
|
|
286
286
|
const page = await context.newPage();
|
|
287
|
-
let screenshotIndex = 0;
|
|
288
287
|
|
|
289
288
|
try {
|
|
289
|
+
const envVars = {};
|
|
290
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
291
|
+
if (key.startsWith('RTGL_VT_')) {
|
|
292
|
+
envVars[key] = value;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (Object.keys(envVars).length > 0) {
|
|
297
|
+
await page.addInitScript((vars) => {
|
|
298
|
+
Object.assign(window, vars);
|
|
299
|
+
}, envVars);
|
|
300
|
+
}
|
|
301
|
+
|
|
290
302
|
const frontMatterUrl = file.frontMatter?.url;
|
|
291
|
-
const constructedUrl = convertToHtmlExtension(
|
|
292
|
-
`${serverUrl}/candidate/${file.path.replace(/\\/g, "/")}`,
|
|
293
|
-
);
|
|
303
|
+
const constructedUrl = convertToHtmlExtension(`${serverUrl}/candidate/${file.path.replace(/\\/g, "/")}`);
|
|
294
304
|
const url = frontMatterUrl ?? configUrl ?? constructedUrl;
|
|
295
305
|
const fileUrl = url.startsWith("http") ? url : new URL(url, serverUrl).href;
|
|
296
306
|
|