-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild_css.js
65 lines (54 loc) · 1.52 KB
/
build_css.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
63
64
65
/* eslint-disable no-console */
const colors = require('colors/safe');
const concat = require('concat-files');
const glob = require('glob');
const fs = require('fs');
const postcss = require('postcss');
const prepend = require('postcss-selector-prepend');
let _currBuild = null;
function buildCSS() {
if (_currBuild) return _currBuild;
const START = '🏗 ' + colors.yellow('Building css...');
const END = '👍 ' + colors.green('css built');
console.log('');
console.log(START);
console.time(END);
return _currBuild =
Promise.resolve()
.then(() => doGlob('css/**/*.css'))
.then((files) => doConcat(files, 'dist/iD.css'))
.then(() => {
const css = fs.readFileSync('dist/iD.css', 'utf8');
return postcss([prepend({ selector: '.ideditor ' })])
.process(css, { from: 'dist/iD.css', to: 'dist/iD.css' });
})
.then(result => fs.writeFileSync('dist/iD.css', result.css))
.then(() => {
console.timeEnd(END);
console.log('');
_currBuild = null;
})
.catch((err) => {
console.error(err);
console.log('');
_currBuild = null;
process.exit(1);
});
}
function doGlob(pattern) {
return new Promise((resolve, reject) => {
glob(pattern, (err, files) => {
if (err) return reject(err);
resolve(files);
});
});
}
function doConcat(files, output) {
return new Promise((resolve, reject) => {
concat(files, output, (err) => {
if (err) return reject(err);
resolve();
});
});
}
module.exports = buildCSS;