broccoli-postcss
Advanced tools
Comparing version 1.1.0 to 1.2.0
# master | ||
# 1.2.0 | ||
* Uses the PostCSS async api. | ||
* Better error messages. | ||
* Display warnings from plugins. | ||
* Sanity check test. | ||
# 1.1.0 | ||
@@ -4,0 +11,0 @@ |
43
index.js
@@ -6,9 +6,10 @@ var path = require('path'); | ||
var postcss = require('postcss'); | ||
var CssSyntaxError = require('postcss/lib/css-syntax-error'); | ||
function PostcssCompiler (inputTrees, inputFile, outputFile, plugins) { | ||
if (!(this instanceof PostcssCompiler)) { | ||
if ( !(this instanceof PostcssCompiler) ) { | ||
return new PostcssCompiler(inputTrees, inputFile, outputFile, plugins); | ||
} | ||
if (!Array.isArray(inputTrees)) { | ||
if ( !Array.isArray(inputTrees) ) { | ||
throw new Error('Expected array for first argument - did you mean [tree] instead of tree?'); | ||
@@ -31,26 +32,40 @@ } | ||
if (!this.plugins || this.plugins.length < 1) { | ||
if ( !this.plugins || this.plugins.length < 1 ) { | ||
throw new Error('You must provide at least 1 plugin in the plugin array'); | ||
} | ||
var plugins = this.plugins; | ||
var processor = postcss(); | ||
var css = fs.readFileSync(fromFilePath, 'utf8'); | ||
this.plugins.forEach(function (plugin) { | ||
var options = plugin.options || {}; | ||
processor.use(plugin.module(options)); | ||
}); | ||
var result = processor.process(css, { | ||
var options = { | ||
from: fromFilePath, | ||
to: toFilePath, | ||
map: { inline: false } | ||
}; | ||
this.plugins.forEach(function (plugin) { | ||
var pluginOptions = plugin.options || {}; | ||
processor.use(plugin.module(pluginOptions)); | ||
}); | ||
mkdirp.sync(path.dirname(toFilePath)); | ||
var processPromise = processor.process(css, options) | ||
.then(function (result) { | ||
mkdirp.sync(path.dirname(toFilePath)); | ||
fs.writeFileSync(toFilePath, result.css); | ||
}) | ||
.then(function (result) { | ||
result.warnings().forEach(function (warn) { | ||
process.stderr.write(warn.toString()); | ||
}); | ||
}) | ||
.catch(function (error) { | ||
if ( error instanceof CssSyntaxError ) { | ||
process.stderr.write(error.message + error.showSourceCode()); | ||
} else { | ||
throw error; | ||
} | ||
}); | ||
fs.writeFileSync(toFilePath, result.css); | ||
} | ||
}; | ||
module.exports = PostcssCompiler; |
{ | ||
"name": "broccoli-postcss", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Postcss compiler for Broccoli", | ||
@@ -10,5 +10,9 @@ "main": "index.js", | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"keywords": [ | ||
"broccoli-plugin", | ||
"css", | ||
"postcss-runner", | ||
"postcss" | ||
@@ -25,4 +29,9 @@ ], | ||
"mkdirp": "^0.5.0", | ||
"postcss": "^4.0.6" | ||
"postcss": "^4.1.6" | ||
}, | ||
"devDependencies": { | ||
"postcss-pseudoelements": "^2.1.1", | ||
"broccoli": "^0.15.3", | ||
"mocha": "*" | ||
} | ||
} |
# broccoli-postcss | ||
[![Build Status](https://travis-ci.org/jeffjewiss/broccoli-postcss.svg?branch=master)](https://travis-ci.org/jeffjewiss/broccoli-postcss) [![npm version](https://badge.fury.io/js/broccoli-postcss.svg)](http://badge.fury.io/js/broccoli-postcss) [![Code Climate](https://codeclimate.com/github/jeffjewiss/broccoli-postcss/badges/gpa.svg)](https://codeclimate.com/github/jeffjewiss/broccoli-postcss) | ||
The broccoli-postcss plugin runs your `css` through postcss plugins of your choosing. | ||
@@ -16,3 +18,3 @@ | ||
var outputTree = compileCSS(inputFile, outputFile, plugins); | ||
var outputTree = compileCSS(inputTrees, inputFile, outputFile, plugins); | ||
``` | ||
@@ -29,3 +31,3 @@ | ||
var compileCSS = require('broccoli-postcss'); | ||
var cssnext = require(‘cssnext’); | ||
var cssnext = require('cssnext'); | ||
@@ -41,3 +43,3 @@ var plugins = [ | ||
var outputTree = compileCSS('styles/app.css', 'assets/app.css', plugins); | ||
var outputTree = compileCSS(['styles'], 'app.css', 'app.css', plugins); | ||
``` |
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
7362
9
75
43
3
2
Updatedpostcss@^4.1.6