Skip to content

Commit

Permalink
feat: add serve command (#5351)
Browse files Browse the repository at this point in the history
* feat: add `--serve` flag to `dev` command

* refactor: simplify internal directory clean up

* refactor: load built functions

* refactor: make things nicer

* refactor: add const

* feat: show debug message

* refactor: rename variable

* chore: add `extract-zip` dependency

* chore: update snapshots

* refactor: conditionally set `quiet` flag

* refactor: simplify code

* chore: update docs

* refactor: rename flag to `prod`

* refactor: update message

* feat: do not set `NETLIFY_DEV` when `prod` is set

* chore: remove lint exceptions

* Apply suggestions from code review

Co-authored-by: Matt Kane <m@mk.gg>

* refactor: treat `NETLIFY_DEV` consistently across function types

* refactor: add `internal` source for env vars

* fix: handle internal vars correctly

* chore: update docs

* refactor: remove unused variable

* feat: set `context=production` when `prod` is used

* refactor: add beta label

* feat: create separate `serve` command

* Update src/commands/serve/serve.mjs

Co-authored-by: Matt Kane <m@mk.gg>

* refactor: remove unused flags

* refactor: abort server when build fails

* refactor: always start functions server

* chore: remove ESLint directive

* fix: fix imports

* refactor: always start functions server

* refactor: ensure internal functions directory

* refactor: reinstate functions server check

* refactor: add missing import

* fix: fix imports

* refactor: move logic for ensuring internal functions directory

* chore: fix test

* chore: update docs

* chore: update snapshot

* refactor: add log message

* Update src/commands/serve/serve.mjs

Co-authored-by: Matt Kane <m@mk.gg>

* chore: update docs

Co-authored-by: Matt Kane <m@mk.gg>
  • Loading branch information
eduardoboucas and ascorbic authored Jan 10, 2023
1 parent 2b7045e commit 0d583d9
Show file tree
Hide file tree
Showing 22 changed files with 923 additions and 658 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ See the [CLI command line reference](https://cli.netlify.com/commands/) to get s
- [login](#login)
- [open](#open)
- [recipes](#recipes)
- [serve](#serve)
- [sites](#sites)
- [status](#status)
- [switch](#switch)
Expand Down Expand Up @@ -219,6 +220,10 @@ Open settings for the site linked to the current folder
| [`recipes:list`](/docs/commands/recipes.md#recipeslist) | (Beta) List the recipes available to create and modify files in a project |


### [serve](/docs/commands/serve.md)

(Beta) Build the site for production and serve locally. This does not watch the code for changes, so if you need to rebuild your site then you must exit and run `serve` again.

### [sites](/docs/commands/sites.md)

Handle various site operations
Expand Down
4 changes: 4 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ Open settings for the site linked to the current folder
| [`recipes:list`](/docs/commands/recipes.md#recipeslist) | (Beta) List the recipes available to create and modify files in a project |


### [serve](/docs/commands/serve.md)

(Beta) Build the site for production and serve locally. This does not watch the code for changes, so if you need to rebuild your site then you must exit and run `serve` again.

### [sites](/docs/commands/sites.md)

Handle various site operations
Expand Down
1 change: 0 additions & 1 deletion docs/commands/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ netlify dev
- `live` (*boolean*) - start a public live session
- `offline` (*boolean*) - disables any features that require network access
- `port` (*string*) - port of netlify dev
- `prod` (*boolean*) - (Beta) build the site for production and serve locally
- `sessionId` (*string*) - (Graph) connect to cloud session with ID [sessionId]
- `targetPort` (*string*) - port of target app server
- `debug` (*boolean*) - Print debugging information
Expand Down
4 changes: 4 additions & 0 deletions docs/commands/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ Open settings for the site linked to the current folder
| [`recipes:list`](/docs/commands/recipes.md#recipeslist) | (Beta) List the recipes available to create and modify files in a project |


### [serve](/docs/commands/serve.md)

(Beta) Build the site for production and serve locally. This does not watch the code for changes, so if you need to rebuild your site then you must exit and run `serve` again.

### [sites](/docs/commands/sites.md)

Handle various site operations
Expand Down
5 changes: 1 addition & 4 deletions src/commands/base-command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,7 @@ export default class BaseCommand extends Command {
* @returns {string}
*/
getDefaultContext() {
const { prod } = this.opts()
const isDevCommand = ['dev', 'dev:exec'].includes(this.name())

if (isDevCommand && prod) {
if (this.name() === 'serve') {
return 'production'
}

Expand Down
Loading

1 comment on commit 0d583d9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Package size: 259 MB

Please sign in to comment.