Skip to content

Commit

Permalink
Merge branch 'main' into renovate/zx-6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
thedavidprice authored Mar 18, 2022
2 parents a64d279 + 024e26c commit 2a40134
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 29 deletions.
31 changes: 29 additions & 2 deletions docs/docs/cli-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -1024,10 +1024,35 @@ https://community.redwoodjs.com/t/prisma-beta-2-and-redwoodjs-limited-generator-
| `model` | Model to generate the sdl for |
| `--crud` | Also generate mutations |
| `--force, -f` | Overwrite existing files |
| `--tests` | Generate service test and scenario [default: true] |
| `--typescript, --ts` | Generate TypeScript files Enabled by default if we detect your project is TypeScript |

> **Note:** The generated sdl will include the `@requireAuth` directive by default to ensure queries and mutations are secure. If your app's queries and mutations are all public, you can set up a custom SDL generator template to apply `@skipAuth` (or a custom validator directive) to suit you application's needs.
**Regenerating the SDL**

Often, as you iterate on your data model, you may add, remove, or rename fields. You still want Redwood to update the generated SDL and service files for those updates because it saves time having to make those changes manually.

But, since the `generate` command prevents you from overwriting files accidentally, you could use the `--force` option -- but a `force` will reset any test and scenarios you may have written which you don't want to lose.

In that case, you can run the following to "regenerate" **just** the SDL file and leave your tests and scenarios intact and not lose your hard work.

```
yarn redwood g sdl <model> --force --tests=false
```

**Example**

```terminal
~/redwood-app$ yarn redwood generate sdl user --force --tests=false
yarn run v1.22.4
$ /redwood-app/node_modules/.bin/redwood g sdl user
✔ Generating SDL files...
✔ Writing `./api/src/graphql/users.sdl.js`...
✔ Writing `./api/src/services/users/users.js`...
Done in 1.04s.
```

**Destroying**

```
Expand All @@ -1044,6 +1069,7 @@ yarn run v1.22.4
$ /redwood-app/node_modules/.bin/redwood g sdl user
✔ Generating SDL files...
✔ Writing `./api/src/graphql/users.sdl.js`...
✔ Writing `./api/src/services/users/users.scenarios.js`...
✔ Writing `./api/src/services/users/users.test.js`...
✔ Writing `./api/src/services/users/users.js`...
Done in 1.04s.
Expand Down Expand Up @@ -1167,8 +1193,8 @@ Services are where Redwood puts its business logic. They can be used by your Gra
| `name` | Name of the service |
| `--force, -f` | Overwrite existing files |
| `--typescript, --ts` | Generate TypeScript files Enabled by default if we detect your project is TypeScript |
| `--tests` | Generate test files [default: true] |
| `--stories` | Generate Storybook files [default: true] |
| `--tests` | Generate test and scenario files [default: true] |


**Destroying**

Expand All @@ -1185,6 +1211,7 @@ Generating a user service:
yarn run v1.22.4
$ /redwood-app/node_modules/.bin/redwood g service user
✔ Generating service files...
✔ Writing `./api/src/services/users/users.scenarios.js`...
✔ Writing `./api/src/services/users/users.test.js`...
✔ Writing `./api/src/services/users/users.js`...
Done in 1.02s.
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@azure/msal-browser": "2.22.1",
"@babel/cli": "7.16.7",
"@babel/core": "7.16.7",
"@clerk/clerk-js": "2.17.4",
"@clerk/clerk-js": "2.17.6",
"@clerk/clerk-sdk-node": "2.9.10",
"@clerk/types": "1.29.2",
"@nhost/nhost-js": "0.3.12",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"listr": "0.14.3",
"listr-verbose-renderer": "0.6.0",
"lodash": "4.17.21",
"node-ssh": "12.0.3",
"node-ssh": "12.0.4",
"param-case": "3.0.4",
"pascalcase": "1.0.0",
"pluralize": "8.0.0",
Expand Down
14 changes: 12 additions & 2 deletions packages/cli/src/commands/build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs'
import path from 'path'

import execa from 'execa'
import Listr from 'listr'
Expand Down Expand Up @@ -155,8 +156,8 @@ export const handler = async ({
},
side.includes('web') && {
title: 'Building Web...',
task: () => {
return execa(
task: async () => {
await execa(
`yarn cross-env NODE_ENV=production webpack --config ${require.resolve(
'@redwoodjs/core/config/webpack.production.js'
)}`,
Expand All @@ -166,6 +167,15 @@ export const handler = async ({
cwd: rwjsPaths.web.base,
}
)

console.log('Creating 200.html...')

const indexHtmlPath = path.join(getPaths().web.dist, 'index.html')

fs.copyFileSync(
indexHtmlPath,
path.join(getPaths().web.dist, '200.html')
)
},
},
side.includes('web') &&
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/commands/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ const mapRouterPathToHtml = (routerPath) => {
// This is used directly in build.js for nested ListrTasks
export const getTasks = async (dryrun, routerPathFilter = null) => {
const prerenderRoutes = detectPrerenderRoutes()

const indexHtmlPath = path.join(getPaths().web.dist, 'index.html')
if (prerenderRoutes.length === 0) {
console.error('\nSkipping prerender...')
console.error(
console.log('\nSkipping prerender...')
console.log(
c.warning(
'You have not marked any routes as `prerender` in `Routes.{js,tsx}` \n'
)
Expand All @@ -63,7 +63,7 @@ export const getTasks = async (dryrun, routerPathFilter = null) => {
return []
}

if (!fs.existsSync(path.join(getPaths().web.dist), 'index.html')) {
if (!fs.existsSync(indexHtmlPath)) {
console.error(
'You must run `yarn rw build web` before trying to prerender.'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ functions = "api/dist/functions"
[[redirects]]
from = "/*"
to = "/index.html"
to = "/200.html"
status = 200
`
2 changes: 1 addition & 1 deletion packages/prerender/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { AuthContextInterface } from '@redwoodjs/auth'
import { getConfig, getPaths } from '@redwoodjs/internal'

const INDEX_FILE = path.join(getPaths().web.dist, 'index.html')
const DEFAULT_INDEX = path.join(getPaths().web.dist, 'defaultIndex.html')
const DEFAULT_INDEX = path.join(getPaths().web.dist, '200.html')

export const getRootHtmlPath = () => {
if (fs.existsSync(DEFAULT_INDEX)) {
Expand Down
11 changes: 6 additions & 5 deletions packages/prerender/src/runPrerender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ export const writePrerenderedHtmlFile = (
content: string
) => {
const outputHtmlAbsPath = path.join(getPaths().base, outputHtmlPath)
// Copy default index.html to 200.html first
// Copy default (unprerendered) index.html to 200.html first
// This is to prevent recursively rendering the home page
if (outputHtmlPath === 'web/dist/index.html') {
fs.copyFileSync(
outputHtmlAbsPath,
path.join(getPaths().base, 'web/dist/200.html')
)
const html200Path = path.join(getPaths().web.dist, '200.html')

if (!fs.existsSync(html200Path)) {
fs.copyFileSync(outputHtmlAbsPath, html200Path)
}
}

writeToDist(outputHtmlAbsPath, content)
Expand Down
24 changes: 12 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1983,11 +1983,11 @@ __metadata:
languageName: node
linkType: hard

"@clerk/clerk-js@npm:2.17.4":
version: 2.17.4
resolution: "@clerk/clerk-js@npm:2.17.4"
"@clerk/clerk-js@npm:2.17.6":
version: 2.17.6
resolution: "@clerk/clerk-js@npm:2.17.6"
dependencies:
"@clerk/types": ^1.29.0
"@clerk/types": ^1.29.2
"@popperjs/core": ^2.4.4
browser-tabs-lock: ^1.2.15
classnames: ^2.3.1
Expand All @@ -1999,7 +1999,7 @@ __metadata:
react-dom: 17.0.2
react-popper: ^2.2.3
regenerator-runtime: ^0.13.7
checksum: 2699217983df86c8096c1e5053dab71fd2457c8e52afc1bd90dd3e448f4429f368c8ca868bc7e5ed7795db1497e73c26c318c656e6e10790928c841ad12c9ab5
checksum: e7eece94eecac686e1bd672aed50662968307f1579a25af19599792bbb028d8dbfe07e1324fd5a5381f65c194d514b6c32417abfa965f88377fdbae743bb678b
languageName: node
linkType: hard

Expand All @@ -2021,7 +2021,7 @@ __metadata:
languageName: node
linkType: hard

"@clerk/types@npm:1.29.2, @clerk/types@npm:^1.29.0":
"@clerk/types@npm:1.29.2, @clerk/types@npm:^1.29.2":
version: 1.29.2
resolution: "@clerk/types@npm:1.29.2"
checksum: 0bebcf9ca225675e5352f7b41b2332f613e9ed0171746979b335198a96ceb7181c47292f90054bf39477d78afdc4f213a6a70ba0b7decc82626710a1f5fa19d1
Expand Down Expand Up @@ -5777,7 +5777,7 @@ __metadata:
"@azure/msal-browser": 2.22.1
"@babel/cli": 7.16.7
"@babel/core": 7.16.7
"@clerk/clerk-js": 2.17.4
"@clerk/clerk-js": 2.17.6
"@clerk/clerk-sdk-node": 2.9.10
"@clerk/types": 1.29.2
"@nhost/nhost-js": 0.3.12
Expand Down Expand Up @@ -5829,7 +5829,7 @@ __metadata:
listr: 0.14.3
listr-verbose-renderer: 0.6.0
lodash: 4.17.21
node-ssh: 12.0.3
node-ssh: 12.0.4
param-case: 3.0.4
pascalcase: 1.0.0
pluralize: 8.0.0
Expand Down Expand Up @@ -22188,17 +22188,17 @@ __metadata:
languageName: node
linkType: hard

"node-ssh@npm:12.0.3":
version: 12.0.3
resolution: "node-ssh@npm:12.0.3"
"node-ssh@npm:12.0.4":
version: 12.0.4
resolution: "node-ssh@npm:12.0.4"
dependencies:
is-stream: ^2.0.0
make-dir: ^3.1.0
sb-promise-queue: ^2.1.0
sb-scandir: ^3.1.0
shell-escape: ^0.2.0
ssh2: ^1.5.0
checksum: 8ebf7ee67a24979eb77ffdcd1f7e5e491653f5132a925913b2446af6b4c6e92d9a982de12123b0df908ef860c30325e146d83cf2c534ec13f9f643fa316c1d45
checksum: 077ffcdca7613b9192e59b2e9246065b7b84b5c29d7ed67f4c3985d224e8aa242cc8b95f1197171383ac415a2a55e500e5328495373b88e010abb50f8e77e516
languageName: node
linkType: hard

Expand Down

0 comments on commit 2a40134

Please sign in to comment.