Skip to content

Commit be8c04e

Browse files
authored
[Website] Report Blueprint v2 progress (#2674)
## Motivation for the change, related issues Captures the Blueprint v2 execution progress events and communicates the progress to the user. There is a few follow-up items in the code that I'm not addressing in this PR – they are related to Blueprints v2-specific code on playground.wordpress.net so it's fine if they're imperfect. Supersedes #2663 A part of #2586
1 parent a9b9eba commit be8c04e

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

packages/playground/client/src/blueprints-v2-handler.ts

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export class BlueprintsV2Handler {
1818
sapiName,
1919
scope,
2020
} = this.options;
21-
const downloadProgress = progressTracker!.stage();
21+
const downloadProgress = progressTracker!.stage(0.25);
22+
const executionProgress = progressTracker!.stage(0.75);
2223

2324
// Connect the Comlink API client to the remote worker,
2425
// boot the playground, and run the blueprint steps.
@@ -31,6 +32,56 @@ export class BlueprintsV2Handler {
3132

3233
// Connect the Comlink API client to the remote worker download monitor
3334
await playground.onDownloadProgress(downloadProgress.loadingListener);
35+
await playground.addEventListener(
36+
'blueprint.message',
37+
({ message }: any) => {
38+
switch (message.type) {
39+
case 'blueprint.target_resolved': {
40+
// @TODO: Evaluate consistenty with the CLI worker
41+
// if (!this.blueprintTargetResolved) {
42+
// this.blueprintTargetResolved = true;
43+
// for (const php of this
44+
// .phpInstancesThatNeedMountsAfterTargetResolved) {
45+
// // console.log('mounting resources for php', php);
46+
// this.phpInstancesThatNeedMountsAfterTargetResolved.delete(
47+
// php
48+
// );
49+
// await mountResources(php, args.mount || []);
50+
// }
51+
// }
52+
break;
53+
}
54+
case 'blueprint.progress': {
55+
executionProgress.set(message.progress);
56+
executionProgress.setCaption(message.caption);
57+
break;
58+
}
59+
case 'blueprint.error': {
60+
// @TODO: Error reporting.
61+
const red = '\x1b[31m';
62+
const bold = '\x1b[1m';
63+
const reset = '\x1b[0m';
64+
if (message.details) {
65+
logger.error(
66+
`${red}${bold}Fatal error:${reset} Uncaught ${message.details.exception}: ${message.details.message}\n` +
67+
` at ${message.details.file}:${message.details.line}\n` +
68+
(message.details.trace
69+
? message.details.trace + '\n'
70+
: '')
71+
);
72+
} else {
73+
logger.error(
74+
`${red}${bold}Error:${reset} ${message.message}\n`
75+
);
76+
}
77+
78+
// TODO: Should we report the error like that?
79+
throw new Error(message.message);
80+
break;
81+
}
82+
}
83+
}
84+
);
3485

3586
await playground.boot({
3687
mounts,
@@ -48,12 +99,16 @@ export class BlueprintsV2Handler {
4899
collectPhpLogs(logger, playground);
49100
onClientConnected?.(playground);
50101

102+
// @TODO: Get the landing page from the Blueprint.
103+
playground.goTo('/');
104+
51105
/**
52106
* Pre-fetch WordPress update checks to speed up the initial wp-admin load.
53107
*
54108
* @see https://github.com/WordPress/wordpress-playground/pull/2295
55109
*/
56-
// @TODO
110+
// @TODO get the enabled features somehow – probably using the same
111+
// resolveRuntimeConfiguration() logic as the redux site-slice.ts
57112
// if (compiled.features.networking) {
58113
// await playground.prefetchUpdateChecks();
59114
// }

packages/playground/remote/src/lib/playground-worker-endpoint-blueprints-v2.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ class PlaygroundWorkerEndpointV2 extends PlaygroundWorkerEndpoint {
5959
cliArgs: ['--site-url=' + siteUrl],
6060
blueprint: blueprint as BlueprintV2Declaration,
6161
onMessage: async (message: any) => {
62-
for (const listener of this.blueprintMessageListeners) {
63-
await listener(message);
64-
}
62+
this.dispatchEvent({
63+
type: 'blueprint.message',
64+
message,
65+
});
6566
},
6667
});
6768
await streamed.finished;

0 commit comments

Comments
 (0)