import { readFile, readdir, stat } from 'node:fs/promises'; import assert from 'node:assert/strict'; import { createHash } from 'node:crypto'; for (const path of ['dist/index.html', 'dist/download.html', 'dist/help.html', 'dist/compare.html', 'dist/404.html', 'dist/privacy.html', 'dist/app-notices.html']) { const html = await readFile(path, 'utf8'); assert.ok(html.includes('|/); for (const tag of ['og:title', 'og:description', 'og:url', 'og:image', 'og:image:alt', 'twitter:card', 'twitter:image', 'application/ld+json']) assert.ok(html.includes(tag), `${path} needs ${tag}`); assert.equal((html.match(//g) || []).length, 1, `${path} needs exactly one title`); } const html = await readFile('dist/index.html', 'utf8'); const download = await readFile('dist/download.html', 'utf8'); assert.match(html, /href="\/download"[^>]*><svg[^>]*class="mac-download-icon"[^>]*>.*?<\/svg>Download for Mac/); assert.doesNotMatch(html, /href="[^"]+\.dmg"/); assert.match(download, /How to install Inkspring/); const installer = download.match(/href="(\/updates\/[^"]+\.dmg)" download/); assert.ok(installer, 'Download page must link to the installer'); const installerBytes = await readFile('dist' + installer[1]); assert.ok(download.includes(createHash('sha256').update(installerBytes).digest('hex')), 'Download page must show the installer checksum'); const appcast = await readFile('dist/updates/appcast.xml', 'utf8'); assert.ok(appcast.includes(`url="https://inkspring.ai${installer[1]}" length="${installerBytes.length}"`), 'Sparkle must use the same DMG as the download page'); assert.ok((await readdir('dist/updates')).every(file => !file.endsWith('.zip')), 'The site must only distribute DMG installers'); const missing = await readFile('dist/404.html', 'utf8'); assert.match(missing, /name="robots" content="noindex, follow"/); assert.match(missing, /<h1>This page went missing\.<\/h1>/); const help = await readFile('dist/help.html', 'utf8'); assert.match(help, /<h1>Inkspring Help<\/h1>/); for (const [, anchor] of help.matchAll(/href="#([^"]+)"/g)) { assert.ok(help.includes(`id="${anchor}"`), `Help anchor #${anchor} needs a destination`); } for (const page of [html, download, help]) { for (const asset of page.matchAll(/(?:src|href)="(\/[^"#?]+\.(?:js|css|png|jpg|svg|woff2))"/g)) await stat('dist' + asset[1]); } const comparePage = await readFile('dist/compare.html', 'utf8'); assert.match(comparePage, /<h1>Inkspring compared with /); assert.match(comparePage, /"@type":"FAQPage"/, 'Compare page needs its FAQ data'); const files = await readdir('dist'); assert.ok(!files.includes('api') && !files.includes('server')); await stat('dist/og/inkspring-monochrome.png'); for (const path of ['dist/index.html', 'dist/download.html', 'dist/help.html', 'dist/compare.html', 'dist/404.html', 'dist/privacy.html', 'dist/app-notices.html']) assert.doesNotMatch(await readFile(path, 'utf8'), /src="\/analytics\.js"|googletagmanager|data-analytics-settings/i); assert.doesNotMatch(await readFile('dist/index.html', 'utf8'), /projectatom\.ai/); assert.match(await readFile('dist/index.html', 'utf8'), /data-visitor-site="inkspring"/); console.log('Static page checks passed.');