-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwrapper.js
58 lines (44 loc) · 1.34 KB
/
wrapper.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
// Stylus 'CSS' wrapper for SocketStream 0.3
var fs = require('fs'),
stylus = require('stylus'),
plugins = {},
_prependedStylus;
exports.prependStylus = function(prependedStylus) {
if(typeof prependedStylus === 'string') {
_prependedStylus = prependedStylus;
}
};
exports.init = function(root, config) {
return {
name: 'Stylus',
extensions: ['styl', 'stylus'],
assetType: 'css',
contentType: 'text/css',
compile: function(path, options, cb) {
// Get dir from path to enable @include commmand
var dir = path.split('/'); dir.pop();
var input = fs.readFileSync(path, 'utf8');
var compress = options && options.compress;
if(_prependedStylus) {
input = _prependedStylus + '\n' + input;
}
var sss = stylus(input, {filename: path, paths: [dir.join('/')]});
for (var c in config) {
sss.set(c, config[c]);
}
if (config && config.extra) {
for (var plugin in config.extra) {
sss.use(config.extra[plugin]());
}
}
sss.render(function(err, css) {
if (err) {
var message = '! - Unable to compile Stylus file %s into CSS';
console.log(String.prototype.hasOwnProperty('red') && message.red || message, path);
console.log(err);
}
cb(css);
});
}
};
};