DEV Community

Marrakech Transport
Marrakech Transport

Posted on

Automating Price Validation Across 633 Static Pages Before Every Deploy

Here's a nightmare scenario for any service-oriented website: a pricing error ships to production, a customer sees it, and you're either honouring a wrong price or having an awkward conversation.

For navetteforyou.com — a private transfer booking site serving Marrakech — pricing accuracy isn't just a nice-to-have. It's a business rule: no price below a certain floor should ever appear on any page, in any language, in any format. Not in the HTML, not in the structured data, not in a PDF guide.

We solved this with a pre-deploy validation script that runs in under 10 seconds and catches every violation before it reaches Vercel.

The Problem

Our site generates 633 static HTML pages at build time across 8 languages. Each page can contain:

  • Visible prices in the booking widget
  • Schema.org JSON-LD with price ranges
  • Guide content mentioning fare examples
  • Meta descriptions that sometimes reference pricing

A single typo — 300 instead of 3000, or a test value left in a translation file — could propagate across dozens of pages before anyone notices.

The Solution: static-price-check.ts

The script is deceptively simple:

import { readdir, readFile } from "node:fs/promises";
import { join } from "node:path";

const FLOOR = 600; // MAD — nothing below this should appear
const DIST_DIR = "dist";
const PRICE_REGEX = /(?:MAD|درهم|DH)\s*(\d[\d\s.,]*\d|\d+)/gi;
const ALT_REGEX = /(\d[\d\s.,]*\d|\d+)\s*(?:MAD|درهم|DH)/gi;

async function* walkHtml(dir: string): AsyncGenerator<string> {
  for (const entry of await readdir(dir, { withFileTypes: true })) {
    const path = join(dir, entry.name);
    if (entry.isDirectory()) yield* walkHtml(path);
    else if (entry.name.endsWith(".html")) yield path;
  }
}

let pages = 0, amounts = 0, violations: string[] = [];

for await (const file of walkHtml(DIST_DIR)) {
  pages++;
  const html = await readFile(file, "utf-8");

  for (const regex of [PRICE_REGEX, ALT_REGEX]) {
    let match;
    while ((match = regex.exec(html)) !== null) {
      const raw = match[1].replace(/[\s.,]/g, "");
      const value = parseInt(raw, 10);
      if (!isNaN(value)) {
        amounts++;
        if (value > 0 && value < FLOOR) {
          violations.push(`${file}: ${match[0]} (${value} MAD)`);
        }
      }
    }
  }
}

console.log(`Scanned ${pages} pages, ${amounts} amounts.`);
if (violations.length) {
  console.error("FAIL — prices below floor:");
  violations.forEach(v => console.error(`  ${v}`));
  process.exit(1);
} else {
  console.log("PASS");
}
Enter fullscreen mode Exit fullscreen mode

What It Catches

The regex patterns match prices in multiple formats:

  • MAD 600 / 600 MAD (English/European format)
  • درهم 600 / 600 درهم (Arabic format)
  • DH 600 / 600 DH (informal Moroccan format)
  • 1,200 MAD / MAD 1.200 (thousands separators)

It scans the raw HTML, which means it catches prices in:

  • Visible text content
  • JSON-LD structured data blocks
  • Alt text on images
  • Meta tags
  • PDF link text

Integration with the Deploy Pipeline

The script runs as a gate before every production deploy:

bun run build           # Generate all 633 pages
bun scripts/static-price-check.ts  # Validate pricing
npx vercel deploy --prebuilt --prod --yes  # Deploy only if PASS
Enter fullscreen mode Exit fullscreen mode

If the script exits with code 1 (violations found), the deploy doesn't happen. This is enforced both locally and could be added to CI.

Real Numbers

On our last deploy:

Scanned 633 pages, 17113 amounts.
PASS
Enter fullscreen mode Exit fullscreen mode

17,113 price amounts checked across 633 pages in about 4 seconds. The script is fast because it's just string scanning — no DOM parsing, no headless browser, no network requests.

Why This Matters Beyond Pricing

The pattern generalises. Any business rule that can be expressed as "this value must never appear in the output" can use the same approach:

  • Phone numbers: Ensure only your official number appears (catch test numbers left in translations)
  • Competitor names: Flag accidental mentions
  • Deprecated URLs: Catch old domains that should have been updated
  • Banned words: Ensure brand guidelines are met across all locales

Lessons Learned

Regex is good enough. We considered using a proper HTML parser, but for price extraction, regex against the raw HTML is simpler, faster, and catches everything including content inside <script> tags (where JSON-LD lives).

Run it on the build output, not the source. Scanning dist/ catches issues from every layer: content files, translation strings, computed values, template logic. Scanning source files would miss half the surface area.

Make it fast. A validation script that takes 30 seconds gets skipped. Ours takes 4 seconds. That's fast enough to run on every single deploy without friction.

Exit codes matter. The script exits 0 on pass, 1 on fail. This lets it slot into any CI pipeline with zero configuration — && chaining handles the rest.

The full stack: Astro for static generation, Bun for the validation script runtime, Vercel for hosting.

Operated by Serenity Morocco Tours — visit navetteforyou.com or reach us on WhatsApp at +212 701 664 704.

Top comments (0)