-
Notifications
You must be signed in to change notification settings - Fork 0
/
brunch-config.coffee
127 lines (116 loc) · 3.22 KB
/
brunch-config.coffee
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
{exec} = require 'child_process'
path = require 'path'
autoprefixer = require 'autoprefixer'
notifier = require 'node-notifier'
pushserve = require 'pushserve'
coffeelintOptions = require './coffeelint-options'
icon =
pass: path.join __dirname, 'pass.png'
fail: path.join __dirname, 'fail.png'
# assumes default port
port = 3333
postBrunchTasks = ->
buildStyleGuide()
runTests()
buildStyleGuide = ->
# include compiled stylesheets so the guide can be used to create accurate styles
# in isolation from the rest of the frontend
command = "styledocco
--out public/style-guide
--include public/stylesheets/app.css
--include public/stylesheets/vendor.css
--preprocessor 'stylus -p' app/stylesheets"
exec command
runTests = ->
command = "phantomjs ./node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js http://localhost:#{port}/test/ progress"
try
exec command, notifyTestResults
catch error
notifyTestResults {code: 1}, "error running tests: #{JSON.stringify error}"
runCITests = ->
# assumes default port
command = "phantomjs ./node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js http://localhost:#{port}/test/ xunit > test-results.xml"
server = pushserve {port, path: 'public'}, ->
exec command, ->
server.close()
notifyTestResults = (error, stdout) ->
success = not error? or error.code is 0
notifier.notify
title: 'Brunch: Tests'
message: "#{if success then 'Passed' else 'Failed'}!"
sound: on
icon: if success then icon.pass else icon.fail
if success
console.log 'tests passed'
else if stdout
console.log "test(s) failed: #{stdout}"
appPattern = /^app/
testPattern = /^test/
# block regexes (http://coffeescript.org/#regexes)
vendorScriptsPattern = ///^ # all matches must start at beginning of string
(
vendor
[\\/] # path separator
(?!test) # exclude vendor/test scripts
|node_modules # or instead of all that, npm dependencies
)
///
vendorStylesheetsPattern = ///^
(
vendor
[\\/] # path separator
(?!test) # exclude vendor/test stylesheets
|node_modules # or instead of all that, npm dependencies
)
///
vendorTestPattern = ///^
vendor
[\\/] # path separator
test
///
exports.config =
files:
javascripts:
joinTo:
'javascripts/app.js': appPattern
'javascripts/vendor.js': vendorScriptsPattern
'test/javascripts/test.js': testPattern
'test/javascripts/vendor.js': vendorTestPattern
stylesheets:
joinTo:
'stylesheets/app.css': appPattern
'stylesheets/vendor.css': vendorStylesheetsPattern
'test/stylesheets/test.css': testPattern
'test/stylesheets/vendor.css': vendorTestPattern
modules:
nameCleaner: (path) ->
path.replace(///^
app
[\\/] # path separator
scripts
[\\/] # path separator
///, '')
plugins:
postBrunch: postBrunchTasks
postcss:
processors: autoprefixer
coffeelint:
pattern: ///^
(
app
|test # app or test directory
)
[\\/] # path separator
.* # allow subdirectories and any file name
\.coffee$ # that ends in .coffee
///
options: coffeelintOptions
sourceMaps: no
overrides:
production:
plugins:
# override postBrunch tasks, they're considered development-time only (e.g. testing and styleguide)
postBrunch: ->
test:
plugins:
postBrunch: runCITests