@wp-playground/blueprints 0.1.32 → 0.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-playground/blueprints",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.35",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
6
|
"import": "./index.js",
|
|
@@ -20,5 +20,5 @@
|
|
|
20
20
|
"publishConfig": {
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "0962f89a2b1a438997960a25c26f5341db063a3e"
|
|
24
24
|
}
|
package/src/lib/compile.ts
CHANGED
|
@@ -82,9 +82,12 @@ export function compileBlueprint(
|
|
|
82
82
|
run: async (playground: UniversalPHP) => {
|
|
83
83
|
try {
|
|
84
84
|
// Start resolving resources early
|
|
85
|
-
for (const {
|
|
86
|
-
for (const resource of
|
|
87
|
-
resource.
|
|
85
|
+
for (const { resources } of compiled) {
|
|
86
|
+
for (const resource of resources) {
|
|
87
|
+
resource.setPlayground(playground);
|
|
88
|
+
if (resource.isAsync) {
|
|
89
|
+
resource.resolve();
|
|
90
|
+
}
|
|
88
91
|
}
|
|
89
92
|
}
|
|
90
93
|
|
|
@@ -92,10 +95,17 @@ export function compileBlueprint(
|
|
|
92
95
|
const result = await run(playground);
|
|
93
96
|
onStepCompleted(result, step);
|
|
94
97
|
}
|
|
95
|
-
|
|
98
|
+
try {
|
|
96
99
|
await (playground as any).goTo(
|
|
97
100
|
blueprint.landingPage || '/'
|
|
98
101
|
);
|
|
102
|
+
} catch (e) {
|
|
103
|
+
/*
|
|
104
|
+
* NodePHP exposes no goTo method.
|
|
105
|
+
* We can't use `goto` in playground here,
|
|
106
|
+
* because it may be a Comlink proxy object
|
|
107
|
+
* with no such method.
|
|
108
|
+
*/
|
|
99
109
|
}
|
|
100
110
|
} finally {
|
|
101
111
|
progress.finish();
|
|
@@ -159,7 +169,7 @@ function compileStep<S extends StepDefinition>(
|
|
|
159
169
|
rootProgressTracker,
|
|
160
170
|
totalProgressWeight,
|
|
161
171
|
}: CompileStepArgsOptions
|
|
162
|
-
): { run: CompiledStep; step: S;
|
|
172
|
+
): { run: CompiledStep; step: S; resources: Array<Resource> } {
|
|
163
173
|
const stepProgress = rootProgressTracker.stage(
|
|
164
174
|
(step.progress?.weight || 1) / totalProgressWeight
|
|
165
175
|
);
|
|
@@ -195,6 +205,7 @@ function compileStep<S extends StepDefinition>(
|
|
|
195
205
|
* The weight of each async resource is the same, and is the same as the
|
|
196
206
|
* weight of the step itself.
|
|
197
207
|
*/
|
|
208
|
+
const resources = getResources(args);
|
|
198
209
|
const asyncResources = getResources(args).filter(
|
|
199
210
|
(resource) => resource.isAsync
|
|
200
211
|
);
|
|
@@ -204,7 +215,7 @@ function compileStep<S extends StepDefinition>(
|
|
|
204
215
|
resource.progress = stepProgress.stage(evenWeight);
|
|
205
216
|
}
|
|
206
217
|
|
|
207
|
-
return { run, step,
|
|
218
|
+
return { run, step, resources };
|
|
208
219
|
}
|
|
209
220
|
|
|
210
221
|
/**
|
package/src/lib/resources.ts
CHANGED
|
@@ -344,6 +344,11 @@ export class DecoratedResource<T extends Resource> extends Resource {
|
|
|
344
344
|
return this.resource.resolve();
|
|
345
345
|
}
|
|
346
346
|
|
|
347
|
+
/** @inheritDoc */
|
|
348
|
+
override async setPlayground(playground: UniversalPHP) {
|
|
349
|
+
return this.resource.setPlayground(playground);
|
|
350
|
+
}
|
|
351
|
+
|
|
347
352
|
/** @inheritDoc */
|
|
348
353
|
get progress() {
|
|
349
354
|
return this.resource.progress;
|
|
@@ -16,11 +16,12 @@ export const defineSiteUrl: StepHandler<DefineSiteUrlStep> = async (
|
|
|
16
16
|
playground,
|
|
17
17
|
{ siteUrl }
|
|
18
18
|
) => {
|
|
19
|
+
const documentRoot = await playground.documentRoot;
|
|
19
20
|
await updateFile(
|
|
20
21
|
playground,
|
|
21
|
-
|
|
22
|
+
`${documentRoot}/wp-config.php`,
|
|
22
23
|
(contents) =>
|
|
23
|
-
`<?php
|
|
24
|
+
`<?php
|
|
24
25
|
if ( ! defined( 'WP_HOME' ) ) {
|
|
25
26
|
define('WP_HOME', "${siteUrl}");
|
|
26
27
|
}
|
|
@@ -9,19 +9,21 @@ export type SetSiteOptionsStep = {
|
|
|
9
9
|
|
|
10
10
|
export const setSiteOptions: StepHandler<SetSiteOptionsStep> = async (
|
|
11
11
|
client,
|
|
12
|
-
options
|
|
12
|
+
{ options }
|
|
13
13
|
) => {
|
|
14
|
-
const
|
|
15
|
-
code: `<?php
|
|
14
|
+
const code = `<?php
|
|
16
15
|
include 'wordpress/wp-load.php';
|
|
17
16
|
$site_options = ${phpVar(options)};
|
|
18
17
|
foreach($site_options as $name => $value) {
|
|
19
18
|
update_option($name, $value);
|
|
20
19
|
}
|
|
21
20
|
echo "Success";
|
|
22
|
-
|
|
21
|
+
`;
|
|
22
|
+
const result = await client.run({
|
|
23
|
+
code,
|
|
23
24
|
});
|
|
24
25
|
assertSuccess(result);
|
|
26
|
+
return { code, result };
|
|
25
27
|
};
|
|
26
28
|
|
|
27
29
|
export interface UpdateUserMetaStep {
|
|
@@ -33,17 +35,19 @@ export const updateUserMeta: StepHandler<UpdateUserMetaStep> = async (
|
|
|
33
35
|
client,
|
|
34
36
|
{ meta, userId }
|
|
35
37
|
) => {
|
|
36
|
-
const
|
|
37
|
-
code: `<?php
|
|
38
|
+
const code = `<?php
|
|
38
39
|
include 'wordpress/wp-load.php';
|
|
39
40
|
$meta = ${phpVar(meta)};
|
|
40
41
|
foreach($meta as $name => $value) {
|
|
41
42
|
update_user_meta(${phpVar(userId)}, $name, $value);
|
|
42
43
|
}
|
|
43
44
|
echo "Success";
|
|
44
|
-
|
|
45
|
+
`;
|
|
46
|
+
const result = await client.run({
|
|
47
|
+
code,
|
|
45
48
|
});
|
|
46
49
|
assertSuccess(result);
|
|
50
|
+
return { code, result };
|
|
47
51
|
};
|
|
48
52
|
|
|
49
53
|
async function assertSuccess(result: PHPResponse) {
|