Spaces:
Paused
Paused
File size: 1,004 Bytes
3dc792e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import { mkdir } from "node:fs/promises";
import { join } from "node:path";
export function sanitizePathSegment(value: string): string {
return value
.trim()
.replace(/[^a-zA-Z0-9._-]+/g, "-")
.replace(/^-+|-+$/g, "")
.slice(0, 80);
}
export function isoTimestampForPath(date = new Date()): string {
return date.toISOString().replace(/[:.]/g, "-");
}
export async function createRunDirectory(
outputDir: string,
journeyId: string,
startedAt = new Date(),
): Promise<{ runId: string; runDir: string }> {
const runId = `${isoTimestampForPath(startedAt)}-${sanitizePathSegment(journeyId)}`;
const runDir = join(outputDir, runId);
await mkdir(join(runDir, "screenshots"), { recursive: true });
await mkdir(join(runDir, "snapshots"), { recursive: true });
await mkdir(join(runDir, "console"), { recursive: true });
await mkdir(join(runDir, "network"), { recursive: true });
await mkdir(join(runDir, "ui-changes"), { recursive: true });
return { runId, runDir };
}
|