Skip to content

Commit

Permalink
Drop dependency on deprecated gulp-util
Browse files Browse the repository at this point in the history
  • Loading branch information
ohbarye committed Dec 30, 2017
1 parent 455250c commit 3284a51
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 32 deletions.
13 changes: 7 additions & 6 deletions lib/extra_api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var through = require("through2");
var gutil = require("gulp-util");
var fancyLog = require('fancy-log');
var chalk = require('chalk');
var notifier = require("node-notifier");
var report = require("./report");

Expand All @@ -9,17 +10,17 @@ var report = require("./report");
var logLevel = 2;

// Default logger
var fnLog = gutil.log;
var fnLog = fancyLog;

var logError = module.exports.logError = function (options, isError) {
if (!logLevel) return;
if (logLevel === 1 && !isError) return;

color = isError ? "red" : "green";
if (!gutil.colors[color]) return;
fnLog(gutil.colors.cyan('gulp-notify') + ':',
'[' + gutil.colors.blue(options.title) + ']',
gutil.colors[color].call(gutil.colors, options.message)
if (!chalk[color]) return;
fnLog(chalk.cyan('gulp-notify') + ':',
'[' + chalk.blue(options.title) + ']',
chalk[color].call(chalk, options.message)
);
};

Expand Down
18 changes: 9 additions & 9 deletions lib/report.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var template = require("lodash.template");
var gutil = require("gulp-util");
var PluginError = require('plugin-error');
var api = require("./extra_api");
var extend = require("node.extend");
var path = require("path");
Expand All @@ -20,7 +20,7 @@ var defaults = {
module.exports = function (reporter, message, options, templateOptions, callback) {
var self = this;
callback = callback || function () {};
if (!reporter) return callback(new gutil.PluginError("gulp-notify", "No reporter specified."));
if (!reporter) return callback(new PluginError("gulp-notify", "No reporter specified."));

// Try/catch the only way to go to ensure catching all errors? Domains?
try {
Expand All @@ -30,11 +30,11 @@ module.exports = function (reporter, message, options, templateOptions, callback
}
api.logError(options, (message instanceof Error));
reporter(options, function (err) {
if (err) return callback(new gutil.PluginError("gulp-notify", err));
if (err) return callback(new PluginError("gulp-notify", err));
return callback();
});
} catch (err) {
return callback(new gutil.PluginError("gulp-notify", err));
return callback(new PluginError("gulp-notify", err));
}
};

Expand Down Expand Up @@ -66,11 +66,11 @@ function generate (outputData, object, title, message, subtitle, open, templateO
}

return extend(defaults.regular, outputData, {
title: gutil.template(title, {
title: template(title)({
file: object,
options: templateOptions
}),
message: gutil.template(message, {
message: template(message)({
file: object,
options: templateOptions
})
Expand Down Expand Up @@ -105,19 +105,19 @@ function constructOptions (options, object, templateOptions) {
} else {
title = outputData.title || title;
}

if (typeof outputData.subtitle === "function") {
subtitle = outputData.subtitle(object);
} else {
subtitle = outputData.subtitle || subtitle;
}

if (typeof outputData.open === "function") {
open = outputData.open(object);
} else {
open = outputData.open || open;
}

if (typeof outputData.message === "function") {
message = outputData.message(object);
if (!message) {
Expand Down
4 changes: 2 additions & 2 deletions lib/withReporter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var gutil = require("gulp-util");
var PluginError = require('plugin-error');
var api = require("./extra_api");
var notify = require("./notify");

module.exports = function (reporter) {
if (!reporter) throw new gutil.PluginError("gulp-notify", "No custom reporter defined.");
if (!reporter) throw new PluginError("gulp-notify", "No custom reporter defined.");

var inner = function (options) {
options = setOptions(options, reporter);
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"dependencies": {
"chalk": "^2.3.0",
"fancy-log": "^1.3.2",
"gulp-util": "^3.0.8",
"lodash.template": "^4.4.0",
"node-notifier": "^5.0.1",
"node.extend": "^1.1.6",
Expand Down
29 changes: 15 additions & 14 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var gulp = require('gulp'),
should = require('should'),
through = require('through2'),
plumber = require('gulp-plumber'),
gutil = require('gulp-util'),
PluginError = require('plugin-error'),
Vinyl = require('vinyl'),
join = require('path').join,
fs = require('fs'),
notify = require('../');
Expand Down Expand Up @@ -52,7 +53,7 @@ describe('gulp output stream', function() {
var testString = "this is a test";
var expectedIcon = join(__dirname, '..', 'assets', 'gulp.png');

var expectedFile = new gutil.File({
var expectedFile = new Vinyl({
path: "test/fixtures/1.txt",
cwd: "test/",
base: "test/fixtures/",
Expand All @@ -79,7 +80,7 @@ describe('gulp output stream', function() {
var testString = "this is a test";
var expectedIcon = "testIcon";

var expectedFile = new gutil.File({
var expectedFile = new Vinyl({
path: "test/fixtures/1.txt",
cwd: "test/",
base: "test/fixtures/",
Expand Down Expand Up @@ -257,7 +258,7 @@ describe('gulp output stream', function() {
});

var testString = "some exception",
expectedFile = new gutil.File({
expectedFile = new Vinyl({
path: "test/fixtures/1.txt",
cwd: "test/",
base: "test/fixtures/",
Expand Down Expand Up @@ -378,7 +379,7 @@ describe('gulp output stream', function() {
});

it('should handle streamed files', function (done) {
var expectedFile = new gutil.File({
var expectedFile = new Vinyl({
path: "test/fixtures/1.txt",
cwd: "test/",
base: "test/fixtures/",
Expand Down Expand Up @@ -413,7 +414,7 @@ describe('gulp output stream', function() {
});

it('should support lodash template for titles and messages', function (done) {
var expectedFile = new gutil.File({
var expectedFile = new Vinyl({
path: "test/fixtures/1.txt",
cwd: "test/",
base: "test/fixtures/",
Expand Down Expand Up @@ -572,7 +573,7 @@ describe('gulp output stream', function() {

gulp.src(srcFile)
.pipe(through.obj(function (file, enc, cb) {
this.emit("error", new gutil.PluginError("testPlugin", "foo"));
this.emit("error", new PluginError("testPlugin", "foo"));
cb();
}))
.on("error", notifier.onError())
Expand All @@ -596,7 +597,7 @@ describe('gulp output stream', function() {

gulp.src(srcFile)
.pipe(through.obj(function (file, enc, cb) {
this.emit("error", new gutil.PluginError("testPlugin", "foo"));
this.emit("error", new PluginError("testPlugin", "foo"));
cb();
}))
.on("error", notifier.onError())
Expand Down Expand Up @@ -649,7 +650,7 @@ describe('gulp output stream', function() {

gulp.src(srcFile)
.pipe(through.obj(function (file, enc, cb) {
this.emit("error", new gutil.PluginError("testPlugin", testMessage));
this.emit("error", new PluginError("testPlugin", testMessage));
cb();
}))
.on("error", onError)
Expand All @@ -673,7 +674,7 @@ describe('gulp output stream', function() {

gulp.src(srcFile)
.pipe(through.obj(function (file, enc, cb) {
this.emit("error", new gutil.PluginError("testPlugin", testMessage));
this.emit("error", new PluginError("testPlugin", testMessage));
cb();
}))
.on("error", custom.onError())
Expand All @@ -699,7 +700,7 @@ describe('gulp output stream', function() {

gulp.src(srcFile)
.pipe(through.obj(function (file, enc, cb) {
this.emit("error", new gutil.PluginError("testPlugin", testMessage));
this.emit("error", new PluginError("testPlugin", testMessage));
cb();
}))
.on("error", custom.onError())
Expand All @@ -722,7 +723,7 @@ describe('gulp output stream', function() {

custom.onError({
icon: expectedIcon,
})(new gutil.PluginError("testPlugin", testMessage));
})(new PluginError("testPlugin", testMessage));
});

it('should have Frog sound per default onError', function (done) {
Expand All @@ -738,7 +739,7 @@ describe('gulp output stream', function() {

custom.onError({
icon: expectedIcon,
})(new gutil.PluginError("testPlugin", testMessage));
})(new PluginError("testPlugin", testMessage));
});

it('should support lodash template for titles and messages on onError', function (done) {
Expand All @@ -760,7 +761,7 @@ describe('gulp output stream', function() {

gulp.src(srcFile)
.pipe(through.obj(function (file, enc, cb) {
this.emit("error", new gutil.PluginError("testPlugin", "test"));
this.emit("error", new PluginError("testPlugin", "test"));
cb();
}))
.on('error', onError);
Expand Down

0 comments on commit 3284a51

Please sign in to comment.