Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp-now load .zip downloaded from wordpress-playground #137

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from

Conversation

rhildred
Copy link

@rhildred rhildred commented Jan 7, 2024

What?

Bring .zip from wordpress-playground into node.js with wp-now. I also exposed the existing wp-cli code on the command line with @wp-now/wp-now wp --version for further testing.

Why?

I am leading a class in wordpress this term. There is a lab each week, for which students hand in a .zip of their site. Wordpress-playground offers the ability for students to produce the .zip that I am looking for. To mark the lab, I have code that makes a folder for each student. I want to be able to start a terminal in vscode in the student folder, type npx @wp-now/wp-now start and see the student's wordpress.

I exposed the wp-cli interface in wp-now so that I can author a plugin that creates a static site from wordpress using ob_start. For instance:

 class WDS_CLI {

	public function build() {
		if (!file_exists('dist')) {
			mkdir('dist', 0777, true);
		}
		ob_start();
		// Include the template file
		include 'index.php';

		// End buffering and return its contents
		$output = ob_get_clean();
		$myfile = fopen("dist/index.html", "w") or die("Unable to open file!");
		fwrite($myfile, $output);
		fclose($myfile);		   
	}
}

How?

I added a mode that looks for a wp-content folder without a wp-include folder. From there it was fairly short work to get the mounts correct to use the folder.

Testing Instructions

  1. Make a site in wordpress-playground and download a .zip.
  2. In a checked out copy of playground tools do
    npm run build
  3. mkdir test && cd test
  4. unzip ~/Downloads/wordpress-playground\ \(8\).zip or something
  5. run node ../dist/packages/wp-now/main.js start

Thanks so much for this package and your advice on using it with my students. My plan is to use wp-playground and the .zip download for my student's first wordpress class on Monday night.

@rhildred
Copy link
Author

This now works with my wp-bundler wp-cli command. https://github.com/rhildred/wp-bundler. The idea is that I can add the wp-bundler plugin in wordpress playground and it will build on cloudflare pages or github pages with wp-now wp wp-bundler build


php.mount(`${projectPath}/wp-content`, `${documentRoot}/wp-content`);

if (!fs.existsSync(`${projectPath}/wp-content/db.php`)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see why you put that in here. Normally mountSqlitePlugin() takes care of that, but it also overrides the database file – and in your case the database file is already there. I'd love mountSqlitePlugin() to respect any pre-existing databases so that runWpContentMode() could work with both a "regular" WordPress and a Playground export. What do you think @sejas @danielbachhuber ?

@adamziel
Copy link
Collaborator

This is a great use-case @rhildred, thank you for proposing this PR! It marks an important step in making Playground portable between the browser and a local dev environment ❤️ I left an inline note to see if we could make one of the existing modes support that use-case instead of creating a new mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants