Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add deprecated warning for gulplog v1 messages #254

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.js
Expand Up @@ -3,6 +3,7 @@
var fs = require('fs');
var path = require('path');
var log = require('gulplog');
var oldLog = require('gulplog-v1');

var Liftoff = require('liftoff');
var interpret = require('interpret');
Expand Down Expand Up @@ -117,7 +118,8 @@ function onPrepare(env) {
env = overrideEnvFlagsByConfigAndCliOpts(env, cfg, opts);

// Set up event listeners for logging again after configuring.
toConsole(log, env.config.flags);
toConsole(log, env.config.flags, false);
toConsole(oldLog, env.config.flags, true);

cli.execute(env, env.nodeFlags, onExecute);
}
Expand Down
39 changes: 34 additions & 5 deletions lib/shared/log/to-console.js
@@ -1,5 +1,6 @@
'use strict';

var chalk = require('chalk');
var fancyLog = require('fancy-log');

/* istanbul ignore next */
Expand All @@ -20,14 +21,42 @@ function cleanup(log) {
function removeListeners(level) {
if (level === 'error') {
log.removeListener(level, noop);
log.removeListener(level, fancyLog.error);
log.removeListener(level, onError);
log.removeListener(level, onErrorDeprecated);
} else {
log.removeListener(level, fancyLog);
log.removeListener(level, onLog);
log.removeListener(level, onLogDeprecated);
}
}
}

function toConsole(log, opts) {
var deprecatedPrinted = false;

function onError(msg) {
fancyLog.error(msg);
}

function onErrorDeprecated(msg) {
if (!deprecatedPrinted) {
fancyLog(chalk.yellow("gulplog v1 is deprecated. Please help your plugins update!"));
deprecatedPrinted = true;
}
fancyLog.error(msg);
}

function onLog(msg) {
fancyLog(msg);
}

function onLogDeprecated(msg) {
if (!deprecatedPrinted) {
fancyLog(chalk.yellow("gulplog v1 is deprecated. Please help your plugins update!"));
deprecatedPrinted = true;
}
fancyLog(msg);
}

function toConsole(log, opts, deprecated) {
// Remove previous listeners to enable to call this twice.
cleanup(log);

Expand All @@ -48,9 +77,9 @@ function toConsole(log, opts) {
})
.forEach(function(level) {
if (level === 'error') {
log.on(level, fancyLog.error);
log.on(level, deprecated ? onErrorDeprecated : onError);
} else {
log.on(level, fancyLog);
log.on(level, deprecated ? onLogDeprecated : onLog);
}
});
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -34,6 +34,7 @@
"copy-props": "^4.0.0",
"fancy-log": "^2.0.0",
"gulplog": "^2.0.1",
"gulplog-v1": "npm:gulplog@1.0.0",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to create a scoped package for this instead of using aliases.

"interpret": "^3.1.1",
"liftoff": "^4.0.0",
"mute-stdout": "^2.0.0",
Expand Down