gulp-minify-css
Advanced tools
Comparing version 0.1.0 to 0.2.0
43
index.js
var es = require('event-stream'), | ||
cleanCSS = require('clean-css'), | ||
clone = require('clone'); | ||
clone = require('clone'), | ||
BufferStreams = require('bufferstreams'), | ||
gutil = require('gulp-util'); | ||
module.exports = function(opt){ | ||
// File level transform function | ||
function minifyCSSTransform(opt) { | ||
// Return a callback function handling the buffered content | ||
return function(err, buf, cb) { | ||
// Handle any error | ||
if(err) cb(gutil.PluginError('minify-css', err)); | ||
// Use the buffered content | ||
buf = Buffer(cleanCSS.process(String(buf), opt)); | ||
// Bring it back to streams | ||
cb(null, buf); | ||
} | ||
} | ||
// Plugin function | ||
function minifyCSSGulp(opt){ | ||
if (!opt) opt = {}; | ||
function modifyContents(file, cb){ | ||
if(file.isNull()) return cb(null, file); | ||
if(file.isStream()) { | ||
file.contents = file.contents.pipe(new BufferStreams(minifyCSSTransform(opt))); | ||
return cb(null, file); | ||
} | ||
var newFile = clone(file); | ||
@@ -15,3 +45,10 @@ | ||
} | ||
return es.map(modifyContents); | ||
} | ||
} | ||
// Export the file level transform function for other plugins usage | ||
minifyCSSGulp.fileTransform = minifyCSSTransform; | ||
// Export the plugin main function | ||
module.exports = minifyCSSGulp; |
{ | ||
"name": "gulp-minify-css", | ||
"description": "Minify css with clean-css.", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"repository": "https://github.com/jonathanepollack/gulp-minify-css.git", | ||
"homepage": "https://github.com/jonathanepollack/gulp-minify-css", | ||
"keywords": [ | ||
"gulpplugin" | ||
], | ||
"keywords": [ | ||
"gulpplugin" | ||
], | ||
"main": "./index.js", | ||
"dependencies": { | ||
"event-stream": "~3.0.16", | ||
"clean-css": "~1.0.12", | ||
"clone": "~0.1.9" | ||
"event-stream": "~3.0.16", | ||
"clean-css": "~1.0.12", | ||
"clone": "~0.1.9", | ||
"bufferstreams": "0.0.1", | ||
"gulp-util": "~2.2.5" | ||
}, | ||
"engines": { | ||
"node": ">= 0.8" | ||
}, | ||
"node": ">= 0.10" | ||
}, | ||
"scripts": { | ||
@@ -25,3 +27,3 @@ "test": "mocha" | ||
"chai": "~1.7.2", | ||
"gulp": "~0.1.0" | ||
"gulp": "~3.2.0" | ||
}, | ||
@@ -33,2 +35,2 @@ "licenses": [ | ||
] | ||
} | ||
} |
@@ -14,3 +14,3 @@ [![Build Status](https://travis-ci.org/jonathanepollack/gulp-minify-css.png?branch=master)](https://travis-ci.org/jonathanepollack/gulp-minify-css) | ||
<td>Node Version</td> | ||
<td>>= 0.8</td> | ||
<td>>= 0.10</td> | ||
</tr> | ||
@@ -17,0 +17,0 @@ </table> |
@@ -6,2 +6,3 @@ var gulp = require('gulp'), | ||
es = require('event-stream'), | ||
Stream = require('stream'), | ||
path = require('path'), | ||
@@ -13,22 +14,48 @@ fs = require('fs'); | ||
describe('gulp-minify-css minification', function() { | ||
var filename = path.join(__dirname, './fixture/index.css'); | ||
it('should minify my files', function(done) { | ||
gulp.file(filename) | ||
.pipe(minifyCSS()) | ||
.pipe(es.map(function(file){ | ||
var source = fs.readFileSync(filename), | ||
expected = cleanCSS.process(source.toString()); | ||
expect(expected).to.be.equal(file.contents.toString()); | ||
done(); | ||
})); | ||
describe('with buffers', function() { | ||
var filename = path.join(__dirname, './fixture/index.css'); | ||
it('should minify my files', function(done) { | ||
gulp.src(filename) | ||
.pipe(minifyCSS()) | ||
.pipe(es.map(function(file){ | ||
var source = fs.readFileSync(filename), | ||
expected = cleanCSS.process(source.toString()); | ||
expect(expected).to.be.equal(file.contents.toString()); | ||
done(); | ||
})); | ||
}); | ||
it('should return file.contents as a buffer', function(done) { | ||
gulp.src(filename) | ||
.pipe(minifyCSS()) | ||
.pipe(es.map(function(file) { | ||
expect(file.contents).to.be.an.instanceof(Buffer); | ||
done(); | ||
})); | ||
}); | ||
}); | ||
describe('with streams', function() { | ||
var filename = path.join(__dirname, './fixture/index.css'); | ||
it('should minify my files', function(done) { | ||
gulp.src(filename, {buffer: false}) | ||
.pipe(minifyCSS()) | ||
.pipe(es.map(function(file){ | ||
var source = fs.readFileSync(filename), | ||
expected = cleanCSS.process(source.toString()); | ||
file.contents.pipe(es.wait(function(err, data) { | ||
expect(expected).to.be.equal(data); | ||
done(); | ||
})); | ||
})); | ||
}); | ||
it('should return file.contents as a buffer', function(done) { | ||
gulp.file(filename) | ||
.pipe(minifyCSS()) | ||
.pipe(es.map(function(file) { | ||
expect(file.contents).to.be.an.instanceof(Buffer); | ||
done(); | ||
})); | ||
it('should return file.contents as a buffer', function(done) { | ||
gulp.src(filename, {buffer: false}) | ||
.pipe(minifyCSS()) | ||
.pipe(es.map(function(file) { | ||
expect(file.contents).to.be.an.instanceof(Stream); | ||
done(); | ||
})); | ||
}); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9236
168
5
+ Addedbufferstreams@0.0.1
+ Addedgulp-util@~2.2.5
+ Addedansi-regex@0.2.1(transitive)
+ Addedansi-styles@1.1.0(transitive)
+ Addedarray-find-index@1.0.2(transitive)
+ Addedbufferstreams@0.0.1(transitive)
+ Addedcamelcase@2.1.1(transitive)
+ Addedcamelcase-keys@2.1.0(transitive)
+ Addedchalk@0.5.1(transitive)
+ Addedclone-stats@0.0.1(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedcurrently-unhandled@0.4.1(transitive)
+ Addeddateformat@1.0.12(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addedduplexer2@0.0.2(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfind-up@1.1.2(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-stdin@4.0.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedgulp-util@2.2.20(transitive)
+ Addedhas-ansi@0.1.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addedindent-string@2.1.0(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-finite@1.1.0(transitive)
+ Addedis-utf8@0.2.1(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedload-json-file@1.1.0(transitive)
+ Addedlodash._escapehtmlchar@2.4.1(transitive)
+ Addedlodash._escapestringchar@2.4.1(transitive)
+ Addedlodash._htmlescapes@2.4.1(transitive)
+ Addedlodash._isnative@2.4.1(transitive)
+ Addedlodash._objecttypes@2.4.1(transitive)
+ Addedlodash._reinterpolate@2.4.1(transitive)
+ Addedlodash._reunescapedhtml@2.4.1(transitive)
+ Addedlodash._shimkeys@2.4.1(transitive)
+ Addedlodash.defaults@2.4.1(transitive)
+ Addedlodash.escape@2.4.1(transitive)
+ Addedlodash.isobject@2.4.1(transitive)
+ Addedlodash.keys@2.4.1(transitive)
+ Addedlodash.template@2.4.1(transitive)
+ Addedlodash.templatesettings@2.4.1(transitive)
+ Addedlodash.values@2.4.1(transitive)
+ Addedloud-rejection@1.6.0(transitive)
+ Addedmap-obj@1.0.1(transitive)
+ Addedmeow@3.7.0(transitive)
+ Addedminimist@0.2.41.2.8(transitive)
+ Addedmultipipe@0.1.2(transitive)
+ Addednormalize-package-data@2.5.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedparse-json@2.2.0(transitive)
+ Addedpath-exists@2.1.0(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-type@1.1.0(transitive)
+ Addedpify@2.3.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedread-pkg@1.1.0(transitive)
+ Addedread-pkg-up@1.0.1(transitive)
+ Addedreadable-stream@1.0.341.1.14(transitive)
+ Addedredent@1.0.0(transitive)
+ Addedrepeating@2.0.1(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.20(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedstrip-ansi@0.3.0(transitive)
+ Addedstrip-bom@2.0.0(transitive)
+ Addedstrip-indent@1.0.1(transitive)
+ Addedsupports-color@0.2.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedthrough2@0.5.1(transitive)
+ Addedtrim-newlines@1.0.0(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)
+ Addedvinyl@0.2.3(transitive)
+ Addedxtend@3.0.0(transitive)