-
Notifications
You must be signed in to change notification settings - Fork 273
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: create first version of the command #188
Conversation
Nx has a command that will set up a new "project" for you and add all the necessary boilerplate:
If you use it to create a |
packages/wp-now/src/start-server.ts
Outdated
multipartData += `${json[key]}${eol}`; | ||
} | ||
|
||
multipartData += `--${boundary}--${eol}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this not interfere with other multipart segments?
I would imagine that if we have more than one call to generateMultipartFormDataString
and then concatenate the strings we'll get empty parts because the boundary will be duplicated with no content in between
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's one-off per request and not meant to be concatenated. Eventually I'd love to somehow get rid of this entirely
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not add the final boundary outside of the function then? or create a kind of multipartJoinSegments
function so we don't do this?
I guess I was just a little confused because the function name suggests to me that it's a generic function to create multiple multi-part chunks.
packages/wp-now/src/wp-now.ts
Outdated
define('WP_HOME', "${this.options.absoluteUrl}"); | ||
define('WP_SITEURL', "${this.options.absoluteUrl}"); | ||
?>${contents}` | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems like @adamziel has been abstracting this into setupSiteUrl()
if we're concatenating <?php
multiple times we'll run into trouble, plus by defining WP_HOME
twice we might run into PHP crashes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference: defineSiteUrl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice addition! 🥳
In order to use defineSiteUrl
I would like to accept a custom documentRoot
.
Another option would be changing the wp-now
documentRoot to /wordpress
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tricky question: How could we handle wp-now run script.php
where script.php needs files outside of the current working directory? e.g. include "../../vendor/something.phar";
.
Calling php.useHostFilesystem()
would make it just work, but you couldn't mount WordPress anymore. Since it's all JavaScript, we could add support for mounting inside already–mounted paths, but first I'd like to explore what use-cases we're dealing with.
Would I need to ever go one level up from the WordPress path:
- If I'm a core developer? Probably no
- If I'm a plugin developer? Maybe...? But hopefully unlikely
- If I want to use wp-now just for its PHP and without WordPress? Surely! But that's out of scope for this project.
packages/wp-now/src/wp-now.ts
Outdated
|
||
mount() { | ||
this.mountWordpress() | ||
this.mountSqlite() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mountSqlite
is async
but this function isn't. we might want to make this async
and await this.mountSqlite()
or acknowledge that mount()
might return before mountSqlite
has completed (or technically, before it has even begun to process)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
mountSqlite
shouldn't be async 👍
Fixed here: 684fb86
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked out this branch, ran yarn install
, and then nx preview
crashed with this error:
nx preview wp-now start --path=/Users/danielbachhuber/projects/vanilla
> nx run wp-now:"build:bundle"
> nx run wp-now:"build:package-json"
> nx run wp-now:build
> nx run wp-now:preview start --path=/Users/danielbachhuber/projects/vanilla
(node:55204) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/danielbachhuber/projects/wordpress-playground/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:286
throw new ERR_MODULE_NOT_FOUND(
^
CustomError: Cannot find package '/Users/danielbachhuber/projects/wordpress-playground/node_modules/@php-wasm/node/' imported from /Users/danielbachhuber/projects/wordpress-playground/dist/packages/wp-now/main.js
at legacyMainResolve (/Users/danielbachhuber/projects/wordpress-playground/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:286:9)
at packageResolve (/Users/danielbachhuber/projects/wordpress-playground/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:750:14)
at moduleResolve (/Users/danielbachhuber/projects/wordpress-playground/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:798:18)
at Object.defaultResolve (/Users/danielbachhuber/projects/wordpress-playground/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:912:11)
at /Users/danielbachhuber/projects/wordpress-playground/node_modules/ts-node/src/esm.ts:218:35
at entrypointFallback (/Users/danielbachhuber/projects/wordpress-playground/node_modules/ts-node/src/esm.ts:168:34)
at /Users/danielbachhuber/projects/wordpress-playground/node_modules/ts-node/src/esm.ts:217:14
at addShortCircuitFlag (/Users/danielbachhuber/projects/wordpress-playground/node_modules/ts-node/src/esm.ts:409:21)
at resolve (/Users/danielbachhuber/projects/wordpress-playground/node_modules/ts-node/src/esm.ts:197:12)
at resolve (file:///Users/danielbachhuber/projects/wordpress-playground/packages/nx-extensions/src/executors/built-script/loader.mjs:37:15)
—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
> NX Ran target preview for project wp-now and 3 task(s) they depend on (1s)
With additional flags:
start
--path=/Users/danielbachhuber/projects/vanilla
✖ 1/4 failed
✔ 3/4 succeeded [0 read from cache]
Is there another setup step I'm missing?
I see the README now. Might be worth mentioning that in the PR description. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of minor nits. I think this is good to land otherwise
packages/wp-now/README.md
Outdated
@@ -0,0 +1,31 @@ | |||
# WP-NOW | |||
|
|||
`wp-now` is an intuitive Command Line Interface (CLI) tool designed to streamline the process of setting up a local WordPress environment by using only Node.js. This powerful tool is an ideal choice for developers working on WordPress themes and plugins. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`wp-now` is an intuitive Command Line Interface (CLI) tool designed to streamline the process of setting up a local WordPress environment by using only Node.js. This powerful tool is an ideal choice for developers working on WordPress themes and plugins. | |
`wp-now` is a Command Line Interface (CLI) tool designed to streamline the process of setting up a local WordPress environment by using only Node.js. This powerful tool is optimized for developers working on WordPress themes and plugins. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done here: dec0385
Thanks for the suggestion.
packages/wp-now/src/run-cli.ts
Outdated
type: 'string', | ||
default: process.cwd(), | ||
}); | ||
yargs.option('wp-content', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this argument is confusing. Can we remove it for now, and re-think it at a later point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed! 55189e4
The goal of the parameter was to map the wp-content folder to a diferent path.
Currently we are mapping it to: ~/.wp-now/wp-content/${projectName}-${sha1(projectPath)}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my approval shouldn't matter, but I'm giving it to say I see no reason to block this. thanks for creating associated issues!
@dmsnell, thank you for your invaluable code reviews 🙏. Your help has increased the quality of the code. Much appreciated! Now that we've successfully merged the first prototype, I believe it will be easier to iterate and improve |
nice work on the code. thanks for your effort and time on this! |
if (mode === 'plugin' || mode === 'theme') { | ||
const folderName = path.basename(this.options.projectPath); | ||
const partialPath = mode === 'plugin' ? 'plugins' : 'themes'; | ||
fs.ensureDirSync(path.join(wpContentPath, partialPath, folderName)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put ensureDirSync
directly in NodePHP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 , Not sure about this change. I'll take a deeper look tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rationale: I keep seeing confused developers "why is my mount() not working?" Everyone is going to get stuck here for a moment, make a few checks, and realize they need this to ensure the directory exists – we can remove the speed bump and just do it for them.
Proposed changes
wp-now start
Testing instructions
nx preview wp-now start --path=/Users/path-to-your-theme-or-plugin
http://127.0.0.1:8881
index
: Simple php filetheme
: loads WordPress with your theme includedplugin
: loads WordPress with your plugin includedScreencast
wp-now-run-source-code-peq.mp4