-
Notifications
You must be signed in to change notification settings - Fork 0
/
postcss.js
54 lines (47 loc) · 1.34 KB
/
postcss.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
var autoprefixer = require('autoprefixer-core');
var postcssNested = require('postcss-nested');
var postcss = require('postcss');
var fs = require('fs');
var path = require('path');
module.exports = function(dron) {
dron.registerTask('postcss', function(dron) {
this.dron = dron;
var self = this;
dron.watchLocal('*.post.css', function(files) {
if (files.length===0) {
self.dron.warn('No postCSS files found');
} else {
self.process(files);
}
});
}, {
process: function(files) {
var self = this;
files.forEach(function(file) {
fs.readFile(file, 'utf-8', function(err, content) {
if (err) {
self.dron.warn('The file is not readable', file, err);
} else {
var tar = file.replace(/\.post\.css$/, '.css');
postcss([ postcssNested, autoprefixer ]).process(content, {
from: file,
to: tar
}).then(function (result) {
result.warnings().forEach(function (warn) {
self.dron.warn(warn.toString());
});
fs.writeFile(tar, result.css, function() {
if (!err) {
self.dron.log('Processed', path.basename(tar));
}
});
}).catch(function(error) {
self.dron.warn('Error', error);
});
}
});
/**/
});
}
})
}