|
1 | 1 | # Next.js WordPress Starter <!-- omit in toc -->
|
2 | 2 |
|
3 |
| -WebDevStudios fork of the [official Next.js WordPress Example](https://github.com/vercel/next.js/tree/canary/examples/cms-wordpress). Used as a starter for headless WordPress projects. |
| 3 | +WebDevStudios fork of the official Next.js WordPress [example](https://github.com/vercel/next.js/tree/canary/examples/cms-wordpress). Used as a starter for headless WordPress projects. |
4 | 4 |
|
5 |
| -👉 https://nextjs-wordpress-starter.vercel.app |
| 5 | +**This project is still in active development. Use at your own risk.** |
| 6 | + |
| 7 | +https://nextjs-wordpress-starter-staging.vercel.app/ |
6 | 8 |
|
7 | 9 | <a href="https://webdevstudios.com/contact/"><img src="https://webdevstudios.com/wp-content/uploads/2018/04/wds-github-banner.png" alt="WebDevStudios. Your Success is Our Mission."></a>
|
8 | 10 |
|
9 | 11 | ## 🗂 Table of Contents <!-- omit in toc -->
|
10 | 12 |
|
11 |
| -- [🎓 Preface](#-preface) |
| 13 | +- [🎓 Overview](#-overview) |
| 14 | + - [Why?](#why) |
| 15 | + - [How's this all work?](#hows-this-all-work) |
| 16 | +- [🚀 Frontend Setup (Next.js)](#-frontend-setup-nextjs) |
12 | 17 | - [Dependencies](#dependencies)
|
13 |
| - - [Git Branches](#git-branches) |
14 |
| - - [Credentials](#credentials) |
15 |
| -- [🚀 Front-end Setup (Next.js)](#-front-end-setup-nextjs) |
16 |
| - - [Clone this repository](#clone-this-repository) |
17 |
| - - [Link Project with Vercel](#link-project-with-vercel) |
18 |
| - - [Install Front-end](#install-front-end) |
19 |
| - - [Start Dev Server](#start-dev-server) |
20 |
| -- [🔧 Back-end Setup (WordPress)](#-back-end-setup-wordpress) |
21 |
| - - [Setup Local](#setup-local) |
22 |
| - - [Migrate DB Pro](#migrate-db-pro) |
23 |
| - - [Copy WP Engine Environments](#copy-wp-engine-environments) |
24 |
| -- [💻 Development](#-development) |
| 18 | + - [Install](#install) |
| 19 | +- [🔧 Backend Setup (WordPress)](#-backend-setup-wordpress) |
| 20 | + - [Dependencies](#dependencies-1) |
| 21 | + - [Install](#install-1) |
| 22 | +- [💻 Frontend Development](#-frontend-development) |
25 | 23 | - [Git Workflow](#git-workflow)
|
26 | 24 | - [Deployments](#deployments)
|
27 | 25 | - [Storybook](#storybook)
|
| 26 | +- [WebDevStudios Specific Info](#webdevstudios-specific-info) |
| 27 | + - [WordPress Github](#wordpress-github) |
| 28 | + - [WP Engine](#wp-engine) |
28 | 29 | - [Chromatic](#chromatic)
|
| 30 | + - [1Password](#1password) |
| 31 | + - [Migrate DB Pro](#migrate-db-pro) |
| 32 | + - [Copy WP Engine Environments](#copy-wp-engine-environments) |
29 | 33 | - [:octocat: Contributing](#octocat-contributing)
|
30 | 34 |
|
31 | 35 | ---
|
32 | 36 |
|
33 |
| -## 🎓 Preface |
| 37 | +## 🎓 Overview |
34 | 38 |
|
35 |
| -### Dependencies |
| 39 | +### Why? |
36 | 40 |
|
37 |
| -You will need the following dependencies installed on your computer: |
| 41 | +It's easy to query a WordPress REST-API and map over some blog posts in JavaScript. That's where many examples on the Internet stop and you'd be hard pressed to find anything about supporting advanced features because **_headless WordPress is hard!_** |
38 | 42 |
|
39 |
| -- [Node 12](https://nodejs.org/en/) |
40 |
| -- [Yarn](https://yarnpkg.com/) |
41 |
| -- [Vercel CLI](https://vercel.com/download) |
| 43 | +At WebDevStudios we believe that WordPress is so much more than a blog-- and our clients require support for things like: SEO, forms, post previews, search, comments, authentication, custom post types, custom fields, etc... |
42 | 44 |
|
43 |
| -### Git Branches |
| 45 | +With this starter, we've figured out "the hard stuff" and placed the sum of our knowledge into something the community (and our future projects) could use as a jumping off point. |
44 | 46 |
|
45 |
| -- `develop` - auto deploys on Vercel |
46 |
| -- `staging` - auto deploys on Vercel |
47 |
| -- `main` - auto deploys on Vercel |
48 |
| -- `Pull Requests` - deployment previews are automatically generated by Vercel |
| 47 | +### How's this all work? |
49 | 48 |
|
50 |
| -### Credentials |
| 49 | +The frontend (Next.js) talks to the backend (WordPress) via GraphQL. |
51 | 50 |
|
52 |
| -- Credentials are in 1password --> Next.js Starter --> WordPress |
| 51 | +<details> |
| 52 | +<img src="https://dl.dropbox.com/s/9wsal7szatfwt6g/nextjs-wordpress-starter-frontend-backend-graphic.png?dl=0" alt="A graphic showing the relationship between environments"> |
| 53 | +</details> |
53 | 54 |
|
54 | 55 | ---
|
55 | 56 |
|
56 |
| -## 🚀 Front-end Setup (Next.js) |
| 57 | +## 🚀 Frontend Setup (Next.js) |
57 | 58 |
|
58 |
| -The following instructions will standup a local install of Next.js (front-end). It queries data from WordPress (back-end). |
| 59 | +The following steps will stand up a local install of Next.js. |
59 | 60 |
|
60 |
| -### Clone this repository |
| 61 | +### Dependencies |
61 | 62 |
|
62 |
| -```bash |
63 |
| -git clone [email protected]:WebDevStudios/nextjs-wordpress-starter.git |
64 |
| -``` |
| 63 | +Before you get started, make sure you have the following dependencies installed on your computer: |
65 | 64 |
|
66 |
| -### Link Project with Vercel |
| 65 | +- [Node 12](https://nodejs.org/en/) |
| 66 | +- [Yarn](https://yarnpkg.com/) |
| 67 | +- [Vercel CLI](https://vercel.com/download) |
67 | 68 |
|
68 |
| -If this step fails, you'll most likely need be added to the WDS Team in Vercel first. Learn more about [Project Linking](https://vercel.com/docs/cli#commands/overview/project-linking) with the Vercel CLI. |
| 69 | +### Install |
69 | 70 |
|
70 |
| -Install the [Vercel CLI](https://vercel.com/download): |
| 71 | +**Step 1: Clone the repo** |
71 | 72 |
|
72 | 73 | ```bash
|
73 |
| -npm i -g vercel |
| 74 | +git clone [email protected]:WebDevStudios/nextjs-wordpress-starter.git |
74 | 75 | ```
|
75 | 76 |
|
76 |
| -Change directories into this project: |
| 77 | +**Step 2: Change directories** |
77 | 78 |
|
78 | 79 | ```bash
|
79 | 80 | cd nextjs-wordpress-starter
|
80 | 81 | ```
|
81 | 82 |
|
82 |
| -Initialize Vercel by answering the questions in the command line when prompted: |
| 83 | +**Step 3: Install dependencies** |
83 | 84 |
|
84 | 85 | ```bash
|
85 |
| -vercel |
| 86 | +yarn |
86 | 87 | ```
|
87 | 88 |
|
88 |
| -### Install Front-end |
| 89 | +**Step 4: Setup ENV Variables** |
89 | 90 |
|
90 |
| -Pull down the ENV vars from Vercel: |
| 91 | +Copy the sample ENV file, then add your credentials: |
91 | 92 |
|
92 | 93 | ```bash
|
93 |
| -vercel env pull |
| 94 | +cp .env.sample .env |
94 | 95 | ```
|
95 | 96 |
|
96 |
| -Install dependencies: |
| 97 | +--OR-- |
| 98 | + |
| 99 | +[Link the project with Vercel](https://vercel.com/docs/cli#commands/overview/project-linking), then pull down the ENV variables: |
| 100 | + |
| 101 | +<details> |
| 102 | + |
| 103 | +The following steps require A) access to a Vercel account and B) assumes the ENV vars are already set up on Vercel. If you need access to the WDS Team account on Vercel, please reach out to Greg. |
| 104 | + |
| 105 | +**Step 1: Install the [Vercel CLI](https://vercel.com/download)** |
97 | 106 |
|
98 | 107 | ```bash
|
99 |
| -yarn |
| 108 | +npm i -g vercel |
| 109 | +``` |
| 110 | + |
| 111 | +**Step 2: Initialize Vercel** |
| 112 | + |
| 113 | +```bash |
| 114 | +vercel init |
100 | 115 | ```
|
101 | 116 |
|
102 |
| -### Start Dev Server |
| 117 | +Answer the questions in the command line when prompted. |
| 118 | + |
| 119 | +**Step 3: Pull down the ENV variables** |
103 | 120 |
|
104 | 121 | ```bash
|
105 |
| -yarn dev |
| 122 | +vercel env pull |
106 | 123 | ```
|
107 | 124 |
|
108 |
| -The frontend is now available at http://localhost:3000 |
| 125 | +</details> |
109 | 126 |
|
110 | 127 | ---
|
111 | 128 |
|
112 |
| -## 🔧 Back-end Setup (WordPress) |
| 129 | +## 🔧 Backend Setup (WordPress) |
113 | 130 |
|
114 |
| -The backend is hosted at WP Engine. There are 3 environments...please use Develop for working locally. |
| 131 | +The following steps will stand up a local install of WordPress. |
115 | 132 |
|
116 |
| -- [Develop](https://nextjsdevstart.wpengine.com/wp-admin/) |
117 |
| -- [Staging](https://nextjsstgstart.wpengine.com/wp-admin/) |
118 |
| -- [Production](https://nextjs.wpengine.com/wp-admin) |
| 133 | +### Dependencies |
119 | 134 |
|
120 |
| -**Note: There is no frontend for WordPress** - But it is running [wd_s](https://github.com/WebDevStudios/wd_s) which houses `/acf-json` and other functions. |
| 135 | +Before you get started, make sure you have the following dependency installed on your computer: |
121 | 136 |
|
122 |
| -### Setup Local |
| 137 | +- [Local WP](https://localwp.com/) |
123 | 138 |
|
124 |
| -There is an [Local export available](https://drive.google.com/drive/folders/1Ju81KThAUHOuWRNslw_m7xZScwoJYkr0). Simply import the `nextjs-wp-XX.XX.XX.zip` file and you can tinker with the WordPress backend. |
| 139 | +### Install |
125 | 140 |
|
126 |
| -### Migrate DB Pro |
| 141 | +**Step 1: Download the Local WP export** |
127 | 142 |
|
128 |
| -You can use Migrate DB Pro to pull databases and files. **Please see 1password --> Next.js Starter --> Migrate DB Pro** |
| 143 | +- [nextjs-wp-01.29.2021.zip (162MB)](https://drive.google.com/file/d/1iTVxyTS6ezy6RUhba9CbAjZL1x3iZyv7/view?usp=sharing) |
129 | 144 |
|
130 |
| -### Copy WP Engine Environments |
| 145 | +**Step 2: Import the .zip** |
131 | 146 |
|
132 |
| -WP Engine supports [copying environments](https://wpengine.com/support/copy-site/). For example, to copy Develop --> Staging: |
| 147 | +- https://localwp.com/help-docs/getting-started/how-to-import-a-wordpress-site-into-local/ |
133 | 148 |
|
134 |
| -1. Log into the WP Engine [User Portal](https://my.wpengine.com/sites) |
135 |
| -2. Click on [Nextjsstgstart](https://my.wpengine.com/installs/nextjsstgstart) |
136 |
| -3. In the top right corner, click the "Copy environment" button |
137 |
| -4. Select the options: |
138 |
| -  |
139 |
| -5. Click "Preview copy" and a modal will appear to let you verify the options |
140 |
| -6. Click "Copy environment" |
| 149 | +**Step 3: Start the `nextjs-wp` site** |
| 150 | + |
| 151 | +**Note:** Make sure your Local URL matches the `LOCAL_WORDPRESS_API_URL` in the frontend `.env` file! |
141 | 152 |
|
142 | 153 | ---
|
143 | 154 |
|
144 |
| -## 💻 Development |
| 155 | +## 💻 Frontend Development |
145 | 156 |
|
146 | 157 | ### Git Workflow
|
147 | 158 |
|
148 | 159 | 1. Create a `feature` branch off `staging`
|
149 |
| -2. Open a draft Pull Request on Github |
150 |
| -3. When finished with your work, fill out the PR template and publish your PR |
151 |
| -4. Vercel will create a deployment preview. It must pass and deploy successfully |
152 |
| -5. After peer review, PR will be merged back into `staging` |
153 |
| -6. Repeat ♻️ |
| 160 | +2. Work locally adhereing to coding standards |
| 161 | +3. When ready, open a draft Pull Request on Github |
| 162 | +4. When finished, fill out the PR template and publish your PR |
| 163 | +5. Your PR must pass assertions and deploy successfully |
| 164 | +6. After peer review, the PR will be merged back into `staging` |
| 165 | +7. Repeat ♻️ |
154 | 166 |
|
155 | 167 | ### Deployments
|
156 | 168 |
|
157 |
| -[Vercel](https://nextjs-wordpress-starter-gregrickaby.webdevstudios.vercel.app) is connected to this Github repository and automatically builds and deploys. Learn more about [Vercel + Github integration](https://vercel.com/docs/git/vercel-for-github). |
| 169 | +[Vercel](https://nextjs-wordpress-starter-gregrickaby.webdevstudios.vercel.app) is connected to this Github repository and will automatically build and deploy. Learn more about [Vercel + Github integration](https://vercel.com/docs/git/vercel-for-github). |
158 | 170 |
|
159 | 171 | ### Storybook
|
160 | 172 |
|
161 |
| -To view this project's storybook on your Local: |
| 173 | +To work with Storybook on your Local, run the following command: |
162 | 174 |
|
163 | 175 | ```bash
|
164 | 176 | yarn storybook
|
165 | 177 | ```
|
166 | 178 |
|
167 |
| -View this project's [Storybook](https://staging--5fe0becf19ad53002147b034.chromatic.com/) |
| 179 | +Stories are written in `.mdx` and should be placed next to the component. Learn more about [Storybook](https://storybook.js.org/). |
| 180 | + |
| 181 | +## WebDevStudios Specific Info |
| 182 | + |
| 183 | +The following information pertains to internal tools and workflows at WebDevStudios. |
| 184 | + |
| 185 | +<details> |
| 186 | + |
| 187 | +### WordPress Github |
| 188 | + |
| 189 | +There is a Github repo for the backend. This repo manages plugins and the headless theme. Future projects should probably mimic this setup: |
| 190 | + |
| 191 | +https://github.com/WebDevStudios/nextjs-starter-wordpress |
| 192 | + |
| 193 | +**Note: There is no frontend for WordPress** - But it is running a headless theme which houses `/acf-json` and other headless-related functions. |
| 194 | + |
| 195 | +### WP Engine |
| 196 | + |
| 197 | +There are 3 WordPress environments on WP Engine: |
| 198 | + |
| 199 | +- [Develop](https://nextjsdevstart.wpengine.com/wp-admin/) |
| 200 | +- [Staging](https://nextjsstgstart.wpengine.com/wp-admin/) |
| 201 | +- [Production](https://nextjs.wpengine.com/wp-admin) |
| 202 | + |
| 203 | +Use the orange "WebDevStudios Login" button to log in. |
168 | 204 |
|
169 | 205 | ### Chromatic
|
170 | 206 |
|
171 |
| -This project supports UI review via Chromatic, which is trigger via Github Actions. |
| 207 | +This project supports UI review via Chromatic, which is triggered via Github Actions. |
| 208 | + |
| 209 | +View this project's [Chromatic](https://chromatic.com/library?appId=5fe0becf19ad53002147b034&branch=staging) by logging in with your WDS Github account. |
| 210 | + |
| 211 | +### 1Password |
| 212 | + |
| 213 | +All of the credentials are in the following vault: |
| 214 | + |
| 215 | +```text |
| 216 | +1Password --> Next.js Starter |
| 217 | +``` |
| 218 | + |
| 219 | +### Migrate DB Pro |
| 220 | + |
| 221 | +You can use Migrate DB Pro to pull databases and files. Please see 1password for credentials |
| 222 | + |
| 223 | +### Copy WP Engine Environments |
| 224 | + |
| 225 | +WP Engine supports [copying environments](https://wpengine.com/support/copy-site/). This should be done at the end of two week sprints (or as needed). |
| 226 | + |
| 227 | +**The following steps will copy Develop to Staging:** |
| 228 | + |
| 229 | +1. Log into the WP Engine [User Portal](https://my.wpengine.com/sites) |
| 230 | +2. Click on [Nextjsstgstart](https://my.wpengine.com/installs/nextjsstgstart) |
| 231 | +3. In the top right corner, click the "Copy environment" button |
| 232 | +4. Select the options: |
| 233 | +  |
| 234 | +5. Click "Preview copy" and a modal will appear to let you verify the options |
| 235 | +6. Click "Copy environment" |
172 | 236 |
|
173 |
| -View this project's [Chromatic](https://chromatic.com/library?appId=5fe0becf19ad53002147b034&branch=staging) |
| 237 | +</details> |
174 | 238 |
|
175 | 239 | ---
|
176 | 240 |
|
177 | 241 | ## :octocat: Contributing
|
178 | 242 |
|
179 |
| -Your [contributions](https://github.com/WebDevStudios/nextjs-wordpress-starter/blob/main/.github/CONTRIBUTING.md) and issues are welcome. |
| 243 | +[Contributions](https://github.com/WebDevStudios/nextjs-wordpress-starter/blob/main/.github/CONTRIBUTING.md) are welcome. 🍻 |
0 commit comments