Files
3031023-xyz-public/scripts/verify-build.mjs
T

39 lines
2.6 KiB
JavaScript

import { access, readFile } from 'node:fs/promises';
import { resolve } from 'node:path';
const key = process.env.SITE_KEY;
if (!key) throw new Error('SITE_KEY is required.');
const root = resolve(`dist/${key}`);
const required = ['index.html', '404.html', 'robots.txt', 'sitemap.xml'];
if (key === 'www') required.push('about/index.html', 'services/index.html', 'contact/index.html');
for (const file of required) await access(resolve(root, file));
const pages = await Promise.all(required.filter((file) => file.endsWith('.html')).map(async (file) => ({ file, html: await readFile(resolve(root, file), 'utf8') })));
for (const { file, html } of pages) {
if (html.includes('{{') || html.includes('{%')) throw new Error(`${file} contains an unresolved template placeholder.`);
if (!/<title>[^<]+<\/title>/.test(html)) throw new Error(`${file} is missing a title.`);
for (const match of html.matchAll(/(?:src|href)="(\/images\/[^"?#]+)"/g)) await access(resolve(root, `.${match[1]}`));
}
const home = await readFile(resolve(root, 'index.html'), 'utf8');
if (key === 'www') {
for (const question of ['What services do you offer?', 'How do I book a visit?', 'How far ahead should I book pet care?', 'Can you accommodate special routines?']) if (!home.includes(question)) throw new Error(`Primary FAQ Markdown entry is missing: ${question}.`);
if (home.includes('What information should I bring to a meet and greet?')) throw new Error('Draft FAQ entry appeared in the homepage.');
const services = await readFile(resolve(root, 'services/index.html'), 'utf8');
for (const title of ['Dog walking', 'Grooming', 'Overnight care']) if (!services.includes(title)) throw new Error(`Service Markdown entry is missing: ${title}.`);
const about = await readFile(resolve(root, 'about/index.html'), 'utf8');
for (const name of ['Sarah Mitchell', 'Marcus Rivera', 'Emily Chen', 'David Okonkwo']) if (!about.includes(name)) throw new Error(`Team Markdown entry is missing: ${name}.`);
}
if (key === 'blog') {
const publishedPosts = ['first-walk-after-work', 'gentler-grooming-day', 'overnight-care-checklist', 'weekend-care-prep'];
await Promise.all(publishedPosts.map((slug) => access(resolve(root, `posts/${slug}/index.html`))));
if (home.includes('Draft only example for editorial review')) throw new Error('Draft blog post appeared in the journal.');
try {
await access(resolve(root, 'posts/draft-only-example/index.html'));
throw new Error('Draft blog post generated a public page.');
} catch (error) {
if (error?.code !== 'ENOENT') throw error;
}
}
console.log(`Verified ${key}: ${required.join(', ')}`);