-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.coffee
executable file
·60 lines (49 loc) · 1.45 KB
/
runner.coffee
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
#!/usr/bin/env coffee
require('shelljs/make')
src =
js: __dirname + "/src/js/app.js",
jade: "./src/jade",
stylus: "./src/styl"
console.log(src.js)
destDir = __dirname + "/build"
run = (cmd, async) ->
line = cmd.split("\n").join(" ")
console.info(line)
execWithRerun = (line) ->
exec line, async: async, ->
execWithRerun(line) if async
execWithRerun(line)
target.build = ->
browserify("prod")
jade("prod")
stylus("prod")
target.watch = ->
browserify("dev")
jade("dev")
stylus("dev")
jade = (env) ->
cmd = """
jade #{`(env == "dev" ? "--watch" : "")`} #{src.jade} --out #{destDir}
"""
run cmd, env == "dev"
stylus = (env) ->
cmd = """
stylus #{`(env == "dev" ? "--watch --sourcemap-inline" : "")`} #{src.stylus} --out #{destDir}
"""
run cmd, env == "dev"
browserify = (env) ->
isDev = env == "dev"
# -g [ envify --NODE_ENV #{`(isDev ? "development" : "production")`} ]
cmd = """
#{`(isDev ? "watchify" : "browserify")`} #{src.js} #{`(isDev ? "-d -v" : "")`}
-t [ babelify #{`(isDev ? "--sourceMap" : "")`} --optional utility.inlineExpressions ]
#{`(isDev ? "" : "-g [ envify --NODE_ENV production ]")`}
-t brfs
#{`(isDev ? "--outfile" : " | uglifyjs --stats --compress --mangle --screw-ie8 --output")`}
#{destDir}/bundle.#{`(isDev ? "" : "min.")`}js
"""
run cmd, isDev
unless isDev
run """
gzip -c -9 #{destDir}/bundle.min.js > #{destDir}/bundle.min.js.gz
""", false