gulpjs / gulp-cli

Command Line Interface for gulp.
MIT License
401 stars 106 forks source link

feat: Support theming and translations via config files #260

Closed phated closed 8 months ago

phated commented 8 months ago

This implements theming and translation support via the .gulp.js config files. If a user supplies a message function in their config file, we will call it with various message symbols and extra data. The user can return the message they want to print, return false explicitly to silence the message, or do nothing to fallback to the gulp-cli default message.

Since anything logged via gulplog will pass through this mechanism, users can also intercept string messages from plugins and return something different.

Users can also override the timestamp we print by providing a timestamp function in their config file.

Closes #63 Closes #177 Closes #206 Closes #161 (replaces it)

phated commented 8 months ago

Responding to https://github.com/sttk/gulp-cli/pull/3#issuecomment-1987137214

@phated Your idea is very interesting, but there are some concerns.

  1. There are cases that having to provide a plugin to change messages or styles would be burdensome. Some users might want to change only colors of certain words in certain messages against the background color of their terminal. (In fact, I consider that this case is the most important request regarding this theming feature.) It should be possible to change colors with minimal effort. As an addition to your idea, it can be considered to enable to override the getMessage function in a config file, but the config file would be limited to .js file only.

I'm okay making the theming and translations to be a little more complex for users if it keeps our implementation straightforward and easy to modify. Users can provide the message() function and only handle a single message (like messages.DESCRIPTION, handle every symbol, or any amount of message in between. This implementation also makes it easy to silence specific messages.

I've change the .gulp config file lookup to only support interpret.jsVariants in #261 so users always have access to this feature.

  1. fancy-log always outputs the timestamp at the beginning of the line, and its color or format cannot be changed. There are indeed requests in the issues for changing the color against the terminal background color, so we need to provide the solution for this.

I've removed fancy-log and reimplemented the Timestamp class that I used there. Users can provide a timestamp() function in the config file to override the timestamp.

We will probably deprecate fancy-log post-v5 if we're not using it anymore.

  1. There are cases that CLI options —color and —no-color would not be supported if the external plugin uses a coloring module other than chalk.

Users could intercept this in their message() function and recreate the messages if it bothers them.

  1. In the draft version, the help messages and task tree are not configurable. For these as well, I believe it's necessary to make it possible to change the colors at least against the terminal's background color.

These are completed now. What do you think?

phated commented 8 months ago

@sttk this is ready for review. Please take a look! I've updated the top comment to describe the feature and updated tests, etc. Thank you for all of the amazing work that I used for the basis of these changes 🙇 ❤️

When we finalize this, I will put together the @gulpjs/messages package and update all of the TODOs.

sttk commented 8 months ago

@phated I have replied to your comments. Have a look them.

phated commented 8 months ago

@sttk please review again now that I've addressed all your comments.

phated commented 8 months ago

@sttk I've address the comments and added documentation. Can you provide a final review so I can make the @gulpjs/messages package and finish this PR in the next 3 days? 🙏

sttk commented 8 months ago

@phated I have added this comment, so please take a look. Otherwise, I think everything is good.

phated commented 8 months ago

@sttk Thank you for the thorough review! I am going to create the @gulpjs/messages package and then update this PR to use it before merging.