diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 066e2c508df..5efce66a8b3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -48,14 +48,14 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest, windows-latest] - node-version: [12.x, '*'] + node-version: [14.x, '*'] machine: ['0', '1', '2', '3', '4', '5', '6'] exclude: - os: macOS-latest - node-version: '12.x' + node-version: '14.x' - os: windows-latest - node-version: '12.x' + node-version: '14.x' fail-fast: false steps: # Sets an output parameter if this is a release PR diff --git a/README.md b/README.md index abd9bd1132e..a646e55a335 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ ![Netlify CLI](cli.png) [![Coverage Status](https://codecov.io/gh/netlify/cli/branch/main/graph/badge.svg)](https://codecov.io/gh/netlify/cli) -[![npm version][npm-img]][npm] [![downloads][dl-img]][dl] [![netlify-status][netlify-img]][netlify] [![security][snyk-img]][snyk] +[![npm version][npm-img]][npm] [![downloads][dl-img]][dl] [![netlify-status][netlify-img]][netlify] +[![security][snyk-img]][snyk] Interact with [Netlify](http://netlify.com/) from the comfort of your CLI. -See the [CLI command line reference](https://cli.netlify.com/commands/) to get started and the docs on using [Netlify Dev](https://github.com/netlify/cli/blob/main/docs/netlify-dev.md) to run your site locally. +See the [CLI command line reference](https://cli.netlify.com/commands/) to get started and the docs on using +[Netlify Dev](https://github.com/netlify/cli/blob/main/docs/netlify-dev.md) to run your site locally. ## Table of Contents @@ -46,22 +48,28 @@ See the [CLI command line reference](https://cli.netlify.com/commands/) to get s ## Installation -Netlify CLI requires [Node.js](https://nodejs.org) version 12 or above. To install, run the following command from any directory in your terminal: +Netlify CLI requires [Node.js](https://nodejs.org) version 14 or above. To install, run the following command from any +directory in your terminal: ```bash npm install netlify-cli -g ``` -When using the CLI in a CI environment we recommend installing it locally as a development dependency, instead of globally. -To install locally, run the following command from the root directory of your project: +When using the CLI in a CI environment we recommend installing it locally as a development dependency, instead of +globally. To install locally, run the following command from the root directory of your project: ```bash npm install --save-dev netlify-cli ``` -**Important:** Running `npm install netlify-cli -g` in CI means you're always installing the latest version of the CLI, including **breaking changes**. When you install locally and use a [lock file](https://docs.npmjs.com/cli/v7/commands/npm-ci) you guarantee reproducible builds. To manage CLI updates we recommend using an automated tool like [renovate](https://github.com/renovatebot/renovate) or [dependabot](https://github.com/dependabot). +**Important:** Running `npm install netlify-cli -g` in CI means you're always installing the latest version of the CLI, +including **breaking changes**. When you install locally and use a +[lock file](https://docs.npmjs.com/cli/v7/commands/npm-ci) you guarantee reproducible builds. To manage CLI updates we +recommend using an automated tool like [renovate](https://github.com/renovatebot/renovate) or +[dependabot](https://github.com/dependabot). -Alternatively you may also use Homebrew: `brew install netlify-cli` (thanks [@cglong](https://github.com/netlify/cli/issues/291)). +Alternatively you may also use Homebrew: `brew install netlify-cli` (thanks +[@cglong](https://github.com/netlify/cli/issues/291)). ## Usage @@ -76,7 +84,8 @@ netlify [command] help ## Documentation -To learn how to log in to Netlify and start deploying sites, visit the [documentation on Netlify](https://docs.netlify.com/cli/get-started/). +To learn how to log in to Netlify and start deploying sites, visit the +[documentation on Netlify](https://docs.netlify.com/cli/get-started/). For a full command reference, see the list below, or visit [cli.netlify.com](https://cli.netlify.com/). diff --git a/docs/README.md b/docs/README.md index 5ac86b2770c..8ae49013435 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,12 +5,13 @@ description: All Netlify CLI commands # Netlify CLI Command List -Welcome to the Netlify CLI! This site provides online access to all help strings in the Netlify CLI. For a more in-depth guide, please see our [Getting Started](https://docs.netlify.com/cli/get-started/) guide on our main docs site. +Welcome to the Netlify CLI! This site provides online access to all help strings in the Netlify CLI. For a more in-depth +guide, please see our [Getting Started](https://docs.netlify.com/cli/get-started/) guide on our main docs site. -If you have questions, ideas, or would like to contribute, check out the [repository on GitHub](https://github.com/netlify/cli/). +If you have questions, ideas, or would like to contribute, check out the +[repository on GitHub](https://github.com/netlify/cli/). -**Before you begin** -Make sure you have [Node.js](https://nodejs.org/en/download/) version 12.20.0, 14.14.0, 16.0.0, or later. +**Before you begin** Make sure you have [Node.js](https://nodejs.org/en/download/) version 16.0.0, or later. **Install the CLI** @@ -20,7 +21,8 @@ To install the CLI, pop open your terminal and install with `npm`. npm install netlify-cli -g ``` -**Important:** When using the CLI in a CI environment we recommend installing it locally. See more [here](https://github.com/netlify/cli#installation). +**Important:** When using the CLI in a CI environment we recommend installing it locally. See more +[here](https://github.com/netlify/cli#installation). **Listing commands** diff --git a/docs/netlify-dev.md b/docs/netlify-dev.md index d137db43ec8..905573ed6a6 100644 --- a/docs/netlify-dev.md +++ b/docs/netlify-dev.md @@ -2,12 +2,16 @@
-Netlify Dev brings the power of Netlify's Edge Logic layer, [serverless functions](#netlify-functions) and [add-on ecosystem](#using-add-ons) to your local machine. It runs Netlify's production routing engine in a local dev server to make all redirects, proxy rules, function routes or add-on routes available locally and injects the correct environment variables from your site environment, installed add-ons or your netlify.toml file into your build and function environment. +Netlify Dev brings the power of Netlify's Edge Logic layer, [serverless functions](#netlify-functions) and +[add-on ecosystem](#using-add-ons) to your local machine. It runs Netlify's production routing engine in a local dev +server to make all redirects, proxy rules, function routes or add-on routes available locally and injects the correct +environment variables from your site environment, installed add-ons or your netlify.toml file into your build and +function environment. ``` ┌───────────────┐ @@ -27,13 +31,19 @@ Netlify Dev brings the power of Netlify's Edge Logic layer, [serverless function └──────────┘ ``` -With project detectors, it automatically detects common tools like Gatsby, Hugo, React Static, Eleventy, and more, to give a zero config setup for your local dev server and can help scaffolding new functions as you work on them. Read our blog post for [more on detectors and how you can contribute](https://www.netlify.com/blog/2019/04/24/zero-config-yet-technology-agnostic-how-netlify-dev-detectors-work/)! +With project detectors, it automatically detects common tools like Gatsby, Hugo, React Static, Eleventy, and more, to +give a zero config setup for your local dev server and can help scaffolding new functions as you work on them. Read our +blog post for +[more on detectors and how you can contribute](https://www.netlify.com/blog/2019/04/24/zero-config-yet-technology-agnostic-how-netlify-dev-detectors-work/)! ## Prerequisites - You should have the latest Netlify CLI version. Run `npm install -g netlify-cli` to be sure. - You should be [logged in on Netlify CLI](https://docs.netlify.com/cli/get-started/#authentication) -- Your project should be linked to a `siteID` on Netlify (using [netlify init](https://docs.netlify.com/cli/get-started/#continuous-deployment) or [netlify link](https://docs.netlify.com/cli/get-started/#linking-and-unlinking-sites)). You can confirm this has been done if you have a `.netlify` folder with a `state.json` file containing your `siteID`. +- Your project should be linked to a `siteID` on Netlify (using + [netlify init](https://docs.netlify.com/cli/get-started/#continuous-deployment) or + [netlify link](https://docs.netlify.com/cli/get-started/#linking-and-unlinking-sites)). You can confirm this has been + done if you have a `.netlify` folder with a `state.json` file containing your `siteID`. This is how we pull down your build environment variables and manage your addons on your local machine. @@ -48,7 +58,12 @@ This is how we pull down your build environment variables and manage your addons Pro tip: Aliasing commands -As these commands are expected to be frequently used, it may be helpful to define aliases in your terminal (Mac: [bash](https://jonsuh.com/blog/bash-command-line-shortcuts/), [zsh](https://askubuntu.com/questions/758496/how-to-make-a-permanent-alias-in-oh-my-zsh), Windows: [doskey](https://stackoverflow.com/questions/20530996/aliases-in-windows-command-prompt), [registry](https://stackoverflow.com/questions/20530996/aliases-in-windows-command-prompt)) to your personal preference. For example: +As these commands are expected to be frequently used, it may be helpful to define aliases in your terminal (Mac: +[bash](https://jonsuh.com/blog/bash-command-line-shortcuts/), +[zsh](https://askubuntu.com/questions/758496/how-to-make-a-permanent-alias-in-oh-my-zsh), Windows: +[doskey](https://stackoverflow.com/questions/20530996/aliases-in-windows-command-prompt), +[registry](https://stackoverflow.com/questions/20530996/aliases-in-windows-command-prompt)) to your personal preference. +For example: ```bash ## ~/.zshrc @@ -85,7 +100,8 @@ EXAMPLES $ netlify dev -c "hugo server -w" --targetPort 1313 ``` -The command will automatically open your preferred browser to serve the application. You can customize this behaviour by using the `BROWSER` environment variable: +The command will automatically open your preferred browser to serve the application. You can customize this behaviour by +using the `BROWSER` environment variable: ```bash $ BROWSER=none netlify dev # this will disable the auto opening of the browser @@ -99,11 +115,13 @@ To share your ongoing dev session with a coworker, just run Netlify Dev with a ` netlify dev --live ``` -You will get a URL that looks like `https://clever-cray-2aa156-6639f3.netlify.live/`. This can be accessed by anyone as long as you keep your session open. +You will get a URL that looks like `https://clever-cray-2aa156-6639f3.netlify.live/`. This can be accessed by anyone as +long as you keep your session open. ## netlify.toml [dev] block -Netlify Dev is meant to work with zero config for the majority of users, by using its detector system. However you may wish to assert more control over its behavior, and should make use of the new `[dev]` block in `netlify.toml` to do so: +Netlify Dev is meant to work with zero config for the majority of users, by using its detector system. However you may +wish to assert more control over its behavior, and should make use of the new `[dev]` block in `netlify.toml` to do so: ```toml # sample netlify.toml @@ -130,9 +148,14 @@ Netlify Dev is meant to work with zero config for the majority of users, by usin ## Project detection -Netlify Dev will attempt to detect the site generator or build command that you are using, and run these on your behalf, while adding other development utilities. If you have a JavaScript project, it looks for the best `package.json` script to run for you, using simple heuristics, so you can use the full flexibility of npm scripts. +Netlify Dev will attempt to detect the site generator or build command that you are using, and run these on your behalf, +while adding other development utilities. If you have a JavaScript project, it looks for the best `package.json` script +to run for you, using simple heuristics, so you can use the full flexibility of npm scripts. -**Overriding framework detection**: The number of [frameworks which Netlify Dev can detect](https://github.com/netlify/framework-info/tree/main/src/frameworks) is growing, but if yours is not yet supported (contributions welcome!), you can instruct Netlify Dev to run the project on your behalf by declaring it in a `[dev]` block of your `netlify.toml` file. +**Overriding framework detection**: The number of +[frameworks which Netlify Dev can detect](https://github.com/netlify/framework-info/tree/main/src/frameworks) is +growing, but if yours is not yet supported (contributions welcome!), you can instruct Netlify Dev to run the project on +your behalf by declaring it in a `[dev]` block of your `netlify.toml` file. ```toml # sample dev block in the toml @@ -144,9 +167,8 @@ Netlify Dev will attempt to detect the site generator or build command that you publish = "dist" # If you use a _redirect file, provide the path to your static content folder ``` -If your project is being detected incorrectly or positive by multiple -detectors you can specify `framework` option to test only one detector -against your project. +If your project is being detected incorrectly or positive by multiple detectors you can specify `framework` option to +test only one detector against your project. ```toml [dev] @@ -155,20 +177,27 @@ against your project. Possible values of `framework`: -- `#auto` (default) to check of all [available frameworks](https://github.com/netlify/framework-info/tree/main/src/frameworks). +- `#auto` (default) to check of all + [available frameworks](https://github.com/netlify/framework-info/tree/main/src/frameworks). - One of the framework ids as specified [here](https://github.com/netlify/framework-info/tree/main/src/frameworks). - `#static` for a static file server - `#custom` to use the `command` option to run an app server and `targetPort` option to connect to it ## Explanation of ports in Netlify Dev -There will be a number of ports that you will encounter when using Netlify Dev, especially when running a static site generator like Gatsby which has its own dev server. All the port numbers can be a bit confusing, so here is a brief explainer. +There will be a number of ports that you will encounter when using Netlify Dev, especially when running a static site +generator like Gatsby which has its own dev server. All the port numbers can be a bit confusing, so here is a brief +explainer. -- If your site generator runs on port 8000 for example, Netlify Dev needs to be told to connect to that port, so, it can route the requests successfully to the site generator along with the rest of the local Netlify environment -- If you’re running a project we have a detector for, we hardcode those conventional ports so you don't have to supply it yourself. If we have multiple detectors that match, we'll ask you to choose. -- However, sometimes you’re using some unrecognized site generator or just have a server you want Netlify Dev to connect to. This is when you go to the `netlify.toml` `[dev]` block to specify exactly what port we should listen to. +- If your site generator runs on port 8000 for example, Netlify Dev needs to be told to connect to that port, so, it can + route the requests successfully to the site generator along with the rest of the local Netlify environment +- If you’re running a project we have a detector for, we hardcode those conventional ports so you don't have to supply + it yourself. If we have multiple detectors that match, we'll ask you to choose. +- However, sometimes you’re using some unrecognized site generator or just have a server you want Netlify Dev to connect + to. This is when you go to the `netlify.toml` `[dev]` block to specify exactly what port we should listen to. -As for which port to use while doing local development in Netlify Dev, always search for this box in your console output and use that: +As for which port to use while doing local development in Netlify Dev, always search for this box in your console output +and use that: ```bash ┌──────────────────────────────────────────────────────────────┐ @@ -180,16 +209,20 @@ As for which port to use while doing local development in Netlify Dev, always se **Specifying custom ports for Netlify Dev** -Netlify Dev allows you to specify the following parameters for port as both flags and in config file (`netlify.toml` etc.): +Netlify Dev allows you to specify the following parameters for port as both flags and in config file (`netlify.toml` +etc.): - `targetPort`: The port for your application server, framework or site generator. - `port`: The port for the Netlify Dev server, the one you'll open in the browser. -Netlify Dev tries to acquire these ports but if any of them is not available (already in use by another application), it will throw an error and let you know. +Netlify Dev tries to acquire these ports but if any of them is not available (already in use by another application), it +will throw an error and let you know. ## Redirects -Netlify Dev has the ability emulate the [redirect capability](https://docs.netlify.com/routing/redirects/) Netlify provide on the [ADN](https://netlify.com/features/adn) in your local environment. The same redirect rules which you configure to run on the edge, will also work in your local builds. +Netlify Dev has the ability emulate the [redirect capability](https://docs.netlify.com/routing/redirects/) Netlify +provide on the [ADN](https://netlify.com/features/adn) in your local environment. The same redirect rules which you +configure to run on the edge, will also work in your local builds. Netlify dev supports redirect rules defined in either `_redirects` or `netlify.toml` files. @@ -199,18 +232,26 @@ The order of precedence for applying redirect rules is: 1. `netlify.toml` file (in the project's publish folder) 1. `netlify.toml` file (in the project's root folder) -See the [Redirects Documentation](https://docs.netlify.com/routing/redirects/) for more information on Netlify's redirect and proxying capabilities. +See the [Redirects Documentation](https://docs.netlify.com/routing/redirects/) for more information on Netlify's +redirect and proxying capabilities. ## Environment Variables -If the current project is linked to a Netlify site (`netlify link`), environment variables are pulled down from production and populated in `netlify dev` server. This functionality requires that you’re logged in (`netlify login`) and connected to the internet when running `netlify dev`. +If the current project is linked to a Netlify site (`netlify link`), environment variables are pulled down from +production and populated in `netlify dev` server. This functionality requires that you’re logged in (`netlify login`) +and connected to the internet when running `netlify dev`. -Netlify Dev also supports local environment variables through `.env` files. -Netlify Dev will look in project root directory for `.env` file and will provide those variables to the spawned site generator/server and Netlify Functions. +Netlify Dev also supports local environment variables through `.env` files. Netlify Dev will look in project root +directory for `.env` file and will provide those variables to the spawned site generator/server and Netlify Functions. ## Netlify Functions -Netlify can also create serverless functions for you locally as part of Netlify Functions. The serverless functions can then be run by Netlify Dev in the same way they would be when deployed to the cloud. Once you've configured the [functions directory in your `netlify.toml`](https://docs.netlify.com/configure-builds/file-based-configuration/#sample-file), the functions will be accessible through `netlify dev` server. e.g. at `http://localhost:8888/.netlify/functions/function-name`. Besides interacting with your functions through the browser, you can also use the following commands: +Netlify can also create serverless functions for you locally as part of Netlify Functions. The serverless functions can +then be run by Netlify Dev in the same way they would be when deployed to the cloud. Once you've configured the +[functions directory in your `netlify.toml`](https://docs.netlify.com/configure-builds/file-based-configuration/#sample-file), +the functions will be accessible through `netlify dev` server. e.g. at +`http://localhost:8888/.netlify/functions/function-name`. Besides interacting with your functions through the browser, +you can also use the following commands: ``` ## list of major functionality @@ -219,7 +260,8 @@ netlify functions:create netlify functions:invoke ``` -A number of function templates are available to get you started, and you can add your own utility functions to suit your own project development needs. You can also locally invoke them with test payload data. +A number of function templates are available to get you started, and you can add your own utility functions to suit your +own project development needs. You can also locally invoke them with test payload data. **Create a new function** @@ -227,7 +269,10 @@ A number of function templates are available to get you started, and you can add $ netlify functions:create ``` -Important note: Your functions will likely have `node_modules` in each folder. These are usually gitignored. You can write bash scripts to install them for production, or use the lightweight [`netlify-lambda install`](https://github.com/netlify/netlify-lambda/blob/master/README.md#netlify-lambda-install) CLI to do it for you. +Important note: Your functions will likely have `node_modules` in each folder. These are usually gitignored. You can +write bash scripts to install them for production, or use the lightweight +[`netlify-lambda install`](https://github.com/netlify/netlify-lambda/blob/master/README.md#netlify-lambda-install) CLI +to do it for you.