Replay · Replay entrypoint

Pipeline entrypoint

How is the entire investigation replayed?

What this proves

This entrypoint captures the request, runs the measurements, and rebuilds the publication.

Input
Capture and counting scripts
Output
Rebuilt evidence and publication
File
scripts/run-pipeline.mjs

Inspect the replay entrypoint

JavaScript View raw
#!/usr/bin/env node
import { spawn } from "node:child_process";
import { resolve } from "node:path";
import { scriptsDir } from "./lib.mjs";

const publicationDir = resolve(scriptsDir, "../site");

function runProcess(command, args, options = {}) {
  return new Promise((resolvePromise, rejectPromise) => {
    const child = spawn(command, args, {
      stdio: "inherit",
      env: process.env,
      ...options,
    });
    child.once("error", rejectPromise);
    child.once("exit", (code, signal) => {
      if (code === 0) resolvePromise();
      else rejectPromise(new Error(`${command} failed (${signal || `exit ${code}`})`));
    });
  });
}

function runScript(script, args = []) {
  return runProcess(process.execPath, [resolve(scriptsDir, script), ...args]);
}

async function main() {
  const countArgs = process.argv.slice(2).filter((arg) => arg !== "--capture-only");
  await runScript("capture-sdk-request.mjs");
  if (!process.argv.includes("--capture-only")) {
    await runScript("count-tokens.mjs", countArgs);
    await runProcess("npm", ["run", "build"], { cwd: publicationDir });
  }
}

main().catch((error) => {
  console.error(error.message);
  process.exitCode = 1;
});