Question

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?

Was it helpful?

Solution

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'));

OTHER TIPS

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() or process.stdout.write() to output content. Using them would hide the output from users not using a terminal. Instead, always rely on the UI generic this.log() method, where this is the context of your current generator.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top