-
Notifications
You must be signed in to change notification settings - Fork 14
/
Gruntfile.coffee
205 lines (167 loc) · 6.44 KB
/
Gruntfile.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
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
195
196
197
198
199
200
201
202
203
204
205
module.exports = (grunt)->
# Run `grunt server` for live-reloading development environment
grunt.registerTask('server', [ 'build', 'express', 'watch' ])
# Run `grunt server:unit` for live-reloading unit testing environment
grunt.registerTask('server:unit', [ 'build', 'karma:background', 'watch:unit' ])
# Run `grunt test` (used by `npm test`) for continuous integration (e.g. Travis)
grunt.registerTask('test', [ 'test:unit' ])
# Run `grunt test:unit` for single-run unit testing
grunt.registerTask('test:unit', [ 'build', 'karma:unit' ])
# Run `grunt test:browsers` for real-world browser testing
grunt.registerTask('test:e2e', [ 'build', 'karma:e2e' ])
# Clean, validate & compile web-accessible resources
grunt.registerTask('build', [ 'clean', 'jshint', 'copy', 'ngtemplates', 'less' ])
# Optimize pre-built, web-accessible resources for production, primarily `usemin`
grunt.registerTask('optimize', [ 'useminPrepare', 'concat', 'uglify', 'mincss', 'usemin' ])
# Configuration
grunt.config.init
# Directory CONSTANTS (see what I did there?)
BUILD_DIR: 'build/'
CLIENT_DIR: 'client/'
BOWER_DIR: 'bower_components/'
SERVER_DIR: 'server/'
# Glob CONSTANTS
ALL_FILES: '**/*'
CSS_FILES: '**/*.css'
HTML_FILES: '**/*.html'
IMG_FILES: '**/*.{png,gif,jpg,jpeg}'
JS_FILES: '**/*.js'
LESS_FILES: '**/*.less'
# Wipe the `build` directory
clean:
build: '<%= BUILD_DIR %>'
copy:
# App images from Bower `components` & `client`
images:
files: [
expand: true,
cwd: '<%= BOWER_DIR %>/bootstrap/img'
src: '<%= IMG_FILES %>'
dest: '<%= BUILD_DIR %>/img'
,
expand: true
cwd: '<%= CLIENT_DIR %>'
src: '<%= IMG_FILES %>'
dest: '<%= BUILD_DIR %>'
]
# Copy `client` -> `build`, as resources are served from `build`
client:
files: [
expand: true
cwd: '<%= CLIENT_DIR %>'
src: '<%= ALL_FILES %>'
dest: '<%= BUILD_DIR %>'
]
# Make bower HTTP-accessible
bower:
files:
'<%= BUILD_DIR %>': '<%= BOWER_DIR + ALL_FILES %>'
# app (non-Bower) JS in `client`
js:
files: [
expand: true
cwd: '<%= CLIENT_DIR %>'
src: '<%= JS_FILES %>'
dest: '<%= BUILD_DIR %>'
]
# app (non-Bower) HTML in `client`
templates:
files: [
expand: true
cwd: '<%= CLIENT_DIR %>'
src: '<%= HTML_FILES %>'
dest: '<%= BUILD_DIR %>'
]
# Express requires `server.script` to reload from changes
express:
server:
options:
script: '<%= SERVER_DIR %>/server.js'
# Validate app `client` and `server` JS
jshint:
files: [ '<%= SERVER_DIR + JS_FILES %>'
'<%= CLIENT_DIR + JS_FILES %>' ]
options:
es5: true
laxcomma: true # Common in Express-derived libraries
# Browser-based testing
karma:
options:
configFile: 'karma.conf.js'
# Used for running tests while the server is running
background:
background: true
singleRun: false
# Used for testing site across several browser profiles
e2e:
browsers: [ 'PhantomJS' ] # 'Chrome', 'ChromeCanary', 'Firefox', 'Opera', 'Safari', 'IE', 'bin/browsers.sh'
singleRun: true
# Used for one-time validation (e.g. `grunt test`, `npm test`)
unit:
singleRun: true
# Compile `app.less` -> `app.css`
less:
'<%= BUILD_DIR %>/app/styles/app.css': '<%= CLIENT_DIR %>/app/styles/app.less'
# Minify app `.css` resources -> `.min.css`
mincss:
app:
expand: true
cwd: '<%= BUILD_DIR %>'
src: '<%= CSS_FILES %>'
dest: '<%= BUILD_DIR %>'
ext: '.min.css'
# Convert Angular `.html` templates to `.js` in the `app` module
ngtemplates:
app:
src: '<%= BUILD_DIR %>/app/<%= HTML_FILES %>'
dest: '<%= BUILD_DIR %>/app/scripts/app.templates.js'
options:
base: '<%= BUILD_DIR %>'
# Output for optimized app index
usemin:
html: '<%= BUILD_DIR %>/index.html'
# Input for optimized app index
useminPrepare:
html: '<%= BUILD_DIR %>/index.html'
# "watch" distinct types of files and re-prepare accordingly
watch:
options:
debounceDelay: 200
livereload: true
nospawn: true
# Any public-facing changes should reload the browser & re-run tests (which may depend on those resources)
build:
files: [ '<%= BUILD_DIR + ALL_FILES %>', '!**/<%= BOWER_DIR %>/**' ]
# Changes to app code should be validated and re-copied to the `build`, triggering `watch:build`
js:
files: '<%= CLIENT_DIR + JS_FILES %>'
tasks: [ 'copy:js', 'jshint' ]
# Changes to app styles should re-compile, triggering `watch:build`
less:
files: '<%= CLIENT_DIR + LESS_FILES %>'
tasks: [ 'less' ]
# Changes to server-side code should validate, restart the server, & refresh the browser
server:
files: '<%= SERVER_DIR + ALL_FILES %>'
tasks: [ 'jshint', 'express' ]
# Changes to app templates should re-copy & re-compile them, triggering `watch:build`
templates:
files: '<%= CLIENT_DIR + HTML_FILES %>'
tasks: [ 'copy:templates', 'ngtemplates' ]
# Changes to app code should be validated and re-copied to the `build`, triggering `watch:build`
unit:
files: '<%= CLIENT_DIR + JS_FILES %>'
tasks: [ 'copy:js', 'jshint', 'karma:background:run' ]
# Dependencies
grunt.loadNpmTasks('grunt-angular-templates')
grunt.loadNpmTasks('grunt-contrib-clean')
grunt.loadNpmTasks('grunt-contrib-concat')
grunt.loadNpmTasks('grunt-contrib-copy')
grunt.loadNpmTasks('grunt-contrib-jshint')
grunt.loadNpmTasks('grunt-contrib-less')
grunt.loadNpmTasks('grunt-contrib-mincss')
grunt.loadNpmTasks('grunt-contrib-uglify')
grunt.loadNpmTasks('grunt-contrib-watch')
grunt.loadNpmTasks('grunt-express-server')
grunt.loadNpmTasks('grunt-karma')
grunt.loadNpmTasks('grunt-usemin')