This repository has been archived by the owner on Dec 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCakefile
79 lines (65 loc) · 2.77 KB
/
Cakefile
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
fs = require 'fs'
{exec} = require 'child_process'
inJsLibFiles = [
'public/js/gmaps-noitehojestyles'
'public/js/jquery.prettyPhoto'
'public/js/parseuri'
'public/js/geolocation'
'public/js/app/history/json2'
'public/js/app/history/amplify.store'
'public/js/app/history/history.adapter.jquery'
'public/js/app/history/history'
'public/js/app/history/history.html4'
'public/js/app/jquery.reject.min']
inCoffeeFiles = [
'public/coffee/base'
'public/coffee/map'
'public/coffee/location'
'public/coffee/search'
'public/coffee/ordering'
'public/coffee/prettyPhoto'
'public/coffee/event_details'
'public/coffee/app']
compilerPath = 'tools/closure-compiler-20110502.jar'
outLibsJsFile = 'public/js/app/compiled/libs.js'
outLibsJsMinifiedFile = 'public/js/app/minified/libs.min.js'
outNoiteHojeCoffeeFile = 'public/js/app/compiled/noitehoje.coffee'
outNoiteHojeJsFile = 'public/js/app/compiled/noitehoje.js'
outNoiteHojeJsMinifiedFile = 'public/js/app/minified/noitehoje.min.js'
task 'combine', 'Build single application file from source files', ->
combineJsFiles = (inputfileNames, outputFileName) ->
remaining = inputfileNames.length
appContents = new Array remaining
for file, index in inputfileNames then do (file, index) ->
fs.readFile "#{file}.js", 'utf8', (err, fileContents) ->
throw err if err
appContents[index] = fileContents
combineFiles() if --remaining is 0
combineFiles = ->
fs.writeFileSync outputFileName, appContents.join('\n\n')
combineCoffeeFiles = (inputfileNames, outputFileName) ->
remaining = inputfileNames.length
appContents = new Array remaining
for file, index in inputfileNames then do (file, index) ->
fs.readFile "#{file}.coffee", 'utf8', (err, fileContents) ->
throw err if err
appContents[index] = fileContents
compileCoffee() if --remaining is 0
compileCoffee = ->
fs.writeFile outputFileName, appContents.join('\n\n'), 'utf8', (err) ->
throw err if err
exec "coffee --compile #{outputFileName}", (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
fs.unlink outputFileName, (err) ->
throw err if err
console.log 'Done.'
combineJsFiles inJsLibFiles, outLibsJsFile
combineCoffeeFiles inCoffeeFiles, outNoiteHojeCoffeeFile
task 'minify', 'Minify the resulting application file after build', ->
minifyJs = (inputFile, outputFile) ->
exec "java -jar '#{compilerPath}' --js #{inputFile} --js_output_file #{outputFile}", (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
minifyJs outLibsJsFile, outLibsJsMinifiedFile
minifyJs outNoiteHojeJsFile, outNoiteHojeJsMinifiedFile