From c4ae71ed3a2aa9079b21d22a22faa2922b05b030 Mon Sep 17 00:00:00 2001 From: Ben Robertson Date: Thu, 20 Feb 2020 14:36:51 -0500 Subject: [PATCH 1/7] feat(gatsby-cli): support for PREFIX_PATHS env variable --- packages/gatsby-cli/src/create-cli.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/gatsby-cli/src/create-cli.js b/packages/gatsby-cli/src/create-cli.js index 39f4459472021..5fa6f7d78e93b 100644 --- a/packages/gatsby-cli/src/create-cli.js +++ b/packages/gatsby-cli/src/create-cli.js @@ -166,8 +166,10 @@ function buildLocalCommands(cli, isLocalSite) { builder: _ => _.option(`prefix-paths`, { type: `boolean`, - default: false, - describe: `Build site with link paths prefixed (set pathPrefix in your gatsby-config.js).`, + default: process.env.PREFIX_PATHS || false, + describe: process.env.PREFIX_PATHS + ? `Build site with link paths prefixed (set by env.PREFIX_PATHS) (set pathPrefix in your gatsby-config.js).` + : `Build site with link paths prefixed (set pathPrefix in your gatsby-config.js).`, }) .option(`no-uglify`, { type: `boolean`, @@ -209,8 +211,10 @@ function buildLocalCommands(cli, isLocalSite) { }) .option(`prefix-paths`, { type: `boolean`, - default: false, - describe: `Serve site with link paths prefixed (if built with pathPrefix in your gatsby-config.js).`, + default: process.env.PREFIX_PATHS || false, + describe: process.env.PREFIX_PATHS + ? `Serve site with link paths prefixed (set by env.PREFIX_PATHS) (set pathPrefix in your gatsby-config.js).` + : `Serve site with link paths prefixed (set pathPrefix in your gatsby-config.js).`, }), handler: getCommandHandler(`serve`), From 5270b1301e3702a3c846728c02ab71dfae5d01dc Mon Sep 17 00:00:00 2001 From: Ben Robertson Date: Thu, 20 Feb 2020 14:45:49 -0500 Subject: [PATCH 2/7] docs(gatsby-cli): Document env.PREFIX_PATHS in gatsby-cli README. --- packages/gatsby-cli/README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/gatsby-cli/README.md b/packages/gatsby-cli/README.md index 641ab4d3e6cae..853abed8836ca 100644 --- a/packages/gatsby-cli/README.md +++ b/packages/gatsby-cli/README.md @@ -94,12 +94,12 @@ At the root of a Gatsby app run `gatsby build` to do a production build of a sit #### Options -| Option | Description | Default | -| :--------------------------: | ---------------------------------------------------------------------------------------------------------- | :-----: | -| `--prefix-paths` | Build site with link paths prefixed (set pathPrefix in your config) | `false` | -| `--no-uglify` | Build site without uglifying JS bundles (for debugging) | `false` | -| `--open-tracing-config-file` | Tracer configuration file (OpenTracing compatible). See https://www.gatsbyjs.org/docs/performance-tracing/ | | -| `--no-color`, `--no-colors` | Disables colored terminal output | `false` | +| Option | Description | Default | +| :--------------------------: | ---------------------------------------------------------------------------------------------------------- | :---------------------------: | +| `--prefix-paths` | Build site with link paths prefixed (set pathPrefix in your config) | `env.PREFIX_PATHS` or `false` | +| `--no-uglify` | Build site without uglifying JS bundles (for debugging) | `false` | +| `--open-tracing-config-file` | Tracer configuration file (OpenTracing compatible). See https://www.gatsbyjs.org/docs/performance-tracing/ | | +| `--no-color`, `--no-colors` | Disables colored terminal output | `false` | ### `serve` @@ -107,12 +107,12 @@ At the root of a Gatsby app run `gatsby serve` to serve the production build of #### Options -| Option | Description | -| :--------------: | ---------------------------------------------------------------------------------------- | -| `-H`, `--host` | Set host. Defaults to localhost | -| `-p`, `--port` | Set port. Defaults to 9000 | -| `-o`, `--open` | Open the site in your (default) browser for you | -| `--prefix-paths` | Serve site with link paths prefixed (if built with pathPrefix in your gatsby-config.js). | +| Option | Description | Default | +| :--------------: | ---------------------------------------------------------------------------------------- | :---------------------------: | +| `-H`, `--host` | Set host. Defaults to localhost | | +| `-p`, `--port` | Set port. Defaults to 9000 | | +| `-o`, `--open` | Open the site in your (default) browser for you | | +| `--prefix-paths` | Serve site with link paths prefixed (if built with pathPrefix in your gatsby-config.js). | `env.PREFIX_PATHS` or `false` | ### `clean` From f6f1d7c2e1c230be2ce1ca89b093dac6dfb5db0c Mon Sep 17 00:00:00 2001 From: Ben Robertson Date: Fri, 21 Feb 2020 11:09:20 -0500 Subject: [PATCH 3/7] Update packages/gatsby-cli/src/create-cli.js Co-Authored-By: Ward Peeters --- packages/gatsby-cli/src/create-cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-cli/src/create-cli.js b/packages/gatsby-cli/src/create-cli.js index 5fa6f7d78e93b..86799de017d52 100644 --- a/packages/gatsby-cli/src/create-cli.js +++ b/packages/gatsby-cli/src/create-cli.js @@ -166,7 +166,7 @@ function buildLocalCommands(cli, isLocalSite) { builder: _ => _.option(`prefix-paths`, { type: `boolean`, - default: process.env.PREFIX_PATHS || false, + default: process.env.PREFIX_PATHS === 'true' || process.env.PREFIX_PATHS === '1', describe: process.env.PREFIX_PATHS ? `Build site with link paths prefixed (set by env.PREFIX_PATHS) (set pathPrefix in your gatsby-config.js).` : `Build site with link paths prefixed (set pathPrefix in your gatsby-config.js).`, From 10bc63c1c65cdc4fc5da5af3f0bf1bc28c238698 Mon Sep 17 00:00:00 2001 From: Ben Robertson Date: Fri, 21 Feb 2020 11:09:39 -0500 Subject: [PATCH 4/7] Update packages/gatsby-cli/src/create-cli.js Co-Authored-By: Ward Peeters --- packages/gatsby-cli/src/create-cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-cli/src/create-cli.js b/packages/gatsby-cli/src/create-cli.js index 86799de017d52..6d79912a704bd 100644 --- a/packages/gatsby-cli/src/create-cli.js +++ b/packages/gatsby-cli/src/create-cli.js @@ -211,7 +211,7 @@ function buildLocalCommands(cli, isLocalSite) { }) .option(`prefix-paths`, { type: `boolean`, - default: process.env.PREFIX_PATHS || false, + default: process.env.PREFIX_PATHS === 'true' || process.env.PREFIX_PATHS === '1', describe: process.env.PREFIX_PATHS ? `Serve site with link paths prefixed (set by env.PREFIX_PATHS) (set pathPrefix in your gatsby-config.js).` : `Serve site with link paths prefixed (set pathPrefix in your gatsby-config.js).`, From 3af8c08216ec52ff22d80a8d2d7b5cd8b563f091 Mon Sep 17 00:00:00 2001 From: Ben Robertson Date: Fri, 21 Feb 2020 11:14:24 -0500 Subject: [PATCH 5/7] docs(gatsby-cli): Adds more info about when to use env.PREFIX_PATHS to README. --- packages/gatsby-cli/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/gatsby-cli/README.md b/packages/gatsby-cli/README.md index 853abed8836ca..447a96d4e92d0 100644 --- a/packages/gatsby-cli/README.md +++ b/packages/gatsby-cli/README.md @@ -101,6 +101,8 @@ At the root of a Gatsby app run `gatsby build` to do a production build of a sit | `--open-tracing-config-file` | Tracer configuration file (OpenTracing compatible). See https://www.gatsbyjs.org/docs/performance-tracing/ | | | `--no-color`, `--no-colors` | Disables colored terminal output | `false` | +For prefixing paths, most will want to use the CLI flag (`gatsby build --prefix-paths`). For environments where you can't pass the --prefix-paths flag (ie Gatsby Cloud) this provides another way to prefix paths. + ### `serve` At the root of a Gatsby app run `gatsby serve` to serve the production build of the site @@ -114,6 +116,8 @@ At the root of a Gatsby app run `gatsby serve` to serve the production build of | `-o`, `--open` | Open the site in your (default) browser for you | | | `--prefix-paths` | Serve site with link paths prefixed (if built with pathPrefix in your gatsby-config.js). | `env.PREFIX_PATHS` or `false` | +For prefixing paths, most will want to use the CLI flag (`gatsby build --prefix-paths`). For environments where you can't pass the --prefix-paths flag this provides another way to prefix paths. + ### `clean` At the root of a Gatsby app run `gatsby clean` to wipe out the cache (`.cache` folder) and `public` directories. This is useful **as a last resort** when your local project seems to have issues or content does not seem to be refreshing. Issues this may fix commonly include: From f3bd39a1eef72a004d6bbac43f0aa1e46c6d3d80 Mon Sep 17 00:00:00 2001 From: Ben Robertson Date: Fri, 21 Feb 2020 11:16:39 -0500 Subject: [PATCH 6/7] feat(gatsby-cli): Removes env switching for PATH_PREFIX description. --- packages/gatsby-cli/src/create-cli.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/gatsby-cli/src/create-cli.js b/packages/gatsby-cli/src/create-cli.js index 5fa6f7d78e93b..90ed9298b6414 100644 --- a/packages/gatsby-cli/src/create-cli.js +++ b/packages/gatsby-cli/src/create-cli.js @@ -167,9 +167,7 @@ function buildLocalCommands(cli, isLocalSite) { _.option(`prefix-paths`, { type: `boolean`, default: process.env.PREFIX_PATHS || false, - describe: process.env.PREFIX_PATHS - ? `Build site with link paths prefixed (set by env.PREFIX_PATHS) (set pathPrefix in your gatsby-config.js).` - : `Build site with link paths prefixed (set pathPrefix in your gatsby-config.js).`, + describe: `Build site with link paths prefixed (default is env.PREFIX_PATHS or false) (set pathPrefix in your gatsby-config.js).`, }) .option(`no-uglify`, { type: `boolean`, @@ -212,9 +210,7 @@ function buildLocalCommands(cli, isLocalSite) { .option(`prefix-paths`, { type: `boolean`, default: process.env.PREFIX_PATHS || false, - describe: process.env.PREFIX_PATHS - ? `Serve site with link paths prefixed (set by env.PREFIX_PATHS) (set pathPrefix in your gatsby-config.js).` - : `Serve site with link paths prefixed (set pathPrefix in your gatsby-config.js).`, + describe: `Serve site with link paths prefixed (default is env.PREFIX_PATHS or false) (set pathPrefix value in your gatsby-config.js).`, }), handler: getCommandHandler(`serve`), From 5d773300a0ec78192a40e77dbed8f2a6134a467d Mon Sep 17 00:00:00 2001 From: Ben Robertson Date: Fri, 21 Feb 2020 11:24:18 -0500 Subject: [PATCH 7/7] feat(gatsby-cli): Remove env checking for prefix-paths description. --- packages/gatsby-cli/src/create-cli.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/gatsby-cli/src/create-cli.js b/packages/gatsby-cli/src/create-cli.js index 4fe910c586047..75e851cd9a7ae 100644 --- a/packages/gatsby-cli/src/create-cli.js +++ b/packages/gatsby-cli/src/create-cli.js @@ -169,9 +169,7 @@ function buildLocalCommands(cli, isLocalSite) { default: process.env.PREFIX_PATHS === `true` || process.env.PREFIX_PATHS === `1`, - describe: process.env.PREFIX_PATHS - ? `Build site with link paths prefixed (set by env.PREFIX_PATHS) (set pathPrefix in your gatsby-config.js).` - : `Build site with link paths prefixed (set pathPrefix in your gatsby-config.js).`, + describe: `Build site with link paths prefixed with the pathPrefix value in gatsby-config.js. Default is env.PREFIX_PATHS or false.`, }) .option(`no-uglify`, { type: `boolean`, @@ -216,9 +214,7 @@ function buildLocalCommands(cli, isLocalSite) { default: process.env.PREFIX_PATHS === `true` || process.env.PREFIX_PATHS === `1`, - describe: process.env.PREFIX_PATHS - ? `Serve site with link paths prefixed (set by env.PREFIX_PATHS) (set pathPrefix in your gatsby-config.js).` - : `Serve site with link paths prefixed (set pathPrefix in your gatsby-config.js).`, + describe: `Serve site with link paths prefixed with the pathPrefix value in gatsby-config.js.Default is env.PREFIX_PATHS or false.`, }), handler: getCommandHandler(`serve`),