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: execute blueprint steps given a file path #82

Merged
merged 24 commits into from
Jun 23, 2023
Merged

Conversation

sejas
Copy link
Collaborator

@sejas sejas commented Jun 19, 2023

What?

It adds Blueprint support for wp-now.
Blueprint steps code relies heavily on Web functions and some of them will not work on Javascript for Node.js. We will need to find those steps and convert them into isomorphic javascript.

Why?

How?

After setting up WordPress and for all the modes except index we apply the blueprint steps before any PHP request, so before installing the theme/plugin and before auto-logging.

If the steps defineWpConfigConsts or defineSiteUrl are passed in the blueprint steps, then we will use its value to change the absoluteUrl.

Testing Instructions

  1. Add 127.0.0.1 myurl.wpnow to your /etc/hosts
  2. Create a blueprint JSON file in your current directory named foo.json.
Blueprint example:
{
    "steps": [
        {
            "step": "defineWpConfigConsts",
            "consts": {
                "WP_HOME": "http://myurl.wpnow",
                "WP_SITEURL": "http://myurl.wpnow"
            },
            "virtualize": true
        }
    ]
}

Check out more examples: https://wordpress.github.io/wordpress-playground/docs/blueprints-api/examples

  1. Run nvm use > npm install . This PR requires Node v20+
  2. Build this branch: npx nx build wp-now
  3. Run node dist/packages/wp-now/main.js start --blueprint=foo.json --port=80
  4. Observe blurpinrt steps: 1 and Blueprint step completed: defineWpConfigConsts appear in the console output
  5. Observe the URL http://myurl.wpnow opens in your browser and WordPress still working as expected.

Ngrok case

  1. Run ngrok http 8881.
  2. Modify the foo.json file with the ngrok temporal URL.
  3. Run node dist/packages/wp-now/main.js start --blueprint=foo.json --port=80
  4. Observe the ngrok URL opens and WordPress works as expected.

@sejas sejas added the wp-now label Jun 19, 2023
@sejas sejas self-assigned this Jun 19, 2023
@sergeymitr
Copy link

Hi @sejas.
Thanks for working on this!

I'm getting an error trying start the server:

ReferenceError: CustomEvent is not defined
    at F.notifyProgress (file:///.../node_modules/@wp-playground/blueprints/index.js:725:11)
    at F.finish (file:///.../node_modules/@wp-playground/blueprints/index.js:664:165)
    at Object.run (file:///.../node_modules/@wp-playground/blueprints/index.js:2017:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async yt (file:///.../node_modules/@wp-playground/blueprints/index.js:2079:3)
    at async startWPNow (file:///.../dist/packages/wp-now/main.js:570:5)
    at async startServer (file:///.../dist/packages/wp-now/main.js:831:42)
    at async Object.handler (file:///.../dist/packages/wp-now/main.js:987:25)

Removing dist and node_modules and rebuilding didn't help.

@sejas
Copy link
Collaborator Author

sejas commented Jun 20, 2023

Hi @sejas. Thanks for working on this!

I'm getting an error trying start the server:

@sergeymitr , thanks for trying this PR. I changed the testing instructions to cover the custom domain case.

Not all the blueprints are supported at the moment. For example, install plugins/themes are failing. We will need to adapt those blueprint steps to work in Node.js. This is not limiting for merging this PR, though.

@sejas sejas changed the title WIP wp-now: execute blueprint steps given a file path wp-now: execute blueprint steps given a file path Jun 20, 2023
@sejas sejas marked this pull request as ready for review June 20, 2023 13:20
@sejas sejas requested review from adamziel, wojtekn and kozer June 23, 2023 11:10
"step": "defineWpConfigConsts",
"consts": {
"WP_HOME": "http://127.0.0.1",
"WP_SITEURL": "http://127.0.0.1"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using 127.0.0.1 instead of myurl.wpnow because the DNS tests would fail resolving that custom URL.
The default URL is localhost:8881.

@kozer
Copy link
Collaborator

kozer commented Jun 23, 2023

I checked that @sejas , and works as expected! Nice work!

@sejas sejas merged commit 02f25d4 into trunk Jun 23, 2023
2 checks passed
@sejas sejas deleted the add/wp-now-blueprints branch June 23, 2023 16:43
@sejas
Copy link
Collaborator Author

sejas commented Jun 23, 2023

I merged this branch. It would be great to bump the playground dependencies such us @wp-playground/blueprints when they are released on NPM.

@@ -1,6 +1,6 @@
import { runCli } from './run-cli';

const requiredMajorVersion = 18;
const requiredMajorVersion = 20;
Copy link
Member

Choose a reason for hiding this comment

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

In the future, can we handle version bumps as a separate PR?

Related WordPress/wordpress-playground#591 (review)

@@ -65,6 +66,92 @@ Of these, `wp-now php` currently supports the `--path=<path>` and `--php=<versio
- The `~/.wp-now` home directory is used to store the WP versions and the `wp-content` folders for projects using 'theme', 'plugin', 'wp-content', and 'playground' modes. The path to `wp-content` directory for the 'plugin', 'theme', and 'wp-content' modes is `~/.wp-now/wp-content/${projectName}-${directoryHash}`. 'playground' mode shares the same `~/.wp-now/wp-content/playground` directory, regardless of where it's started.
- For the database setup, `wp-now` is using [SQLite database integration plugin](https://wordpress.org/plugins/sqlite-database-integration/). The path to SQLite database is ` ~/.wp-now/wp-content/${projectName}-${directoryHash}/database/.ht.sqlite`

## Using Blueprints
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for including docs! I cleaned up a couple of things with #85

@dmsnell
Copy link
Contributor

dmsnell commented Jul 18, 2023

Do we need to publish the packages now that this is merged? it doesn't seem like support is there in the version pulled from npx @wp-now/wp-now

@danielbachhuber
Copy link
Member

Do we need to publish the packages now that this is merged? it doesn't seem like support is there in the version pulled from npx @wp-now/wp-now

To close the loop on this: we met in Slack and published the new version.

@dawidurbanski
Copy link
Contributor

Is there any reason why only steps from blueprints are supported?
I just tested this and it seems like neither landingPage option nor preferredVersions is respected.
Should I create new ticket for this? I'm also happy to contribute in this matter.

@dawidurbanski
Copy link
Contributor

Never mind, I see this being mentioned in the PR description: #9

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

Successfully merging this pull request may close these issues.

wp-now: Support for running a Blueprint on start
6 participants