-
Notifications
You must be signed in to change notification settings - Fork 2
/
Cakefile
executable file
·156 lines (126 loc) · 3.91 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# v1.1.1 June 25, 2013
# This file was originally created by Benjamin Lupton <[email protected]> (http://balupton.com)
# and is currently licensed under the Creative Commons Zero (http://creativecommons.org/publicdomain/zero/1.0/)
# making it public domain so you can do whatever you wish with it without worry (you can even remove this notice!)
#
# If you change something here, be sure to reflect the changes in:
# - the Cakefile
# - the scripts section of the package.json file
# - the .travis.yml file
# -----------------
# Variables
WINDOWS = process.platform.indexOf('win') is 0
NODE = process.execPath
NPM = if WINDOWS then process.execPath.replace('node.exe','npm.cmd') else 'npm'
EXT = (if WINDOWS then '.cmd' else '')
APP_DIR = process.cwd()
SRC_DIR = "#{APP_DIR}/src"
OUT_DIR = "#{APP_DIR}/out"
TEST_DIR = "#{APP_DIR}/test"
MODULES_DIR = "#{APP_DIR}/node_modules"
BIN_DIR = "#{MODULES_DIR}/.bin"
DOCPAD_DIR = "#{MODULES_DIR}/docpad"
CAKE = "#{BIN_DIR}/cake#{EXT}"
COFFEE = "#{BIN_DIR}/coffee#{EXT}"
DOCPAD = "#{APP_DIR}/docpad#{EXT}"
# -----------------
# Requires
pathUtil = require('path')
{exec,spawn} = require('child_process')
safe = (next,fn) ->
return (err) ->
return next(err) if err
return fn()
# -----------------
# Actions
clean = (opts,next) ->
(next = opts; opts = {}) unless next?
args = [
'-Rf'
OUT_DIR
pathUtil.join(APP_DIR, 'node_modules')
pathUtil.join(APP_DIR, '*out')
pathUtil.join(APP_DIR, '*log')
pathUtil.join(TEST_DIR, 'node_modules')
pathUtil.join(TEST_DIR, '*out')
pathUtil.join(TEST_DIR, '*log')
]
spawn('rm', args, {stdio:'inherit', cwd:APP_DIR}).on 'exit', safe next, ->
next()
compile = (opts,next) ->
(next = opts; opts = {}) unless next?
spawn(COFFEE, ['-bco', OUT_DIR, SRC_DIR], {stdio:'inherit', cwd:APP_DIR}).on 'exit', safe next, ->
next()
watch = (opts,next) ->
(next = opts; opts = {}) unless next?
spawn(COFFEE, ['-bwco', OUT_DIR, SRC_DIR], {stdio:'inherit', cwd:APP_DIR}).on 'exit', safe next, ->
next()
install = (opts,next) ->
(next = opts; opts = {}) unless next?
spawn(NPM, ['install'], {stdio:'inherit', cwd:APP_DIR}).on 'exit', safe next, ->
spawn(NPM, ['install'], {stdio:'inherit', cwd:TEST_DIR}).on 'exit', safe next, ->
next()
reset = (opts,next) ->
(next = opts; opts = {}) unless next?
clean opts, safe next, ->
install opts, safe next, ->
compile opts, safe next, ->
next()
setup = (opts,next) ->
(next = opts; opts = {}) unless next?
install opts, safe next, ->
compile opts, safe next, ->
next()
test = (opts,next) ->
(next = opts; opts = {}) unless next?
compile opts, safe next, ->
test_run opts, safe next, ->
next()
test_run = (opts,next) ->
(next = opts; opts = {}) unless next?
spawn(NPM, ['test'], {stdio:'inherit', cwd:APP_DIR}).on 'exit', safe next, ->
next()
test_install = (opts,next) ->
(next = opts; opts = {}) unless next?
spawn(NPM, ['install'], {stdio:'inherit', cwd:DOCPAD_DIR}).on 'exit', safe next, ->
next()
test_setup = (opts,next) ->
(next = opts; opts = {}) unless next?
install opts, safe next, ->
test_install opts, safe next, ->
compile opts, safe next, ->
next()
finish = (err) ->
throw err if err
console.log('OK')
# -----------------
# Commands
# clean
task 'clean', 'clean up instance', ->
clean finish
# compile
task 'compile', 'compile our files', ->
compile finish
# dev/watch
task 'dev', 'watch and recompile our files', ->
watch finish
task 'watch', 'watch and recompile our files', ->
watch finish
# install
task 'install', 'install dependencies', ->
install finish
# reset
task 'reset', 'reset instance', ->
reset finish
# setup
task 'setup', 'setup for development', ->
setup finish
# test
task 'test', 'run our tests', ->
test finish
# test-debug
task 'test-debug', 'run our tests in debug mode', ->
test {debug:true}, finish
# test-setup
task 'test-setup', 'setup for testing', ->
test_setup finish