Skip to content
Merged
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
5 changes: 5 additions & 0 deletions packages/playground/blueprints/src/lib/v1/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export interface CompileBlueprintV1Options {
semaphore?: Semaphore;
/** Optional callback with step output */
onStepCompleted?: OnStepCompleted;
/** Optional callback with blueprint validation result */
onBlueprintValidated?: (blueprint: BlueprintV1Declaration) => void;
/**
* Proxy URL to use for cross-origin requests.
*
Expand Down Expand Up @@ -137,6 +139,7 @@ function compileBlueprintJson(
progress = new ProgressTracker(),
semaphore = new Semaphore({ concurrency: 3 }),
onStepCompleted = () => {},
onBlueprintValidated = () => {},
corsProxy,
streamBundledFile,
additionalSteps,
Expand Down Expand Up @@ -304,6 +307,8 @@ function compileBlueprintJson(
throw e;
}

onBlueprintValidated(blueprint);

const steps = (blueprint.steps || []) as StepDefinition[];
const totalProgressWeight = steps.reduce(
(total, step) => total + (step.progress?.weight || 1),
Expand Down
9 changes: 8 additions & 1 deletion packages/playground/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export {
export { phpVar, phpVars } from '@php-wasm/util';
export type { PlaygroundClient, MountDescriptor };

import type { BlueprintV1, OnStepCompleted } from '@wp-playground/blueprints';
import type {
BlueprintV1,
BlueprintV1Declaration,
OnStepCompleted,
} from '@wp-playground/blueprints';
import {
compileBlueprintV1,
runBlueprintV1Steps,
Expand All @@ -45,6 +49,7 @@ export interface StartPlaygroundOptions {
disableProgressBar?: boolean;
blueprint?: BlueprintV1;
onBlueprintStepCompleted?: OnStepCompleted;
onBlueprintValidated?: (blueprint: BlueprintV1Declaration) => void;
/**
* Called when the playground client is connected, but before the blueprint
* steps are run.
Expand Down Expand Up @@ -101,6 +106,7 @@ export async function startPlaygroundWeb({
progressTracker = new ProgressTracker(),
disableProgressBar,
onBlueprintStepCompleted,
onBlueprintValidated,
onClientConnected = () => {},
sapiName,
mounts,
Expand All @@ -125,6 +131,7 @@ export async function startPlaygroundWeb({
const compiled = await compileBlueprintV1(blueprint, {
progress: progressTracker.stage(0.5),
onStepCompleted: onBlueprintStepCompleted,
onBlueprintValidated,
corsProxy,
});

Expand Down
27 changes: 11 additions & 16 deletions packages/playground/website/src/lib/state/redux/boot-site-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import {
updateClientInfo,
} from './slice-clients';
import { logTrackingEvent } from '../../tracking';
import type { Blueprint, StepDefinition } from '@wp-playground/blueprints';
import { getBlueprintDeclaration } from '@wp-playground/blueprints';
import type { Blueprint } from '@wp-playground/blueprints';
import { logger } from '@php-wasm/logger';
import { setupPostMessageRelay } from '@php-wasm/web';
import { startPlaygroundWeb } from '@wp-playground/client';
Expand Down Expand Up @@ -101,20 +100,6 @@ export function bootSiteClient(
blueprint = site.metadata.runtimeConfiguration!;
} else {
blueprint = site.metadata.originalBlueprint;
const blueprintDeclaration = await getBlueprintDeclaration(
blueprint
);
// Log the names of provided Blueprint's steps.
// Only the names (e.g. "runPhp" or "login") are logged. Step options like
// code, password, URLs are never sent anywhere.
const steps = (blueprintDeclaration?.steps || [])
?.filter(
(step: any) => !!(typeof step === 'object' && step?.step)
)
.map((step) => (step as StepDefinition).step);
for (const step of steps) {
logTrackingEvent('step', { step });
}
}

let playground: PlaygroundClient;
Expand All @@ -129,6 +114,16 @@ export function bootSiteClient(
onClientConnected: (playground) => {
(window as any)['playground'] = playground;
},
// Log the names of provided Blueprint's steps.
// Only the names (e.g. "runPhp" or "login") are logged. Step options like
// code, password, URLs are never sent anywhere.
onBlueprintValidated: (blueprint) => {
for (const step of blueprint.steps || []) {
if (typeof step === 'object' && step?.step) {
logTrackingEvent('step', { step: step.step });
}
}
},
mounts: mountDescriptor
? [
{
Expand Down