forked from jarrekk/Jalpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
167 lines (146 loc) · 5.59 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
var UglifyJS = require('uglify-js');
var CleanCSS = require('clean-css');
require('shelljs/global');
var fs = require('fs');
require('colors');
nowDate = new Date();
nowDateStr = nowDate.toISOString().slice(0,10).replace(/-/g,"");
// remove preceding compressed files
rm('-rf', 'static/assets/*.min.js');
rm('-rf', 'static/assets/*.min.css');
// change link/src files to new file path
sed_exp = 's/(.*)[0-9]{8}(.*)/\1' + nowDateStr + '\2/';
sed('-i', /(.*)[0-9]{8}(.*)/, '$1' + nowDateStr + '$2', '_includes/index_head.html');
sed('-i', /(.*)[0-9]{8}(.*)/, '$1' + nowDateStr + '$2', '_includes/head.html');
sed('-i', /(.*)[0-9]{8}(.*)/, '$1' + nowDateStr + '$2', '_includes/category.html');
sed('-i', /(.*)[0-9]{8}(.*)/, '$1' + nowDateStr + '$2', '404.html');
// compress js files function
function compressjs(filename, filelist){
console.log('Now compress index page js files to ' + filename + ' ...')
var result = UglifyJS.minify(filelist, {
mangle: true,
compress: {
sequences: true,
dead_code: true,
conditionals: true,
booleans: true,
unused: true,
if_return: true,
join_vars: true,
drop_console: true
},
});
fs.writeFileSync('static/assets/' + filename, result.code);
console.log("Index page js files compress succeed. You can find it at \"static/assets\".\n".green);
}
// compress css files function
function compresscss(filename, filelist) {
console.log('Now compress other pages css files to ' + filename + ' ...')
var result = new CleanCSS().minify(filelist);
var output = new CleanCSS({
level: {
1: {
transform: function (propertyName, propertyValue) {
if (propertyName == 'src' && propertyValue.indexOf('node_modules/bootstrap/dist/') > -1) {
return propertyValue.replace('node_modules/bootstrap/dist/', '');
}
if (propertyName == 'src' && propertyValue.indexOf('node_modules/components-font-awesome/') > -1) {
return propertyValue.replace('node_modules/components-font-awesome/', '');
}
if (propertyName == 'src' && propertyValue.indexOf('node_modules/font-mfizz/dist/') > -1) {
return propertyValue.replace('node_modules/font-mfizz/dist/', '');
}
if (propertyName == 'background' && propertyValue.indexOf('static/img/') > -1) {
return propertyValue.replace('static/', '');
}
if (propertyName == 'background-image' && propertyValue.indexOf('static/img/') > -1) {
return propertyValue.replace('static/', '');
}
}
}
}
}).minify(result.styles);
fs.writeFileSync('static/assets/' + filename, output.styles);
console.log("Blog page css files compress succeed. You can find it at \"static/assets\".\n".green);
}
// compress js files of 404 page
fofJsFilename = 'fof-' + nowDateStr + '.min.js'
fofJsFileList = [
'node_modules/jquery/dist/jquery.js',
'node_modules/bootstrap/dist/js/bootstrap.js',
'node_modules/pace-progress/pace.js'
]
compressjs(fofJsFilename, fofJsFileList)
// compress css files of 404 page
fofCSSFilename = 'fof-' + nowDateStr + '.min.css'
fofCSSFilelist = [
'node_modules/normalize.css/normalize.css',
'node_modules/bootstrap/dist/css/bootstrap.css',
'node_modules/components-font-awesome/css/font-awesome.css',
'node_modules/animate.css/animate.css',
'static/css/style.css'
]
compresscss(fofCSSFilename, fofCSSFilelist)
// compress js files of index page
indexJsFilename = 'app-index-' + nowDateStr + '.min.js'
indexJsFileList = [
'node_modules/jquery/dist/jquery.js',
'node_modules/bootstrap/dist/js/bootstrap.js',
'node_modules/chart.js/dist/Chart.js',
'node_modules/pace-progress/pace.js',
'node_modules/wowjs/dist/wow.js',
'static/js/scroll.js',
'static/js/count.js'
]
compressjs(indexJsFilename, indexJsFileList)
// compress i18next js files
i18JsFilename = 'i18-' + nowDateStr + '.min.js'
i18JsFileList = ['static/js/i18next.min.js', 'static/js/localization.js']
compressjs(i18JsFilename, i18JsFileList)
// compress css files of index page
indexCSSFilename = 'app-index-' + nowDateStr + '.min.css'
indexCSSFilelist = [
'node_modules/normalize.css/normalize.css',
'node_modules/bootstrap/dist/css/bootstrap.css',
'node_modules/animate.css/animate.css',
'node_modules/components-font-awesome/css/font-awesome.css',
'node_modules/font-mfizz/dist/font-mfizz.css',
'static/css/style.css'
]
compresscss(indexCSSFilename, indexCSSFilelist)
// compress js file of other pages
blogJsFilename = 'app-' + nowDateStr + '.min.js'
blogJsFilelist = [
'node_modules/jquery/dist/jquery.js',
'search/js/bootstrap3-typeahead.min.js',
'node_modules/bootstrap/dist/js/bootstrap.js',
'node_modules/metismenu/dist/metisMenu.js',
'node_modules/jquery-slimscroll/jquery.slimscroll.js',
'node_modules/peity/jquery.peity.js',
'node_modules/pace-progress/pace.js',
'node_modules/wowjs/dist/wow.js',
'static/js/scroll.js',
'static/js/count.js'
],
compressjs(blogJsFilename, blogJsFilelist)
// compress jPage js files
jPageJsFilename = 'jPage-' + nowDateStr + '.min.js'
jPageJsFilelist = [
'static/js/jPages.js',
'static/js/js.js'
]
compressjs(jPageJsFilename, jPageJsFilelist)
// compress css files of index page
blogCSSFilename = 'app-' + nowDateStr + '.min.css'
blogCSSFilelist = [
'node_modules/normalize.css/normalize.css',
'node_modules/bootstrap/dist/css/bootstrap.css',
'node_modules/animate.css/animate.css',
'node_modules/components-font-awesome/css/font-awesome.css',
'node_modules/font-mfizz/dist/font-mfizz.css',
'node_modules/gritter/jquery.gritter.css',
'search/css/cb-search.css',
'static/css/pygments.css',
'static/css/style.css'
]
compresscss(blogCSSFilename, blogCSSFilelist)