forked from trycom/parse-angular-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.coffee
251 lines (208 loc) · 7.95 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
module.exports = (grunt)->
# Run `grunt server` for live-reloading development environment
grunt.registerTask('server', [ 'build', 'karma:background', 'express', 'watch' ])
# Run `grunt test` (used by `npm test`) for continuous integration (e.g. Travis)
grunt.registerTask('test', [ 'build', 'karma:unit' ])
# Run `grunt test:browsers` for real-world browser testing
grunt.registerTask('test:browsers', [ 'karma:browsers', 'server' ])
# Clean, validate & compile web-accessible resources
grunt.registerTask('build', [ 'clean', 'copy', 'ngtemplates', 'compass:prod' ])
# Optimize pre-built, web-accessible resources for production, primarily `usemin`
grunt.registerTask('optimize', [ 'useminPrepare', 'concat', 'ngmin', 'replace:dist', 'uglify', 'compass:prod', 'mincss', 'rev', 'usemin' ])
grunt.registerTask('prod', ['build', 'optimize']);
# Configuration
grunt.config.init
# Directory CONSTANTS (see what I did there?)
BUILD_DIR: 'build/'
CLIENT_DIR: 'client/'
COMPONENTS_DIR: 'components/'
SERVER_DIR: 'server/'
# Glob CONSTANTS
ALL_FILES: '**/*'
CSS_FILES: '**/*.css'
HTML_FILES: '{app/scripts/modules/directives,app/views}/**/*.html'
IMG_FILES: '**/*.{png,gif,jpg,jpeg}'
JS_FILES: '**/*.js'
SASS_FILES: '**/*.scss'
# Wipe the `build` directory
clean:
build: '<%= BUILD_DIR %>'
copy:
# App images from Bower `components` & `client`
images:
files: [
expand: true,
cwd: '<%= COMPONENTS_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 components HTTP-accessible
components:
files:
'<%= BUILD_DIR %>': '<%= COMPONENTS_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 %>'
# ]
# Validate app `client` and `server` JS
jshint:
# files: [ '<%= SERVER_DIR + JS_FILES %>'
# '<%= CLIENT_DIR + JS_FILES %>' ]
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
browsers:
browsers: [ 'PhantomJS' ] # 'Chrome', 'ChromeCanary', 'Firefox', 'Opera', 'Safari', 'IE', 'bin/browsers.sh'
background: true
singleRun: false
# Used for one-time validation (e.g. `grunt test`, `npm test`)
unit:
singleRun: true
compass:
prod:
# http://compass-style.org/help/tutorials/configuration-reference/#configuration-properties
options:
sassDir: '<%= CLIENT_DIR %>/app/styles',
cssDir: '<%= BUILD_DIR %>/app/styles'
# Minify app `.css` resources -> `.min.css`
mincss:
app:
expand: true
cwd: '<%= BUILD_DIR %>'
src: '<%= BUILD_DIR %>/app/styles/*.css'
dest: '<%= BUILD_DIR %>'
ext: '.min.css'
ngmin:
files:
src: '<%= BUILD_DIR %>/app/scripts/all.min.js'
dest: '<%= BUILD_DIR %>/app/scripts/all.min.js'
# Ability to run `jshint` without errors terminating the development server
parallel:
compass: [ grunt: true, args: [ 'compass' ] ]
jshint: [ grunt: true, args: [ 'jshint' ] ]
# "watch" distinct types of files and re-prepare accordingly
watch:
# Any public-facing changes should reload the browser & re-run tests (which may depend on those resources)
build:
files: '<%= BUILD_DIR + ALL_FILES %>'
tasks: [ 'karma:background:run' ]
# Changes to app code should be validated and re-copied to the `build`, triggering `regarde:build`
js:
files: '<%= CLIENT_DIR + JS_FILES %>'
tasks: [ 'copy:js', 'parallel:jshint' ]
compass:
files: '<%= CLIENT_DIR + SASS_FILES %>'
tasks: [ 'compass' ]
# Changes to server-side code should validate, restart the server, & refresh the browser
server:
files: '<%= SERVER_DIR + ALL_FILES %>'
tasks: [ 'parallel:jshint', 'express' ]
# Changes to app templates should re-run ngtemplates
templates:
files: '<%= CLIENT_DIR + HTML_FILES %>'
tasks: [ 'ngtemplates' ]
# Custom watch options
options:
spawn: false
livereload: true
# Express requires `server.script` to reload from changes
express:
server:
options:
script: '<%= SERVER_DIR %>/server.js'
# Prepend a hash on file names for versioning
rev:
files:
src: ['<%= BUILD_DIR %>/app/scripts/all.min.js','<%= BUILD_DIR %>/app/styles/app.min.css']
# Output for optimized app index
usemin:
html: '<%= BUILD_DIR %>/index.html'
# Input for optimized app index
useminPrepare:
html: '<%= BUILD_DIR %>/index.html'
# Convert Angular `.html` templates to `.js` in the `app` module
ngtemplates:
app: # Replace this by your angular module name (here it is defined in app/scripts/app.js)
src: '<%= HTML_FILES %>'
dest: '<%= BUILD_DIR %>app/scripts/app.templates.js'
cwd: '<%= CLIENT_DIR %>'
options:
htmlmin:
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true, # Only if you don't use comment directives!
removeEmptyAttributes: true,
removeRedundantAttributes: true
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
# Replace references to minified versions when building the project for a dist version
replace:
dist:
src: ['<%= BUILD_DIR %>/index.html']
dest: '<%= BUILD_DIR %>/index.html'
replacements: [
from:'parse-1.2.15.js'
to:'parse-1.2.15.min.js'
,
from:'jquery.js'
to:'jquery.min.js'
,
from:'/angular.js'
to: '/angular.min.js'
,
from:'/angular-animate.js'
to: '/angular-animate.min.js'
]
# Dependencies
grunt.loadNpmTasks('grunt-ngmin')
grunt.loadNpmTasks('grunt-contrib-clean')
grunt.loadNpmTasks('grunt-contrib-concat')
grunt.loadNpmTasks('grunt-contrib-copy')
grunt.loadNpmTasks('grunt-contrib-jshint')
grunt.loadNpmTasks('grunt-contrib-compass')
grunt.loadNpmTasks('grunt-contrib-mincss')
grunt.loadNpmTasks('grunt-contrib-uglify')
grunt.loadNpmTasks('grunt-express-server')
grunt.loadNpmTasks('grunt-karma')
grunt.loadNpmTasks('grunt-contrib-watch')
grunt.loadNpmTasks('grunt-parallel')
grunt.loadNpmTasks('grunt-usemin')
grunt.loadNpmTasks('grunt-rev')
grunt.loadNpmTasks('grunt-angular-templates')
grunt.loadNpmTasks('grunt-text-replace')