Skip to content

Commit 63faa52

Browse files
committed
npx degit wpengine/faustjs/examples/next/tutorial#issue-2211 faust-tutorial
1 parent 7749a39 commit 63faa52

30 files changed

+10842
-0
lines changed

faust-tutorial/.env.local.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Your WordPress site URL
2+
NEXT_PUBLIC_WORDPRESS_URL=http://localhost:8888
3+
4+
# Plugin secret found in WordPress Settings->Faust
5+
# Pre-configured for the tutorial - no need to change this!
6+
FAUST_SECRET_KEY=47485b27a3d36728659cd62feb79658b3d05712b41095c13eeb73fcba7d33ac7

faust-tutorial/.wp-env.json

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+
}

faust-tutorial/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Learn Faust.js
2+
3+
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/).

faust-tutorial/eslint.config.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { dirname } from "path";
2+
import { fileURLToPath } from "url";
3+
import { FlatCompat } from "@eslint/eslintrc";
4+
5+
const __filename = fileURLToPath(import.meta.url);
6+
const __dirname = dirname(__filename);
7+
8+
const compat = new FlatCompat({
9+
baseDirectory: __dirname,
10+
});
11+
12+
const eslintConfig = [...compat.extends("next/core-web-vitals")];
13+
14+
export default eslintConfig;

faust-tutorial/faust.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import templates from "./src/wp-templates/index";
2+
import possibleTypes from "./possibleTypes.json";
3+
import { setConfig } from "@faustwp/core";
4+
5+
/**
6+
* @type {import('@faustwp/core').FaustConfig}
7+
**/
8+
export default setConfig({
9+
templates,
10+
possibleTypes,
11+
});

faust-tutorial/jsconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"paths": {
4+
"@/*": ["./src/*"]
5+
}
6+
}
7+
}

faust-tutorial/next.config.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { createSecureHeaders } = require('next-secure-headers');
2+
const { withFaust, getWpHostname } = require('@faustwp/core');
3+
4+
/**
5+
* @type {import('next').NextConfig}
6+
**/
7+
module.exports = withFaust({
8+
reactStrictMode: true,
9+
sassOptions: {
10+
includePaths: ['node_modules'],
11+
},
12+
images: {
13+
domains: [getWpHostname()],
14+
},
15+
async headers() {
16+
return [
17+
{
18+
source: '/:path*',
19+
headers: createSecureHeaders({
20+
xssProtection: false,
21+
}),
22+
},
23+
];
24+
},
25+
});

0 commit comments

Comments
 (0)