-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
60 lines (48 loc) · 1.78 KB
/
build.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
const fs = require('fs');
const { sync: globSync } = require('glob');
const { minify } = require('terser');
const CleanCSS = require('clean-css');
const cssMinify = new CleanCSS();
const options = {
compress: {},
keep_classnames: true,
keep_fnames: true,
mangle: false
};
fs.rmSync('./dist/', { recursive: true, force: true });
fs.mkdirSync('./dist/js', { recursive: true }, (error) => {
if (error) throw error;
});
fs.mkdirSync('./dist/css', { recursive: true }, (error) => {
if (error) throw error;
});
fs.mkdirSync('./dist/css/themes', { recursive: true }, (error) => {
if (error) throw error;
});
const licenseHeader = fs.readFileSync('license-header.txt', 'utf8');
let bundle = '';
const jsFiles = globSync('./src/*.js').reverse();
jsFiles.map(file => {
const content = fs.readFileSync(file, 'utf8');
if (file === 'src/blimpkit.js') {
bundle = content + bundle;
} else bundle += content;
minify(content, options).then((result) => {
fs.writeFileSync(file.replace('src/', 'dist/js/').replace('.js', '.min.js'), licenseHeader + result.code, 'utf8');
}, (error) => {
console.error(`Error minifying ${file}`, error);
});
});
minify(bundle, options).then((result) => {
fs.writeFileSync('dist/js/blimpkit.bundle.min.js', licenseHeader + result.code, 'utf8');
}, (error) => {
console.error(`Error minifying bundle`, error);
});
const cssFiles = [...globSync('./css/*.css'), ...globSync('./css/themes/*.css')];
cssFiles.map(file => {
const result = cssMinify.minify(fs.readFileSync(file, 'utf8'));
fs.writeFileSync(file.replace('css/', 'dist/css/').replace('.css', '.min.css'), licenseHeader + result.styles, 'utf8');
});
fs.cp('./logo', './dist/logo', { recursive: true }, (error) => {
if (error) throw error;
});