Skip to content

Commit

Permalink
Added more checks and release on npm
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rm committed Aug 18, 2014
1 parent c5e8dff commit a837a85
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ var postcss = require('gulp-postcss')
var gulp = require('gulp')
var autoprefixer = require('autoprefixer')
var mqpacker = require('css-mqpacker')
var csswring = require('csswring')
gulp.task('css', function () {
var processors = [
autoprefixer('last 1 version').postcss
, mqpacker.processor
, csswring.postcss
]
return gulp.src('./src/*.css')
.pipe(postcss(processors))
Expand Down
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ var gutil = require('gulp-util')

module.exports = function (processors, options) {

if (!Array.isArray(processors)) {
throw new gutil.PluginError('gulp-postcss', 'Please provide array of postcss processors!')
}

return through.obj(transform)

function transform (file, encoding, cb) {

if (file.isStream()) {
return cb(new gutil.PluginError('gulp-postcss', 'Streams are not supported!'))
}

// Source map is inline by default
var opts = { map: 'inline' }
var processor = postcss()
Expand All @@ -31,14 +39,13 @@ module.exports = function (processors, options) {
opts.from = file.path
}

processors.forEach(processor.use.bind(processor))

// Generate separate source map for gulp-sourcemap
if (file.sourceMap) {
opts.map = true
}

try {
processors.forEach(processor.use.bind(processor))
result = processor.process(file.contents.toString('utf8'), opts)
} catch (err) {
return cb(new gutil.PluginError('gulp-postcss', err))
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-postcss",
"version": "0.0.2",
"version": "1.0.0",
"description": "PostCSS gulp plugin",
"main": "index.js",
"scripts": {
Expand All @@ -11,7 +11,7 @@
"url": "https://github.com/w0rm/gulp-postcss.git"
},
"keywords": [
"gulp",
"gulpplugin",
"postcss",
"css"
],
Expand Down
8 changes: 8 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ it('should correctly wrap postcss errors', function (cb) {
})


it ('should throw error if processors are not provided', function (cb) {
assert.throws( function () { postcss() }, gutil.PluginError )
assert.throws( function () { postcss('') }, gutil.PluginError )
assert.throws( function () { postcss({}) }, gutil.PluginError )
cb()
})


function doubler (css) {
css.eachDecl(function (decl) {
decl.parent.prepend(decl.clone())
Expand Down

0 comments on commit a837a85

Please sign in to comment.