40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { runSeed, deleteProject } from './seed.js';
|
|
import { readArtifact, writeArtifact, removeArtifact } from './artifact.js';
|
|
import type { SeedArtifact } from './types.js';
|
|
|
|
export default async function setup(): Promise<() => Promise<void>> {
|
|
const baseUrl = process.env.RUDDER_E2E_BASE_URL ?? 'https://api.rudder.build';
|
|
|
|
if (process.env.RUDDER_E2E_PROJECT_KEY) {
|
|
const existing = readArtifact();
|
|
if (!existing) {
|
|
writeArtifact({
|
|
baseUrl,
|
|
projectKey: process.env.RUDDER_E2E_PROJECT_KEY,
|
|
} as unknown as SeedArtifact);
|
|
}
|
|
return async () => {};
|
|
}
|
|
|
|
const log = (m: string) => console.log(`[seed] ${m}`);
|
|
log(`seeding ${baseUrl} ...`);
|
|
const artifact = await runSeed(baseUrl, log);
|
|
writeArtifact(artifact);
|
|
log(`seed complete: project=${artifact.projectId}`);
|
|
|
|
return async () => {
|
|
if (process.env.RUDDER_E2E_KEEP === '1') {
|
|
console.log('[seed] RUDDER_E2E_KEEP=1 — leaving project in place');
|
|
return;
|
|
}
|
|
try {
|
|
await deleteProject(artifact);
|
|
console.log(`[seed] deleted project ${artifact.projectId}`);
|
|
} catch (err) {
|
|
console.warn(`[seed] failed to delete project ${artifact.projectId}: ${String(err)}`);
|
|
} finally {
|
|
removeArtifact();
|
|
}
|
|
};
|
|
}
|