-
Notifications
You must be signed in to change notification settings - Fork 31
/
build.coffee
executable file
·145 lines (125 loc) · 5.5 KB
/
build.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
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
#!/usr/bin/env node_modules/.bin/coffee
# Copyright IBM Corp. 2013 All Rights Reserved. See footer for details.
require "shelljs/global"
#-------------------------------------------------------------------------------
main = (command) ->
switch command
when "serve" then runServe()
when "watch" then runWatch()
when "images" then runImages()
else printHelp()
return
#-------------------------------------------------------------------------------
runServe = ->
require "./app.js"
return
#-------------------------------------------------------------------------------
runWatch = ->
if process.platform is "win32"
console.log "sorry, the watch task doesn't work on windows"
process.exit(1)
execA """
node_modules/.bin/node-supervisor
--quiet
--watch lib,app.js,build.coffee
--extensions js,coffee
--no-restart-on error
--exec node_modules/.bin/coffee
-- build.coffee serve
"""
return
#-------------------------------------------------------------------------------
runImages = ->
# uses imagemagick to convert images
sizes = [
"032"
"057"
"064"
"072"
"096"
"114"
"128"
"144"
"256"
]
for size in sizes
execA """
convert
-resize #{size}x#{size}
www/images/icon-512.png
www/images/icon-#{size}.png
"""
#-------------------------------------------------------------------------------
rmIfExistsDir = (dir) ->
return unless test "-d", dir
rm "-Rf", dir
#-------------------------------------------------------------------------------
execA = (cb, command) ->
if !command?
command = cb
cb = ->
if process.platform is "win32"
command = command.replace /\//g, "\\"
command = command.replace /\s\s+/g, " "
exec command, -> cb()
#-------------------------------------------------------------------------------
printSection = (title) ->
console.log ""
console.log title
console.log "-------------------------------------------"
#-------------------------------------------------------------------------------
printHelp = ->
console.log """
usage: build <task>
where <task> is one of:
serve - run server
watch - run server, restart when source changes
images - rebuild images
help - print this help
note that the watch task does not work on windows
"""
return
#-------------------------------------------------------------------------------
main process.argv[2]
#==================================================================
#
# Copyright IBM Corp. 2013 All Rights Reserved
#
#==================================================================
#
# NOTICE TO USERS OF THE SOURCE CODE EXAMPLES
#
# The source code examples provided by IBM are only intended to
# assist in the development of a working software program.
#
# International Business Machines Corporation provides the source
# code examples, both individually and as one or more groups,
# "as is" without warranty of any kind, either expressed or
# implied, including, but not limited to the warranty of
# non-infringement and the implied warranties of merchantability
# and fitness for a particular purpose. The entire risk
# as to the quality and performance of the source code
# examples, both individually and as one or more groups, is with
# you. Should any part of the source code examples prove defective,
# you (and not IBM or an authorized dealer) assume the entire cost
# of all necessary servicing, repair or correction.
#
# IBM does not warrant that the contents of the source code
# examples, whether individually or as one or more groups, will
# meet your requirements or that the source code examples are
# error-free.
#
# IBM may make improvements and/or changes in the source code
# examples at any time.
#
# Changes may be made periodically to the information in the
# source code examples; these changes may be reported, for the
# sample code included herein, in new editions of the examples.
#
# References in the source code examples to IBM products, programs,
# or services do not imply that IBM intends to make these
# available in all countries in which IBM operates. Any reference
# to the IBM licensed program in the source code examples is not
# intended to state or imply that IBM's licensed program must be
# used. Any functionally equivalent program may be used.
#==================================================================