Skip to content

Commit f57b813

Browse files
Gregcop1dunglas
authored andcommitted
doc: Add documentation about client-generator-nextjs (#822)
* doc: Add documentation about client-generator-nextjs * fix: @dunglas review Co-Authored-By: Kévin Dunglas <[email protected]> * doc: explaining server-path flag * fix: @toofff review
1 parent bf25136 commit f57b813

File tree

7 files changed

+114
-4
lines changed

7 files changed

+114
-4
lines changed
Loading
Loading

client-generator/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ It is able to generate apps using the following frontend stacks:
1010

1111
* [React with Redux](react.md)
1212
* [React Native](react-native.md)
13+
* [Next.js](nextjs.md)
1314
* [Vue.js](vuejs.md)
1415
* [Quasar Framework](quasar.md)
1516

client-generator/nextjs.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Next.js Generator
2+
3+
![List screenshot](images/nextjs/client-generator-nextjs-list.png)
4+
5+
The Next.js Client Generator generates routes and components for Server Side Rendered applications using [Next.js](https://zeit.co/blog/next)
6+
7+
## Install
8+
9+
### Next + Express Server
10+
11+
Create a [Next.js application with express server](https://github.com/zeit/next.js/tree/canary/examples/custom-server-express). The easiest way is to execute:
12+
13+
```bash
14+
$ npx create-next-app --example custom-server-express your-app-name
15+
# or
16+
$ yarn create next-app --example custom-server-express your-app-name
17+
```
18+
19+
### Enabling Typescript
20+
21+
Install typescript dependencies
22+
23+
```bash
24+
$ yarn add @types/next @zeit/next-typescript
25+
```
26+
27+
Enable Typescript in your Next.js configuration file (`next.config.js`):
28+
29+
```javascript
30+
const withTypescript = require('@zeit/next-typescript');
31+
32+
module.exports = withTypescript();
33+
```
34+
35+
Create a `.babelrc` file to store Babel configuration:
36+
```json
37+
{
38+
"presets": [
39+
"next/babel",
40+
"@zeit/next-typescript/babel"
41+
]
42+
}
43+
```
44+
45+
Create a `tsconfig.json` file to store Typescript configuration:
46+
```json
47+
{
48+
"compilerOptions": {
49+
"allowJs": true,
50+
"allowSyntheticDefaultImports": true,
51+
"jsx": "preserve",
52+
"lib": ["dom", "es2017"],
53+
"module": "esnext",
54+
"moduleResolution": "node",
55+
"noEmit": true,
56+
"noUnusedLocals": true,
57+
"noUnusedParameters": true,
58+
"preserveConstEnums": true,
59+
"removeComments": false,
60+
"skipLibCheck": true,
61+
"sourceMap": true,
62+
"strict": true,
63+
"target": "esnext",
64+
"typeRoots": [
65+
"node_modules/@types"
66+
]
67+
}
68+
}
69+
```
70+
71+
### Installing the Generator Dependencies
72+
73+
Install required dependencies:
74+
75+
```bash
76+
$ yarn add lodash.get lodash.has @types/lodash isomorphic-unfetch
77+
```
78+
79+
## Starting the Project
80+
81+
You can launch the server with
82+
```bash
83+
$ yarn dev
84+
```
85+
86+
and access it through `http://localhost:3000`
87+
88+
## Generating Routes
89+
90+
```bash
91+
$ npx @api-platform/client-generator https://demo.api-platform.com src/ --generator next --resource book
92+
# Replace the URL by the entrypoint of your Hydra-enabled API
93+
```
94+
95+
> Note: Omit the resource flag to generate files for all resource types exposed by the API.
96+
97+
If your express server is compatible with the `custom-server-express` Next.js example, you can use the `server-path` flag to specify path to the server file. Routes will be added automatically to this file, otherwise, you will receive some hints on how to them to your own custom server.
98+
99+
```bash
100+
$ npx @api-platform/client-generator https://demo.api-platform.com src/ --generator next --server-path ./server.js
101+
```
102+
103+
Go to `https://localhost:3000/books/` to start using your app.
104+
That's it!
105+
106+
## Screenshots
107+
108+
![List](images/nextjs/client-generator-nextjs-list.png)
109+
![Show](images/nextjs/client-generator-nextjs-show.png)

client-generator/react-native.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ $ yarn add redux react-redux redux-thunk redux-form react-native-elements react-
2727
In the app directory, generate the files for the resource you want:
2828

2929
```bash
30-
$ npx @api-platform/client-generator https://demo.api-platform.com . -g react-native --resource book
30+
$ npx @api-platform/client-generator https://demo.api-platform.com . --generator react-native --resource book
3131
```
3232

3333
Replace the URL with the entrypoint of your Hydra-enabled API.

client-generator/typescript.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The TypeScript Generator allows you to create [TypeScript interfaces](https://ww
55
To do so, run the client generator:
66

77
```bash
8-
$ npx @api-platform/client-generator -g typescript https://demo.api-platform.com src/ --resource foo
8+
$ npx @api-platform/client-generator --generator typescript https://demo.api-platform.com src/ --resource foo
99
# Replace the URL by the entrypoint of your Hydra-enabled API
1010
# "src/" represents where the interfaces will be generated
1111
# Omit the resource flag to generate files for all resource types exposed by the API
@@ -20,7 +20,7 @@ NOTE: If you are not sure what the entrypoint is, see [Troubleshooting](troubles
2020
Assuming you have 2 resources in your application, `Foo` and `Bar`, when you run
2121

2222
```bash
23-
npx @api-platform/client-generator -g typescript https://demo.api-platform.com src/
23+
npx @api-platform/client-generator --generator typescript https://demo.api-platform.com src/
2424
```
2525

2626
you will obtain 2 `.ts` files arranged as following:

client-generator/vuejs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Reference the Bootstrap CSS stylesheet in `public/index.html` (optional):
2727

2828
In the app directory, generate the files for the resource you want:
2929

30-
$ generate-api-platform-client -g vue https://demo.api-platform.com src/ --resource foo
30+
$ generate-api-platform-client --generator vue https://demo.api-platform.com src/ --resource foo
3131
# Replace the URL by the entrypoint of your Hydra-enabled API
3232
# Omit the resource flag to generate files for all resource types exposed by the API
3333

0 commit comments

Comments
 (0)