forked from basecamp/pow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
98 lines (82 loc) · 3.13 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require.paths.unshift "#{__dirname}/node_modules"
async = require 'async'
fs = require 'fs'
{print} = require 'sys'
{spawn, exec} = require 'child_process'
build = (watch, callback) ->
if typeof watch is 'function'
callback = watch
watch = false
options = ['-c', '-o', 'lib', 'src']
options.unshift '-w' if watch
coffee = spawn 'coffee', options
coffee.stdout.on 'data', (data) -> print data.toString()
coffee.stderr.on 'data', (data) -> print data.toString()
coffee.on 'exit', (status) -> callback?() if status is 0
buildTemplates = (callback) ->
eco = require 'eco'
compile = (name) ->
(callback) ->
fs.readFile "src/#{name}.eco", "utf8", (err, data) ->
if err then callback err
else fs.writeFile "lib/#{name}.js", eco.compile(data), callback
async.parallel [
compile("cx.pow.firewall.plist")
compile("cx.pow.powd.plist")
compile("resolver")
], callback
task 'docs', 'Generate annotated source code with Docco', ->
fs.readdir 'src', (err, contents) ->
files = ("src/#{file}" for file in contents when /\.coffee$/.test file)
docco = spawn 'docco', files
docco.stdout.on 'data', (data) -> print data.toString()
docco.stderr.on 'data', (data) -> print data.toString()
docco.on 'exit', (status) -> callback?() if status is 0
task 'build', 'Compile CoffeeScript source files', ->
build()
buildTemplates()
task 'watch', 'Recompile CoffeeScript source files when modified', ->
build true
task 'test', 'Run the Pow test suite', ->
build ->
process.env["RUBYOPT"] = "-rubygems"
process.env["NODE_ENV"] = "test"
require.paths.unshift __dirname + "/lib"
{reporters} = require 'nodeunit'
process.chdir __dirname
reporters.default.run ['test']
task 'install', 'Install pow configuration files', ->
sh = (command, callback) ->
exec command, (err, stdout, stderr) ->
if err
console.error stderr
callback err
else
callback()
installLocal = (callback) ->
console.error "*** Installing local configuration files..."
sh "./bin/pow --install-local", callback
installSystem = (callback) ->
exec "./bin/pow --install-system --dry-run", (needsRoot) ->
if needsRoot
console.error "*** Installing system configuration files as root..."
sh "sudo ./bin/pow --install-system", (err) ->
if err
callback err
else
sh "sudo launchctl load /Library/LaunchDaemons/cx.pow.firewall.plist", callback
else
callback()
async.parallel [installLocal, installSystem], (err) ->
throw err if err
console.error "*** Installed"
task 'start', 'Start pow server', ->
agent = "#{process.env['HOME']}/Library/LaunchAgents/cx.pow.powd.plist"
console.error "*** Starting the Pow server..."
exec "launchctl load '#{agent}'", (err, stdout, stderr) ->
console.error stderr if err
task 'stop', 'Stop pow server', ->
agent = "#{process.env['HOME']}/Library/LaunchAgents/cx.pow.powd.plist"
console.error "*** Stopping the Pow server..."
exec "launchctl unload '#{agent}'", (err, stdout, stderr) ->
console.error stderr if err