forked from airbnb/backpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CAKEFILE
82 lines (60 loc) · 2.53 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
{print} = require 'util'
{exec} = require 'child_process'
package = "Backpack"
src_path = "./src"
lib_path = "./lib"
js_path = "#{lib_path}/js"
bndl_path = "#{lib_path}/#{package}-bundle.js"
min_path = "#{lib_path}/#{package}-bundle.min.js"
nm_path = "./node_modules"
bin_path = "#{nm_path}/.bin"
spec_path = "./spec"
spec_lib_path = "#{spec_path}/lib"
spec_src_path = "#{spec_path}/src"
spec_bndl_path = "#{spec_lib_path}/#{package}Spec-bundle.js"
run = (command, callback) ->
# executes a command and runs a callback when it's done,
# prints out info while it's doing so
proc = exec command
proc.stdout.on 'data', (data) -> print data.toString()
proc.stderr.on 'data', (data) -> print data.toString()
proc.on 'exit', (status) -> callback?() if status is 0
# ----------------------------------
# Commands
# ----------------------------------
compile = (watch, callback) ->
# creates /lib_path/js
run "#{bin_path}/coffee -co #{js_path} #{src_path}", callback
watchJS = (callback) ->
# recompiles /src_path to individual JavaScript files in /lib_path/js
run "#{bin_path}/coffee -wco #{js_path} #{src_path}", callback
watchBundle = (callback) ->
# recompiles and joins /src_path to /lib_path
run "#{bin_path}/coffee -j #{bndl_path} -wco #{lib_path} #{src_path}", callback
watchSpecBundle = (callback) ->
run "#{bin_path}/coffee -j #{spec_bndl_path} -wco #{spec_path} #{spec_src_path}", callback
bundle = (callback) ->
# creates /lib_path/Backpack-bundle.js
run "#{bin_path}/coffee -j #{bndl_path} -co #{lib_path} #{src_path}", callback
minify = (callback) ->
# creates /lib_path/Backpack-bundle.min.js
run "#{bin_path}/uglifyjs -o #{min_path} #{bndl_path}", callback
test = (callback) ->
run "open #{spec_path}/SpecRunner.html", callback
docs = (callback) ->
run "#{bin_path}/docco #{src_path}/*.coffee", callback
# ----------------------------------
# Tasks
# ----------------------------------
task 'compile', 'Compile CoffeeScript source files', ->
compile()
task 'build', "Creates /lib_path/Backpack-bundle.js & /lib_path/Backpack-bundle.min.js & /lib_path/js/*.js", ->
compile(bundle(minify))
task 'test', "Opens Jasmine SpecRunner. Watches BackpackSpec-Bundle.js for changes", ->
bundle(test(watchSpecBundle))
task 'docs', 'Generate annotated source code with Docco', ->
docs()
task 'watch', "Recompile CoffeeScript source files when modified to Backpack-bundle.js", ->
watchBundle()
task 'watch:js', "Recompile CoffeeScript source files when modified to individual .js files", ->
watchJS()