-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (32 loc) · 911 Bytes
/
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
const postcss = require('postcss');
const dss = require('dss');
const fs = require('fs');
function runDSS(rawCSS) {
return new Promise((resolve) => {
dss.parse(rawCSS, {}, (result) => {
resolve(result);
});
});
}
function saveResults(result, filename) {
return new Promise((resolve, reject) => {
let strung = JSON.stringify(result, null, 2);
fs.writeFile(filename, strung, null, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
}
module.exports = postcss.plugin('postcss-dss', (options) => {
for (let parser of options.parsers || []) {
dss.parser(parser.atRule, parser.func);
}
return function (root) {
return runDSS(root.toString()).then((res) => {
return saveResults(res, options.fileName);
});
};
});