-
Notifications
You must be signed in to change notification settings - Fork 1
/
Slakefile
86 lines (78 loc) · 2.5 KB
/
Slakefile
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
require! {
fs
}
deferScripts = ['base.js']
build-styles = (options = {}) ->
require! stylus
(err, data) <~ fs.readFile "#__dirname/www/styl/screen.styl"
data .= toString!
stylusCompiler = stylus data
..include "#__dirname/www/styl/"
if options.compression
stylusCompiler.set \compress true
(err, css) <~ stylusCompiler.render
throw err if err
fs.writeFile "#__dirname/www/screen.css", css
build-script = (file, cb) ->
require! child_process.exec
(err, result) <~ exec "lsc.cmd -o #__dirname/www/js -c #__dirname/#file"
throw err if err
cb?!
build-all-scripts = (cb) ->
require! child_process.exec
(err, result) <~ exec "lsc.cmd -o #__dirname/www/js -c #__dirname/www/ls"
throw err if err
cb?!
combine-scripts = (options = {}) ->
require! uglify: "uglify-js"
(err, files) <~ fs.readdir "#__dirname/www/js"
files .= filter -> it isnt 'script.js' and it isnt 'script.js.map'
files .= sort (a, b) ->
| a in deferScripts => 1
| b in deferScripts => -1
| otherwise => 0
files .= map -> "./www/js/#it"
minifyOptions = {}
if not options.compression
minifyOptions
..compress = no
..mangle = no
..outSourceMap = "../js/script.js.map"
..sourceRoot = "../../"
result = uglify.minify files, minifyOptions
{map, code} = result
if not options.compression
code += "\n//@ sourceMappingURL=./js/script.js.map"
fs.writeFile "#__dirname/www/js/script.js.map", map
fs.writeFile "#__dirname/www/script.js", code
run-script = (file) ->
require! child_process.exec
(err, stdout, stderr) <~ exec "lsc #__dirname/#file"
throw err if err
console.error stderr if stderr
console.log stdout
relativizeFilename = (file) ->
file .= replace __dirname, ''
file .= replace do
new RegExp \\\\, \g
'/'
file .= substr 1
option 'currentfile' 'Latest file that triggered the save' 'FILE'
task \build ->
build-styles compression: no
<~ build-all-scripts
combine-scripts compression: no
task \deploy ->
build-styles compression: yes
<~ build-all-scripts
combine-scripts compression: yes
task \build-styles ->
build-styles compression: no
task \build-script ({currentfile}) ->
file = relativizeFilename currentfile
isServer = \srv == file.substr 0, 3
if isServer
run-script file
else
<~ build-script file
combine-scripts compression: no