-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCakefile
68 lines (58 loc) · 2.3 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
fs = require 'fs'
path = require 'path'
exec = require('child_process').exec
coffeescript = require 'coffee-script'
Package = require('node-asset').Package
APP_NAME = 'nodudio'
COFFEE_ARGS = ['--no-wrap', '-c']
BUILD_DIR = 'build'
SOURCE_DIR = 'src'
directoryWalker = (dir, callback, maxLevels, currentLevel, fromRoot) ->
maxLevels = if 'number' is typeof maxLevels then maxLevels else 0
currentLevel = if 'number' is typeof currentLevel then currentLevel else 1
fromRoot = if 'string' is typeof fromRoot then fromRoot else ''
fs.readdir dir, (error, files) ->
if error then console.log error.message
else
files.forEach (file) ->
fs.stat path.join(dir, file), (error, stats) ->
return console.log error.message if error
if stats.isDirectory()
if 0 is maxLevels or maxLevels > currentLevel
directoryWalker path.join(dir, file), callback,
maxLevels, 1 + currentLevel,
fromRoot + file + '/'
callback.call stats, file, fromRoot, path.join(dir, file), stats
run = (cmd, args) ->
args or= []
proc = exec cmd + ' ' + args.join(' ')
proc.stderr.on 'data', (err) -> if err then console.log err.toString()
task 'deps', 'Load in the git submodules', ->
run 'git submodule update --init --recursive'
task 'build', 'Build the ' + APP_NAME + ' from source', ->
invoke 'build:redis'
invoke 'build:nodudio'
invoke 'build:client'
task 'build:nodudio', 'Build the server Coffee-Script to JS', ->
dirs = {}
directoryWalker SOURCE_DIR, (file, shortPath, fullPath) ->
if @isDirectory()
run 'mkdir', ['-p', BUILD_DIR + '/' + shortPath + file]
else if /\.coffee$/.test file
args = Array::slice.call COFFEE_ARGS
args.push.apply args, ['-o', BUILD_DIR + '/' + shortPath, fullPath]
run 'coffee', args
else if /\.(js|node|addon|py)$/.test file
run 'cp', [fullPath, BUILD_DIR + '/' + shortPath + file]
task 'build:redis', 'Build the redis server', ->
run 'cd deps/redis && make'
task 'build:client', 'Build client coffee', ->
coffee_package = new Package 'public/js/all.js', [
'assets/coffee'
],
type: 'coffee'
wrap: yes
compile: no
compress: no
watch: no
coffee_package.serve()