Skip to content

Commit

Permalink
Merge pull request #8 from lukeed/master
Browse files Browse the repository at this point in the history
Updates to syntax for Fly 1.0
  • Loading branch information
Jorge Bucaran committed Mar 18, 2016
2 parents 1d07070 + e803866 commit ed0c303
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
26 changes: 16 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
let postcss = require("postcss")
var postcss = require("postcss")
var assign = require("object-assign")

module.exports = function() {
this.filter("postcss", (data, config) => {
var self = this

self.filter("postcss", function (data, config) {
// Combine our config with defaults using Object.assign
let fullConfig = Object.assign({}, { plugins: [], options: {} }, config)
config = assign({}, {plugins: [], options: {}}, config)

// Return our promise out so we can wrap this async promise-based API
return new Promise((resolve, reject) => {
return new Promise(function (resolve, reject) {
// Pull in the plugins list
postcss(fullConfig.plugins)
postcss(config.plugins)
// Process the CSS with PostCSS and our options object passed to PostCSS
.process(data.toString(), fullConfig.options)
.then((result) => {
.process(data.toString(), config.options)
.then(function (result) {
// Resolve our CSS the way Fly expects it
return resolve({ css: result.css })
return resolve({css: result.css})
})
.catch((err) => {
return reject(err)
.catch(function (err) {
self.emit("plugin_error", {
plugin: "fly-postcss",
error: err
})
})
})
})
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"url": "http://github.com/morishitter"
},
"dependencies": {
"postcss": "^5.0.3"
"postcss": "^5.0.3",
"object-assign": "^4.0.1"
},
"devDependencies": {
"eslint": "^0.21.2",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ npm install -D fly-postcss
### Example

```js
export default function* () {
exports.default = function * () {
yield this
.source('src/*.css')
.postcss({
Expand Down

0 comments on commit ed0c303

Please sign in to comment.