Skip to content

Commit d57d82c

Browse files
committed
Update Faust.js tutorial example setup and docs
Added .wp-env.json and supporting wp-env files for improved local WordPress setup. Updated README with detailed setup instructions and commands. Changed default WordPress port in .env.local.example. Removed obsolete faust-tutorial-blueprint.json. Updated dependencies in package.json and package-lock.json. Improved tutorial documentation in docs/tutorial/learn-faust/index.md.
1 parent a3bcf2e commit d57d82c

File tree

11 files changed

+10466
-8198
lines changed

11 files changed

+10466
-8198
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "faust-tutorial",
3+
"version": "0.1.0",
4+
"private": true,
5+
"license": "0BSD",
6+
"scripts": {
7+
"dev": "next dev --turbopack",
8+
"build": "next build",
9+
"generate": "faust generatePossibleTypes",
10+
"start": "next start",
11+
"lint": "next lint",
12+
"tutorial:start": "npm run wp:start && npm run dev",
13+
"tutorial:stop": "npm run wp:stop",
14+
"tutorial:setup": "npm install && npm run wp:start && npm run wp:db:import",
15+
"tutorial:prune": "npm run wp:destroy && npm run tutorial:setup && npm run tutorial:start",
16+
"wp:start": "npm install && wp-env start",
17+
"wp:stop": "wp-env stop",
18+
"wp:destroy": "wp-env destroy",
19+
"wp:db:query": "wp-env run cli -- wp db query",
20+
"wp:db:export": "wp-env run cli -- wp db export /var/www/html/db/database.sql",
21+
"wp:db:import": "wp-env run cli -- wp db import /var/www/html/db/database.sql",
22+
"wp-env": "wp-env"
23+
},
24+
"dependencies": {
25+
"@apollo/client": "^3.13.9",
26+
"@faustwp/blocks": "^6.1.3",
27+
"@faustwp/cli": "^3.2.4",
28+
"@faustwp/core": "^3.2.4",
29+
"graphql": "^16.11.0",
30+
"next": "^15.4.5",
31+
"next-secure-headers": "^2.2.0",
32+
"react": "^19.0.0",
33+
"react-dom": "^19.0.0"
34+
},
35+
"devDependencies": {
36+
"@eslint/eslintrc": "^3.3.1",
37+
"@wordpress/env": "^10.35.0",
38+
"eslint": "^9.32.0",
39+
"eslint-config-next": "15.1.6",
40+
"postcss": "^8",
41+
"tailwindcss": "^3.4.1"
42+
},
43+
"overrides": {
44+
"@babel/runtime": "^7.26.10"
45+
}
46+
}

docs/tutorial/learn-faust/index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ In order to complete this tutorial, you should:
2020
- Be comfortable running commands on the [command line](https://en.wikipedia.org/wiki/Command-line_interface)
2121
- Have [Node.js and NPM](https://nodejs.org/) installed on your computer
2222

23-
You should also not have any other projects running on port `3000` or `8881`, since the links in this tutorial point to pages on those ports.
23+
You should also not have any other projects running on port `3000` or `8888`, since the links in this tutorial point to pages on those ports. You'll also need [Docker](https://www.docker.com/) installed and running to use wp-env for the WordPress backend.
2424

2525
## Set up
2626

@@ -39,12 +39,12 @@ npx degit wpengine/faustjs/examples/next/tutorial faust-tutorial
3939
Initial set up steps:
4040

4141
- `cd` into the `/faust-tutorial` project folder.
42-
- Run `npm run wp-dev`. This command uses the [`wp-now`](https://www.npmjs.com/package/@wp-now/wp-now) NPM package and the included [`faust-tutorial-blueprint.json`](https://github.com/wpengine/faustjs/blob/canary/examples/next/tutorial/faust-tutorial-blueprint.json) blueprint file to set up a local WordPress environment.
43-
- When asked if it's okay to install the `@wp-now/wp-now` package, answer `y` to confirm.
42+
- Run `npm run tutorial:setup`. This command uses [`wp-env`](https://developer.wordpress.org/block-editor/getting-started/devenv/get-started-with-wp-env/) to set up a local WordPress environment with Docker. The configuration is defined in the `.wp-env.json` file included in the project.
43+
- The setup process will install dependencies, start the WordPress environment, and import a pre-configured database.
4444

4545
After a moment, you should have a WordPress site up-and-running.
4646

47-
By navigating to http://localhost:8881/wp-admin/plugins.php, You can see that the required [FaustWP](https://wordpress.org/plugins/faustwp/) and [WPGraphQL](https://wordpress.org/plugins/wp-graphql/) plugins have already been installed for you.
47+
By navigating to http://localhost:8888/wp-admin/plugins.php, you can see that the required [FaustWP](https://wordpress.org/plugins/faustwp/) and [WPGraphQL](https://wordpress.org/plugins/wp-graphql/) plugins have already been installed for you.
4848

4949
Next, we'll just configure a few last things in WordPress.
5050

@@ -70,7 +70,7 @@ Follow these steps to set up your Faust.js frontend:
7070

7171
```env title=".env.local"
7272
# Your WordPress site URL
73-
NEXT_PUBLIC_WORDPRESS_URL=http://localhost:8881
73+
NEXT_PUBLIC_WORDPRESS_URL=http://localhost:8888
7474
7575
# Plugin secret found in WordPress Settings->Faust
7676
FAUST_SECRET_KEY=ABC123
@@ -166,7 +166,7 @@ export default templates;
166166
167167
This tells Faust to use the `PageTemplate` component as the template to render pages that match `page`, according to the template hierarchy.
168168
169-
Save your changes and visit [http://localhost:3000/sample-page/](http://localhost:3000/sample-page/) in a browser. You should be able to see the title and content for the [Sample Page page in WordPress](http://localhost:8881/wp-admin/post.php?post=2&action=edit).
169+
Save your changes and visit [http://localhost:3000/sample-page/](http://localhost:3000/sample-page/) in a browser. You should be able to see the title and content for the [Sample Page page in WordPress](http://localhost:8888/wp-admin/post.php?post=2&action=edit).
170170
171171
Now that you understand how to leverage the template hierarchy, you can follow this pattern to add additional page templates:
172172
@@ -381,7 +381,7 @@ You should now be able to visit http://localhost:3000/blog/hello-world/ and see
381381

382382
Inspect the blog post content in the browser dev tools and notice that each block is being rendered and that only the paragraph blocks are wrapped in a `div` with a class name of `paragraph-block-wrapper`. Currently, we're not leveraging the `paragraph-block-wrapper` class in any way, but you can see the potential here. By being able to query for and render blocks individually, you have the ability to wrap specific blocks in arbitrary markup, override specific blocks with custom implementations, and more.
383383
384-
Now [edit the Hello World! blog post](http://localhost:8881/wp-admin/post.php?post=1&action=edit). Make several changes to it in terms of font size, padding, margin, a border, an HTML anchor, and additional CSS classes, then save your changes.
384+
Now [edit the Hello World! blog post](http://localhost:8888/wp-admin/post.php?post=1&action=edit). Make several changes to it in terms of font size, padding, margin, a border, an HTML anchor, and additional CSS classes, then save your changes.
385385
386386
Reload the http://localhost:3000/blog/hello-world/ page in your frontend app and see that all the changes you applied are now being reflected. Inspect the paragraph block in DevTools to see markup similar to the example below. You can see that Faust has taken care of rendering the paragraph tag to include these attributes, and even loaded the CSS required to apply the correct styles.
387387
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Your WordPress site URL
2-
NEXT_PUBLIC_WORDPRESS_URL=http://localhost:8881
2+
NEXT_PUBLIC_WORDPRESS_URL=http://localhost:8888
33

44
# Plugin secret found in WordPress Settings->Faust
55
FAUST_SECRET_KEY=
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"phpVersion": "8.3",
3+
"plugins": [
4+
"https://github.com/wp-graphql/wp-graphql/releases/latest/download/wp-graphql.zip",
5+
"https://downloads.wordpress.org/plugin/faustwp.latest-stable.zip"
6+
],
7+
"config": {
8+
"WP_DEBUG": true,
9+
"SCRIPT_DEBUG": false,
10+
"GRAPHQL_DEBUG": true,
11+
"WP_DEBUG_LOG": true,
12+
"WP_DEBUG_DISPLAY": false,
13+
"SAVEQUERIES": false
14+
},
15+
"mappings": {
16+
"db": "./wp-env/db",
17+
"wp-content/uploads": "./wp-env/uploads",
18+
".htaccess": "./wp-env/setup/.htaccess"
19+
},
20+
"lifecycleScripts": {
21+
"afterStart": "wp-env run cli -- wp rewrite structure '/blog/%postname%/' && wp-env run cli -- wp rewrite flush"
22+
}
23+
}

examples/next/tutorial/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,74 @@
11
# Learn Faust.js
22

33
Next.js app to be used with the [Learn Faust tutorial](https://faustjs.org/docs/tutorial/learn-faust/).
4+
5+
## Prerequisites
6+
7+
- Node.js (v18+ recommended)
8+
- [Docker](https://www.docker.com/) (required for running WordPress with wp-env)
9+
10+
**Note:** Make sure Docker is running before starting (`docker ps`)
11+
12+
## Quick Start
13+
14+
1. **Install dependencies**
15+
```bash
16+
npm install
17+
```
18+
19+
2. **Set up environment variables**
20+
21+
Copy the example file and configure:
22+
```bash
23+
cp .env.local.example .env.local
24+
```
25+
26+
3. **Start WordPress and the development server**
27+
```bash
28+
npm run tutorial:setup # First time setup
29+
npm run tutorial:start # Start WordPress and Next.js dev server
30+
```
31+
32+
4. **Access the application**
33+
- Frontend: [http://localhost:3000/](http://localhost:3000/)
34+
- WordPress Admin: [http://localhost:8888/wp-admin/](http://localhost:8888/wp-admin/)
35+
36+
> **Default credentials:** username: `admin`, password: `password`
37+
38+
5. **Configure Faust in WordPress**
39+
40+
Follow the tutorial at [faustjs.org/docs/tutorial/learn-faust/](https://faustjs.org/docs/tutorial/learn-faust/) to complete the setup.
41+
42+
## Available Commands
43+
44+
| Command | Description |
45+
| ------------------ | -------------------------------------------------------------- |
46+
| `tutorial:setup` | Initial setup: installs packages, starts wp-env, imports DB |
47+
| `tutorial:start` | Starts WordPress and the Next.js development server |
48+
| `tutorial:stop` | Stops the WordPress environment |
49+
| `tutorial:prune` | Rebuilds everything from scratch |
50+
| `wp:start` | Starts the WordPress environment |
51+
| `wp:stop` | Stops the WordPress environment |
52+
| `wp:destroy` | Completely removes the WordPress environment |
53+
| `wp:db:query` | Executes a database query within the WordPress environment |
54+
| `wp:db:export` | Exports the WordPress database to `wp-env/db/database.sql` |
55+
| `wp:db:import` | Imports the WordPress database from `wp-env/db/database.sql` |
56+
| `dev` | Runs the Next.js development server only |
57+
| `build` | Builds the Next.js application for production |
58+
59+
## Project Structure
60+
61+
```
62+
├── src # Next.js application source
63+
├── .wp-env.json # wp-env configuration file
64+
└── wp-env
65+
├── db
66+
│ └── database.sql # WordPress database with pre-configured settings
67+
├── setup
68+
│ └── .htaccess # CORS configuration
69+
└── uploads # WordPress uploads directory
70+
```
71+
72+
## Learn More
73+
74+
For detailed step-by-step instructions, visit the [Learn Faust tutorial](https://faustjs.org/docs/tutorial/learn-faust/).

examples/next/tutorial/faust-tutorial-blueprint.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)