-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
84 lines (60 loc) · 2.74 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
80
81
82
browserify = require('browserify')
fs = require('fs')
{exec} = require 'child_process'
deleteFolder = (path) ->
return unless fs.existsSync(path)
fs.readdirSync(path).forEach (file, index) ->
fs.unlinkSync("#{path}/#{file}")
fs.rmdirSync(path)
SRC_DIR_SERVER = './src/server'
DIST_DIR_SERVER = './dist/server'
SRC_DIR_CLIENT = './src/webclient'
DIST_DIR_CLIENT = './dist/webclient.tmp/'
CLIENT_BUNDLE_MAIN = "#{DIST_DIR_CLIENT}/index.js"
DIST_CLIENT_BUNDLE = "#{__dirname}/dist/webclient.js"
SRC_CASH_LIB = './node_modules/cash-dom/dist/cash.min.js'
DIST_CASH_LIB = "#{DIST_DIR_CLIENT}/cash.js"
task 'build', 'Build project from /src/*/*.coffee to /dist/*.js', ->
invoke 'build-server'
invoke 'build-webclient'
task 'build-server', 'Compile server from /src/server/*.coffee to /dist/server/*.js', ->
child = exec "coffee --output #{DIST_DIR_SERVER} --compile #{SRC_DIR_SERVER}", (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
task 'build-webclient', 'Compile and join webclient from /src/webclient/*.coffee to /dist/webclient.js', ->
child = exec "coffee --output #{DIST_DIR_CLIENT} --compile #{SRC_DIR_CLIENT}", (err, stdout, stderr) ->
throw err if err
console.log stdout
invoke 'bundle-webclient'
task 'watch', 'Build project and watch sources for changes', ->
invoke 'watch-server'
invoke 'watch-webclient'
task 'watch-server', 'Build server and watch its sources for changes', ->
child = exec "coffee -o #{DIST_DIR_SERVER} -wc #{SRC_DIR_SERVER}", (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
child.stdout.on 'data', (args...) ->
console.log args...
task 'watch-webclient', 'Build webclient and watch its sources for changes', ->
child = exec "coffee -o #{DIST_DIR_CLIENT} -wc #{SRC_DIR_CLIENT}", (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
child.stdout.on 'data', (args...) ->
console.log args...
invoke 'bundle-webclient'
task 'bundle-webclient', 'Bundle compiled sources of webclient', ->
# Stream for output file
outFileStream = fs.createWriteStream(DIST_CLIENT_BUNDLE)
outFileStream.on 'finish', ->
console.log('Finished webclient bundle:', DIST_CLIENT_BUNDLE)
# Bundle via browserify
bundler = browserify CLIENT_BUNDLE_MAIN,
standalone: 'GatewayChat' # Name of global main class in window object
bundler.transform 'uglifyify',
global: true
bundler = bundler.bundle (error, result) ->
throw error if error?
bundler.pipe(outFileStream)
task 'del-temp-files', 'Delete temporary files', ->
deleteFolder(DIST_DIR_CLIENT)
console.log('Removed temporary files:', DIST_DIR_CLIENT)