-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathbuildCSS.js
37 lines (27 loc) · 1.19 KB
/
buildCSS.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
#!/usr/bin/env node
const fs = require('fs');
const CleanCSS = require('clean-css');
const compileCSS = require('react-with-styles-interface-css-compiler');
const registerMaxSpecificity = require('react-with-styles-interface-css/dist/utils/registerMaxSpecificity').default;
const registerCSSInterfaceWithDefaultTheme = require('../src/utils/registerCSSInterfaceWithDefaultTheme').default;
console.error = msg => { throw new SyntaxError(msg); };
console.warn = msg => { throw new SyntaxError(msg); };
const args = process.argv.slice(2);
const optimizeForProduction = args.includes('-o') || args.includes('--optimize');
registerMaxSpecificity(0);
registerCSSInterfaceWithDefaultTheme();
const path = './scripts/renderAllComponents.jsx';
const CSS = compileCSS(path);
if (CSS === '') {
throw new Error('Failed to compile CSS');
} else {
console.log('CSS compilation complete.');
}
const format = new CleanCSS({
level: optimizeForProduction ? 2 : 0,
format: 'beautify',
inline: ['none'],
});
const { styles: formattedCSS } = format.minify(CSS);
const outputFilePath = optimizeForProduction ? './lib/css/_datepicker.css' : './css/styles.css';
fs.writeFileSync(outputFilePath, formattedCSS, 'utf8');