Last active
July 26, 2016 17:41
-
-
Save dfreedm/6b5457a5d63ae31cb1d3542c3aed3817 to your computer and use it in GitHub Desktop.
polymer-css-build gulp wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
@license | |
Copyright (c) 2016 The Polymer Project Authors. All rights reserved. | |
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt | |
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | |
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt | |
Code distributed by Google as part of the polymer project is also | |
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | |
*/ | |
const polycss = require('./'); | |
const Transform = require('stream').Transform; | |
class PolymerCssBuildTransform extends Transform { | |
constructor(options){ | |
super({objectMode: true}); | |
this.options = options; | |
} | |
_transform(file, encoding, callback) { | |
if (file.isNull()) { | |
return callback(null, file); | |
} | |
if (file.isStream()) { | |
return callback('polymer-css-build does not support streams, sorry'); | |
} | |
if (file.isBuffer()) { | |
polycss([ | |
{ | |
url: file.path, | |
content: file.content.toString('utf-8') | |
} | |
], this.options).then(docs => { | |
let content = docs[0].content; | |
file.content = new Buffer(content); | |
callback(null, file); | |
}) | |
.catch(err => { | |
callback(err); | |
}); | |
} | |
} | |
} | |
module.exports = (options) => new PolymerCssBuildTransform(options); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment