From a837a855e491779b71dd52913650e130d8f06e9d Mon Sep 17 00:00:00 2001 From: Andrey Kuzmin Date: Mon, 18 Aug 2014 08:40:13 +0400 Subject: [PATCH] Added more checks and release on npm --- README.md | 2 ++ index.js | 11 +++++++++-- package.json | 4 ++-- test.js | 8 ++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bd4fbf2..727d279 100644 --- a/README.md +++ b/README.md @@ -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)) diff --git a/index.js b/index.js index 441d520..e8420ec 100644 --- a/index.js +++ b/index.js @@ -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() @@ -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)) diff --git a/package.json b/package.json index 2f3c7ea..1f91171 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gulp-postcss", - "version": "0.0.2", + "version": "1.0.0", "description": "PostCSS gulp plugin", "main": "index.js", "scripts": { @@ -11,7 +11,7 @@ "url": "https://github.com/w0rm/gulp-postcss.git" }, "keywords": [ - "gulp", + "gulpplugin", "postcss", "css" ], diff --git a/test.js b/test.js index d36524c..7aeee7a 100644 --- a/test.js +++ b/test.js @@ -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())