-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathscss.js
executable file
·60 lines (52 loc) · 1.77 KB
/
scss.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
#!/usr/bin/env node
var autoprefixer = require('autoprefixer');
var cssnano = require('cssnano');
var fs = require('fs');
var path = require('path');
var postcss = require('postcss');
var sass = require('node-sass');
var zlib = require('zlib');
// Constants
const DIST = process.env.DIST || false;
const MIN = process.env.MIN || false;
const themes = ['light', 'dark'];
themes.forEach((theme) => {
// Read contents
sass.render({
file: path.join(__dirname, 'src', 'scss', theme + '.scss')
}, function(err, result) {
if (err) {
throw err;
}
postcss([autoprefixer({ targetBrowsers: ['last 2 versions'] })]).process(result.css.toString()).then(postResult => {
var writeCSS = (css, gzip) => {
var filepath = path.join(DIST ? 'dist' : 'build', 'inspire-tree-' + theme + (MIN ? '.min' : '') + '.css');
fs.writeFile(filepath, css, (err) => {
if (err) {
throw err;
}
});
if (gzip) {
zlib.gzip(css, (zlibErr, res) => {
if (zlibErr) {
throw zlibErr;
}
fs.writeFile(filepath + '.gz', res, (err) => {
if (err) {
throw err;
}
});
});
}
};
if (MIN) {
cssnano.process(postResult.css, { zIndex: false }).then((minifyResult) => {
writeCSS(minifyResult.css, true);
});
}
else {
writeCSS(postResult.css);
}
});
});
});