Skip to content

Commit 6b4842d

Browse files
authored
feat(cpa): create project from example using --example CLI arg (#10172)
Adds the ability to create a project using an existing in the Payload repo example through `create-payload-app`: For example: `pnpx create-payload-app --example custom-server` - creates a project from the [custom-server](https://github.com/payloadcms/payload/tree/main/examples/custom-server) example. This is much easier and faster then downloading the whole repo and copying the example to another folder. Note that we don't configure the payload config with the storage / DB adapter there because examples can be very specific.
1 parent 7e0975f commit 6b4842d

File tree

22 files changed

+326
-124
lines changed

22 files changed

+326
-124
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ If you want to add contributions to this repository, please follow the instructi
9696

9797
The [Examples Directory](./examples) is a great resource for learning how to setup Payload in a variety of different ways, but you can also find great examples in our blog and throughout our social media.
9898

99-
If you'd like to run the examples, you can either copy them to a folder outside this repo or run them directly by (1) navigating to the example's subfolder (`cd examples/your-example-folder`) and (2) using the `--ignore-workspace` flag to bypass workspace restrictions (e.g., `pnpm --ignore-workspace install` or `pnpm --ignore-workspace dev`).
99+
If you'd like to run the examples, you can use `create-payload-app` to create a project from one:
100+
101+
```sh
102+
npx create-payload-app --example example_name
103+
```
100104

101105
You can see more examples at:
102106

docs/examples/overview.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ Payload provides a vast array of examples to help you get started with your proj
1919
- [Tests](https://github.com/payloadcms/payload/tree/main/examples/testing)
2020
- [White-label Admin UI](https://github.com/payloadcms/payload/tree/main/examples/whitelabel)
2121

22+
If you'd like to run the examples, you can use `create-payload-app` to create a project from one:
23+
24+
```sh
25+
npx create-payload-app --example example_name
26+
```
27+
2228
We are adding new examples every day, so if your particular use case is not demonstrated in any existing example, please feel free to start a new [Discussion](https://github.com/payloadcms/payload/discussions) or open a new [PR](https://github.com/payloadcms/payload/pulls) to add it yourself.

examples/auth/README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,17 @@ This [Payload Auth Example](https://github.com/payloadcms/payload/tree/main/exam
66

77
To spin up this example locally, follow the steps below:
88

9-
1. Clone this repo
10-
1. Navigate into the project directory and install dependencies using your preferred package manager:
9+
1. Run the following command to create a project from the example:
1110

12-
- `pnpm i --ignore-workspace`\*, `yarn`, or `npm install`
11+
- `npx create-payload-app --example auth`
1312

14-
> \*NOTE: The --ignore-workspace flag is needed if you are running this example within the Payload monorepo to avoid workspace conflicts.
15-
16-
1. Start the server:
13+
2. Start the server:
1714
- Depending on your package manager, run `pnpm dev`, `yarn dev` or `npm run dev`
1815
- When prompted, type `y` then `enter` to seed the database with sample data
19-
1. Access the application:
16+
3. Access the application:
2017
- Open your browser and navigate to `http://localhost:3000` to access the homepage.
2118
- Open `http://localhost:3000/admin` to access the admin panel.
22-
1. Login:
19+
4. Login:
2320

2421
- Use the following credentials to log into the admin panel:
2522
> `Email: demo@payloadcms.com` > `Password: demo`

examples/custom-components/README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,17 @@ This example demonstrates how to use Custom Components in the [Payload](https://
66

77
To spin up this example locally, follow the steps below:
88

9-
1. Clone this repo
10-
1. Navigate into the project directory and install dependencies using your preferred package manager:
9+
1. Run the following command to create a project from the example:
1110

12-
- `pnpm i --ignore-workspace`\*, `yarn`, or `npm install`
11+
- `npx create-payload-app --example custom-components`
1312

14-
> \*NOTE: The --ignore-workspace flag is needed if you are running this example within the Payload monorepo to avoid workspace conflicts.
15-
16-
1. Start the server:
13+
2. Start the server:
1714
- Depending on your package manager, run `pnpm dev`, `yarn dev` or `npm run dev`
1815
- When prompted, type `y` then `enter` to seed the database with sample data
19-
1. Access the application:
16+
3. Access the application:
2017
- Open your browser and navigate to `http://localhost:3000` to access the homepage.
2118
- Open `http://localhost:3000/admin` to access the admin panel.
22-
1. Login:
19+
4. Login:
2320

2421
- Use the following credentials to log into the admin panel:
2522
> `Email: demo@payloadcms.com` > `Password: demo`

examples/custom-server/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Payload 3 with Custom Server
22

3+
Run the following command to create a project from the example:
4+
5+
- `npx create-payload-app --example custom-server`
6+
37
Uses a [Next.js Custom Server](https://nextjs.org/docs/pages/building-your-application/configuring/custom-server) with express.
48

59
Made from official [examples/custom-server](https://github.com/vercel/next.js/tree/canary/examples/custom-server) from Next.js repository.

examples/draft-preview/README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ The [Payload Draft Preview Example](https://github.com/payloadcms/payload/tree/m
66

77
To spin up this example locally, follow these steps:
88

9-
1. Clone this repo
10-
2. `cd` into this directory and run `pnpm i --ignore-workspace`\*, `yarn`, or `npm install`
9+
1. Run the following command to create a project from the example:
1110

12-
> \*If you are running using pnpm within the Payload Monorepo, the `--ignore-workspace` flag is needed so that pnpm generates a lockfile in this example's directory despite the fact that one exists in root.
11+
- `npx create-payload-app --example draft-preview`
1312

14-
3. `cp .env.example .env` to copy the example environment variables
15-
4. `pnpm dev`, `yarn dev` or `npm run dev` to start the server
16-
5. `open http://localhost:3000/admin` to access the admin panel
17-
6. Login with email `demo@payloadcms.com` and password `demo`
13+
2. `cp .env.example .env` to copy the example environment variables
14+
3. `pnpm dev`, `yarn dev` or `npm run dev` to start the server
15+
4. `open http://localhost:3000/admin` to access the admin panel
16+
5. Login with email `demo@payloadcms.com` and password `demo`
1817

1918
That's it! Changes made in `./src` will be reflected in your app. See the [Development](#development) section for more details.
2019

examples/email/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ This example demonstrates how to integrate email functionality into Payload.
66

77
To spin up this example locally, follow these steps:
88

9-
1. Clone this repo
9+
1. Run the following command to create a project from the example:
10+
11+
- `npx create-payload-app --example email`
12+
1013
2. `cp .env.example .env` to copy the example environment variables
1114
3. `pnpm install && pnpm dev` to install dependencies and start the dev server
1215
4. open `http://localhost:3000/admin` to access the admin panel

examples/form-builder/README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ The [Payload Form Builder Example](https://github.com/payloadcms/payload/tree/ma
66

77
## Quick Start
88

9-
1. Clone this repo
10-
2. `cd` into this directory and run `pnpm i --ignore-workspace`\*, `yarn`, or `npm install`
9+
1. Run the following command to create a project from the example:
1110

12-
> \*If you are running using pnpm within the Payload Monorepo, the `--ignore-workspace` flag is needed so that pnpm generates a lockfile in this example's directory despite the fact that one exists in root.
11+
- `npx create-payload-app --example form-builder`
1312

14-
3. `cp .env.example .env` to copy the example environment variables
13+
2. `cp .env.example .env` to copy the example environment variables
1514

16-
4. `pnpm dev`, `yarn dev` or `npm run dev` to start the server
15+
3. `pnpm dev`, `yarn dev` or `npm run dev` to start the server
1716
- Press `y` when prompted to seed the database
18-
5. `open http://localhost:3000` to access the home page
19-
6. `open http://localhost:3000/admin` to access the admin panel
17+
4. `open http://localhost:3000` to access the home page
18+
5. `open http://localhost:3000/admin` to access the admin panel
2019
- Login with email `demo@payloadcms.com` and password `demo`
2120

2221
That's it! Changes made in `./src` will be

examples/live-preview/README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ The [Payload Live Preview Example](https://github.com/payloadcms/payload/tree/ma
66

77
## Quick Start
88

9-
1. Clone this repo
10-
2. `cd` into this directory and run `pnpm i --ignore-workspace`\*, `yarn`, or `npm install`
9+
1. Run the following command to create a project from the example:
1110

12-
> \*If you are running using pnpm within the Payload Monorepo, the `--ignore-workspace` flag is needed so that pnpm generates a lockfile in this example's directory despite the fact that one exists in root.
11+
- `npx create-payload-app --example live-preview`
1312

14-
3. `cp .env.example .env` to copy the example environment variables
13+
2. `cp .env.example .env` to copy the example environment variables
1514

16-
4. `pnpm dev`, `yarn dev` or `npm run dev` to start the server
15+
3. `pnpm dev`, `yarn dev` or `npm run dev` to start the server
1716
- Press `y` when prompted to seed the database
18-
5. `open http://localhost:3000` to access the home page
19-
6. `open http://localhost:3000/admin` to access the admin panel
17+
4. `open http://localhost:3000` to access the home page
18+
5. `open http://localhost:3000/admin` to access the admin panel
2019
- Login with email `demo@payloadcms.com` and password `demo`
2120

2221
That's it! Changes made in `./src` will be reflected in your app. See the [Development](#development) section for more details.

examples/localization/README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ To facilitate the localization process, this example uses the next-intl library.
88

99
## Setup
1010

11-
1. `cp .env.example .env` (copy the .env.example file to .env)
12-
2. `pnpm install` (`pnpm i --ignore-workspaces` if you are running from the monorepo)
13-
3. `pnpm run dev`
14-
4. Seed your database in the admin panel (see below)
11+
1. Run the following command to create a project from the example:
12+
13+
- `npx create-payload-app --example localization`
14+
15+
2. `cp .env.example .env` (copy the .env.example file to .env)
16+
3. `pnpm install`
17+
4. `pnpm run dev`
18+
5. Seed your database in the admin panel (see below)
1519

1620
## Seed
1721

0 commit comments

Comments
 (0)