-
Notifications
You must be signed in to change notification settings - Fork 18
/
Cakefile
194 lines (162 loc) · 5.24 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
fs = require 'fs'
cp = require 'child_process'
flour = require 'flour'
async = require 'cake-async'
rimraf = require 'rimraf'
util = require 'util'
flour.minifiers.disable 'js'
cc = (n) -> "\x1B[#{n}m"
console.log """#{cc 32}
██ ███ ██ ██ █████ ██ ████
███ ██ ██ ██ ██ ██ ██
██ ██ ██ ███████ ██ ███
██ ████ ██ ██ ██
██ ██ █████ ██ ████ ████
██
██
#{cc 33}#{cc 7}
#{process.argv[2..].map((s,i)->"#{cc 35-i} #{s.toUpperCase()} ").join("#{cc 39} ")}
#{cc 27}#{cc 36}
"""
# Config
# ==============
sources_base = [
'lib/rye.js'
'lib/util.js'
'lib/data.js'
'lib/query.js'
'lib/collection.js'
'lib/manipulation.js'
'lib/events.js'
'lib/style.js'
]
sources_full = sources_base.concat [
'lib/touch-events.js'
'lib/request.js'
]
dist_bundle_options = {
before: '(function(global){',
after: """; if (typeof module !== 'undefined') { module.exports = Rye } else { global.Rye = Rye } })(typeof window !== 'undefined' ? window : {})"""
}
option '-l', '--light', 'Light version'
getSources = (o) ->
if o.light then sources_base else sources_full
getDist = (o, min) ->
dest = if o.light then 'dist/rye-base' else 'dist/rye'
dest += if min then '.min.js' else '.js'
# Build & Watch
# ==============
async task 'build:prod', (o, done) ->
try fs.mkdirSync 'dist'
flour.minifiers.enable 'js'
bundle getSources(o), dist_bundle_options, getDist(o, true), (output, file) ->
flour.minifiers.disable 'js'
done()
async task 'build:dev', (o, done) ->
try fs.mkdirSync 'dist'
bundle getSources(o), dist_bundle_options, getDist(o), done
async task 'build:test', (o, done) ->
bundle 'test/*.coffee', 'test/spec.js', done
task 'build', ->
invoke async 'build:prod'
invoke async 'build:dev'
invoke async 'build:test'
task 'watch', ->
invoke async 'build:dev'
invoke async 'build:test'
async.end ->
watch 'test/*.coffee', -> invoke 'build:test'
watch 'lib/*.js', -> invoke 'build:dev'
# Clear
# ==============
task 'clear', ->
rimraf.sync 'dist'
try fs.unlinkSync 'test/spec.js'
# Lint
# ==============
async task 'lint', (o, done) ->
flour.linters.js.options =
forin : true
immed : true
# indent : true
latedef : true
newcap : true
noarg : true
noempty : true
nonew : true
quotmark : 'single'
undef : true
unused : true
asi : true
boss : true
curly : true
eqnull : true
laxbreak : true
laxcomma : true
sub : true
supernew : true
browser : true
shadow : 'inner'
flour.linters.js.globals =
Rye : true
lint 'lib/*.js', done
# Testing
# ==============
option '-b', '--browser [BROWSER]', 'Browser for test tasks'
option '-q', '--quick', 'Skip slow tests'
option '-p', '--port', 'Server port'
option '-g', '--grep [STRING]', 'Grep test'
###
Examples:
cake test (open default browser and run all tests)
cake -q test (run in Chrome, skip slow tests)
cake -q -b Safari (run in Safari, skip slow tests)
Browsers: 'Google Chrome', 'Firefox', 'Safari', 'PhantomJS'
###
async task 'test', (o, done) ->
invoke 'build:dev'
invoke 'build:test'
assets = "/test/assets/"
port = o.port || 3000
if o.quick
url = "file:///#{process.cwd()}#{assets}index.html?grep=(slow)&invert=true"
else
url = "http://localhost:#{port}#{assets}"
url += "?grep=#{o.grep}" if o.grep
# server
unless o.quick
server = require ".#{assets}server"
server.listen port
# browser
browser = o.browser or 'Google Chrome'
if browser is 'PhantomJS'
phantomjs = cp.spawn 'phantomjs', [".#{assets}phantomjs.coffee", url]
phantomjs.stdout.pipe process.stdout
phantomjs.on 'exit', (code) ->
done()
process.exit(code)
else
if process.platform is 'darwin'
browsers = require ".#{assets}browsers-osx"
osa = cp.spawn 'osascript'
osa.stdin.write browsers browser, url
osa.stdin.end()
else
cp.exec "open -a '#{browser}' '#{url}'"
done()
# Coverage
# ==============
task 'build:cov', ->
rimraf.sync '.coverage'
cp.exec 'jscoverage lib .coverage', (err) ->
if err?.code is 127
console.log 'cov requires github.com/visionmedia/node-jscoverage'
return
cov_sources = sources_full.map (f) -> f.replace('lib/', '.coverage/')
flour.minifiers.disable 'js'
bundle cov_sources, '.coverage/rye.instrumented.js'
# Open test harness in a browser so we don't have
# to run a server or know the absolute URL
task 'cov', ->
invoke 'build:cov'
cp.exec 'open test/assets/coverage.html'