-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
346 lines (322 loc) · 8.73 KB
/
Gruntfile.js
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
'use strict';
var path = require('path');
var folderMount = function folderMount(connect, point) {
return connect.static(path.resolve(point));
};
module.exports = function (grunt) {
// load all grunt tasks
require('load-grunt-tasks')(grunt);
// Project configuration.
grunt.initConfig({
connect: {
main: {
options: {
port: 9001,
//base: 'dist'
middleware: function(connect, options) {
return [folderMount(connect, options.base)]
}
}
}
},
watch: {
main: {
options: {
livereload: true,
spawn: false
},
files: ['js/**/*','css/**/*','img/**/*','partial/**/*','service/**/*','filter/**/*','directive/**/*','index.html'],
tasks: [] //all the tasks are run dynamically during the watch event handler
}
},
jshint: {
main: {
options: {
jshintrc: '.jshintrc'
},
src: ['js/**/*.js','partial/**/*.js','service/**/*.js','filter/**/*.js','directive/**/*.js']
}
},
clean: {
before:{
src:['dist','temp']
},
after: {
src:['temp']
}
},
/*
less: {
production: {
options: {
},
files: {
"temp/app.css": "css/app.less"
}
}
},
*/
ngtemplates: {
main: {
options: {
module:'adaperio',
htmlmin: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
}
},
src: [ 'partial/**/*.html','directive/**/*.html' ],
dest: 'temp/templates.js'
}
},
copy: {
main: {
files: [
{src: ['*.html'], dest: 'dist/'},
{src: ['package.json'], dest: 'dist/version'},
{src: ['bower_components/**'], dest: 'dist/'},
{src: ['pic/**'], dest: 'dist/'},
{src: ['doc/**'], dest: 'dist/'},
{src: ['fonts/**'], dest: 'dist/'},
// This is original lines
//{src: ['bower_components/angular-ui-utils/ui-utils-ieshiv.min.js'], dest: 'dist/'},
//{src: ['bower_components/font-awesome/fonts/**'], dest: 'dist/',filter:'isFile',expand:true}
]
},
css:{
// this is called only when quick target is built
files: [
{
expand: true,
src: ['css/**'],
dest: 'dist/',
},
{
expand: true,
src: ['css/app.css'],
dest: 'dist/',
rename: function(dest, src) {
return 'dist/css/app.full.min.css';
}
}
]
},
js:{
files: [
{src: ['js/**'], dest: 'dist/'},
{src: ['lib/**'], dest: 'dist/'},
]
}
},
dom_munger:{
readscripts: {
options: {
read:{selector:'script[data-build!="exclude"]',attribute:'src',writeto:'appjs'}
},
src:'index.html'
},
readcss: {
options: {
read:{selector:'link[rel="stylesheet"]',attribute:'href',writeto:'appcss'}
},
src:'index.html'
},
removescripts: {
options:{
remove:'script[data-remove!="exclude"]',
append:{selector:'head',html:'<script src="app.full.min.js"></script>'}
},
src:'dist/index.html'
},
addscript: {
options:{
append:{selector:'body',html:'<script src="app.full.min.js"></script>'}
},
src:'dist/index.html'
},
addanalytics: {
options:{
append:{selector:'body',html:'<script src="js/analytics.js"></script>'}
},
src:'dist/index.html'
},
addfavicon: {
options:{
append:{selector:'head',html:'<link rel="icon" href="pic/favicon.ico" type="image/x-icon" />'}
},
src:'dist/index.html'
},
removecss: {
options:{
remove:'link',
append:{selector:'head',html:'<link rel="stylesheet" href="css/app.full.min.css">'}
},
src:'dist/index.html'
},
addcss: {
options:{
append:{selector:'head',html:'<link rel="stylesheet" href="css/app.full.min.css">'}
},
src:'dist/index.html'
}
},
cssmin: {
main: {
src:['css/app.css','<%= dom_munger.data.appcss %>'],
dest:'dist/css/app.full.min.css'
}
},
concat: {
main: {
src: ['<%= dom_munger.data.appjs %>','<%= ngtemplates.main.dest %>'],
dest: 'temp/app.full.js'
}
},
ngmin: {
main: {
src:'temp/app.full.js',
dest: 'temp/app.full.js'
}
},
uglify: {
main: {
src: 'temp/app.full.js',
dest:'dist/app.full.min.js'
}
},
htmlmin: {
main: {
options: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
},
files: {
'dist/index.html': 'dist/index.html'
}
}
},
imagemin: {
main:{
files: [{
expand: true, cwd:'dist/',
src:['**/{*.png,*.jpg}'],
dest: 'dist/'
}]
}
},
jasmine: {
unit: {
src: ['<%= dom_munger.data.appjs %>','bower_components/angular-mocks/angular-mocks.js'],
options: {
keepRunner: true,
specs: ['js/**/*-spec.js','partial/**/*-spec.js','service/**/*-spec.js','filter/**/*-spec.js','directive/**/*-spec.js']
}
}
},
shell: {
bumpVersion: {
command: 'npm version patch',
options:
{
failOnError: true,
}
},
deployToServer: {
//command: 'scp -i ~/.ssh/machome_nuakko.pem -r dist/* ec2-user@adaperio.com:/var/www/html',
command: 'rsync -avz -e "ssh -i /Users/tonykent/.ssh/adaperio_large.pem" --progress dist/* ubuntu@api.adaperio.ru:/var/www/',
options:
{
failOnError: true
}
}
}
});
// Non-optimized web-site
grunt.registerTask('build',[
'clean:before',
//'less',
'dom_munger:readcss',
'dom_munger:readscripts',
'ngtemplates',
'cssmin',
//'concat',
//'ngmin',
//'uglify',
'copy',
'copy:css',
'copy:js',
'dom_munger:removecss',
'dom_munger:addcss',
//'dom_munger:removescripts',
//'dom_munger:addscript',
//'dom_munger:addanalytics',
'dom_munger:addfavicon',
'clean:after']);
// Optmized web site (good for deployment)
grunt.registerTask('release',[
'jshint',
'clean:before',
//'less',
'dom_munger:readcss',
'dom_munger:readscripts',
'ngtemplates',
'cssmin',
'concat',
'ngmin',
'uglify',
'copy',
'copy:css',
'copy:js',
'dom_munger:removecss',
'dom_munger:addcss',
'dom_munger:removescripts',
'dom_munger:addscript',
//'dom_munger:addanalytics',
'dom_munger:addfavicon',
'htmlmin',
'imagemin',
'clean:after']);
grunt.registerTask('server', ['dom_munger:readscripts','jshint','connect', 'watch']);
grunt.registerTask('test',['dom_munger:readscripts','jasmine']);
grunt.registerTask('deploy', [
'clean',
//'shell:bumpVersion', // this requires everything to be commited
'build', //'release'
'shell:deployToServer'
]);
grunt.event.on('watch', function(action, filepath) {
//https://github.com/gruntjs/grunt-contrib-watch/issues/156
if (filepath.lastIndexOf('.js') !== -1 && filepath.lastIndexOf('.js') === filepath.length - 3) {
//lint the changed js file
grunt.config('jshint.main.src', filepath);
grunt.task.run('jshint');
//find the appropriate unit test for the changed file
var spec = filepath;
if (filepath.lastIndexOf('-spec.js') === -1 || filepath.lastIndexOf('-spec.js') !== filepath.length - 8) {
var spec = filepath.substring(0,filepath.length - 3) + '-spec.js';
}
//if the spec exists then lets run it
if (grunt.file.exists(spec)) {
grunt.config('jasmine.unit.options.specs',spec);
grunt.task.run('jasmine:unit');
}
}
//if index.html changed, we need to reread the <script> tags so our next run of jasmine
//will have the correct environment
if (filepath === 'index.html') {
grunt.task.run('dom_munger:readscripts');
}
});
};