Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ Netlify settings:
- Build command: blank
- Publish directory: `.`

Route rewrites are maintained in `netlify.toml` (`[[redirects]]` entries) to keep deploy configuration centralized.

Run `npm run check` before deploying.
6 changes: 1 addition & 5 deletions _redirects
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
/start-a-project /start-a-project.html 200
/fix-list-builder /fix-list-builder.html 200
/maintenance-plans /maintenance-plans.html 200
/inspection-report-repairs /inspection-report-repairs.html 200
/thank-you /thank-you.html 200
# Route rewrites are maintained in netlify.toml.
34 changes: 33 additions & 1 deletion scripts/check-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ const requiredFiles = [
"assets/styles.css",
"assets/app.js",
"netlify.toml",
"_redirects",
"robots.txt",
"sitemap.xml",
];

const requiredRewrites = [
["/start-a-project", "/start-a-project.html"],
["/fix-list-builder", "/fix-list-builder.html"],
["/maintenance-plans", "/maintenance-plans.html"],
["/inspection-report-repairs", "/inspection-report-repairs.html"],
["/thank-you", "/thank-you.html"],
];

const formRequirements = {
"start-a-project.html": "vail-project-intake",
"fix-list-builder.html": "vail-fix-list",
Expand All @@ -35,6 +42,10 @@ function exists(file) {
return fs.existsSync(path.join(root, file));
}

function escapeRegExp(value) {
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}

for (const file of requiredFiles) {
if (!exists(file)) {
failures.push(`Missing required file: ${file}`);
Expand Down Expand Up @@ -92,6 +103,27 @@ if (exists("netlify.toml")) {
if (!/command\s*=\s*["']["']/.test(netlifyConfig)) {
failures.push('netlify.toml must contain command = ""');
}

for (const [from, to] of requiredRewrites) {
const rewritePattern = new RegExp(
`\\[\\[redirects\\]\\][\\s\\S]*?from\\s*=\\s*["']${escapeRegExp(from)}["'][\\s\\S]*?to\\s*=\\s*["']${escapeRegExp(to)}["'][\\s\\S]*?status\\s*=\\s*200`,
"m",
);

if (!rewritePattern.test(netlifyConfig)) {
failures.push(`netlify.toml is missing rewrite ${from} -> ${to} (200)`);
}
}
}

if (exists("_redirects")) {
const redirects = read("_redirects");
for (const [from, to] of requiredRewrites) {
const redirectLine = new RegExp(`^\\s*${escapeRegExp(from)}\\s+${escapeRegExp(to)}\\s+200\\s*$`, "m");
if (redirectLine.test(redirects)) {
failures.push(`_redirects duplicates netlify.toml rewrite ${from} -> ${to} (200)`);
}
}
}

if (failures.length > 0) {
Expand Down
Loading