forked from effkay/brunch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
94 lines (72 loc) · 2.86 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
fs = require "fs"
path = require "path"
{spawn, exec} = require "child_process"
stdout = process.stdout
# Use executables installed with npm bundle.
process.env["PATH"] = "node_modules/.bin:#{process.env["PATH"]}"
# ANSI Terminal Colors.
bold = "\033[0;1m"
red = "\033[0;31m"
green = "\033[0;32m"
reset = "\033[0m"
# Log a message with a color.
log = (message, color, explanation) ->
console.log "#{color}#{message}#{reset} #{(explanation or '')}"
# default handler for exec commands
onExec = (error, stdout, stderr) ->
console.log stdout if stdout
console.log stderr if stderr
# print the error message and kill the process
if error
process.stdout.write "#{red}#{error.stack}#{reset}\n"
process.exit -1
## Setup ##
task "setup", "Install development dependencies", ->
log "Installing dependencies into node_modules ...", green
exec "npm install", onExec
task "link", "Link local brunch as your global npm module", ->
log "Installing Brunch ...", green
exec "npm link", onExec
## Building ##
build = (callback) ->
log "Compiling CoffeeScript to JavaScript ...", green
command = "rm -rf lib && coffee --compile --lint --output lib src"
exec command, (error, stdout, stderr) ->
onExec error, stdout, stderr
callback() if callback?
task "build", "Compile CoffeeScript to JavaScript", ->
build()
task "watch", "Continously compile CoffeeScript to JavaScript", ->
command = spawn "coffee", ["--compile", "--watch", "--lint", "--output", "lib", "src"]
command.stdout.on "data", (data) ->
process.stdout.write "#{green}#{data}#{reset}"
command.stderr.on "data", (data) ->
process.stdout.write "#{red}#{data}#{reset}"
command.on "error", (error) ->
process.stdout.write "#{red}#{error.stack}#{reset}\n"
process.exit -1
## Testing ##
task "test", "Run test (spec) suite", ->
sys = require "sys"
{loadHelpersInFolder, executeSpecsInFolder} = require "jasmine-node"
re =
helper: /[-_]helper\.coffee$/
spec: /spec\.coffee$/i
specFolder = path.join __dirname, "spec"
callback = (runner, log) -> sys.print "\n"
loadHelpersInFolder specFolder, re.helper
executeSpecsInFolder specFolder, callback, false, true, re.spec, false
## Publishing ##
task "publish", "Publish new version to Git (push and add tag) and NPM", ->
exec "git push origin master", (error, stdout, stderr) ->
onExec error, stdout, stderr
fs.readFile "package.json", "utf8", (err, package) ->
package = JSON.parse(package)
log "Publishing to NPM ...", green
exec "npm publish", (error, stdout, stderr) ->
onExec error, stdout, stderr
# Create a tag for this version and push changes to Github.
log "Tagging version #{package.version} ...", green
exec "git tag #{package.version}", (error, stdout, stderr) ->
onExec error, stdout, stderr
exec "git push --tags origin master", onExec