This repository was archived by the owner on Feb 21, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCakefile
More file actions
285 lines (239 loc) · 5.87 KB
/
Cakefile
File metadata and controls
285 lines (239 loc) · 5.87 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
fs = require "fs"
uglifyjs = require "uglify-js"
{print} = require "sys"
{exec} = require "child_process"
###
Directory where the Espresso module will be generated
###
ESPRESSO_DIR = ".espresso"
###
Module's index filename. DO NOT MODIFY!
###
ESPRESSO_INDEX = "index.coffee"
###
Types of source files. DO NOT MODIFY!
###
SOURCES = { COFFEE: "coffee", LESS: "less" }
###
Directory where the source code is
###
APP_DIR = "app"
###
Module directories
###
APP_SRC = [
"config",
"routes",
"services",
"socket"
]
###
Server filename. File that is run by Node
###
SERVER_FILENAME = "app.coffee"
###
Angular app source folder under APP_DIR
###
ANGULAR_APP_SRC = "#{__dirname}/#{APP_DIR}/angular"
###
Client files (static resources) output directory. DO NOT MODIFY!
###
PUBLIC_DIR = "#{__dirname}/public"
###
Angular app output folder under PUBLIC_DIR
###
ANGULAR_APP_OUT = "#{PUBLIC_DIR}/angular"
###
Client scripts source folder other than angular files
###
CLIENT_RESOURCES_SRC = "#{APP_DIR}/resources"
###
Client scripts output folder other than angular files
###
CLIENT_RESOURCES_OUT = "#{PUBLIC_DIR}/js"
###
Styles source folder
###
STYLES_SRC = "#{__dirname}/styles"
###
Styles output filename
###
STYLES_NAME = "espresso.css"
###
Styles output folder
###
STYLES_OUT = "#{PUBLIC_DIR}/styles"
###
Compiles all APP_SRC directories and into ESPRESSO_DIR
###
buildModule = ->
options = "-c -b -o"
compile SOURCES.COFFEE, "#{options} #{ESPRESSO_DIR}/#{input} #{APP_DIR}/#{input}" for input in APP_SRC
compile SOURCES.COFFEE, "#{options} #{ESPRESSO_DIR} #{APP_DIR}/#{ESPRESSO_INDEX}"
###
Compiles ESPRESSO_INDEX in the project root
###
buildServer = ->
options = "-c -b"
compile SOURCES.COFFEE, "#{options} #{SERVER_FILENAME}"
###
Compiles and uglifies client dirs
###
buildClient = ->
clientDirs = [
{
type: SOURCES.COFFEE,
output: "#{ANGULAR_APP_OUT}",
input: "#{ANGULAR_APP_SRC}"
},
{
type: SOURCES.COFFEE,
output: "#{CLIENT_RESOURCES_OUT}",
input: "#{CLIENT_RESOURCES_SRC}"
},
{
type: SOURCES.LESS,
output: "#{STYLES_OUT}",
input: "#{STYLES_SRC}"
}
]
for dir in clientDirs
do (dir) ->
switch dir.type
when SOURCES.COFFEE
compile dir.type, "-c -b -o #{dir.output} #{dir.input}", ->
uglifyDirectory dir.output
when SOURCES.LESS
compile dir.type, "-x #{dir.input}/*.less > #{dir.output}/#{STYLES_NAME}"
###
Uglifies a directory
@dir - Directory to be uglified
###
uglifyDirectory = (dir) ->
console.log "Uglifying #{dir}"
fs.readdir dir, (err, files) ->
return if err?
for file in files
do (file) ->
fs.stat "#{dir}/#{file}",
(err, stats) ->
if err then throw err
if stats? and stats.isDirectory()
uglifyDirectory "#{dir}/#{file}"
else
uglifyFile "#{dir}/#{file}"
###
Uglifies a file
@file - File to be uglified
###
uglifyFile = (file) ->
result = uglifyjs.minify "#{file}"
data = result.code
fs.writeFile file, data, (err) ->
if err
throw err
console.log "#{file} uglified"
###
Deletes ESPRESSO_DIR
###
cleanEspresso = (callback) ->
dir = "#{__dirname}/#{ESPRESSO_DIR}"
deleteDirectory dir, ->
fs.rmdir dir, (err) ->
if err
throw err
if callback then callback()
###
Deletes ANGULAR_APP_OUT, CLIENT_RESOURCES_OUT, and STYLES_OUT
###
cleanClient = (callback) ->
clientDirs = [
"#{ANGULAR_APP_OUT}",
"#{CLIENT_RESOURCES_OUT}",
"#{STYLES_OUT}"
]
for dir in clientDirs
do (dir) ->
deleteDirectory dir, ->
fs.rmdir dir, (err) ->
if err then throw err
if callback then callback()
###
Deletes a directory
@dir - Directory to be deleted
###
deleteDirectory = (dir) ->
fs.readdir dir, (err, files) ->
return if err?
for file in files
do (file) ->
fs.stat "#{dir}/#{file}",
(err, stats) ->
if err then throw err
if stats? and stats.isDirectory()
deleteDirectory "#{dir}/#{file}"
else
deleteFile "#{dir}/#{file}"
###
Deletes a file
@file - File to be deleted
###
deleteFile = (file) ->
fs.unlink file, (err) ->
if err
throw err
###
Executes a compilation command
@type - Type of source (SOURCES.COFFEE or SOURCES.LESS)
@options - Command options
###
compile = (type, options, callback) ->
switch type
when SOURCES.COFFEE
exec "coffee #{options}", {}, (error, stdout, stderr) ->
if error
console.log stderr.toString()
throw error
if callback then callback()
when SOURCES.LESS
exec "lessc #{options}", {}, (error, stdout, stderr) ->
if error
console.log stderr.toString()
throw error
if callback then callback()
###
Tasks
###
task "build", "Builds app", (callback) ->
invoke "clean"
console.log "Building module..."
buildModule()
console.log "Building client..."
buildClient()
console.log "Building server..."
buildServer()
task "build:module", "Builds the Espresso module", ->
invoke "clean:module"
console.log "Building module..."
buildModule()
console.log "Building server..."
buildServer()
task "build:client", "Builds client scripts", ->
invoke "clean:client"
console.log "Building client..."
buildClient()
task "clean", "Clean module and client", ->
invoke "clean:module"
invoke "clean:client"
task "clean:module", "Cleans the Espresso module", ->
cleanEspresso ->
console.log "Module cleaned"
task "clean:client", "Cleans the client", ->
cleanClient ->
console.log "Client cleaned"
task "run", "Runs the app", ->
console.log "App running, press ^C to quit"
exec "node app", (err, stdout, stderr) ->
if err
console.log "Error starting the app. Run 'cake build' to make sure everything's good"
throw err