I have tried console.log('message')
, but it returns the message in black.
Is there a way to log a message in color in a generator?
You can use the same color module Chalk as used by the generator system to colorize your text.
First install it:npm install --save chalk
Then:
var chalk = require('chalk');
this.log(chalk.bold.yellow('message'));
For new users viewing this question console.log();
should "never" be used in Yeoman, according to the Documentation. Instead use generator.log();
mainly seen in practice as this.log()
.
To allow for this flexibility [of running in various user interfaces, not just in terminals], Yeoman provides a set of user interface element abstractions. It is your responsibility as an author to only use those abstractions when interacting with your end user. [Emphasis added.] Using other ways will probably prevent your generator from running correctly in different Yeoman tools.
For example, it is important to never use
console.log()
orprocess.stdout.write()
to output content. Using them would hide the output from users not using a terminal. Instead, always rely on the UI genericthis.log()
method, wherethis
is the context of your current generator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With