-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (47 loc) · 1.4 KB
/
index.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
59
60
61
62
var path = require('path');
exports.summary = 'Compile stylus files to CSS';
exports.usage = '<src> [options]';
exports.options = {
"dest" : {
alias : 'd'
,default : '<src>'
,describe : 'destination file'
},
"charset" : {
alias : 'c'
,default : 'utf-8'
,describe : 'file encoding type'
}
};
exports.run = function (options, done) {
var src = options.src;
var dest = options.dest;
exports.async.eachSeries(exports.files, function(inputFile, callback){
var outputFile = dest;
if(exports.file.isDirFormat(dest)){
outputFile = path.join(dest , path.basename(inputFile) );
// replace file extname to .css
outputFile = outputFile.replace('.styl', '.css');
}
exports.compileStylus(inputFile, outputFile, options, callback);
}, done);
};
exports.compileStylus = function(inputFile, outputFile, options, done) {
var data = exports.file.read(inputFile);
var stylus = require('stylus');
var s = stylus(data);
// Load Nib if available
try {
s.use(require('nib')());
} catch (e) {}
s.render(function(err, css) {
if (err) {
return done(err);
}
if (outputFile) {
exports.file.write(outputFile, css);
exports.log(inputFile, ">", outputFile);
}
done(null, css);
});
};