Initial rewrite
This commit is contained in:
parent
a5f64a3ff8
commit
0d183c8335
200 changed files with 12537 additions and 18659 deletions
53
scripts/check-no-js.mjs
Normal file
53
scripts/check-no-js.mjs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import { readdir, readFile, stat } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
|
||||
const dist = path.resolve('dist');
|
||||
const failures = [];
|
||||
|
||||
async function walk(dir) {
|
||||
const entries = await readdir(dir, { withFileTypes: true });
|
||||
const files = [];
|
||||
|
||||
for (const entry of entries) {
|
||||
const fullPath = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
files.push(...(await walk(fullPath)));
|
||||
} else {
|
||||
files.push(fullPath);
|
||||
}
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
try {
|
||||
await stat(dist);
|
||||
} catch {
|
||||
throw new Error('dist/ does not exist. Run npm run build first.');
|
||||
}
|
||||
|
||||
const files = await walk(dist);
|
||||
const jsFiles = files.filter((file) => file.endsWith('.js'));
|
||||
|
||||
if (jsFiles.length > 0) {
|
||||
failures.push(
|
||||
`Unexpected JavaScript assets:\n${jsFiles.map((file) => `- ${file}`).join('\n')}`
|
||||
);
|
||||
}
|
||||
|
||||
for (const file of files.filter((candidate) => candidate.endsWith('.html'))) {
|
||||
const html = await readFile(file, 'utf8');
|
||||
const scripts = (
|
||||
html.match(/<script\b(?![^>]*type=["']application\/ld\+json["'])[^>]*>/gi) ?? []
|
||||
).filter((script) => !script.includes('data-theme-script'));
|
||||
if (scripts?.length) {
|
||||
failures.push(`Unexpected script tag in ${file}:\n${scripts.join('\n')}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (failures.length > 0) {
|
||||
console.error(failures.join('\n\n'));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('No unexpected JavaScript found in dist/.');
|
||||
Loading…
Add table
Add a link
Reference in a new issue