Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(CLI): add check node version middleware, rm .nvmrc, yarn engines #9728

Merged
merged 13 commits into from
Dec 22, 2023
1 change: 0 additions & 1 deletion __fixtures__/test-project-rsa/.nvmrc

This file was deleted.

3 changes: 1 addition & 2 deletions __fixtures__/test-project-rsa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"root": true
},
"engines": {
"node": "=20.x",
"yarn": ">=1.22.21"
"node": "=20.x"
},
"prisma": {
"seed": "yarn rw exec seed"
Expand Down
1 change: 0 additions & 1 deletion __fixtures__/test-project-rsc-external-packages/.nvmrc

This file was deleted.

3 changes: 1 addition & 2 deletions __fixtures__/test-project-rsc-external-packages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"root": true
},
"engines": {
"node": "=20.x",
"yarn": ">=1.22.21"
"node": "=20.x"
},
"prisma": {
"seed": "yarn rw exec seed"
Expand Down
1 change: 0 additions & 1 deletion __fixtures__/test-project/.nvmrc

This file was deleted.

3 changes: 1 addition & 2 deletions __fixtures__/test-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"root": true
},
"engines": {
"node": "=20.x",
"yarn": ">=1.22.21"
"node": "=20.x"
},
"prisma": {
"seed": "yarn rw exec seed"
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/tutorial/chapter1/prerequisites.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ You could definitely learn them all at once, but it will be harder to determine

### Redwood Versions

You will want to be on at least version 5.0.0 to complete the tutorial. If this is your first time using Redwood then no worries: the latest version will be installed automatically when you create your app skeleton!
You will want to be on at least version 7.0.0 to complete the tutorial. If this is your first time using Redwood then no worries: the latest version will be installed automatically when you create your app skeleton!

If you have an existing site created with a prior version, you'll need to upgrade and (most likely) apply code modifications. Follow this two step process:

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/tutorial/foreword.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ It's usually something that goes into more detail about a specific point, refers

:::info

This tutorial assumes you are using version 5.0.0 or greater of RedwoodJS.
This tutorial assumes you are using version 7.0.0 or greater of RedwoodJS.

:::

Expand Down
17 changes: 15 additions & 2 deletions packages/cli/src/commands/build.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import terminalLink from 'terminal-link'

import c from '../lib/colors'
import { exitWithError } from '../lib/exit'
import { sides } from '../lib/project'
import checkForBabelConfig from '../middleware/checkForBabelConfig'
import { checkNodeVersion } from '../middleware/checkNodeVersion'

export const command = 'build [side..]'
export const description = 'Build for production'
Expand Down Expand Up @@ -47,7 +49,18 @@ export const builder = (yargs) => {
default: false,
description: 'Measure build performance',
})
.middleware(checkForBabelConfig)
.middleware(() => {
const check = checkNodeVersion()

if (check.ok) {
return
}

exitWithError(undefined, {
message: `${c.error('Error')}: ${check.message}`,
includeEpilogue: false,
})
})
.epilogue(
`Also see the ${terminalLink(
'Redwood CLI Reference',
Expand Down
14 changes: 12 additions & 2 deletions packages/cli/src/commands/dev.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import terminalLink from 'terminal-link'

import checkForBabelConfig from '../middleware/checkForBabelConfig'
import c from '../lib/colors'
import { checkNodeVersion } from '../middleware/checkNodeVersion'

export const command = 'dev [side..]'
export const description = 'Start development servers for api, and web'

export const builder = (yargs) => {
yargs
.positional('side', {
Expand Down Expand Up @@ -32,7 +34,15 @@ export const builder = (yargs) => {
description:
'Port on which to expose API server debugger. If you supply the flag with no value it defaults to 18911.',
})
.middleware(checkForBabelConfig)
.middleware(() => {
const check = checkNodeVersion()

if (check.ok) {
return
}

console.warn(`${c.warning('Warning')}: ${check.message}\n`)
})
.epilogue(
`Also see the ${terminalLink(
'Redwood CLI Reference',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,27 @@ exports[`netlify should add netlify.toml 1`] = `
publish = "web/dist"
functions = "api/dist/functions"

[dev]
# To use [Netlify Dev](https://www.netlify.com/products/dev/),
# install netlify-cli from https://docs.netlify.com/cli/get-started/#installation
# and then use netlify link https://docs.netlify.com/cli/get-started/#link-and-unlink-sites
# to connect your local project to a site already on Netlify
# then run netlify dev and our app will be accessible on the port specified below
framework = "redwoodjs"
# Set targetPort to the [web] side port as defined in redwood.toml
targetPort = 8910
# Point your browser to this port to access your RedwoodJS app
port = 8888
[build.environment]
NODE_VERSION = "20"

[[redirects]]
from = "/*"
to = "/200.html"
status = 200

# To use Netlify Dev, install Netlify's CLI (\`netlify-cli\`) from NPM and use \`netlify link\`
# to connect your local project to a site on Netlify. Then run \`netlify dev\`.
#
# Quick links to the docs:
# - Netlfy Dev https://www.netlify.com/products/dev
# - Netlify's CLI https://docs.netlify.com/cli/get-started/#installation
# - \`netlify link\` https://docs.netlify.com/cli/get-started/#link-and-unlink-sites
[dev]
framework = "redwoodjs"
# Make sure \`targetPort\` matches \`web.port\` in the \`redwood.toml\`:
targetPort = 8910
# Point your browser to this port to access your app:
port = 8888
"
`;

Expand All @@ -31,21 +36,26 @@ exports[`netlify should call the handler without error 1`] = `
publish = "web/dist"
functions = "api/dist/functions"

[dev]
# To use [Netlify Dev](https://www.netlify.com/products/dev/),
# install netlify-cli from https://docs.netlify.com/cli/get-started/#installation
# and then use netlify link https://docs.netlify.com/cli/get-started/#link-and-unlink-sites
# to connect your local project to a site already on Netlify
# then run netlify dev and our app will be accessible on the port specified below
framework = "redwoodjs"
# Set targetPort to the [web] side port as defined in redwood.toml
targetPort = 8910
# Point your browser to this port to access your RedwoodJS app
port = 8888
[build.environment]
NODE_VERSION = "20"

[[redirects]]
from = "/*"
to = "/200.html"
status = 200

# To use Netlify Dev, install Netlify's CLI (\`netlify-cli\`) from NPM and use \`netlify link\`
# to connect your local project to a site on Netlify. Then run \`netlify dev\`.
#
# Quick links to the docs:
# - Netlfy Dev https://www.netlify.com/products/dev
# - Netlify's CLI https://docs.netlify.com/cli/get-started/#installation
# - \`netlify link\` https://docs.netlify.com/cli/get-started/#link-and-unlink-sites
[dev]
framework = "redwoodjs"
# Make sure \`targetPort\` matches \`web.port\` in the \`redwood.toml\`:
targetPort = 8910
# Point your browser to this port to access your app:
port = 8888
"
`;
30 changes: 18 additions & 12 deletions packages/cli/src/commands/setup/deploy/templates/netlify.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@ import { getConfig } from '../../../../lib'

const config = getConfig()

export const NETLIFY_TOML = `[build]
export const NETLIFY_TOML = `\
[build]
command = "yarn rw deploy netlify"
publish = "web/dist"
functions = "api/dist/functions"

[dev]
# To use [Netlify Dev](https://www.netlify.com/products/dev/),
# install netlify-cli from https://docs.netlify.com/cli/get-started/#installation
# and then use netlify link https://docs.netlify.com/cli/get-started/#link-and-unlink-sites
# to connect your local project to a site already on Netlify
# then run netlify dev and our app will be accessible on the port specified below
framework = "redwoodjs"
# Set targetPort to the [web] side port as defined in redwood.toml
targetPort = ${config.web.port}
# Point your browser to this port to access your RedwoodJS app
port = 8888
[build.environment]
NODE_VERSION = "20"

[[redirects]]
from = "/*"
to = "/200.html"
status = 200

# To use Netlify Dev, install Netlify's CLI (\`netlify-cli\`) from NPM and use \`netlify link\`
# to connect your local project to a site on Netlify. Then run \`netlify dev\`.
#
# Quick links to the docs:
# - Netlfy Dev https://www.netlify.com/products/dev
# - Netlify's CLI https://docs.netlify.com/cli/get-started/#installation
# - \`netlify link\` https://docs.netlify.com/cli/get-started/#link-and-unlink-sites
[dev]
framework = "redwoodjs"
# Make sure \`targetPort\` matches \`web.port\` in the \`redwood.toml\`:
targetPort = ${config.web.port}
# Point your browser to this port to access your app:
port = 8888
`
44 changes: 22 additions & 22 deletions packages/cli/src/commands/setup/deploy/templates/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,29 @@ import { getPaths } from '../../../../lib'
export const PROJECT_NAME = path.basename(getPaths().base)

export const RENDER_YAML = (database) => {
return `#####
# Documentation
# Redwood: https://render.com/docs/deploy-redwood
# YAML (all config values): https://render.com/docs/yaml-spec
#####
return `# Quick links to the docs:
# - Redwood on Render: https://render.com/docs/deploy-redwood
# - Render's Blueprint spec: https://render.com/docs/yaml-spec

services:
- name: ${PROJECT_NAME}-web
type: web
env: static
buildCommand: yarn install && yarn rw deploy render web
buildCommand: corepack enable && yarn install && yarn rw deploy render web
staticPublishPath: ./web/dist

envVars:
- key: NODE_VERSION
value: 18
- key: SKIP_INSTALL_DEPS
value: true

routes:
- type: rewrite
source: /.redwood/functions/*
#####
# NOTE: replace destination api url after first deploy to Render
# example:
# destination: https://myredwoodproject-api.onrender.com/*
#####
# Replace \`destination\` here after your first deploy:
#
# \`\`\`
# destination: https://my-redwood-project-api.onrender.com/*
# \`\`\`
destination: replace_with_api_url/*
- type: rewrite
source: /*
Expand All @@ -40,35 +38,37 @@ services:
plan: free
env: node
region: oregon
buildCommand: yarn && yarn rw build api
buildCommand: corepack enable && yarn && yarn rw build api
startCommand: yarn rw deploy render api

envVars:
- key: NODE_VERSION
value: 18
${database}
`
}

export const POSTGRES_YAML = ` - key: DATABASE_URL
export const POSTGRES_YAML = `\
- key: DATABASE_URL
fromDatabase:
name: ${PROJECT_NAME}-db
property: connectionString

databases:
- name: ${PROJECT_NAME}-db
region: oregon
`
region: oregon`

export const SQLITE_YAML = ` - key: DATABASE_URL
export const SQLITE_YAML = `\
- key: DATABASE_URL
value: file:./data/sqlite.db
disk:
name: sqlite-data
mountPath: /opt/render/project/src/api/db/data
sizeGB: 1`

export const RENDER_HEALTH_CHECK = `// render-health-check
export const RENDER_HEALTH_CHECK = `\
// render-health-check
export const handler = async () => {
return {
statusCode: 200,
}
}`
}
`
28 changes: 15 additions & 13 deletions packages/cli/src/lib/exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,21 @@ export function exitWithError(
const line = chalk.red('-'.repeat(process.stderr.columns))

// Generate and print a nice message to the user
const content = [
line,
message,
includeEpilogue && `\n${line}`,
includeEpilogue && epilogue,
includeReferenceCode &&
` - Here's your unique error reference to quote: '${errorReferenceCode}'`,
line,
]
.filter(Boolean)
.join('\n')

console.error()
const content = !includeEpilogue
? message
: [
'',
line,
message,
`\n${line}`,
epilogue,
includeReferenceCode &&
` - Here's your unique error reference to quote: '${errorReferenceCode}'`,
line,
]
.filter(Boolean)
.join('\n')

console.error(content)

// Record the error in telemetry
Expand Down
Loading