forked from sciactive/pnotify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.js
113 lines (94 loc) · 2.64 KB
/
make.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
#!/user/bin/env nodejs
"use strict"
require('shelljs/make')
let pnotify_js = {
"core": "pnotify.js",
"animate": "pnotify.animate.js",
"buttons": "pnotify.buttons.js",
"callbacks": "pnotify.callbacks.js",
"confirm": "pnotify.confirm.js",
"desktop": "pnotify.desktop.js",
"history": "pnotify.history.js",
"mobile": "pnotify.mobile.js",
"nonblock": "pnotify.nonblock.js",
}
let pnotify_css = {
"core": "pnotify.css",
"brighttheme": "pnotify.brighttheme.css",
"buttons": "pnotify.buttons.css",
"history": "pnotify.history.css",
"mobile": "pnotify.mobile.css",
"nonblock": "pnotify.nonblock.css",
}
let root = __dirname + '/'
for (let module in pnotify_js) {
target[module+"_js"] = () => compress_js(module, pnotify_js[module])
;((target) => {
const existing = target[module]
target[module] = () => {
existing && existing()
target[module+"_js"]()
}
})(target)
}
for (let module in pnotify_css) {
target[module+"_css"] = () => compress_css(module, pnotify_css[module])
;((target) => {
const existing = target[module]
target[module] = () => {
existing && existing()
target[module+"_css"]()
}
})(target)
}
target.dist = () => {
for (let module in pnotify_js) {
target[module+"_js"]()
}
for (let module in pnotify_css) {
target[module+"_css"]()
}
}
// Functions
let compress_js = (module, filename) => {
setup()
const src_filename = "src/" + filename
const dst_filename = "dist/" + filename
echo("Compressing JavaScript "+module+" from "+src_filename+" to "+dst_filename)
echo("Generating source map for "+dst_filename+" in "+dst_filename+".map")
const intro = get_intro(src_filename)
const UglifyJS = require('uglify-js')
const options = {
sourceRoot: "../",
outSourceMap: filename,
sourceMapUrl: filename+".map"
}
const result = UglifyJS.minify(src_filename, options)
;(intro + result.code).to(dst_filename)
result.map.to(dst_filename+".map")
}
let compress_css = (module, filename) => {
setup()
const src_filename = "src/" + filename
const dst_filename = "dist/" + filename
echo("Compressing CSS "+module+" from "+src_filename+" to "+dst_filename)
const CleanCSS = require('clean-css')
const options = {
rebase: false
}
;(new CleanCSS(options).minify(cat(src_filename).stdout)).styles.to(dst_filename)
}
let setup = () => {
cd(__dirname)
mkdir('-p', 'dist')
}
let get_intro = (filename) => {
let code = cat(filename)
if (code.slice(0, 2) == "//") {
return code.slice(0, code.indexOf("\n") + 1)
} else if (code.slice(0, 2) == "/*") {
return code.slice(0, code.indexOf("*/\n") + 3)
} else {
return ""
}
}