Fable clean up
This commit is contained in:
parent
3441a7e4af
commit
4ce8a4f41d
46 changed files with 642 additions and 911 deletions
|
|
@ -1,59 +1,17 @@
|
|||
import { readdir, readFile, stat } from 'node:fs/promises';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { dist, requireDist, resolveFile } from './lib/dist.mjs';
|
||||
import { walk } from './lib/walk.mjs';
|
||||
|
||||
const dist = path.resolve('dist');
|
||||
const allowedPreservedRoutes = new Set(['/fleeting/', '/reconcile/']);
|
||||
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;
|
||||
}
|
||||
|
||||
async function exists(file) {
|
||||
try {
|
||||
return (await stat(file)).isFile();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function targetExists(pathname) {
|
||||
if (allowedPreservedRoutes.has(pathname)) return true;
|
||||
|
||||
const safePath = path
|
||||
.normalize(decodeURIComponent(pathname))
|
||||
.replace(/^\/+/, '')
|
||||
.replace(/^(\.\.(\/|\\|$))+/, '');
|
||||
const candidate = path.join(dist, safePath);
|
||||
const candidates = [
|
||||
candidate,
|
||||
path.join(candidate, 'index.html'),
|
||||
path.join(dist, `${safePath}.html`),
|
||||
];
|
||||
|
||||
for (const file of candidates) {
|
||||
if (await exists(file)) return true;
|
||||
}
|
||||
return false;
|
||||
return (await resolveFile(pathname)) !== null;
|
||||
}
|
||||
|
||||
try {
|
||||
await stat(dist);
|
||||
} catch {
|
||||
throw new Error('dist/ does not exist. Run npm run build first.');
|
||||
}
|
||||
await requireDist();
|
||||
|
||||
const files = await walk(dist);
|
||||
const checkedFiles = files.filter((file) => /\.(html|xml|css|webmanifest)$/.test(file));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue