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

Replace gulp-util with alternatives #124

Merged
merged 5 commits into from
Jan 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/extra_api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var through = require("through2");
var gutil = require("gulp-util");
var fancyLog = require('fancy-log');
var colors = require('ansi-colors');
var notifier = require("node-notifier");
var report = require("./report");

Expand All @@ -9,17 +9,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 (!colors[color]) return;
fnLog(colors.cyan('gulp-notify') + ':',
'[' + colors.blue(options.title) + ']',
colors[color].call(colors, 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
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@
"gulp": "gulp --gulpfile ./examples/gulpfile.js"
},
"dependencies": {
"gulp-util": "^3.0.8",
"ansi-colors": "^1.0.1",
"fancy-log": "^1.3.2",
"lodash.template": "^4.4.0",
"node-notifier": "^5.0.1",
"node.extend": "^1.1.6",
"plugin-error": "^0.1.2",
"through2": "^2.0.3"
},
"devDependencies": {
"gulp": "^3.8.10",
"gulp-plumber": "^1.1.0",
"mocha": "^3.2.0",
"should": "^11.2.0"
"should": "^11.2.0",
"vinyl": "^2.1.0"
},
"engines": {
"node": ">=0.8.0",
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