@wp-playground/cli 0.7.17 → 0.7.19

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/cli.js ADDED
@@ -0,0 +1,43 @@
1
+ import m from"fs";import h,{basename as R}from"path";import x from"yargs";import z from"express";import{rotatePHPRuntime as E,SupportedPHPVersions as I,PHPRequestHandler as H,PHPResponse as W}from"@php-wasm/universal";import{logger as f}from"@php-wasm/logger";import{NodePHP as _}from"@php-wasm/node";import{rootCertificates as k}from"tls";import{dirname as q}from"@php-wasm/util";import{unzip as b,defineSiteUrl as F,zipWpContent as B,runWpInstallationWizard as C,runBlueprintSteps as D,compileBlueprint as T}from"@wp-playground/blueprints";import P from"fs-extra";import A from"os";import{EmscriptenDownloadMonitor as j,ProgressTracker as L}from"@php-wasm/progress";import{RecommendedPHPVersion as O}from"@wp-playground/wordpress";async function M(e){const t=z(),r=await new Promise((o,a)=>{const n=t.listen(e.port,()=>{const d=n.address();d===null||typeof d=="string"?a(new Error("Server address is not available")):o(n)})});t.use("/",async(o,a)=>{const n=await e.handleRequest({url:o.url,headers:U(o),method:o.method,body:await N(o)});a.statusCode=n.httpStatusCode;for(const d in n.headers)a.setHeader(d,n.headers[d]);a.end(n.bytes)});const i=r.address().port;await e.onBind(i)}const N=async e=>await new Promise(t=>{const r=[];e.on("data",s=>{r.push(s)}),e.on("end",()=>{t(Buffer.concat(r))})}),U=e=>{const t={};if(e.rawHeaders&&e.rawHeaders.length)for(let r=0;r<e.rawHeaders.length;r+=2)t[e.rawHeaders[r].toLowerCase()]=e.rawHeaders[r+1];return t};async function V(e,t,r){const s=async()=>await _.loadRuntime(t),i=new _;return i.requestHandler=e,i.initializeRuntime(await s()),i.setSapiName("cli"),i.setPhpIniPath("/tmp/php.ini"),i.writeFile("/tmp/php.ini",""),i.setPhpIniEntry("memory_limit","256M"),i.setPhpIniEntry("allow_url_fopen","1"),i.setPhpIniEntry("disable_functions",""),i.setPhpIniEntry("openssl.cafile","/tmp/ca-bundle.crt"),i.writeFile("/tmp/ca-bundle.crt",k.join(`
2
+ `)),r||Z(await e.getPrimaryPhp(),i,"/wordpress"),E({php:i,cwd:"/wordpress",recreateRuntime:s,maxRequests:400}),i}function Z(e,t,r){const s=Object.getOwnPropertySymbols(e)[0];for(const i of[r,"/tmp"])t.fileExists(i)||t.mkdir(i),e.fileExists(i)||e.mkdir(i),t[s].FS.mount(t[s].PROXYFS,{root:i,fs:e[s].FS},i)}async function J(e,t,r){const s=(await e.run({code:"<?php echo php_ini_loaded_file();"})).text,i=q(s);e.fileExists(i)||e.mkdir(i),e.fileExists(s)||e.writeFile(s,"");const o=e.readFileAsText(s),a=Object.entries(t).map(([n,d])=>`${n} = ${d}`).join(`
3
+ `);e.writeFile(s,[o,a].join(`
4
+ `));try{await r()}finally{e.writeFile(s,o)}}const v=h.join(A.homedir(),".wordpress-playground");async function S(e,t,r){const s=h.join(v,t);return P.existsSync(s)||(P.ensureDirSync(v),await Q(e,s,r)),$(s)}async function Q(e,t,r){const i=(await r.monitorFetch(fetch(e))).body.getReader(),o=P.createWriteStream(t);for(;;){const{done:a,value:n}=await i.read();if(n&&o.write(n),a)break}o.close(),o.closed||await new Promise((a,n)=>{o.on("finish",d=>{d?n(d):a(null)})})}function $(e,t){return new File([P.readFileSync(e)],t??R(e))}async function Y(e="latest"){if(e==="trunk"||e==="nightly")return{url:"https://wordpress.org/nightly-builds/wordpress-latest.zip",version:"nightly-"+new Date().toISOString().split("T")[0]};let t=await fetch("https://api.wordpress.org/core/version-check/1.7/?channel=beta").then(r=>r.json());t=t.offers.filter(r=>r.response==="autoupdate");for(const r of t){if(e==="beta"&&r.version.includes("beta"))return{url:r.download,version:r.version};if(e==="latest")return{url:r.download,version:r.version};if(r.version.substring(0,e.length)===e)return{url:r.download,version:r.version}}return{url:`https://wordpress.org/wordpress-${e}.zip`,version:e}}async function G(e,t="latest",r){const s=await Y(t),[i,o]=await Promise.all([S(s.url,`${s.version}.zip`,r),S("https://github.com/WordPress/sqlite-database-integration/archive/refs/heads/main.zip","sqlite.zip",r)]);await K(e,i,o);const a=h.join(v,`prebuilt-wp-content-for-wp-${s.version}.zip`);if(m.existsSync(a))await b(e,{zipFile:$(a),extractToPath:"/wordpress"});else{await F(e,{siteUrl:"http://playground.internal"}),await J(e,{disable_functions:"fsockopen",allow_url_fopen:"0"},async()=>await C(e,{options:{}}));const n=await B(e);m.writeFileSync(a,n)}}async function K(e,t,r){e.mkdir("/tmp/unzipped-wordpress"),await b(e,{zipFile:t,extractToPath:"/tmp/unzipped-wordpress"});const s=e.fileExists("/tmp/unzipped-wordpress/wordpress")?"/tmp/unzipped-wordpress/wordpress":"/tmp/unzipped-wordpress";e.mv(s,"/wordpress"),e.mkdir("/tmp/sqlite-database-integration"),await b(e,{zipFile:r,extractToPath:"/tmp/sqlite-database-integration"}),e.mv("/tmp/sqlite-database-integration/sqlite-database-integration-main","/wordpress/sqlite-database-integration");const o=e.readFileAsText("/wordpress/sqlite-database-integration/db.copy").replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'","__DIR__.'/../sqlite-database-integration/'").replace("'{SQLITE_PLUGIN}'","__DIR__.'/../sqlite-database-integration/load.php'");e.writeFile("/wordpress/wp-content/db.php",o),e.writeFile("/wordpress/wp-includes/default-filters.php",e.readFileAsText("/wordpress/wp-includes/default-filters.php")+`
5
+ // Redirect /wp-admin to /wp-admin/
6
+ add_filter( 'redirect_canonical', function( $redirect_url ) {
7
+ if ( '/wp-admin' === $redirect_url ) {
8
+ return $redirect_url . '/';
9
+ }
10
+ return $redirect_url;
11
+ } );
12
+
13
+ // Needed because gethostbyname( 'wordpress.org' ) returns
14
+ // a private network IP address for some reason.
15
+ add_filter( 'allowed_redirect_hosts', function( $deprecated = '' ) {
16
+ return array(
17
+ 'wordpress.org',
18
+ 'api.wordpress.org',
19
+ 'downloads.wordpress.org',
20
+ );
21
+ } );
22
+
23
+ // Support permalinks without "index.php"
24
+ add_filter( 'got_url_rewrite', '__return_true' );
25
+ `),e.writeFile("/wordpress/wp-config.php",e.readFileAsText("/wordpress/wp-config-sample.php"))}function X(e){return/^latest$|^trunk$|^nightly$|^(?:(\d+)\.(\d+)(?:\.(\d+))?)((?:-beta(?:\d+)?)|(?:-RC(?:\d+)?))?$/.test(e)}async function ee(){const e=await x(process.argv.slice(2)).usage("Usage: wp-playground <command> [options]").positional("command",{describe:"Command to run",type:"string",choices:["server","run-blueprint","build-snapshot"]}).option("outfile",{describe:"When building, write to this output file.",type:"string",default:"wordpress.zip"}).option("port",{describe:"Port to listen on when serving.",type:"number",default:9400}).option("php",{describe:"PHP version to use.",type:"string",default:O,choices:I}).option("wp",{describe:"WordPress version to use.",type:"string",default:"latest"}).option("mount",{describe:"Mount a directory to the PHP runtime. You can provide --mount multiple times. Format: /host/path:/vfs/path",type:"array",string:!0}).option("login",{describe:"Should log the user in",type:"boolean",default:!1}).option("blueprint",{describe:"Blueprint to execute.",type:"string"}).option("skipWordPressSetup",{describe:"Do not download, unzip, and install WordPress. Useful for mounting a pre-configured WordPress directory at /wordpress.",type:"boolean",default:!1}).option("quiet",{describe:"Do not output logs and progress messages.",type:"boolean",default:!1}).check(p=>{if(p.wp!==void 0&&!X(p.wp))throw new Error('Unrecognized WordPress version. Please use "latest" or numeric versions such as "6.2", "6.0.1", "6.2-beta1", or "6.2-RC1"');if(p.blueprint!==void 0){const l=h.resolve(process.cwd(),p.blueprint);if(!m.existsSync(l))throw new Error("Blueprint file does not exist");const w=m.readFileSync(l,"utf-8");try{p.blueprint=JSON.parse(w)}catch{throw new Error("Blueprint file is not a valid JSON file")}}return!0});e.wrap(e.terminalWidth());const t=await e.argv;t.quiet&&(f.handlers=[]);async function r(p){const{php:l,reap:w}=await n.processManager.acquirePHPInstance();try{await l.run({code:`<?php
26
+ $zip = new ZipArchive();
27
+ if(false === $zip->open('/tmp/build.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
28
+ throw new Exception('Failed to create ZIP');
29
+ }
30
+ $files = new RecursiveIteratorIterator(
31
+ new RecursiveDirectoryIterator('/wordpress')
32
+ );
33
+ foreach ($files as $file) {
34
+ echo $file . PHP_EOL;
35
+ if (!$file->isFile()) {
36
+ continue;
37
+ }
38
+ $zip->addFile($file->getPathname(), $file->getPathname());
39
+ }
40
+ $zip->close();
41
+
42
+ `});const u=l.readFileAsBuffer("/tmp/build.zip");m.writeFileSync(p,u)}finally{w()}}async function s(p,l,w){if(!t.skipWordPressSetup){f.log(`Setting up WordPress ${l}`);const c=new j;c.addEventListener("progress",g=>{const y=Math.round(Math.min(100,100*g.detail.loaded/g.detail.total));t.quiet||process.stdout.write(`\rDownloading WordPress ${y}%... `)}),await G(p,l,c)}const u=(t.mount||[]).map(c=>{const[g,y]=c.split(":");return{hostPath:h.resolve(process.cwd(),g),vfsPath:y}});for(const c of u)p.mount(c.hostPath,c.vfsPath);await F(p,{siteUrl:w})}function i(){let p;t.blueprint?p=t.blueprint:p={preferredVersions:{php:t.php,wp:t.wp},login:t.login};const l=new L;let w="",u=!1;return l.addEventListener("progress",c=>{u||(c.detail.progress===100&&(u=!0),w=c.detail.caption||w||"Running the Blueprint",process.stdout.write(`\r\x1B[K${w.trim()} – ${c.detail.progress}%`),u&&process.stdout.write(`
43
+ `))}),T(p,{progress:l})}const o=t._[0];["run-blueprint","server","build-snapshot"].includes(o)||(e.showHelp(),process.exit(1));const a=i();let n,d=!1;f.log("Starting a PHP server..."),M({port:t.port,onBind:async p=>{const l=`http://127.0.0.1:${p}`;n=new H({phpFactory:async({isPrimary:u})=>V(n,a.versions.php,u),documentRoot:"/wordpress",absoluteUrl:l});const w=await n.getPrimaryPhp();if(await s(w,a.versions.wp,l),d=!0,a){const{php:u,reap:c}=await n.processManager.acquirePHPInstance();try{f.log("Running the Blueprint..."),await D(a,u),f.log("Finished running the blueprint")}finally{c()}}o==="build-snapshot"?(r(t.outfile),f.log(`WordPress exported to ${t.outfile}`),process.exit(0)):o==="run-blueprint"?(f.log("Blueprint executed"),process.exit(0)):f.log(`WordPress is running on ${l}`)},async handleRequest(p){return d?await n.request(p):W.forHttpCode(502,"WordPress is not ready yet")}})}ee();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-playground/cli",
3
- "version": "0.7.17",
3
+ "version": "0.7.19",
4
4
  "description": "WordPress Playground CLI",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,19 +23,19 @@
23
23
  "type": "module",
24
24
  "main": "main.js",
25
25
  "bin": "wp-playground.js",
26
- "gitHead": "e3dcff126eb945284ef91b5c764746281ac7df4c",
26
+ "gitHead": "687ec237085853ff5c808814c28be349146a5d1a",
27
27
  "dependencies": {
28
28
  "comlink": "^4.4.1",
29
29
  "express": "4.19.2",
30
30
  "fs-extra": "11.1.1",
31
31
  "ws": "8.13.0",
32
32
  "yargs": "17.7.2",
33
- "@php-wasm/universal": "0.7.17",
34
- "@php-wasm/logger": "0.7.17",
35
- "@wp-playground/blueprints": "0.7.17",
36
- "@php-wasm/node": "0.7.17",
37
- "@php-wasm/progress": "0.7.17",
38
- "@wp-playground/wordpress": "0.7.17",
39
- "@php-wasm/util": "0.7.17"
33
+ "@php-wasm/universal": "0.7.19",
34
+ "@php-wasm/logger": "0.7.19",
35
+ "@wp-playground/blueprints": "0.7.19",
36
+ "@php-wasm/node": "0.7.19",
37
+ "@php-wasm/progress": "0.7.19",
38
+ "@wp-playground/wordpress": "0.7.19",
39
+ "@php-wasm/util": "0.7.19"
40
40
  }
41
41
  }
package/wp-playground.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import './cli.cjs';
2
+ import './cli.js';
package/cli.cjs DELETED
@@ -1,43 +0,0 @@
1
- "use strict";const P=require("fs"),m=require("path"),z=require("yargs"),q=require("express"),h=require("@php-wasm/universal"),g=require("@php-wasm/logger"),S=require("@php-wasm/node"),x=require("tls"),E=require("@php-wasm/util"),f=require("@wp-playground/blueprints"),b=require("fs-extra"),H=require("os"),F=require("@php-wasm/progress"),I=require("@wp-playground/wordpress");async function W(e){const t=q(),r=await new Promise((o,a)=>{const n=t.listen(e.port,()=>{const p=n.address();p===null||typeof p=="string"?a(new Error("Server address is not available")):o(n)})});t.use("/",async(o,a)=>{const n=await e.handleRequest({url:o.url,headers:B(o),method:o.method,body:await k(o)});a.statusCode=n.httpStatusCode;for(const p in n.headers)a.setHeader(p,n.headers[p]);a.end(n.bytes)});const i=r.address().port;await e.onBind(i)}const k=async e=>await new Promise(t=>{const r=[];e.on("data",s=>{r.push(s)}),e.on("end",()=>{t(Buffer.concat(r))})}),B=e=>{const t={};if(e.rawHeaders&&e.rawHeaders.length)for(let r=0;r<e.rawHeaders.length;r+=2)t[e.rawHeaders[r].toLowerCase()]=e.rawHeaders[r+1];return t};async function C(e,t,r){const s=async()=>await S.NodePHP.loadRuntime(t),i=new S.NodePHP;return i.requestHandler=e,i.initializeRuntime(await s()),i.setSapiName("cli"),i.setPhpIniPath("/tmp/php.ini"),i.writeFile("/tmp/php.ini",""),i.setPhpIniEntry("memory_limit","256M"),i.setPhpIniEntry("allow_url_fopen","1"),i.setPhpIniEntry("disable_functions",""),i.setPhpIniEntry("openssl.cafile","/tmp/ca-bundle.crt"),i.writeFile("/tmp/ca-bundle.crt",x.rootCertificates.join(`
2
- `)),r||D(await e.getPrimaryPhp(),i,"/wordpress"),h.rotatePHPRuntime({php:i,cwd:"/wordpress",recreateRuntime:s,maxRequests:400}),i}function D(e,t,r){for(const s of[r,"/tmp"])t.fileExists(s)||t.mkdir(s),e.fileExists(s)||e.mkdir(s),t[h.__private__dont__use].FS.mount(t[h.__private__dont__use].PROXYFS,{root:s,fs:e[h.__private__dont__use].FS},s)}async function T(e,t,r){const s=(await e.run({code:"<?php echo php_ini_loaded_file();"})).text,i=E.dirname(s);e.fileExists(i)||e.mkdir(i),e.fileExists(s)||e.writeFile(s,"");const o=e.readFileAsText(s),a=Object.entries(t).map(([n,p])=>`${n} = ${p}`).join(`
3
- `);e.writeFile(s,[o,a].join(`
4
- `));try{await r()}finally{e.writeFile(s,o)}}const v=m.join(H.homedir(),".wordpress-playground");async function $(e,t,r){const s=m.join(v,t);return b.existsSync(s)||(b.ensureDirSync(v),await A(e,s,r)),R(s)}async function A(e,t,r){const i=(await r.monitorFetch(fetch(e))).body.getReader(),o=b.createWriteStream(t);for(;;){const{done:a,value:n}=await i.read();if(n&&o.write(n),a)break}o.close(),o.closed||await new Promise((a,n)=>{o.on("finish",p=>{p?n(p):a(null)})})}function R(e,t){return new File([b.readFileSync(e)],t??m.basename(e))}async function L(e="latest"){if(e==="trunk"||e==="nightly")return{url:"https://wordpress.org/nightly-builds/wordpress-latest.zip",version:"nightly-"+new Date().toISOString().split("T")[0]};let t=await fetch("https://api.wordpress.org/core/version-check/1.7/?channel=beta").then(r=>r.json());t=t.offers.filter(r=>r.response==="autoupdate");for(const r of t){if(e==="beta"&&r.version.includes("beta"))return{url:r.download,version:r.version};if(e==="latest")return{url:r.download,version:r.version};if(r.version.substring(0,e.length)===e)return{url:r.download,version:r.version}}return{url:`https://wordpress.org/wordpress-${e}.zip`,version:e}}async function j(e,t="latest",r){const s=await L(t),[i,o]=await Promise.all([$(s.url,`${s.version}.zip`,r),$("https://github.com/WordPress/sqlite-database-integration/archive/refs/heads/main.zip","sqlite.zip",r)]);await M(e,i,o);const a=m.join(v,`prebuilt-wp-content-for-wp-${s.version}.zip`);if(P.existsSync(a))await f.unzip(e,{zipFile:R(a),extractToPath:"/wordpress"});else{await f.defineSiteUrl(e,{siteUrl:"http://playground.internal"}),await T(e,{disable_functions:"fsockopen",allow_url_fopen:"0"},async()=>await f.runWpInstallationWizard(e,{options:{}}));const n=await f.zipWpContent(e);P.writeFileSync(a,n)}}async function M(e,t,r){e.mkdir("/tmp/unzipped-wordpress"),await f.unzip(e,{zipFile:t,extractToPath:"/tmp/unzipped-wordpress"});const s=e.fileExists("/tmp/unzipped-wordpress/wordpress")?"/tmp/unzipped-wordpress/wordpress":"/tmp/unzipped-wordpress";e.mv(s,"/wordpress"),e.mkdir("/tmp/sqlite-database-integration"),await f.unzip(e,{zipFile:r,extractToPath:"/tmp/sqlite-database-integration"}),e.mv("/tmp/sqlite-database-integration/sqlite-database-integration-main","/wordpress/sqlite-database-integration");const o=e.readFileAsText("/wordpress/sqlite-database-integration/db.copy").replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'","__DIR__.'/../sqlite-database-integration/'").replace("'{SQLITE_PLUGIN}'","__DIR__.'/../sqlite-database-integration/load.php'");e.writeFile("/wordpress/wp-content/db.php",o),e.writeFile("/wordpress/wp-includes/default-filters.php",e.readFileAsText("/wordpress/wp-includes/default-filters.php")+`
5
- // Redirect /wp-admin to /wp-admin/
6
- add_filter( 'redirect_canonical', function( $redirect_url ) {
7
- if ( '/wp-admin' === $redirect_url ) {
8
- return $redirect_url . '/';
9
- }
10
- return $redirect_url;
11
- } );
12
-
13
- // Needed because gethostbyname( 'wordpress.org' ) returns
14
- // a private network IP address for some reason.
15
- add_filter( 'allowed_redirect_hosts', function( $deprecated = '' ) {
16
- return array(
17
- 'wordpress.org',
18
- 'api.wordpress.org',
19
- 'downloads.wordpress.org',
20
- );
21
- } );
22
-
23
- // Support permalinks without "index.php"
24
- add_filter( 'got_url_rewrite', '__return_true' );
25
- `),e.writeFile("/wordpress/wp-config.php",e.readFileAsText("/wordpress/wp-config-sample.php"))}function N(e){return/^latest$|^trunk$|^nightly$|^(?:(\d+)\.(\d+)(?:\.(\d+))?)((?:-beta(?:\d+)?)|(?:-RC(?:\d+)?))?$/.test(e)}async function O(){const e=await z(process.argv.slice(2)).usage("Usage: wp-playground <command> [options]").positional("command",{describe:"Command to run",type:"string",choices:["server","run-blueprint","build-snapshot"]}).option("outfile",{describe:"When building, write to this output file.",type:"string",default:"wordpress.zip"}).option("port",{describe:"Port to listen on when serving.",type:"number",default:9400}).option("php",{describe:"PHP version to use.",type:"string",default:I.RecommendedPHPVersion,choices:h.SupportedPHPVersions}).option("wp",{describe:"WordPress version to use.",type:"string",default:"latest"}).option("mount",{describe:"Mount a directory to the PHP runtime. You can provide --mount multiple times. Format: /host/path:/vfs/path",type:"array",string:!0}).option("login",{describe:"Should log the user in",type:"boolean",default:!1}).option("blueprint",{describe:"Blueprint to execute.",type:"string"}).option("skipWordPressSetup",{describe:"Do not download, unzip, and install WordPress. Useful for mounting a pre-configured WordPress directory at /wordpress.",type:"boolean",default:!1}).option("quiet",{describe:"Do not output logs and progress messages.",type:"boolean",default:!1}).check(l=>{if(l.wp!==void 0&&!N(l.wp))throw new Error('Unrecognized WordPress version. Please use "latest" or numeric versions such as "6.2", "6.0.1", "6.2-beta1", or "6.2-RC1"');if(l.blueprint!==void 0){const d=m.resolve(process.cwd(),l.blueprint);if(!P.existsSync(d))throw new Error("Blueprint file does not exist");const w=P.readFileSync(d,"utf-8");try{l.blueprint=JSON.parse(w)}catch{throw new Error("Blueprint file is not a valid JSON file")}}return!0});e.wrap(e.terminalWidth());const t=await e.argv;t.quiet&&(g.logger.handlers=[]);async function r(l){const{php:d,reap:w}=await n.processManager.acquirePHPInstance();try{await d.run({code:`<?php
26
- $zip = new ZipArchive();
27
- if(false === $zip->open('/tmp/build.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
28
- throw new Exception('Failed to create ZIP');
29
- }
30
- $files = new RecursiveIteratorIterator(
31
- new RecursiveDirectoryIterator('/wordpress')
32
- );
33
- foreach ($files as $file) {
34
- echo $file . PHP_EOL;
35
- if (!$file->isFile()) {
36
- continue;
37
- }
38
- $zip->addFile($file->getPathname(), $file->getPathname());
39
- }
40
- $zip->close();
41
-
42
- `});const u=d.readFileAsBuffer("/tmp/build.zip");P.writeFileSync(l,u)}finally{w()}}async function s(l,d,w){if(!t.skipWordPressSetup){g.logger.log(`Setting up WordPress ${d}`);const c=new F.EmscriptenDownloadMonitor;c.addEventListener("progress",y=>{const _=Math.round(Math.min(100,100*y.detail.loaded/y.detail.total));t.quiet||process.stdout.write(`\rDownloading WordPress ${_}%... `)}),await j(l,d,c)}const u=(t.mount||[]).map(c=>{const[y,_]=c.split(":");return{hostPath:m.resolve(process.cwd(),y),vfsPath:_}});for(const c of u)l.mount(c.hostPath,c.vfsPath);await f.defineSiteUrl(l,{siteUrl:w})}function i(){let l;t.blueprint?l=t.blueprint:l={preferredVersions:{php:t.php,wp:t.wp},login:t.login};const d=new F.ProgressTracker;let w="",u=!1;return d.addEventListener("progress",c=>{u||(c.detail.progress===100&&(u=!0),w=c.detail.caption||w||"Running the Blueprint",process.stdout.write(`\r\x1B[K${w.trim()} – ${c.detail.progress}%`),u&&process.stdout.write(`
43
- `))}),f.compileBlueprint(l,{progress:d})}const o=t._[0];["run-blueprint","server","build-snapshot"].includes(o)||(e.showHelp(),process.exit(1));const a=i();let n,p=!1;g.logger.log("Starting a PHP server..."),W({port:t.port,onBind:async l=>{const d=`http://127.0.0.1:${l}`;n=new h.PHPRequestHandler({phpFactory:async({isPrimary:u})=>C(n,a.versions.php,u),documentRoot:"/wordpress",absoluteUrl:d});const w=await n.getPrimaryPhp();if(await s(w,a.versions.wp,d),p=!0,a){const{php:u,reap:c}=await n.processManager.acquirePHPInstance();try{g.logger.log("Running the Blueprint..."),await f.runBlueprintSteps(a,u),g.logger.log("Finished running the blueprint")}finally{c()}}o==="build-snapshot"?(r(t.outfile),g.logger.log(`WordPress exported to ${t.outfile}`),process.exit(0)):o==="run-blueprint"?(g.logger.log("Blueprint executed"),process.exit(0)):g.logger.log(`WordPress is running on ${d}`)},async handleRequest(l){return p?await n.request(l):h.PHPResponse.forHttpCode(502,"WordPress is not ready yet")}})}O();