Skip to content
Permalink
Browse files

feat(gatsby-cli): Added support and docs for NO_COLOR env variable (#…

…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 gatsbybot committed Aug 5, 2019
1 parent 69aec1a commit ccebe174078529329a26350224a1a5730567c695
Showing with 12 additions and 7 deletions.
  1. +4 −0 docs/docs/gatsby-cli.md
  2. +1 −7 packages/gatsby-cli/src/create-cli.js
  3. +7 −0 packages/gatsby-cli/src/reporter/index.js
@@ -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/)).
@@ -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}"`)
@@ -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.

0 comments on commit ccebe17

Please sign in to comment.
You can’t perform that action at this time.