forked from osdio/gulp-react-native-css
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (32 loc) · 947 Bytes
/
index.js
File metadata and controls
45 lines (32 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var through = require("through2"),
gutil = require("gulp-util"),
parseCss = require('./lib/parseCss');
var ext = gutil.replaceExtension;
module.exports = function () {
"use strict";
function reactNativeCss(file, enc, callback) {
/*jshint validthis:true*/
// Do nothing if no contents
if (file.isNull()) {
this.push(file);
return callback();
}
if (file.isStream()) {
// accepting streams is optional
this.emit("error",
new gutil.PluginError("gulp-react-native-css", "Stream content is not supported"));
return callback();
}
// check if file.contents is a `Buffer`
if (file.isBuffer()) {
var source = file.contents.toString();
var style = parseCss(source.replace(/\r?\n|\r/g, ""));
var prefix = "module.exports =";
file.contents = new Buffer(prefix + style);
file.path = ext(file.path, '.js');
this.push(file);
}
return callback();
}
return through.obj(reactNativeCss);
};