-
Notifications
You must be signed in to change notification settings - Fork 58
/
generate_dist.js
80 lines (77 loc) · 2.3 KB
/
generate_dist.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const fs = require('fs')
const path = require('path')
const compressor = require('node-minify')
const wrench = require('wrench')
function getDirectories (srcpath) {
return fs.readdirSync(srcpath)
.filter(function(file){
return fs.statSync(path.join(srcpath, file)).isDirectory() &&
file.indexOf('.') < 0 &&
file !== 'node_modules' &&
file !== 'dist' &&
file !== 'assets'
})
}
var importsAll = ''
var dir = getDirectories('./')
for(var i in dir) {
var item = dir[i]
importsAll += `@import url("./${item}.min.css");\n`
fs.createReadStream(`./${item}/component.json`).pipe(fs.createWriteStream(`./dist/${item}.json`));
if(item === 'base') {
compressor.minify({
compressor: 'clean-css',
input: ['./base/reset.css','./base/mobileui.css','./base/colors.css','./base/font.css','./base/icons.css'],
output: './dist/base.min.css',
options: {
advanced: false,
aggressiveMerging: false
},
callback: function (err, min) {
if(err) console.log('ERROR: ', err)
wrench.copyDirSyncRecursive('./base/fonts', './dist/fonts', {
forceDelete: true
})
}
})
compressor.minify({
compressor: 'gcc',
input: './base/base.js',
output: './dist/base.min.js',
callback: function (err, min) {
if(err) console.log('ERROR: ', err)
}
});
} else {
if(fs.existsSync(`./${item}/style.css`)){
compressor.minify({
compressor: 'clean-css',
input: `./${item}/style.css`,
output: `./dist/${item}.min.css`,
options: {
advanced: false,
aggressiveMerging: false
},
callback: function (err, min) {
if(err) console.log('ERROR: ', err)
}
})
}
if(fs.existsSync(`./${item}/script.js`)){
compressor.minify({
compressor: 'uglifyjs',
input: `./${item}/script.js`,
output: `./dist/${item}.min.js`,
callback: function (err, min) {
if(err) console.log('ERROR: ', err)
}
});
}
}
}
var fileNameImport = './dist/imports.css'
if (fs.existsSync(fileNameImport)) {
fs.unlinkSync(fileNameImport)
}
var fd = fs.openSync(fileNameImport, 'w')
fs.writeSync(fd, importsAll)