@wp-playground/blueprints 0.9.18 → 0.9.20
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/blueprint-schema.json +62 -6
- package/index.cjs +105 -20
- package/index.d.ts +7 -2275
- package/index.js +490 -280
- package/lib/blueprint.d.ts +89 -0
- package/lib/compile.d.ts +47 -0
- package/lib/resources.d.ts +210 -0
- package/lib/steps/handlers.d.ts +2 -0
- package/lib/steps/import-theme-starter-content.d.ts +25 -0
- package/lib/steps/index.d.ts +4 -2
- package/lib/steps/install-theme.d.ts +6 -1
- package/lib/steps/set-site-language.d.ts +22 -0
- package/package.json +2 -2
- package/vitest-setup-file.d.ts +0 -0
package/blueprint-schema.json
CHANGED
|
@@ -80,8 +80,7 @@
|
|
|
80
80
|
"additionalProperties": {
|
|
81
81
|
"type": "string"
|
|
82
82
|
},
|
|
83
|
-
"description": "PHP Constants to define on every request"
|
|
84
|
-
"deprecated": "This experimental option will change without warning.\nUse `steps` instead."
|
|
83
|
+
"description": "PHP Constants to define on every request"
|
|
85
84
|
},
|
|
86
85
|
"plugins": {
|
|
87
86
|
"type": "array",
|
|
@@ -95,8 +94,7 @@
|
|
|
95
94
|
}
|
|
96
95
|
]
|
|
97
96
|
},
|
|
98
|
-
"description": "WordPress plugins to install and activate"
|
|
99
|
-
"deprecated": "This experimental option will change without warning.\nUse `steps` instead."
|
|
97
|
+
"description": "WordPress plugins to install and activate"
|
|
100
98
|
},
|
|
101
99
|
"siteOptions": {
|
|
102
100
|
"type": "object",
|
|
@@ -109,8 +107,7 @@
|
|
|
109
107
|
"description": "The site title"
|
|
110
108
|
}
|
|
111
109
|
},
|
|
112
|
-
"description": "WordPress site options to define"
|
|
113
|
-
"deprecated": "This experimental option will change without warning.\nUse `steps` instead."
|
|
110
|
+
"description": "WordPress site options to define"
|
|
114
111
|
},
|
|
115
112
|
"login": {
|
|
116
113
|
"anyOf": [
|
|
@@ -546,6 +543,34 @@
|
|
|
546
543
|
},
|
|
547
544
|
"required": ["file", "step"]
|
|
548
545
|
},
|
|
546
|
+
{
|
|
547
|
+
"type": "object",
|
|
548
|
+
"additionalProperties": false,
|
|
549
|
+
"properties": {
|
|
550
|
+
"progress": {
|
|
551
|
+
"type": "object",
|
|
552
|
+
"properties": {
|
|
553
|
+
"weight": {
|
|
554
|
+
"type": "number"
|
|
555
|
+
},
|
|
556
|
+
"caption": {
|
|
557
|
+
"type": "string"
|
|
558
|
+
}
|
|
559
|
+
},
|
|
560
|
+
"additionalProperties": false
|
|
561
|
+
},
|
|
562
|
+
"step": {
|
|
563
|
+
"type": "string",
|
|
564
|
+
"const": "importThemeStarterContent",
|
|
565
|
+
"description": "The step identifier."
|
|
566
|
+
},
|
|
567
|
+
"themeSlug": {
|
|
568
|
+
"type": "string",
|
|
569
|
+
"description": "The name of the theme to import content from."
|
|
570
|
+
}
|
|
571
|
+
},
|
|
572
|
+
"required": ["step", "themeSlug"]
|
|
573
|
+
},
|
|
549
574
|
{
|
|
550
575
|
"type": "object",
|
|
551
576
|
"additionalProperties": false,
|
|
@@ -650,6 +675,10 @@
|
|
|
650
675
|
"activate": {
|
|
651
676
|
"type": "boolean",
|
|
652
677
|
"description": "Whether to activate the theme after installing it."
|
|
678
|
+
},
|
|
679
|
+
"importStarterContent": {
|
|
680
|
+
"type": "boolean",
|
|
681
|
+
"description": "Whether to import the theme's starter content after installing it."
|
|
653
682
|
}
|
|
654
683
|
},
|
|
655
684
|
"additionalProperties": false,
|
|
@@ -1173,6 +1202,33 @@
|
|
|
1173
1202
|
}
|
|
1174
1203
|
},
|
|
1175
1204
|
"required": ["command", "step"]
|
|
1205
|
+
},
|
|
1206
|
+
{
|
|
1207
|
+
"type": "object",
|
|
1208
|
+
"additionalProperties": false,
|
|
1209
|
+
"properties": {
|
|
1210
|
+
"progress": {
|
|
1211
|
+
"type": "object",
|
|
1212
|
+
"properties": {
|
|
1213
|
+
"weight": {
|
|
1214
|
+
"type": "number"
|
|
1215
|
+
},
|
|
1216
|
+
"caption": {
|
|
1217
|
+
"type": "string"
|
|
1218
|
+
}
|
|
1219
|
+
},
|
|
1220
|
+
"additionalProperties": false
|
|
1221
|
+
},
|
|
1222
|
+
"step": {
|
|
1223
|
+
"type": "string",
|
|
1224
|
+
"const": "setSiteLanguage"
|
|
1225
|
+
},
|
|
1226
|
+
"language": {
|
|
1227
|
+
"type": "string",
|
|
1228
|
+
"description": "The language to set, e.g. 'en_US'"
|
|
1229
|
+
}
|
|
1230
|
+
},
|
|
1231
|
+
"required": ["language", "step"]
|
|
1176
1232
|
}
|
|
1177
1233
|
]
|
|
1178
1234
|
},
|
package/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("@php-wasm/node-polyfills");const o=require("@php-wasm/util"),g=require("@php-wasm/logger"),N=require("@php-wasm/scopes"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("@php-wasm/node-polyfills");const o=require("@php-wasm/util"),g=require("@php-wasm/logger"),N=require("@php-wasm/scopes"),V=require("@wp-playground/common"),G=require("@php-wasm/progress"),b=require("@php-wasm/universal"),we=require("ajv"),j=["db.php","plugins/akismet","plugins/hello.php","plugins/wordpress-importer","mu-plugins/sqlite-database-integration","mu-plugins/playground-includes","mu-plugins/0-playground.php","mu-plugins/0-sqlite.php","themes/twentytwenty","themes/twentytwentyone","themes/twentytwentytwo","themes/twentytwentythree","themes/twentytwentyfour","themes/twentytwentyfive","themes/twentytwentysix"],R=async(e,{pluginPath:t,pluginName:n},i)=>{i==null||i.tracker.setCaption(`Activating ${n||t}`);const r=await e.documentRoot,s=await e.run({code:`<?php
|
|
2
2
|
define( 'WP_ADMIN', true );
|
|
3
3
|
require_once( ${o.phpVar(r)}. "/wp-load.php" );
|
|
4
4
|
require_once( ${o.phpVar(r)}. "/wp-admin/includes/plugin.php" );
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
throw new Exception( 'Theme ' . getenv('themeFolderName') . ' could not be activated.' );
|
|
50
50
|
}
|
|
51
51
|
die('Theme activated successfully');
|
|
52
|
-
`,env:{docroot:i,themeFolderName:t}});if(s.text!=="Theme activated successfully")throw g.logger.debug(s),new Error(`Theme ${t} could not be activated – WordPress exited with no error. Sometimes, when $_SERVER or site options are not configured correctly, WordPress exits early with a 301 redirect. Inspect the "debug" logs in the console for more details`)},
|
|
52
|
+
`,env:{docroot:i,themeFolderName:t}});if(s.text!=="Theme activated successfully")throw g.logger.debug(s),new Error(`Theme ${t} could not be activated – WordPress exited with no error. Sometimes, when $_SERVER or site options are not configured correctly, WordPress exits early with a 301 redirect. Inspect the "debug" logs in the console for more details`)},Q=async(e,{code:t})=>await e.run({code:t}),Y=async(e,{options:t})=>await e.run(t),q=async(e,{path:t})=>{await e.unlink(t)},Z=async(e,{sql:t},n)=>{n==null||n.tracker.setCaption("Executing SQL Queries");const i=`/tmp/${o.randomFilename()}.sql`;await e.writeFile(i,new Uint8Array(await t.arrayBuffer()));const r=await e.documentRoot,s=o.phpVars({docroot:r,sqlFilename:i}),a=await e.run({code:`<?php
|
|
53
53
|
require_once ${s.docroot} . '/wp-load.php';
|
|
54
54
|
|
|
55
55
|
$handle = fopen(${s.sqlFilename}, 'r');
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
$wpdb->query($buffer);
|
|
69
69
|
$buffer = '';
|
|
70
70
|
}
|
|
71
|
-
`});return await q(e,{path:i}),a},
|
|
71
|
+
`});return await q(e,{path:i}),a},v=async(e,{request:t})=>{g.logger.warn('Deprecated: The Blueprint step "request" is deprecated and will be removed in a future release.');const n=await e.request(t);if(n.httpStatusCode>399||n.httpStatusCode<200)throw g.logger.warn("WordPress response was",{response:n}),new Error(`Request failed with status ${n.httpStatusCode}`);return n},ge=`<?php
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
74
|
* Rewrites the wp-config.php file to ensure specific constants are defined
|
|
@@ -399,25 +399,25 @@ function skip_whitespace($tokens) {
|
|
|
399
399
|
}
|
|
400
400
|
return $output;
|
|
401
401
|
}
|
|
402
|
-
`,
|
|
402
|
+
`,P=async(e,{consts:t,method:n="define-before-run"})=>{switch(n){case"define-before-run":await ye(e,t);break;case"rewrite-wp-config":{const i=await e.documentRoot,r=o.joinPaths(i,"/wp-config.php"),s=await e.readFileAsText(r),a=await $e(e,s,t);await e.writeFile(r,a);break}default:throw new Error(`Invalid method: ${n}`)}};async function ye(e,t){for(const n in t)await e.defineConstant(n,t[n])}async function $e(e,t,n){await e.writeFile("/tmp/code.php",t);const i=o.phpVars({consts:n});return await e.run({code:`${ge}
|
|
403
403
|
$wp_config_path = '/tmp/code.php';
|
|
404
404
|
$wp_config = file_get_contents($wp_config_path);
|
|
405
405
|
$new_wp_config = rewrite_wp_config_to_define_constants($wp_config, ${i.consts});
|
|
406
406
|
file_put_contents($wp_config_path, $new_wp_config);
|
|
407
|
-
`}),await e.readFileAsText("/tmp/code.php")}const
|
|
407
|
+
`}),await e.readFileAsText("/tmp/code.php")}const k=async(e,{username:t="admin",password:n="password"}={},i)=>{var s,a,l;i==null||i.tracker.setCaption((i==null?void 0:i.initialCaption)||"Logging in"),await e.request({url:"/wp-login.php"});const r=await e.request({url:"/wp-login.php",method:"POST",body:{log:t,pwd:n,rememberme:"forever"}});if(!((l=(a=(s=r.headers)==null?void 0:s.location)==null?void 0:a[0])!=null&&l.includes("/wp-admin/")))throw g.logger.warn("WordPress response was",{response:r,text:r.text}),new Error(`Failed to log in as ${t} with password ${n}`)},C=async(e,{options:t})=>{const n=await e.documentRoot;await e.run({code:`<?php
|
|
408
408
|
include ${o.phpVar(n)} . '/wp-load.php';
|
|
409
409
|
$site_options = ${o.phpVar(t)};
|
|
410
410
|
foreach($site_options as $name => $value) {
|
|
411
411
|
update_option($name, $value);
|
|
412
412
|
}
|
|
413
413
|
echo "Success";
|
|
414
|
-
`})},
|
|
414
|
+
`})},X=async(e,{meta:t,userId:n})=>{const i=await e.documentRoot;await e.run({code:`<?php
|
|
415
415
|
include ${o.phpVar(i)} . '/wp-load.php';
|
|
416
416
|
$meta = ${o.phpVar(t)};
|
|
417
417
|
foreach($meta as $name => $value) {
|
|
418
418
|
update_user_meta(${o.phpVar(n)}, $name, $value);
|
|
419
419
|
}
|
|
420
|
-
`})},
|
|
420
|
+
`})},J=async e=>{var u;await P(e,{consts:{WP_ALLOW_MULTISITE:1}});const t=new URL(await e.absoluteUrl);if(t.port!==""){let m=`The current host is ${t.host}, but WordPress multisites do not support custom ports.`;throw t.hostname==="localhost"&&(m+=" For development, you can set up a playground.test domain using the instructions at https://wordpress.github.io/wordpress-playground/contributing/code."),new Error(m)}const n=t.pathname.replace(/\/$/,"")+"/",i=`${t.protocol}//${t.hostname}${n}`;await C(e,{options:{siteurl:i,home:i}}),await k(e,{});const r=await e.documentRoot,a=(await e.run({code:`<?php
|
|
421
421
|
define( 'WP_ADMIN', true );
|
|
422
422
|
require_once(${o.phpVar(r)} . "/wp-load.php");
|
|
423
423
|
|
|
@@ -449,9 +449,9 @@ foreach($plugins as $plugin_path) {
|
|
|
449
449
|
}
|
|
450
450
|
}
|
|
451
451
|
echo json_encode($deactivated_plugins);
|
|
452
|
-
`})).json,
|
|
453
|
-
$_SERVER['HTTP_HOST'] = ${o.phpVar(
|
|
454
|
-
$folder = ${o.phpVar(
|
|
452
|
+
`})).json,c=(u=(await v(e,{request:{url:"/wp-admin/network.php"}})).text.match(/name="_wpnonce"\s+value="([^"]+)"/))==null?void 0:u[1],f=await v(e,{request:{url:"/wp-admin/network.php",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:_e({_wpnonce:c,_wp_http_referer:n+"wp-admin/network.php",sitename:"My WordPress Website Sites",email:"admin@localhost.com",submit:"Install"})}});if(f.httpStatusCode!==200)throw g.logger.warn("WordPress response was",{response:f,text:f.text,headers:f.headers}),new Error(`Failed to enable multisite. Response code was ${f.httpStatusCode}`);await P(e,{consts:{MULTISITE:!0,SUBDOMAIN_INSTALL:!1,SITE_ID_CURRENT_SITE:1,BLOG_ID_CURRENT_SITE:1,DOMAIN_CURRENT_SITE:t.hostname,PATH_CURRENT_SITE:n}});const h=new URL(await e.absoluteUrl),p=N.isURLScoped(h)?"scope:"+N.getURLScope(h):null;await e.writeFile("/internal/shared/preload/sunrise.php",`<?php
|
|
453
|
+
$_SERVER['HTTP_HOST'] = ${o.phpVar(h.hostname)};
|
|
454
|
+
$folder = ${o.phpVar(p)};
|
|
455
455
|
if ($folder && strpos($_SERVER['REQUEST_URI'],"/$folder") === false) {
|
|
456
456
|
$_SERVER['REQUEST_URI'] = "/$folder/" . ltrim($_SERVER['REQUEST_URI'], '/');
|
|
457
457
|
}
|
|
@@ -459,7 +459,7 @@ echo json_encode($deactivated_plugins);
|
|
|
459
459
|
if ( !defined( 'BLOG_ID_CURRENT_SITE' ) ) {
|
|
460
460
|
define( 'BLOG_ID_CURRENT_SITE', 1 );
|
|
461
461
|
}
|
|
462
|
-
`),await
|
|
462
|
+
`),await k(e,{});for(const m of a)await R(e,{pluginPath:m})};function _e(e){return Object.keys(e).map(t=>encodeURIComponent(t)+"="+encodeURIComponent(e[t])).join("&")}const K=async(e,{fromPath:t,toPath:n})=>{await e.writeFile(n,await e.readFileAsBuffer(t))},ee=async(e,{fromPath:t,toPath:n})=>{await e.mv(t,n)},te=async(e,{path:t})=>{await e.mkdir(t)},ne=async(e,{path:t})=>{await e.rmdir(t)},O=async(e,{path:t,data:n})=>{n instanceof File&&(n=new Uint8Array(await n.arrayBuffer())),t.startsWith("/wordpress/wp-content/mu-plugins")&&!await e.fileExists("/wordpress/wp-content/mu-plugins")&&await e.mkdir("/wordpress/wp-content/mu-plugins"),await e.writeFile(t,n)},W=async(e,{siteUrl:t})=>{await P(e,{consts:{WP_HOME:t,WP_SITEURL:t}})},ie=async(e,{file:t},n)=>{var r;(r=n==null?void 0:n.tracker)==null||r.setCaption("Importing content"),await O(e,{path:"/tmp/import.wxr",data:t});const i=await e.documentRoot;await e.run({code:`<?php
|
|
463
463
|
require ${o.phpVar(i)} . '/wp-load.php';
|
|
464
464
|
require ${o.phpVar(i)} . '/wp-admin/includes/admin.php';
|
|
465
465
|
|
|
@@ -479,10 +479,57 @@ echo json_encode($deactivated_plugins);
|
|
|
479
479
|
});
|
|
480
480
|
|
|
481
481
|
$result = $importer->import( '/tmp/import.wxr' );
|
|
482
|
-
`})},
|
|
482
|
+
`})},U=async(e,{themeSlug:t=""},n)=>{var r;(r=n==null?void 0:n.tracker)==null||r.setCaption("Importing theme starter content");const i=await e.documentRoot;await e.run({code:`<?php
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Ensure that the customizer loads as an admin user.
|
|
486
|
+
*
|
|
487
|
+
* For compatibility with themes, this MUST be run prior to theme inclusion, which is why this is a plugins_loaded filter instead
|
|
488
|
+
* of running _wp_customize_include() manually after load.
|
|
489
|
+
*/
|
|
490
|
+
function importThemeStarterContent_plugins_loaded() {
|
|
491
|
+
// Set as the admin user, this ensures we can customize the site.
|
|
492
|
+
wp_set_current_user(
|
|
493
|
+
get_users( [ 'role' => 'Administrator' ] )[0]
|
|
494
|
+
);
|
|
495
|
+
|
|
496
|
+
// Force the site to be fresh, although it should already be.
|
|
497
|
+
add_filter( 'pre_option_fresh_site', '__return_true' );
|
|
498
|
+
|
|
499
|
+
/*
|
|
500
|
+
* Simulate this request as the customizer loading with the current theme in preview mode.
|
|
501
|
+
*
|
|
502
|
+
* See _wp_customize_include()
|
|
503
|
+
*/
|
|
504
|
+
$_REQUEST['wp_customize'] = 'on';
|
|
505
|
+
$_REQUEST['customize_theme'] = ${o.phpVar(t)} ?: get_stylesheet();
|
|
506
|
+
|
|
507
|
+
/*
|
|
508
|
+
* Claim this is a ajax request saving settings, to avoid the preview filters being applied.
|
|
509
|
+
*/
|
|
510
|
+
$_REQUEST['action'] = 'customize_save';
|
|
511
|
+
add_filter( 'wp_doing_ajax', '__return_true' );
|
|
512
|
+
|
|
513
|
+
$_GET = $_REQUEST;
|
|
514
|
+
}
|
|
515
|
+
playground_add_filter( 'plugins_loaded', 'importThemeStarterContent_plugins_loaded', 0 );
|
|
516
|
+
|
|
517
|
+
require ${o.phpVar(i)} . '/wp-load.php';
|
|
518
|
+
|
|
519
|
+
// Return early if there's no starter content.
|
|
520
|
+
if ( ! get_theme_starter_content() ) {
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// Import the Starter Content.
|
|
525
|
+
$wp_customize->import_theme_starter_content();
|
|
526
|
+
|
|
527
|
+
// Publish the changeset, which publishes the starter content.
|
|
528
|
+
wp_publish_post( $wp_customize->changeset_post_id() );
|
|
529
|
+
`})},S=async(e,{zipFile:t,zipPath:n,extractToPath:i})=>{if(n)g.logger.warn('The "zipPath" option of the unzip() Blueprint step is deprecated and will be removed. Use "zipFile" instead.');else if(!t)throw new Error("Either zipPath or zipFile must be provided");await V.unzipFile(e,t||n,i)},re=async(e,{wordPressFilesZip:t,pathInZip:n=""})=>{const i=await e.documentRoot;let r=o.joinPaths("/tmp","import");await e.mkdir(r),await S(e,{zipFile:t,extractToPath:r}),r=o.joinPaths(r,n);const s=o.joinPaths(r,"wp-content"),a=o.joinPaths(i,"wp-content");for(const h of j){const p=o.joinPaths(s,h);await z(e,p);const u=o.joinPaths(a,h);await e.fileExists(u)&&(await e.mkdir(o.dirname(p)),await e.mv(u,p))}const l=o.joinPaths(r,"wp-content","database");await e.fileExists(l)||await e.mv(o.joinPaths(i,"wp-content","database"),l);const c=await e.listFiles(r);for(const h of c)await z(e,o.joinPaths(i,h)),await e.mv(o.joinPaths(r,h),o.joinPaths(i,h));await e.rmdir(r),await W(e,{siteUrl:await e.absoluteUrl});const f=o.phpVar(o.joinPaths(i,"wp-admin","upgrade.php"));await e.run({code:`<?php
|
|
483
530
|
$_GET['step'] = 'upgrade_db';
|
|
484
|
-
require ${
|
|
485
|
-
`})};async function
|
|
531
|
+
require ${f};
|
|
532
|
+
`})};async function z(e,t){await e.fileExists(t)&&(await e.isDir(t)?await e.rmdir(t):await e.unlink(t))}async function se(e){const t=await e.request({url:"/wp-admin/export.php?download=true&content=all"});return new File([t.bytes],"export.xml")}async function oe(e,{targetPath:t,zipFile:n,ifAlreadyInstalled:i="overwrite"}){const s=n.name.replace(/\.zip$/,""),a=o.joinPaths(await e.documentRoot,"wp-content"),l=o.joinPaths(a,o.randomString()),c=o.joinPaths(l,"assets",s);await e.fileExists(c)&&await e.rmdir(l,{recursive:!0}),await e.mkdir(l);try{await S(e,{zipFile:n,extractToPath:c});let f=await e.listFiles(c,{prependPath:!0});f=f.filter(E=>!E.endsWith("/__MACOSX"));const h=f.length===1&&await e.isDir(f[0]);let p,u="";h?(u=f[0],p=f[0].split("/").pop()):(u=c,p=s);const m=`${t}/${p}`;if(await e.fileExists(m)){if(!await e.isDir(m))throw new Error(`Cannot install asset ${p} to ${m} because a file with the same name already exists. Note it's a file, not a directory! Is this by mistake?`);if(i==="overwrite")await e.rmdir(m,{recursive:!0});else{if(i==="skip")return{assetFolderPath:m,assetFolderName:p};throw new Error(`Cannot install asset ${p} to ${t} because it already exists and the ifAlreadyInstalled option was set to ${i}`)}}return await e.mv(u,m),{assetFolderPath:m,assetFolderName:p}}finally{await e.rmdir(l,{recursive:!0})}}function x(e){const t=e.split(".").shift().replace(/-/g," ");return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}const ae=async(e,{pluginZipFile:t,ifAlreadyInstalled:n,options:i={}},r)=>{const s=t.name.split("/").pop()||"plugin.zip",a=x(s);r==null||r.tracker.setCaption(`Installing the ${a} plugin`);const{assetFolderPath:l}=await oe(e,{ifAlreadyInstalled:n,zipFile:t,targetPath:`${await e.documentRoot}/wp-content/plugins`});("activate"in i?i.activate:!0)&&await R(e,{pluginPath:l,pluginName:a},r)},pe=async(e,{themeZipFile:t,ifAlreadyInstalled:n,options:i={}},r)=>{const s=x(t.name);r==null||r.tracker.setCaption(`Installing the ${s} theme`);const{assetFolderName:a}=await oe(e,{ifAlreadyInstalled:n,zipFile:t,targetPath:`${await e.documentRoot}/wp-content/themes`});("activate"in i?i.activate:!0)&&await L(e,{themeFolderName:a},r),("importStarterContent"in i?i.importStarterContent:!1)&&await U(e,{themeSlug:a},r)},ce=async(e,t,n)=>{var r;(r=n==null?void 0:n.tracker)==null||r.setCaption("Resetting WordPress data");const i=await e.documentRoot;await e.run({env:{DOCROOT:i},code:`<?php
|
|
486
533
|
require getenv('DOCROOT') . '/wp-load.php';
|
|
487
534
|
|
|
488
535
|
$GLOBALS['@pdo']->query('DELETE FROM wp_posts WHERE id > 0');
|
|
@@ -496,11 +543,11 @@ echo json_encode($deactivated_plugins);
|
|
|
496
543
|
|
|
497
544
|
$GLOBALS['@pdo']->query('DELETE FROM wp_commentmeta');
|
|
498
545
|
$GLOBALS['@pdo']->query("UPDATE SQLITE_SEQUENCE SET SEQ=0 WHERE NAME='wp_commentmeta'");
|
|
499
|
-
`})},
|
|
546
|
+
`})},le=async(e,{options:t})=>{await e.request({url:"/wp-admin/install.php?step=2",method:"POST",body:{language:"en",prefix:"wp_",weblog_title:"My WordPress Website",user_name:t.adminPassword||"admin",admin_password:t.adminPassword||"password",admin_password2:t.adminPassword||"password",Submit:"Install WordPress",pw_weak:"1",admin_email:"admin@localhost.com"}})},de=async(e,{selfContained:t=!1}={})=>{const n="/tmp/wordpress-playground.zip",i=await e.documentRoot,r=o.joinPaths(i,"wp-content");let s=j;t&&(s=s.filter(c=>!c.startsWith("themes/twenty")).filter(c=>c!=="mu-plugins/sqlite-database-integration"));const a=o.phpVars({zipPath:n,wpContentPath:r,documentRoot:i,exceptPaths:s.map(c=>o.joinPaths(i,"wp-content",c)),additionalPaths:t?{[o.joinPaths(i,"wp-config.php")]:"wp-config.php"}:{}});await Pe(e,`zipDir(${a.wpContentPath}, ${a.zipPath}, array(
|
|
500
547
|
'exclude_paths' => ${a.exceptPaths},
|
|
501
548
|
'zip_root' => ${a.documentRoot},
|
|
502
549
|
'additional_paths' => ${a.additionalPaths}
|
|
503
|
-
));`);const
|
|
550
|
+
));`);const l=await e.readFileAsBuffer(n);return e.unlink(n),l},be=`<?php
|
|
504
551
|
|
|
505
552
|
function zipDir($root, $output, $options = array())
|
|
506
553
|
{
|
|
@@ -559,7 +606,7 @@ function join_paths()
|
|
|
559
606
|
|
|
560
607
|
return preg_replace('#/+#', '/', join('/', $paths));
|
|
561
608
|
}
|
|
562
|
-
`;async function
|
|
609
|
+
`;async function Pe(e,t){return await e.run({code:be+t})}const ue=async(e,{command:t,wpCliPath:n="/tmp/wp-cli.phar"})=>{if(!await e.fileExists(n))throw new Error(`wp-cli.phar not found at ${n}`);let i;if(typeof t=="string"?(t=t.trim(),i=Ee(t)):i=t,i.shift()!=="wp")throw new Error('The first argument must be "wp".');await e.writeFile("/tmp/stdout",""),await e.writeFile("/tmp/stderr",""),await e.writeFile("/wordpress/run-cli.php",`<?php
|
|
563
610
|
// Set up the environment to emulate a shell script
|
|
564
611
|
// call.
|
|
565
612
|
|
|
@@ -581,7 +628,45 @@ function join_paths()
|
|
|
581
628
|
define('STDERR', fopen('php://stderr', 'wb'));
|
|
582
629
|
|
|
583
630
|
require( ${o.phpVar(n)} );
|
|
584
|
-
`);const s=await e.run({scriptPath:"/wordpress/run-cli.php"});if(s.errors)throw new Error(s.errors);return s};function
|
|
631
|
+
`);const s=await e.run({scriptPath:"/wordpress/run-cli.php"});if(s.errors)throw new Error(s.errors);return s};function Ee(e){let i=0,r="";const s=[];let a="";for(let l=0;l<e.length;l++){const c=e[l];i===0?c==='"'||c==="'"?(i=1,r=c):c.match(/\s/)?(a&&s.push(a),a=""):a+=c:i===1&&(c==="\\"?(l++,a+=e[l]):c===r?(i=0,r=""):a+=c)}return a&&s.push(a),s}const he=async(e,{language:t},n)=>{n==null||n.tracker.setCaption((n==null?void 0:n.initialCaption)||"Translating"),await e.defineConstant("WPLANG",t);const i=await e.documentRoot,s=[{url:`https://downloads.wordpress.org/translation/core/${(await e.run({code:`<?php
|
|
632
|
+
require '${i}/wp-includes/version.php';
|
|
633
|
+
echo $wp_version;
|
|
634
|
+
`})).text}/${t}.zip`,type:"core"}],l=(await e.run({code:`<?php
|
|
635
|
+
require_once('${i}/wp-load.php');
|
|
636
|
+
require_once('${i}/wp-admin/includes/plugin.php');
|
|
637
|
+
echo json_encode(
|
|
638
|
+
array_values(
|
|
639
|
+
array_map(
|
|
640
|
+
function($plugin) {
|
|
641
|
+
return [
|
|
642
|
+
'slug' => $plugin['TextDomain'],
|
|
643
|
+
'version' => $plugin['Version']
|
|
644
|
+
];
|
|
645
|
+
},
|
|
646
|
+
array_filter(
|
|
647
|
+
get_plugins(),
|
|
648
|
+
function($plugin) {
|
|
649
|
+
return !empty($plugin['TextDomain']);
|
|
650
|
+
}
|
|
651
|
+
)
|
|
652
|
+
)
|
|
653
|
+
)
|
|
654
|
+
);`})).json;for(const{slug:h,version:p}of l)s.push({url:`https://downloads.wordpress.org/translation/plugin/${h}/${p}/${t}.zip`,type:"plugin"});const f=(await e.run({code:`<?php
|
|
655
|
+
require_once('${i}/wp-load.php');
|
|
656
|
+
require_once('${i}/wp-admin/includes/theme.php');
|
|
657
|
+
echo json_encode(
|
|
658
|
+
array_values(
|
|
659
|
+
array_map(
|
|
660
|
+
function($theme) {
|
|
661
|
+
return [
|
|
662
|
+
'slug' => $theme->get('TextDomain'),
|
|
663
|
+
'version' => $theme->get('Version')
|
|
664
|
+
];
|
|
665
|
+
},
|
|
666
|
+
wp_get_themes()
|
|
667
|
+
)
|
|
668
|
+
)
|
|
669
|
+
);`})).json;for(const{slug:h,version:p}of f)s.push({url:`https://downloads.wordpress.org/translation/theme/${h}/${p}/${t}.zip`,type:"theme"});await e.isDir(`${i}/wp-content/languages/plugins`)||await e.mkdir(`${i}/wp-content/languages/plugins`),await e.isDir(`${i}/wp-content/languages/themes`)||await e.mkdir(`${i}/wp-content/languages/themes`);for(const{url:h,type:p}of s)try{const u=await fetch(h);if(!u.ok)throw new Error(`Failed to download translations for ${p}: ${u.statusText}`);let m=`${i}/wp-content/languages`;p==="plugin"?m+="/plugins":p==="theme"&&(m+="/themes"),await V.unzipFile(e,new File([await u.blob()],`${t}-${p}.zip`),m)}catch(u){if(p==="core")throw new Error(`Failed to download translations for WordPress. Please check if the language code ${t} is correct. You can find all available languages and translations on https://translate.wordpress.org/.`);g.logger.warn(`Error downloading translations for ${p}: ${u}`)}},Te=Object.freeze(Object.defineProperty({__proto__:null,activatePlugin:R,activateTheme:L,cp:K,defineSiteUrl:W,defineWpConfigConsts:P,enableMultisite:J,exportWXR:se,importThemeStarterContent:U,importWordPressFiles:re,importWxr:ie,installPlugin:ae,installTheme:pe,login:k,mkdir:te,mv:ee,request:v,resetData:ce,rm:q,rmdir:ne,runPHP:Q,runPHPWithOptions:Y,runSql:Z,runWpInstallationWizard:le,setSiteLanguage:he,setSiteOptions:C,unzip:S,updateUserMeta:X,wpCLI:ue,writeFile:O,zipWpContent:de},Symbol.toStringTag,{value:"Module"})),ve=["vfs","literal","wordpress.org/themes","wordpress.org/plugins","url"];function ke(e){return e&&typeof e=="object"&&typeof e.resource=="string"&&ve.includes(e.resource)}class _{static create(t,{semaphore:n,progress:i}){let r;switch(t.resource){case"vfs":r=new Re(t,i);break;case"literal":r=new Se(t,i);break;case"wordpress.org/themes":r=new Le(t,i);break;case"wordpress.org/plugins":r=new qe(t,i);break;case"url":r=new je(t,i);break;default:throw new Error(`Invalid resource: ${t}`)}return r=new Ce(r),n&&(r=new Oe(r,n)),r}setPlayground(t){this.playground=t}get isAsync(){return!1}}class Re extends _{constructor(t,n){super(),this.resource=t,this.progress=n}async resolve(){var n;const t=await this.playground.readFileAsBuffer(this.resource.path);return(n=this.progress)==null||n.set(100),new File([t],this.name)}get name(){return this.resource.path.split("/").pop()||""}}class Se extends _{constructor(t,n){super(),this.resource=t,this.progress=n}async resolve(){var t;return(t=this.progress)==null||t.set(100),new File([this.resource.contents],this.resource.name)}get name(){return this.resource.name}}class I extends _{constructor(t){super(),this.progress=t}async resolve(){var n,i;(n=this.progress)==null||n.setCaption(this.caption);const t=this.getURL();try{let r=await fetch(t);if(!r.ok)throw new Error(`Could not download "${t}"`);if(r=await G.cloneResponseMonitorProgress(r,((i=this.progress)==null?void 0:i.loadingListener)??xe),r.status!==200)throw new Error(`Could not download "${t}"`);return new File([await r.blob()],this.name)}catch(r){throw new Error(`Could not download "${t}".
|
|
585
670
|
Check if the URL is correct and the server is reachable.
|
|
586
671
|
If it is reachable, the server might be blocking the request.
|
|
587
672
|
Check the browser console and network tabs for more information.
|
|
@@ -605,10 +690,10 @@ function join_paths()
|
|
|
605
690
|
https://raw.githubusercontent.com/username/repository/branch/filename
|
|
606
691
|
|
|
607
692
|
Error:
|
|
608
|
-
${r}`)}}get caption(){return`Downloading ${this.name}`}get name(){try{return new URL(this.getURL(),"http://example.com").pathname.split("/").pop()}catch{return this.getURL()}}get isAsync(){return!0}}const
|
|
693
|
+
${r}`)}}get caption(){return`Downloading ${this.name}`}get name(){try{return new URL(this.getURL(),"http://example.com").pathname.split("/").pop()}catch{return this.getURL()}}get isAsync(){return!0}}const xe=()=>{};class je extends I{constructor(t,n){super(n),this.resource=t}getURL(){return this.resource.url}get caption(){return this.resource.caption??super.caption}}class Le extends I{constructor(t,n){super(n),this.resource=t}get name(){return x(this.resource.slug)}getURL(){return`https://downloads.wordpress.org/theme/${fe(this.resource.slug)}`}}class qe extends I{constructor(t,n){super(n),this.resource=t}get name(){return x(this.resource.slug)}getURL(){return`https://downloads.wordpress.org/plugin/${fe(this.resource.slug)}`}}function fe(e){return!e||e.endsWith(".zip")?e:e+".latest-stable.zip"}class me extends _{constructor(t){super(),this.resource=t}async resolve(){return this.resource.resolve()}async setPlayground(t){return this.resource.setPlayground(t)}get progress(){return this.resource.progress}set progress(t){this.resource.progress=t}get name(){return this.resource.name}get isAsync(){return this.resource.isAsync}}class Ce extends me{async resolve(){return this.promise||(this.promise=super.resolve()),this.promise}}class Oe extends me{constructor(t,n){super(t),this.semaphore=n}async resolve(){return this.isAsync?this.semaphore.run(()=>super.resolve()):super.resolve()}}const We="http://json-schema.org/schema",Ue="#/definitions/Blueprint",Ie={Blueprint:{type:"object",properties:{landingPage:{type:"string",description:"The URL to navigate to after the blueprint has been run."},description:{type:"string",description:"Optional description. It doesn't do anything but is exposed as a courtesy to developers who may want to document which blueprint file does what.",deprecated:"Use meta.description instead."},meta:{type:"object",properties:{title:{type:"string",description:"A clear and concise name for your Blueprint."},description:{type:"string",description:"A brief explanation of what your Blueprint offers."},author:{type:"string",description:"A GitHub username of the author of this Blueprint."},categories:{type:"array",items:{type:"string"},description:"Relevant categories to help users find your Blueprint in the future Blueprints section on WordPress.org."}},required:["title","author"],additionalProperties:!1,description:"Optional metadata. Used by the Blueprints gallery at https://github.com/WordPress/blueprints"},preferredVersions:{type:"object",properties:{php:{anyOf:[{$ref:"#/definitions/SupportedPHPVersion"},{type:"string",const:"latest"}],description:"The preferred PHP version to use. If not specified, the latest supported version will be used"},wp:{type:"string",description:"The preferred WordPress version to use. If not specified, the latest supported version will be used"}},required:["php","wp"],additionalProperties:!1,description:"The preferred PHP and WordPress versions to use."},features:{type:"object",properties:{networking:{type:"boolean",description:"Should boot with support for network request via wp_safe_remote_get?"}},additionalProperties:!1},constants:{type:"object",additionalProperties:{type:"string"},description:"PHP Constants to define on every request"},plugins:{type:"array",items:{anyOf:[{type:"string"},{$ref:"#/definitions/FileReference"}]},description:"WordPress plugins to install and activate"},siteOptions:{type:"object",additionalProperties:{type:"string"},properties:{blogname:{type:"string",description:"The site title"}},description:"WordPress site options to define"},login:{anyOf:[{type:"boolean"},{type:"object",properties:{username:{type:"string"},password:{type:"string"}},required:["username","password"],additionalProperties:!1}],description:"User to log in as. If true, logs the user in as admin/password."},phpExtensionBundles:{type:"array",items:{$ref:"#/definitions/SupportedPHPExtensionBundle"},description:"The PHP extensions to use."},steps:{type:"array",items:{anyOf:[{$ref:"#/definitions/StepDefinition"},{type:"string"},{not:{}},{type:"boolean",const:!1},{type:"null"}]},description:"The steps to run after every other operation in this Blueprint was executed."},$schema:{type:"string"}},additionalProperties:!1},SupportedPHPVersion:{type:"string",enum:["8.3","8.2","8.1","8.0","7.4","7.3","7.2","7.1","7.0"]},FileReference:{anyOf:[{$ref:"#/definitions/VFSReference"},{$ref:"#/definitions/LiteralReference"},{$ref:"#/definitions/CoreThemeReference"},{$ref:"#/definitions/CorePluginReference"},{$ref:"#/definitions/UrlReference"}]},VFSReference:{type:"object",properties:{resource:{type:"string",const:"vfs",description:"Identifies the file resource as Virtual File System (VFS)"},path:{type:"string",description:"The path to the file in the VFS"}},required:["resource","path"],additionalProperties:!1},LiteralReference:{type:"object",properties:{resource:{type:"string",const:"literal",description:"Identifies the file resource as a literal file"},name:{type:"string",description:"The name of the file"},contents:{anyOf:[{type:"string"},{type:"object",properties:{BYTES_PER_ELEMENT:{type:"number"},buffer:{type:"object",properties:{byteLength:{type:"number"}},required:["byteLength"],additionalProperties:!1},byteLength:{type:"number"},byteOffset:{type:"number"},length:{type:"number"}},required:["BYTES_PER_ELEMENT","buffer","byteLength","byteOffset","length"],additionalProperties:{type:"number"}}],description:"The contents of the file"}},required:["resource","name","contents"],additionalProperties:!1},CoreThemeReference:{type:"object",properties:{resource:{type:"string",const:"wordpress.org/themes",description:"Identifies the file resource as a WordPress Core theme"},slug:{type:"string",description:"The slug of the WordPress Core theme"}},required:["resource","slug"],additionalProperties:!1},CorePluginReference:{type:"object",properties:{resource:{type:"string",const:"wordpress.org/plugins",description:"Identifies the file resource as a WordPress Core plugin"},slug:{type:"string",description:"The slug of the WordPress Core plugin"}},required:["resource","slug"],additionalProperties:!1},UrlReference:{type:"object",properties:{resource:{type:"string",const:"url",description:"Identifies the file resource as a URL"},url:{type:"string",description:"The URL of the file"},caption:{type:"string",description:"Optional caption for displaying a progress message"}},required:["resource","url"],additionalProperties:!1},SupportedPHPExtensionBundle:{type:"string",enum:["kitchen-sink","light"]},StepDefinition:{type:"object",discriminator:{propertyName:"step"},required:["step"],oneOf:[{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"activatePlugin"},pluginPath:{type:"string",description:"Path to the plugin directory as absolute path (/wordpress/wp-content/plugins/plugin-name); or the plugin entry file relative to the plugins directory (plugin-name/plugin-name.php)."},pluginName:{type:"string",description:"Optional. Plugin name to display in the progress bar."}},required:["pluginPath","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"activateTheme"},themeFolderName:{type:"string",description:"The name of the theme folder inside wp-content/themes/"}},required:["step","themeFolderName"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"cp"},fromPath:{type:"string",description:"Source path"},toPath:{type:"string",description:"Target path"}},required:["fromPath","step","toPath"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"defineWpConfigConsts"},consts:{type:"object",additionalProperties:{},description:"The constants to define"},method:{type:"string",enum:["rewrite-wp-config","define-before-run"],description:`The method of defining the constants in wp-config.php. Possible values are:
|
|
609
694
|
|
|
610
695
|
- rewrite-wp-config: Default. Rewrites the wp-config.php file to explicitly call define() with the requested name and value. This method alters the file on the disk, but it doesn't conflict with existing define() calls in wp-config.php.
|
|
611
696
|
|
|
612
697
|
- define-before-run: Defines the constant before running the requested script. It doesn't alter any files on the disk, but constants defined this way may conflict with existing define() calls in wp-config.php.`},virtualize:{type:"boolean",deprecated:`This option is noop and will be removed in a future version.
|
|
613
698
|
This option is only kept in here to avoid breaking Blueprint schema validation
|
|
614
|
-
for existing apps using this option.`}},required:["consts","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"defineSiteUrl"},siteUrl:{type:"string",description:"The URL"}},required:["siteUrl","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"enableMultisite"}},required:["step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"importWxr"},file:{$ref:"#/definitions/FileReference",description:"The file to import"}},required:["file","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"importWordPressFiles"},wordPressFilesZip:{$ref:"#/definitions/FileReference",description:"The zip file containing the top-level WordPress files and directories."},pathInZip:{type:"string",description:"The path inside the zip file where the WordPress files are."}},required:["step","wordPressFilesZip"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},ifAlreadyInstalled:{type:"string",enum:["overwrite","skip","error"],description:"What to do if the asset already exists."},step:{type:"string",const:"installPlugin",description:"The step identifier."},pluginZipFile:{$ref:"#/definitions/FileReference",description:"The plugin zip file to install."},options:{$ref:"#/definitions/InstallPluginOptions",description:"Optional installation options."}},required:["pluginZipFile","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},ifAlreadyInstalled:{type:"string",enum:["overwrite","skip","error"],description:"What to do if the asset already exists."},step:{type:"string",const:"installTheme",description:"The step identifier."},themeZipFile:{$ref:"#/definitions/FileReference",description:"The theme zip file to install."},options:{type:"object",properties:{activate:{type:"boolean",description:"Whether to activate the theme after installing it."}},additionalProperties:!1,description:"Optional installation options."}},required:["step","themeZipFile"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"login"},username:{type:"string",description:"The user to log in as. Defaults to 'admin'."},password:{type:"string",description:"The password to log in with. Defaults to 'password'."}},required:["step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"mkdir"},path:{type:"string",description:"The path of the directory you want to create"}},required:["path","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"mv"},fromPath:{type:"string",description:"Source path"},toPath:{type:"string",description:"Target path"}},required:["fromPath","step","toPath"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"resetData"}},required:["step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"request"},request:{$ref:"#/definitions/PHPRequest",description:"Request details (See /wordpress-playground/api/universal/interface/PHPRequest)"}},required:["request","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"rm"},path:{type:"string",description:"The path to remove"}},required:["path","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"rmdir"},path:{type:"string",description:"The path to remove"}},required:["path","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"runPHP",description:"The step identifier."},code:{type:"string",description:"The PHP code to run."}},required:["code","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"runPHPWithOptions"},options:{$ref:"#/definitions/PHPRunOptions",description:"Run options (See /wordpress-playground/api/universal/interface/PHPRunOptions/))"}},required:["options","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"runWpInstallationWizard"},options:{$ref:"#/definitions/WordPressInstallationOptions"}},required:["options","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"runSql",description:"The step identifier."},sql:{$ref:"#/definitions/FileReference",description:"The SQL to run. Each non-empty line must contain a valid SQL query."}},required:["sql","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"setSiteOptions",description:'The name of the step. Must be "setSiteOptions".'},options:{type:"object",additionalProperties:{},description:"The options to set on the site."}},required:["options","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"unzip"},zipFile:{$ref:"#/definitions/FileReference",description:"The zip file to extract"},zipPath:{type:"string",description:"The path of the zip file to extract",deprecated:"Use zipFile instead."},extractToPath:{type:"string",description:"The path to extract the zip file to"}},required:["extractToPath","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"updateUserMeta"},meta:{type:"object",additionalProperties:{},description:'An object of user meta values to set, e.g. { "first_name": "John" }'},userId:{type:"number",description:"User ID"}},required:["meta","step","userId"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"writeFile"},path:{type:"string",description:"The path of the file to write to"},data:{anyOf:[{$ref:"#/definitions/FileReference"},{type:"string"},{type:"object",properties:{BYTES_PER_ELEMENT:{type:"number"},buffer:{type:"object",properties:{byteLength:{type:"number"}},required:["byteLength"],additionalProperties:!1},byteLength:{type:"number"},byteOffset:{type:"number"},length:{type:"number"}},required:["BYTES_PER_ELEMENT","buffer","byteLength","byteOffset","length"],additionalProperties:{type:"number"}}],description:"The data to write"}},required:["data","path","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"wp-cli",description:"The step identifier."},command:{anyOf:[{type:"string"},{type:"array",items:{type:"string"}}],description:"The WP CLI command to run."},wpCliPath:{type:"string",description:"wp-cli.phar path"}},required:["command","step"]}]},InstallPluginOptions:{type:"object",properties:{activate:{type:"boolean",description:"Whether to activate the plugin after installing it."}},additionalProperties:!1},PHPRequest:{type:"object",properties:{method:{$ref:"#/definitions/HTTPMethod",description:"Request method. Default: `GET`."},url:{type:"string",description:"Request path or absolute URL."},headers:{$ref:"#/definitions/PHPRequestHeaders",description:"Request headers."},body:{anyOf:[{type:"string"},{type:"object",properties:{BYTES_PER_ELEMENT:{type:"number"},buffer:{type:"object",properties:{byteLength:{type:"number"}},required:["byteLength"],additionalProperties:!1},byteLength:{type:"number"},byteOffset:{type:"number"},length:{type:"number"}},required:["BYTES_PER_ELEMENT","buffer","byteLength","byteOffset","length"],additionalProperties:{type:"number"}},{type:"object",additionalProperties:{anyOf:[{type:"string"},{type:"object",properties:{BYTES_PER_ELEMENT:{type:"number"},buffer:{type:"object",properties:{byteLength:{type:"number"}},required:["byteLength"],additionalProperties:!1},byteLength:{type:"number"},byteOffset:{type:"number"},length:{type:"number"}},required:["BYTES_PER_ELEMENT","buffer","byteLength","byteOffset","length"],additionalProperties:{type:"number"}},{type:"object",properties:{size:{type:"number"},type:{type:"string"},lastModified:{type:"number"},name:{type:"string"},webkitRelativePath:{type:"string"}},required:["lastModified","name","size","type","webkitRelativePath"],additionalProperties:!1}]}}],description:"Request body. If an object is given, the request will be encoded as multipart and sent with a `multipart/form-data` header."}},required:["url"],additionalProperties:!1},HTTPMethod:{type:"string",enum:["GET","POST","HEAD","OPTIONS","PATCH","PUT","DELETE"]},PHPRequestHeaders:{type:"object",additionalProperties:{type:"string"}},PHPRunOptions:{type:"object",properties:{relativeUri:{type:"string",description:"Request path following the domain:port part."},scriptPath:{type:"string",description:"Path of the .php file to execute."},protocol:{type:"string",description:"Request protocol."},method:{$ref:"#/definitions/HTTPMethod",description:"Request method. Default: `GET`."},headers:{$ref:"#/definitions/PHPRequestHeaders",description:"Request headers."},body:{anyOf:[{type:"string"},{type:"object",properties:{BYTES_PER_ELEMENT:{type:"number"},buffer:{type:"object",properties:{byteLength:{type:"number"}},required:["byteLength"],additionalProperties:!1},byteLength:{type:"number"},byteOffset:{type:"number"},length:{type:"number"}},required:["BYTES_PER_ELEMENT","buffer","byteLength","byteOffset","length"],additionalProperties:{type:"number"}}],description:"Request body."},env:{type:"object",additionalProperties:{type:"string"},description:"Environment variables to set for this run."},$_SERVER:{type:"object",additionalProperties:{type:"string"},description:"$_SERVER entries to set for this run."},code:{type:"string",description:"The code snippet to eval instead of a php file."}},additionalProperties:!1},WordPressInstallationOptions:{type:"object",properties:{adminUsername:{type:"string"},adminPassword:{type:"string"}},additionalProperties:!1}},Ue={$schema:Oe,$ref:Ce,definitions:We},{wpCLI:Ie,...M}=be,Fe={...M,"wp-cli":Ie,importFile:M.importWxr};function Be(e,{progress:t=new z.ProgressTracker,semaphore:n=new o.Semaphore({concurrency:3}),onStepCompleted:i=()=>{}}={}){var l,u,m,E,I,F,B;e={...e,steps:(e.steps||[]).filter(He).filter(ze)};for(const c of e.steps)typeof c=="object"&&c.step==="importFile"&&(c.step="importWxr",g.logger.warn('The "importFile" step is deprecated. Use "importWxr" instead.'));if(e.constants&&e.steps.unshift({step:"defineWpConfigConsts",consts:e.constants}),e.siteOptions&&e.steps.unshift({step:"setSiteOptions",options:e.siteOptions}),e.plugins){const c=e.plugins.map(w=>typeof w=="string"?w.startsWith("https://")?{resource:"url",url:w}:{resource:"wordpress.org/plugins",slug:w}:w).map(w=>({step:"installPlugin",pluginZipFile:w}));e.steps.unshift(...c)}e.login&&e.steps.push({step:"login",...e.login===!0?{username:"admin",password:"password"}:e.login}),e.phpExtensionBundles||(e.phpExtensionBundles=[]),e.phpExtensionBundles||(e.phpExtensionBundles=[]),e.phpExtensionBundles.length===0&&e.phpExtensionBundles.push("kitchen-sink");const r=(l=e.steps)==null?void 0:l.findIndex(c=>typeof c=="object"&&(c==null?void 0:c.step)==="wp-cli");r!==void 0&&r>-1&&(e.phpExtensionBundles.includes("light")&&(e.phpExtensionBundles=e.phpExtensionBundles.filter(c=>c!=="light"),g.logger.warn("The wpCli step used in your Blueprint requires the iconv and mbstring PHP extensions. However, you did not specify the kitchen-sink extension bundle. Playground will override your choice and load the kitchen-sink PHP extensions bundle to prevent the WP-CLI step from failing. ")),(u=e.steps)==null||u.splice(r,0,{step:"writeFile",data:{resource:"url",url:"https://playground.wordpress.net/wp-cli.phar"},path:"/tmp/wp-cli.phar"}));const s=(m=e.steps)==null?void 0:m.findIndex(c=>typeof c=="object"&&(c==null?void 0:c.step)==="importWxr");s!==void 0&&s>-1&&(e.phpExtensionBundles.includes("light")&&(e.phpExtensionBundles=e.phpExtensionBundles.filter(c=>c!=="light"),g.logger.warn("The importWxr step used in your Blueprint requires the iconv and mbstring PHP extensions. However, you did not specify the kitchen-sink extension bundle. Playground will override your choice and load the kitchen-sink PHP extensions bundle to prevent the WP-CLI step from failing. ")),(E=e.steps)==null||E.splice(s,0,{step:"installPlugin",pluginZipFile:{resource:"url",url:"https://playground.wordpress.net/wordpress-importer.zip",caption:"Downloading the WordPress Importer plugin"}}));const{valid:a,errors:d}=Ne(e);if(!a){const c=new Error(`Invalid blueprint: ${d[0].message} at ${d[0].instancePath}`);throw c.errors=d,c}const p=e.steps||[],h=p.reduce((c,w)=>{var y;return c+(((y=w.progress)==null?void 0:y.weight)||1)},0),f=p.map(c=>Ge(c,{semaphore:n,rootProgressTracker:t,totalProgressWeight:h}));return{versions:{php:De((I=e.preferredVersions)==null?void 0:I.php,P.SupportedPHPVersions,P.LatestSupportedPHPVersion),wp:((F=e.preferredVersions)==null?void 0:F.wp)||"latest"},phpExtensions:Me([],e.phpExtensionBundles||[]),features:{networking:((B=e.features)==null?void 0:B.networking)??!1},run:async c=>{try{for(const{resources:w}of f)for(const y of w)y.setPlayground(c),y.isAsync&&y.resolve();for(const[w,{run:y,step:A}]of Object.entries(f))try{const $=await y(c);i($,A)}catch($){throw g.logger.error($),new Error(`Error when executing the blueprint step #${w} (${JSON.stringify(A)}) ${$ instanceof Error?`: ${$.message}`:$}`,{cause:$})}}finally{try{await c.goTo(e.landingPage||"/")}catch{}t.finish()}}}}const Ae=new fe({discriminator:!0});let T;function Ne(e){var r;T=Ae.compile(Ue);const t=T(e);if(t)return{valid:t};const n=new Set;for(const s of T.errors)s.schemaPath.startsWith("#/properties/steps/items/anyOf")||n.add(s.instancePath);const i=(r=T.errors)==null?void 0:r.filter(s=>!(s.schemaPath.startsWith("#/properties/steps/items/anyOf")&&n.has(s.instancePath)));return{valid:t,errors:i}}function De(e,t,n){return e&&t.includes(e)?e:n}function Me(e,t){const n=P.SupportedPHPExtensionsList.filter(r=>e.includes(r)),i=t.flatMap(r=>r in P.SupportedPHPExtensionBundles?P.SupportedPHPExtensionBundles[r]:[]);return Array.from(new Set([...n,...i]))}function He(e){return!!(typeof e=="object"&&e)}function ze(e){return["setPhpIniEntry","request"].includes(e.step)?(g.logger.warn(`The "${e.step}" Blueprint is no longer supported and you can remove it from your Blueprint.`),!1):!0}function Ge(e,{semaphore:t,rootProgressTracker:n,totalProgressWeight:i}){var f;const r=n.stage((((f=e.progress)==null?void 0:f.weight)||1)/i),s={};for(const l of Object.keys(e)){let u=e[l];Te(u)&&(u=_.create(u,{semaphore:t})),s[l]=u}const a=async l=>{var u;try{return r.fillSlowly(),await Fe[e.step](l,await Ve(s),{tracker:r,initialCaption:(u=e.progress)==null?void 0:u.caption})}finally{r.finish()}},d=H(s),p=H(s).filter(l=>l.isAsync),h=1/(p.length+1);for(const l of p)l.progress=r.stage(h);return{run:a,step:e,resources:d}}function H(e){const t=[];for(const n in e){const i=e[n];i instanceof _&&t.push(i)}return t}async function Ve(e){const t={};for(const n in e){const i=e[n];i instanceof _?t[n]=await i.resolve():t[n]=i}return t}async function Qe(e,t){await e.run(t)}function Ye(){}exports.activatePlugin=R;exports.activateTheme=L;exports.compileBlueprint=Be;exports.cp=X;exports.defineSiteUrl=W;exports.defineWpConfigConsts=b;exports.enableMultisite=Z;exports.exportWXR=ie;exports.importWordPressFiles=ne;exports.importWxr=te;exports.installPlugin=se;exports.installTheme=oe;exports.login=v;exports.mkdir=K;exports.mv=J;exports.request=k;exports.resetData=ae;exports.rm=q;exports.rmdir=ee;exports.runBlueprintSteps=Qe;exports.runPHP=G;exports.runPHPWithOptions=V;exports.runSql=Q;exports.runWpInstallationWizard=pe;exports.setPluginProxyURL=Ye;exports.setSiteOptions=O;exports.unzip=S;exports.updateUserMeta=Y;exports.wpCLI=de;exports.wpContentFilesExcludedFromExport=j;exports.writeFile=C;exports.zipWpContent=ce;
|
|
699
|
+
for existing apps using this option.`}},required:["consts","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"defineSiteUrl"},siteUrl:{type:"string",description:"The URL"}},required:["siteUrl","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"enableMultisite"}},required:["step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"importWxr"},file:{$ref:"#/definitions/FileReference",description:"The file to import"}},required:["file","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"importThemeStarterContent",description:"The step identifier."},themeSlug:{type:"string",description:"The name of the theme to import content from."}},required:["step","themeSlug"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"importWordPressFiles"},wordPressFilesZip:{$ref:"#/definitions/FileReference",description:"The zip file containing the top-level WordPress files and directories."},pathInZip:{type:"string",description:"The path inside the zip file where the WordPress files are."}},required:["step","wordPressFilesZip"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},ifAlreadyInstalled:{type:"string",enum:["overwrite","skip","error"],description:"What to do if the asset already exists."},step:{type:"string",const:"installPlugin",description:"The step identifier."},pluginZipFile:{$ref:"#/definitions/FileReference",description:"The plugin zip file to install."},options:{$ref:"#/definitions/InstallPluginOptions",description:"Optional installation options."}},required:["pluginZipFile","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},ifAlreadyInstalled:{type:"string",enum:["overwrite","skip","error"],description:"What to do if the asset already exists."},step:{type:"string",const:"installTheme",description:"The step identifier."},themeZipFile:{$ref:"#/definitions/FileReference",description:"The theme zip file to install."},options:{type:"object",properties:{activate:{type:"boolean",description:"Whether to activate the theme after installing it."},importStarterContent:{type:"boolean",description:"Whether to import the theme's starter content after installing it."}},additionalProperties:!1,description:"Optional installation options."}},required:["step","themeZipFile"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"login"},username:{type:"string",description:"The user to log in as. Defaults to 'admin'."},password:{type:"string",description:"The password to log in with. Defaults to 'password'."}},required:["step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"mkdir"},path:{type:"string",description:"The path of the directory you want to create"}},required:["path","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"mv"},fromPath:{type:"string",description:"Source path"},toPath:{type:"string",description:"Target path"}},required:["fromPath","step","toPath"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"resetData"}},required:["step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"request"},request:{$ref:"#/definitions/PHPRequest",description:"Request details (See /wordpress-playground/api/universal/interface/PHPRequest)"}},required:["request","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"rm"},path:{type:"string",description:"The path to remove"}},required:["path","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"rmdir"},path:{type:"string",description:"The path to remove"}},required:["path","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"runPHP",description:"The step identifier."},code:{type:"string",description:"The PHP code to run."}},required:["code","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"runPHPWithOptions"},options:{$ref:"#/definitions/PHPRunOptions",description:"Run options (See /wordpress-playground/api/universal/interface/PHPRunOptions/))"}},required:["options","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"runWpInstallationWizard"},options:{$ref:"#/definitions/WordPressInstallationOptions"}},required:["options","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"runSql",description:"The step identifier."},sql:{$ref:"#/definitions/FileReference",description:"The SQL to run. Each non-empty line must contain a valid SQL query."}},required:["sql","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"setSiteOptions",description:'The name of the step. Must be "setSiteOptions".'},options:{type:"object",additionalProperties:{},description:"The options to set on the site."}},required:["options","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"unzip"},zipFile:{$ref:"#/definitions/FileReference",description:"The zip file to extract"},zipPath:{type:"string",description:"The path of the zip file to extract",deprecated:"Use zipFile instead."},extractToPath:{type:"string",description:"The path to extract the zip file to"}},required:["extractToPath","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"updateUserMeta"},meta:{type:"object",additionalProperties:{},description:'An object of user meta values to set, e.g. { "first_name": "John" }'},userId:{type:"number",description:"User ID"}},required:["meta","step","userId"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"writeFile"},path:{type:"string",description:"The path of the file to write to"},data:{anyOf:[{$ref:"#/definitions/FileReference"},{type:"string"},{type:"object",properties:{BYTES_PER_ELEMENT:{type:"number"},buffer:{type:"object",properties:{byteLength:{type:"number"}},required:["byteLength"],additionalProperties:!1},byteLength:{type:"number"},byteOffset:{type:"number"},length:{type:"number"}},required:["BYTES_PER_ELEMENT","buffer","byteLength","byteOffset","length"],additionalProperties:{type:"number"}}],description:"The data to write"}},required:["data","path","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"wp-cli",description:"The step identifier."},command:{anyOf:[{type:"string"},{type:"array",items:{type:"string"}}],description:"The WP CLI command to run."},wpCliPath:{type:"string",description:"wp-cli.phar path"}},required:["command","step"]},{type:"object",additionalProperties:!1,properties:{progress:{type:"object",properties:{weight:{type:"number"},caption:{type:"string"}},additionalProperties:!1},step:{type:"string",const:"setSiteLanguage"},language:{type:"string",description:"The language to set, e.g. 'en_US'"}},required:["language","step"]}]},InstallPluginOptions:{type:"object",properties:{activate:{type:"boolean",description:"Whether to activate the plugin after installing it."}},additionalProperties:!1},PHPRequest:{type:"object",properties:{method:{$ref:"#/definitions/HTTPMethod",description:"Request method. Default: `GET`."},url:{type:"string",description:"Request path or absolute URL."},headers:{$ref:"#/definitions/PHPRequestHeaders",description:"Request headers."},body:{anyOf:[{type:"string"},{type:"object",properties:{BYTES_PER_ELEMENT:{type:"number"},buffer:{type:"object",properties:{byteLength:{type:"number"}},required:["byteLength"],additionalProperties:!1},byteLength:{type:"number"},byteOffset:{type:"number"},length:{type:"number"}},required:["BYTES_PER_ELEMENT","buffer","byteLength","byteOffset","length"],additionalProperties:{type:"number"}},{type:"object",additionalProperties:{anyOf:[{type:"string"},{type:"object",properties:{BYTES_PER_ELEMENT:{type:"number"},buffer:{type:"object",properties:{byteLength:{type:"number"}},required:["byteLength"],additionalProperties:!1},byteLength:{type:"number"},byteOffset:{type:"number"},length:{type:"number"}},required:["BYTES_PER_ELEMENT","buffer","byteLength","byteOffset","length"],additionalProperties:{type:"number"}},{type:"object",properties:{size:{type:"number"},type:{type:"string"},lastModified:{type:"number"},name:{type:"string"},webkitRelativePath:{type:"string"}},required:["lastModified","name","size","type","webkitRelativePath"],additionalProperties:!1}]}}],description:"Request body. If an object is given, the request will be encoded as multipart and sent with a `multipart/form-data` header."}},required:["url"],additionalProperties:!1},HTTPMethod:{type:"string",enum:["GET","POST","HEAD","OPTIONS","PATCH","PUT","DELETE"]},PHPRequestHeaders:{type:"object",additionalProperties:{type:"string"}},PHPRunOptions:{type:"object",properties:{relativeUri:{type:"string",description:"Request path following the domain:port part."},scriptPath:{type:"string",description:"Path of the .php file to execute."},protocol:{type:"string",description:"Request protocol."},method:{$ref:"#/definitions/HTTPMethod",description:"Request method. Default: `GET`."},headers:{$ref:"#/definitions/PHPRequestHeaders",description:"Request headers."},body:{anyOf:[{type:"string"},{type:"object",properties:{BYTES_PER_ELEMENT:{type:"number"},buffer:{type:"object",properties:{byteLength:{type:"number"}},required:["byteLength"],additionalProperties:!1},byteLength:{type:"number"},byteOffset:{type:"number"},length:{type:"number"}},required:["BYTES_PER_ELEMENT","buffer","byteLength","byteOffset","length"],additionalProperties:{type:"number"}}],description:"Request body."},env:{type:"object",additionalProperties:{type:"string"},description:"Environment variables to set for this run."},$_SERVER:{type:"object",additionalProperties:{type:"string"},description:"$_SERVER entries to set for this run."},code:{type:"string",description:"The code snippet to eval instead of a php file."}},additionalProperties:!1},WordPressInstallationOptions:{type:"object",properties:{adminUsername:{type:"string"},adminPassword:{type:"string"}},additionalProperties:!1}},Fe={$schema:We,$ref:Ue,definitions:Ie},{wpCLI:Be,...M}=Te,Ae={...M,"wp-cli":Be,importFile:M.importWxr};function De(e,{progress:t=new G.ProgressTracker,semaphore:n=new o.Semaphore({concurrency:3}),onStepCompleted:i=()=>{}}={}){var p,u,m,E,F,B,A;e={...e,steps:(e.steps||[]).filter(Ve).filter(Ge)};for(const d of e.steps)typeof d=="object"&&d.step==="importFile"&&(d.step="importWxr",g.logger.warn('The "importFile" step is deprecated. Use "importWxr" instead.'));if(e.constants&&e.steps.unshift({step:"defineWpConfigConsts",consts:e.constants}),e.siteOptions&&e.steps.unshift({step:"setSiteOptions",options:e.siteOptions}),e.plugins){const d=e.plugins.map(w=>typeof w=="string"?w.startsWith("https://")?{resource:"url",url:w}:{resource:"wordpress.org/plugins",slug:w}:w).map(w=>({step:"installPlugin",pluginZipFile:w}));e.steps.unshift(...d)}e.login&&e.steps.push({step:"login",...e.login===!0?{username:"admin",password:"password"}:e.login}),e.phpExtensionBundles||(e.phpExtensionBundles=[]),e.phpExtensionBundles||(e.phpExtensionBundles=[]),e.phpExtensionBundles.length===0&&e.phpExtensionBundles.push("kitchen-sink");const r=(p=e.steps)==null?void 0:p.findIndex(d=>typeof d=="object"&&(d==null?void 0:d.step)==="wp-cli");r!==void 0&&r>-1&&(e.phpExtensionBundles.includes("light")&&(e.phpExtensionBundles=e.phpExtensionBundles.filter(d=>d!=="light"),g.logger.warn("The wpCli step used in your Blueprint requires the iconv and mbstring PHP extensions. However, you did not specify the kitchen-sink extension bundle. Playground will override your choice and load the kitchen-sink PHP extensions bundle to prevent the WP-CLI step from failing. ")),(u=e.steps)==null||u.splice(r,0,{step:"writeFile",data:{resource:"url",url:"https://playground.wordpress.net/wp-cli.phar"},path:"/tmp/wp-cli.phar"}));const s=(m=e.steps)==null?void 0:m.findIndex(d=>typeof d=="object"&&(d==null?void 0:d.step)==="importWxr");s!==void 0&&s>-1&&(e.phpExtensionBundles.includes("light")&&(e.phpExtensionBundles=e.phpExtensionBundles.filter(d=>d!=="light"),g.logger.warn("The importWxr step used in your Blueprint requires the iconv and mbstring PHP extensions. However, you did not specify the kitchen-sink extension bundle. Playground will override your choice and load the kitchen-sink PHP extensions bundle to prevent the WP-CLI step from failing. ")),(E=e.steps)==null||E.splice(s,0,{step:"installPlugin",pluginZipFile:{resource:"url",url:"https://playground.wordpress.net/wordpress-importer.zip",caption:"Downloading the WordPress Importer plugin"}}));const{valid:a,errors:l}=ze(e);if(!a){const d=new Error(`Invalid blueprint: ${l[0].message} at ${l[0].instancePath}`);throw d.errors=l,d}const c=e.steps||[],f=c.reduce((d,w)=>{var y;return d+(((y=w.progress)==null?void 0:y.weight)||1)},0),h=c.map(d=>Qe(d,{semaphore:n,rootProgressTracker:t,totalProgressWeight:f}));return{versions:{php:Me((F=e.preferredVersions)==null?void 0:F.php,b.SupportedPHPVersions,b.LatestSupportedPHPVersion),wp:((B=e.preferredVersions)==null?void 0:B.wp)||"latest"},phpExtensions:He([],e.phpExtensionBundles||[]),features:{networking:((A=e.features)==null?void 0:A.networking)??!1},run:async d=>{try{for(const{resources:w}of h)for(const y of w)y.setPlayground(d),y.isAsync&&y.resolve();for(const[w,{run:y,step:D}]of Object.entries(h))try{const $=await y(d);i($,D)}catch($){throw g.logger.error($),new Error(`Error when executing the blueprint step #${w} (${JSON.stringify(D)}) ${$ instanceof Error?`: ${$.message}`:$}`,{cause:$})}}finally{try{await d.goTo(e.landingPage||"/")}catch{}t.finish()}}}}const Ne=new we({discriminator:!0});let T;function ze(e){var r;T=Ne.compile(Fe);const t=T(e);if(t)return{valid:t};const n=new Set;for(const s of T.errors)s.schemaPath.startsWith("#/properties/steps/items/anyOf")||n.add(s.instancePath);const i=(r=T.errors)==null?void 0:r.filter(s=>!(s.schemaPath.startsWith("#/properties/steps/items/anyOf")&&n.has(s.instancePath)));return{valid:t,errors:i}}function Me(e,t,n){return e&&t.includes(e)?e:n}function He(e,t){const n=b.SupportedPHPExtensionsList.filter(r=>e.includes(r)),i=t.flatMap(r=>r in b.SupportedPHPExtensionBundles?b.SupportedPHPExtensionBundles[r]:[]);return Array.from(new Set([...n,...i]))}function Ve(e){return!!(typeof e=="object"&&e)}function Ge(e){return["setPhpIniEntry","request"].includes(e.step)?(g.logger.warn(`The "${e.step}" Blueprint is no longer supported and you can remove it from your Blueprint.`),!1):!0}function Qe(e,{semaphore:t,rootProgressTracker:n,totalProgressWeight:i}){var h;const r=n.stage((((h=e.progress)==null?void 0:h.weight)||1)/i),s={};for(const p of Object.keys(e)){let u=e[p];ke(u)&&(u=_.create(u,{semaphore:t})),s[p]=u}const a=async p=>{var u;try{return r.fillSlowly(),await Ae[e.step](p,await Ye(s),{tracker:r,initialCaption:(u=e.progress)==null?void 0:u.caption})}finally{r.finish()}},l=H(s),c=H(s).filter(p=>p.isAsync),f=1/(c.length+1);for(const p of c)p.progress=r.stage(f);return{run:a,step:e,resources:l}}function H(e){const t=[];for(const n in e){const i=e[n];i instanceof _&&t.push(i)}return t}async function Ye(e){const t={};for(const n in e){const i=e[n];i instanceof _?t[n]=await i.resolve():t[n]=i}return t}async function Ze(e,t){await e.run(t)}function Xe(){}exports.activatePlugin=R;exports.activateTheme=L;exports.compileBlueprint=De;exports.cp=K;exports.defineSiteUrl=W;exports.defineWpConfigConsts=P;exports.enableMultisite=J;exports.exportWXR=se;exports.importThemeStarterContent=U;exports.importWordPressFiles=re;exports.importWxr=ie;exports.installPlugin=ae;exports.installTheme=pe;exports.login=k;exports.mkdir=te;exports.mv=ee;exports.request=v;exports.resetData=ce;exports.rm=q;exports.rmdir=ne;exports.runBlueprintSteps=Ze;exports.runPHP=Q;exports.runPHPWithOptions=Y;exports.runSql=Z;exports.runWpInstallationWizard=le;exports.setPluginProxyURL=Xe;exports.setSiteLanguage=he;exports.setSiteOptions=C;exports.unzip=S;exports.updateUserMeta=X;exports.wpCLI=ue;exports.wpContentFilesExcludedFromExport=j;exports.writeFile=O;exports.zipWpContent=de;
|