-
Notifications
You must be signed in to change notification settings - Fork 34
/
Cakefile
41 lines (33 loc) · 1.49 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
fs = require 'fs'
glob = require 'glob'
exec = require('child_process').exec
coffee = require 'coffee-script'
path = require 'path'
escapeShell = (arg) -> "'" + arg.replace(/[^\\]'/g, (m, i, s) -> m.slice(0, 1) + "\\'") + "'"
src = __dirname + '/src'
bin = __dirname + '/bin'
task 'build', 'build project', (options) ->
# Remove bin contents
exec "rm -rf #{escapeShell bin}", (err, stdout, stderr) ->
if err? then throw err
# Copy src content into bin
exec "cp -R #{escapeShell src} #{escapeShell bin}", (err, stdout, stderr) ->
if err? then throw err
# Compile coffee files
for filename in glob.sync bin+'/*.coffee'
if filename.substring(filename.length-7) is '.coffee'
# Get script from coffee file
script = fs.readFileSync filename, 'utf8'
# Compile into js code
js = coffee.compile script
# Write js file with compiled code
file = fs.openSync filename.substring(0, filename.length-7)+'.js', 'w+'
fs.writeSync file, js
fs.closeSync file
# Delete coffee file
fs.unlinkSync filename
# Ensure redis-dump is executable
exec "chmod +x #{escapeShell bin+'/cli/redis-dump'}", (err, stdout, stderr) ->
if err? then throw err
# Finish
console.log 'built redis-dump.'