You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.8 KiB
106 lines
3.8 KiB
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { execFileSync } from 'node:child_process';
|
|
|
|
const projectRoot = process.cwd();
|
|
const srcDir = path.join(projectRoot, 'src');
|
|
const publicDir = path.join(projectRoot, 'public');
|
|
|
|
function walkFiles(dir) {
|
|
const results = [];
|
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
const full = path.join(dir, entry.name);
|
|
if (entry.isDirectory()) {
|
|
results.push(...walkFiles(full));
|
|
} else if (entry.isFile() && /\.(ts|tsx|css)$/.test(entry.name)) {
|
|
results.push(full);
|
|
}
|
|
}
|
|
return results;
|
|
}
|
|
|
|
const files = walkFiles(srcDir);
|
|
const assetRegex = /\/assets\/images\/[a-zA-Z0-9_./-]+\.(?:svg|png)/g;
|
|
const referencedAssets = new Map();
|
|
|
|
for (const file of files) {
|
|
const content = fs.readFileSync(file, 'utf8');
|
|
const matches = content.match(assetRegex) || [];
|
|
for (const m of matches) {
|
|
if (!referencedAssets.has(m)) {
|
|
referencedAssets.set(m, []);
|
|
}
|
|
referencedAssets.get(m).push(path.relative(projectRoot, file));
|
|
}
|
|
}
|
|
|
|
let missingCount = 0;
|
|
for (const [assetPath, refs] of referencedAssets.entries()) {
|
|
const diskPath = path.join(publicDir, assetPath.replace(/^\//, ''));
|
|
if (!fs.existsSync(diskPath)) {
|
|
console.error(`MISSING ASSET: ${assetPath} (referenced in ${refs.join(', ')})`);
|
|
missingCount++;
|
|
} else {
|
|
const stat = fs.statSync(diskPath);
|
|
if (stat.size === 0) {
|
|
console.error(`EMPTY ASSET: ${assetPath}`);
|
|
missingCount++;
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log(`Checked ${referencedAssets.size} unique asset paths across ${files.length} source files.`);
|
|
if (missingCount === 0) {
|
|
console.log('ALL REFERENCED ASSETS EXIST AND ARE NON-EMPTY!');
|
|
} else {
|
|
process.exitCode = 1;
|
|
}
|
|
|
|
// Check for browser binary to capture verification screenshots
|
|
const browserCandidates = [
|
|
'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
|
|
'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
|
|
'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe',
|
|
'C:\\Program Files\\Microsoft\\Edge\\Application\\msedge.exe',
|
|
];
|
|
|
|
const browserExe = browserCandidates.find((p) => fs.existsSync(p));
|
|
if (browserExe) {
|
|
console.log(`Found browser for headless screenshots: ${browserExe}`);
|
|
const outDir = 'C:\\Users\\sajjadi\\.gemini\\antigravity\\brain\\a47845ed-184b-46c9-81b1-4e446791ee9a\\scratch\\screenshots';
|
|
fs.mkdirSync(outDir, { recursive: true });
|
|
|
|
const targets = [
|
|
{ name: 'test-hub', url: 'http://localhost:5174/test', width: 1280, height: 950 },
|
|
{ name: 'shop-home', url: 'http://localhost:5174/shop-home?bare=1', width: 375, height: 1150 },
|
|
{ name: 'shop-booth', url: 'http://localhost:5174/shop-booth?bare=1', width: 375, height: 1233 },
|
|
{ name: 'shop-single-page', url: 'http://localhost:5174/shop-single-page?bare=1', width: 375, height: 1233 },
|
|
{ name: 'shop-cart', url: 'http://localhost:5174/shop-cart?bare=1', width: 375, height: 814 },
|
|
{ name: 'shop-order-detail', url: 'http://localhost:5174/shop-order-detail?bare=1', width: 375, height: 1061 },
|
|
{ name: 'provider-requst', url: 'http://localhost:5174/provider-requst?bare=1', width: 375, height: 1768 },
|
|
];
|
|
|
|
for (const t of targets) {
|
|
const outFile = path.join(outDir, `${t.name}.png`);
|
|
try {
|
|
execFileSync(
|
|
browserExe,
|
|
[
|
|
'--headless=new',
|
|
'--disable-gpu',
|
|
'--hide-scrollbars',
|
|
`--window-size=${t.width},${t.height}`,
|
|
`--screenshot=${outFile}`,
|
|
'--virtual-time-budget=2000',
|
|
t.url,
|
|
],
|
|
{ stdio: 'pipe', timeout: 15000 }
|
|
);
|
|
console.log(`Captured ${outFile}`);
|
|
} catch (err) {
|
|
console.warn(`Could not capture ${t.name}: ${err.message}`);
|
|
}
|
|
}
|
|
} else {
|
|
console.log('No standard Chrome/Edge binary found for headless screenshots.');
|
|
}
|