Skip to content

Commit

Permalink
feat(gatsby-cli): Added support and docs for NO_COLOR env variable (#…
Browse files Browse the repository at this point in the history
…16372)

* Added support and docs for NO_COLOR env variable

Closes #16324

* Refactored noColor section

* Moved FORCE_COLOR env variable into Reporter

* rewrite code style 💅
  • Loading branch information
evolkmann authored and GatsbyJS Bot committed Aug 5, 2019
1 parent 69aec1a commit ccebe17
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 4 additions & 0 deletions docs/docs/gatsby-cli.md
Expand Up @@ -153,3 +153,7 @@ You can type in a command, such as one of these:
When combined with the [GraphQL explorer](/docs/introducing-graphiql/), these REPL commands could be very helpful for understanding your Gatsby site's data.

See the Gatsby REPL documentation [here](/docs/gatsby-repl/).

### Disabling colored output

In addition to the explicit `--no-color` option, the CLI respects the presence of the `NO_COLOR` environment variable (see [no-color.org](https://no-color.org/)).
8 changes: 1 addition & 7 deletions packages/gatsby-cli/src/create-cli.js
Expand Up @@ -82,14 +82,8 @@ function buildLocalCommands(cli, isLocalSite) {
function getCommandHandler(command, handler) {
return argv => {
report.setVerbose(!!argv.verbose)
if (argv.noColor) {
// disables colors in popular terminal output coloring packages
// - chalk: see https://www.npmjs.com/package/chalk#chalksupportscolor
// - ansi-colors: see https://github.com/doowb/ansi-colors/blob/8024126c7115a0efb25a9a0e87bc5e29fd66831f/index.js#L5-L7
process.env.FORCE_COLOR = `0`
}

report.setNoColor(!!argv.noColor)
report.setNoColor(argv.noColor || process.env.NO_COLOR)

process.env.gatsby_log_level = argv.verbose ? `verbose` : `normal`
report.verbose(`set gatsby_log_level: "${process.env.gatsby_log_level}"`)
Expand Down
7 changes: 7 additions & 0 deletions packages/gatsby-cli/src/reporter/index.js
Expand Up @@ -38,6 +38,13 @@ const reporter: Reporter = {
if (isNoColor) {
errorFormatter.withoutColors()
}

// disables colors in popular terminal output coloring packages
// - chalk: see https://www.npmjs.com/package/chalk#chalksupportscolor
// - ansi-colors: see https://github.com/doowb/ansi-colors/blob/8024126c7115a0efb25a9a0e87bc5e29fd66831f/index.js#L5-L7
if (isNoColor) {
process.env.FORCE_COLOR = `0`
}
},
/**
* Log arguments and exit process with status 1.
Expand Down

0 comments on commit ccebe17

Please sign in to comment.