gulp-svgmin
Advanced tools
+16
-16
@@ -5,23 +5,23 @@ /* jshint node:true */ | ||
| var gulp = require('gulp'), | ||
| gutil = require('gulp-util'), | ||
| clear = require('clear'), | ||
| mocha = require('gulp-mocha'), | ||
| jshint = require('gulp-jshint'), | ||
| stylish = require('jshint-stylish'); | ||
| var gulp = require('gulp'), | ||
| mocha = require('gulp-mocha'), | ||
| jshint = require('gulp-jshint'); | ||
| gulp.task('lint', function () { | ||
| gulp.task('lint', function() { | ||
| gulp.src('*.js') | ||
| .pipe(jshint()) | ||
| .pipe(jshint.reporter('jshint-stylish')) | ||
| .pipe(jshint('.jshintrc')) | ||
| .pipe(jshint.reporter('jshint-stylish')); | ||
| }); | ||
| gulp.task('test', function() { | ||
| gulp.src('test.js', {read: false}) | ||
| .pipe(mocha()); | ||
| }); | ||
| gulp.task('default', function() { | ||
| gulp.run('lint'); | ||
| gulp.watch('*.js', function(event) { | ||
| clear(); | ||
| gutil.log(gutil.colors.cyan(event.path.replace(process.cwd(), '')) + ' ' + event.type + '. (' + gutil.colors.magenta(gutil.date('HH:MM:ss')) + ')'); | ||
| gulp.run('lint'); | ||
| }); | ||
| gulp.task('watch', function() { | ||
| gulp.watch('*.js', ['dev']); | ||
| }); | ||
| gulp.task('dev', ['lint', 'test']); | ||
| gulp.task('default', ['dev', 'watch']); |
+17
-18
@@ -14,3 +14,2 @@ /* jshint node:true */ | ||
| function minifySVGTransform(svgo) { | ||
| if (!(svgo instanceof SVGOptim)) { | ||
@@ -22,6 +21,5 @@ svgo = new SVGOptim(svgo); | ||
| return function(err, buf, cb) { | ||
| // Handle any error | ||
| if (err) { | ||
| cb(new gutil.PluginError(PLUGIN_NAME, err)); | ||
| return cb(new gutil.PluginError(PLUGIN_NAME, err)); | ||
| } | ||
@@ -32,3 +30,3 @@ | ||
| if (result.error) { | ||
| cb(new gutil.PluginError(PLUGIN_NAME, result.error)); | ||
| return cb(new gutil.PluginError(PLUGIN_NAME, result.error)); | ||
| } | ||
@@ -49,5 +47,5 @@ | ||
| // When null just pass through | ||
| if(file.isNull()) { | ||
| stream.push(file); done(); | ||
| return; | ||
| if (file.isNull()) { | ||
| stream.push(file); | ||
| return done(); | ||
| } | ||
@@ -57,15 +55,16 @@ | ||
| file.contents = file.contents.pipe( | ||
| new BufferStreams(minifySVGTransform(svgo))); | ||
| new BufferStreams(minifySVGTransform(svgo)) | ||
| ); | ||
| stream.push(file); | ||
| return done(); | ||
| } | ||
| svgo.optimize(String(file.contents), function(result) { | ||
| if (result.error) { | ||
| return stream.emit('error', new gutil.PluginError(PLUGIN_NAME, result.error)); | ||
| } | ||
| file.contents = new Buffer(result.data); | ||
| stream.push(file); | ||
| done(); | ||
| } else { | ||
| svgo.optimize(String(file.contents), function(result) { | ||
| if (result.error) { | ||
| stream.emit('error', new gutil.PluginError(PLUGIN_NAME, result.error)); | ||
| } | ||
| file.contents = new Buffer(result.data); | ||
| stream.push(file); | ||
| done(); | ||
| }); | ||
| } | ||
| }); | ||
| }; | ||
@@ -72,0 +71,0 @@ |
+10
-11
| { | ||
| "name": "gulp-svgmin", | ||
| "version": "0.4.6", | ||
| "version": "0.4.7", | ||
| "description": "Minify SVG files with gulp.", | ||
@@ -24,17 +24,16 @@ "license": "MIT", | ||
| "dependencies": { | ||
| "svgo": "~0.4.4", | ||
| "svgo": "~0.4.5", | ||
| "bufferstreams": "0.0.2", | ||
| "gulp-util": "~2.2.6" | ||
| "gulp-util": "~2.2.20" | ||
| }, | ||
| "devDependencies": { | ||
| "chai": "~1.9.0", | ||
| "clear": "0.0.1", | ||
| "gulp": "~3.5.2", | ||
| "gulp-mocha": "~0.4.1", | ||
| "gulp-jshint": "~1.4.0", | ||
| "jshint-stylish": "~0.1.5", | ||
| "mocha": "~1.17.1", | ||
| "event-stream": "~3.1.0" | ||
| "chai": "~1.9.2", | ||
| "gulp": "~3.8.8", | ||
| "gulp-jshint": "~1.8.5", | ||
| "gulp-mocha": "^1.1.1", | ||
| "jshint-stylish": "~1.0.0", | ||
| "mocha": "~1.21.5", | ||
| "event-stream": "~3.1.7" | ||
| }, | ||
| "main": "index.js" | ||
| } |
+1
-1
@@ -1,2 +0,2 @@ | ||
| # [gulp](https://github.com/wearefractal/gulp)-svgmin [](https://travis-ci.org/ben-eb/gulp-svgmin) [](http://badge.fury.io/js/gulp-svgmin) [](https://gemnasium.com/ben-eb/gulp-svgmin) | ||
| # [gulp](https://github.com/gulpjs/gulp)-svgmin [](https://travis-ci.org/ben-eb/gulp-svgmin) [](http://badge.fury.io/js/gulp-svgmin) [](https://gemnasium.com/ben-eb/gulp-svgmin) | ||
@@ -3,0 +3,0 @@ > Minify SVG with [SVGO](https://github.com/svg/svgo). |
+68
-124
@@ -8,151 +8,95 @@ /* jshint node: true */ | ||
| gutil = require('gulp-util'), | ||
| svgmin = require('./index'), | ||
| svgmin = require('./index.js'), | ||
| es = require('event-stream'), | ||
| Stream = require('stream'); | ||
| var doctype = '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'; | ||
| var head = '<?xml version="1.0" encoding="utf-8"?>', | ||
| doctype = '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">', | ||
| fullsvg = '<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve">' + | ||
| '<circle cx="50" cy="50" r="40" fill="yellow" />' + | ||
| '<!-- test comment --></svg>', | ||
| raw = head + doctype + fullsvg; | ||
| var raw = '<?xml version="1.0" encoding="utf-8"?>' + doctype + | ||
| '<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve">' + | ||
| '<circle cx="50" cy="50" r="40" fill="yellow" /><!-- test comment -->' + | ||
| '</svg>'; | ||
| var compressed = '<svg xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40" fill="#ff00"/></svg>'; | ||
| describe('gulp-svgmin', function() { | ||
| var makeTest = function(plugins, content, expected) { | ||
| it('in stream mode', function(done) { | ||
| var stream = svgmin(plugins); | ||
| var fakeFile = new gutil.File({ | ||
| contents: new Stream() | ||
| }); | ||
| describe('with null contents', function() { | ||
| it('should let null files pass through', function(done) { | ||
| var s = svgmin(), | ||
| n = 0; | ||
| s.pipe(es.through(function(file) { | ||
| expect(file.path).to.equal('bibabelula.md'); | ||
| expect(file.contents).to.equal(null); | ||
| n++; | ||
| }, function() { | ||
| expect(n).to.equal(1); | ||
| done(); | ||
| })); | ||
| s.write(new gutil.File({ | ||
| path: 'bibabelula.md', | ||
| contents: null | ||
| stream.on('data', function(data) { | ||
| data.contents.pipe(es.wait(function(err, data) { | ||
| expect(String(data)).satisfy(expected); | ||
| done(); | ||
| })); | ||
| s.end(); | ||
| }); | ||
| stream.write(fakeFile); | ||
| fakeFile.contents.write(content); | ||
| fakeFile.contents.end(); | ||
| }); | ||
| it('in buffer mode', function(done) { | ||
| var stream = svgmin(plugins); | ||
| stream.on('data', function(data) { | ||
| expect(String(data.contents)).satisfy(expected); | ||
| done(); | ||
| }); | ||
| stream.write(new gutil.File({ | ||
| contents: new Buffer(content) | ||
| })); | ||
| }); | ||
| }; | ||
| describe('in buffer mode', function() { | ||
| it('should minify svg with svgo', function(cb) { | ||
| describe('gulp-svgmin', function() { | ||
| describe('with null contents', function() { | ||
| it('should let null files pass through', function(done) { | ||
| var stream = svgmin(); | ||
| var i = 0; | ||
| stream.on('data', function(data) { | ||
| expect(String(data.contents)).to.equal(compressed); | ||
| cb(); | ||
| }); | ||
| stream.pipe(es.through( | ||
| function(file) { | ||
| expect(file.path).to.equal('bibabelula.md'); | ||
| expect(file.contents).to.equal(null); | ||
| i += 1; | ||
| }, | ||
| function() { | ||
| expect(i).to.eql(1); | ||
| done(); | ||
| } | ||
| )); | ||
| stream.write(new gutil.File({ | ||
| contents: new Buffer(raw) | ||
| path: 'bibabelula.md', | ||
| contents: null | ||
| })); | ||
| stream.end(); | ||
| }); | ||
| }); | ||
| it('should honor disabling plugins, such as keeping the doctype', function(cb) { | ||
| var stream = svgmin([{ | ||
| removeDoctype: false | ||
| }]); | ||
| stream.on('data', function(data) { | ||
| expect(String(data.contents)).to.have.string(doctype); | ||
| cb(); | ||
| }); | ||
| stream.write(new gutil.File({ | ||
| contents: new Buffer(raw) | ||
| })); | ||
| describe('should minify svg with svgo', function() { | ||
| makeTest([], raw, function(content) { | ||
| return compressed === content; | ||
| }); | ||
| }); | ||
| it('should allow disabling multiple plugins', function(cb) { | ||
| var stream = svgmin([{ | ||
| removeDoctype: false | ||
| }, { | ||
| removeComments: false | ||
| }]); | ||
| stream.on('data', function(data) { | ||
| expect(String(data.contents)).to.have.string(doctype).and.to.have.string('test comment'); | ||
| cb(); | ||
| }); | ||
| stream.write(new gutil.File({ | ||
| contents: new Buffer(raw) | ||
| })); | ||
| describe('should honor disabling plugins, such as keeping the doctype', function() { | ||
| var plugins = [ | ||
| { removeDoctype: false } | ||
| ]; | ||
| makeTest(plugins, raw, function(content) { | ||
| return expect(content).to.contain(doctype); | ||
| }); | ||
| }); | ||
| describe('stream mode', function() { | ||
| it('should minify svg with svgo', function(cb) { | ||
| var stream = svgmin(); | ||
| var fakeFile = new gutil.File({ | ||
| contents: new Stream() | ||
| }); | ||
| stream.on('data', function(data) { | ||
| data.contents.pipe(es.wait(function(err, data) { | ||
| expect(data).to.equal(compressed); | ||
| cb(); | ||
| })); | ||
| }); | ||
| stream.write(fakeFile); | ||
| fakeFile.contents.write(raw); | ||
| fakeFile.contents.end(); | ||
| describe('should allow disabling multiple plugins', function() { | ||
| var plugins = [ | ||
| { removeDoctype: false }, | ||
| { removeComments: false } | ||
| ]; | ||
| makeTest(plugins, raw, function(content) { | ||
| return expect(content).to.contain(doctype).and.contain('test comment'); | ||
| }); | ||
| it('should honor disabling plugins, such as keeping the doctype', function(cb) { | ||
| var stream = svgmin([{ | ||
| removeDoctype: false | ||
| }]); | ||
| var fakeFile = new gutil.File({ | ||
| contents: new Stream() | ||
| }); | ||
| stream.on('data', function(data) { | ||
| data.contents.pipe(es.wait(function(err, data) { | ||
| expect(data).to.have.string(doctype); | ||
| cb(); | ||
| })); | ||
| }); | ||
| stream.write(fakeFile); | ||
| fakeFile.contents.write(raw); | ||
| fakeFile.contents.end(); | ||
| }); | ||
| it('should allow disabling multiple plugins', function(cb) { | ||
| var stream = svgmin([{ | ||
| removeDoctype: false | ||
| }, { | ||
| removeComments: false | ||
| }]); | ||
| var fakeFile = new gutil.File({ | ||
| contents: new Stream() | ||
| }); | ||
| stream.on('data', function(data) { | ||
| data.contents.pipe(es.wait(function(err, data) { | ||
| expect(data).to.have.string(doctype).and.to.have.string('test comment'); | ||
| cb(); | ||
| })); | ||
| }); | ||
| stream.write(fakeFile); | ||
| fakeFile.contents.write(raw); | ||
| fakeFile.contents.end(); | ||
| }); | ||
| }); | ||
| }); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
7
-12.5%9492
-15.87%167
-19.71%1
Infinity%Updated
Updated