-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gruntfile.js.example
475 lines (467 loc) · 14.7 KB
/
Gruntfile.js.example
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
'use strict';
module.exports = function (grunt) {
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
/*
* CONFIGURABLE PATHS AND VARIABLES
* NOTE: Also some values are defined directly in the grunt-replace tasks.
*/
var yeomanConfig = {
app: 'app',
dist: 'dist',
prod_url: '<url_for_prod_mip_backend>',
qa_url: '<url_for_qa_mip_backend>',
kehitys_url: '<url_for_kehitys_mip_backend>',
local_url: 'http://localhost:8000/api/'
};
try {
yeomanConfig.app = require('./bower.json').appPath || yeomanConfig.app;
} catch (e) {}
grunt.initConfig({
yeoman: yeomanConfig,
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'<%= yeoman.dist %>/*',
'!<%= yeoman.dist %>/.git*'
]
}]
},
removetemplate: {
files: [{
dot: true,
src: ['<%= yeoman.dist %>/app.templates.js']
}]
},
removehtml: {
files: [{
dot: true,
src: '<%= yeoman.dist %>/pages'
}]
},
server: '.tmp'
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'<%= yeoman.app %>//{,*/}*.js'
]
},
karma: {
unit: {
configFile: 'karma.conf.js',
singleRun: true
}
},
usemin: {
html: ['<%= yeoman.dist %>/{,*/}*.html'],
css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
options: {
dirs: ['<%= yeoman.dist %>']
}
},
htmlmin: {
dist: {
options: {
/*removeCommentsFromCDATA: true,
// https://github.com/yeoman/grunt-usemin/issues/44
//collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeOptionalTags: true*/
},
files: [{
expand: true,
cwd: '<%= yeoman.app %>',
src: ['*.html'],
dest: '<%= yeoman.dist %>'
}]
}
},
ngmin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.dist %>',
src: '*.js',
dest: '<%= yeoman.dist %>'
}]
}
},
useminPrepare: {
html: '<%= yeoman.app %>app/index.html',
options: {
dest: '<%= yeoman.dist %>'
}
},
rev: {
dist: {
files: {
src: [
'<%= yeoman.dist %>/**/*.js',
'!<%= yeoman.dist %>/lib/**',
'!<%= yeoman.dist %>/languages/*',
]
}
}
},
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: [
'**/*',
]
}]
},
lib: {
files: [{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: [
//'**/*.{js,css,png,jpg,html}'
//'*.{ico,txt}',
//'.htaccess',
'lib/bower_components/**/*',
//'resources/images/{,*/}*.{gif,webp}'
]
}]
}
},
replace: {
prod: {
options: {
patterns: [
{
match: '<%= yeoman.local_url %>',
replacement: '<%= yeoman.prod_url %>'
},
{
match: /'ORGANISATION'[:]\s(\'.*\')/g,
replacement: function () {
return "'ORGANISATION': 'Example Organisation'";
}
},
{
match: /'PROVINCE_NAME'[:]\s(\'.*\')/g,
replacement: function () {
return "'PROVINCE_NAME': 'Example Province'";
}
},
{
match: /'KYPPI_ADMIN_ORGANISATION_CODE'\s*[:]\s*(\d*)/g,
replacement: function () {
return "'KYPPI_ADMIN_ORGANISATION_CODE': 17";
}
},
{
match: /'DEFAULT_COORDINATES'\s*[:]\s*\[.*\]/g,
replacement: function () {
return "'DEFAULT_COORDINATES': [60.46, 22.68]";
}
},
{
match: /'DEFAULT_MAP_CENTER'\s*[:]\s*\[.*\]/g,
replacement: function () {
return "'DEFAULT_MAP_CENTER': [6709459.248768231831491, 237488.841283306537662]";
}
}
],
usePrefix : false
},
files: [{
expand: true,
flatten: true,
src: ['<%= yeoman.dist %>/app.js'],
dest: '<%= yeoman.dist %>'
}
]
},
qa: {
options: {
patterns: [
{
match: '<%= yeoman.local_url %>',
replacement: '<%= yeoman.qa_url %>'
},
{
match: /'ORGANISATION'[:]\s(\'.*\')/g,
replacement: function () {
return "'ORGANISATION': 'Example Organisation'";
}
},
{
match: /'PROVINCE_NAME'[:]\s(\'.*\')/g,
replacement: function () {
return "'PROVINCE_NAME': 'Example Province'";
}
},
{
match: /'KYPPI_ADMIN_ORGANISATION_CODE'\s*[:]\s*(\d*)/g,
replacement: function () {
return "'KYPPI_ADMIN_ORGANISATION_CODE': 17";
}
},
{
match: /'DEFAULT_COORDINATES'\s*[:]\s*\[.*\]/g,
replacement: function () {
return "'DEFAULT_COORDINATES': [60.46, 22.68]";
}
},
{
match: /'DEFAULT_MAP_CENTER'\s*[:]\s*\[.*\]/g,
replacement: function () {
return "'DEFAULT_MAP_CENTER': [6709459.248768231831491, 237488.841283306537662]";
}
}
],
usePrefix : false
},
files: [
{expand: true, flatten: true, src: ['<%= yeoman.dist %>/app.js'], dest: '<%= yeoman.dist %>'}
]
},
kehitys: {
options: {
patterns: [
{
match: '<%= yeoman.local_url %>',
replacement: '<%= yeoman.kehitys_url %>'
},
{
match: /'ORGANISATION'[:]\s(\'.*\')/g,
replacement: function () {
return "'ORGANISATION': 'Example Organisation'";
}
},
{
match: /'PROVINCE_NAME'[:]\s(\'.*\')/g,
replacement: function () {
return "'PROVINCE_NAME': 'Example Province'";
}
},
{
match: /'KYPPI_ADMIN_ORGANISATION_CODE'\s*[:]\s*(\d*)/g,
replacement: function () {
return "'KYPPI_ADMIN_ORGANISATION_CODE': 17";
}
},
{
match: /'DEFAULT_COORDINATES'\s*[:]\s*\[.*\]/g,
replacement: function () {
return "'DEFAULT_COORDINATES': [60.46, 22.68]";
}
},
{
match: /'DEFAULT_MAP_CENTER'\s*[:]\s*\[.*\]/g,
replacement: function () {
return "'DEFAULT_MAP_CENTER': [6709459.248768231831491, 237488.841283306537662]";
}
}
],
usePrefix : false
},
files: [
{expand: true, flatten: true, src: ['<%= yeoman.dist %>/app.js'], dest: '<%= yeoman.dist %>'}
]
},
translationsFi: {
options: {
patterns: [
{
match: /"Guest_user_info_content"[:]\s(\".*\")/g,
replacement: function () {
return "\"Guest_user_info_content\": \"Finnish: Guest info view (the view that opens for viewer after login) common text.\"";
}
}, {
match: /"Guest_user_info_content1"[:]\s(\".*\")/g,
replacement: function () {
return "\"Guest_user_info_content1\": \"Finnish: Guest info view (the view that opens for viewer after login) building inventory text.\"";
}
}, {
match: /"Guest_user_info_content2"[:]\s(\".*\")/g,
replacement: function () {
return "\"Guest_user_info_content2\": \"Finnish: Guest info view (the view that opens for viewer after login) archaeologic inventory text.\"";
}
}, {
match: /"Guest_user_info_content3"[:]\s(\".*\")/g,
replacement: function () {
return "\"Guest_user_info_content3\": \"Finnish: Guest info view (the view that opens for viewer after login) archaeologic collections text.\"";
}
}
],
usePrefix: false
},
files: [
{ expand: true, flatten: true, src: ['<%= yeoman.app %>/languages/fi-FI/common.lang.json'], dest: '<%= yeoman.dist %>/languages/fi-FI/' }
]
},
translationsSv: {
options: {
patterns: [
{
match: /"Guest_user_info_content"[:]\s(\".*\")/g,
replacement: function () {
return "\"Guest_user_info_content\": \"Swedish: Guest info view (the view that opens for viewer after login) common text.\"";
}
}, {
match: /"Guest_user_info_content1"[:]\s(\".*\")/g,
replacement: function () {
return "\"Guest_user_info_content1\": \"Swedish: Guest info view (the view that opens for viewer after login) building inventory text.\"";
}
}, {
match: /"Guest_user_info_content2"[:]\s(\".*\")/g,
replacement: function () {
return "\"Guest_user_info_content2\": \"Swedish: Guest info view (the view that opens for viewer after login) archaeologic inventory text.\"";
}
}, {
match: /"Guest_user_info_content3"[:]\s(\".*\")/g,
replacement: function () {
return "\"Guest_user_info_content3\": \"Swedish: Guest info view (the view that opens for viewer after login) archaeologic collections text.\"";
}
}
],
usePrefix: false
},
files: [
{ expand: true, flatten: true, src: ['<%= yeoman.app %>/languages/sv-FI/common.lang.json'], dest: '<%= yeoman.dist %>/languages/sv-FI/' }
]
},
translationsEn: {
options: {
patterns: [
{
match: /"Guest_user_info_content"[:]\s(\".*\")/g,
replacement: function () {
return "\"Guest_user_info_content\": \"English: Guest info view (the view that opens for viewer after login) common text.\"";
}
}, {
match: /"Guest_user_info_content1"[:]\s(\".*\")/g,
replacement: function () {
return "\"Guest_user_info_content1\": \"English: Guest info view (the view that opens for viewer after login) building inventory text.\"";
}
}, {
match: /"Guest_user_info_content2"[:]\s(\".*\")/g,
replacement: function () {
return "\"Guest_user_info_content2\": \"English: Guest info view (the view that opens for viewer after login) archaeologic inventory text.\"";
}
}, {
match: /"Guest_user_info_content3"[:]\s(\".*\")/g,
replacement: function () {
return "\"Guest_user_info_content3\": \"English: Guest info view (the view that opens for viewer after login) archaeologic collections text.\"";
}
}
],
usePrefix: false
},
files: [
{ expand: true, flatten: true, src: ['<%= yeoman.app %>/languages/en-US/common.lang.json'], dest: '<%= yeoman.dist %>/languages/en-US/' }
]
}
},
ngtemplates: {
mip: {
src: '<%= yeoman.app %>/**/**/*.{html,tpl.html}',
dest: '<%= yeoman.dist %>/app.templates.js',
options: {
url: function(url) {
return url.replace('app/', '');
}
}
}
},
concat: {
dist: {
src: [ '<%= yeoman.dist %>/app.js', 'dist/app.templates.js'],
dest: '<%= yeoman.dist %>/app.js'
}
},
uglify: {
js: { //target
files: [{
expand: true,
cwd: './dist/',
src: ['./**/*.js', './*.js', '!./**/lib/**'],
dest: './dist/',
ext: '.js'
}]
}
}
});
/*
* PRODUCTION BUILD
* replace method expects us to create the production build from the dev version (API_URL will not be replaced if it doesn't match the dev_url)
*/
grunt.registerTask('build', [
'clean:dist', //clean the dist folder
//'jshint', //check code quality
'useminPrepare', //required by rev
'copy:dist', //copy app to dist folder
'ngtemplates', //create angular templates of the html files
'concat', //concatenate the angular templates to the app.js
'clean:removetemplate', //remove the created template file (it's already concatenated)
'clean:removehtml', //remove the html files that were turned into angular templates
'replace:prod', // replace the API_URL and other variables in app.js with the production url
'replace:translationsFi', // replace the info texts shown to katselija after login
'replace:translationsSv', // replace the info texts shown to katselija after login
'replace:translationsEn', // replace the info texts shown to katselija after login
//'uglify:js', //uglify the files, each separately
'rev', //modify the .js file names
'usemin' //change the index.html to use the revved .js files
]);
/*
* QA BUILD
*/
grunt.registerTask('qa_build', [
'clean:dist',
//'jshint',
'useminPrepare',
'copy:dist',
'ngtemplates',
'concat',
'clean:removetemplate',
'clean:removehtml',
'replace:qa',
'replace:translationsFi',
'replace:translationsSv',
'replace:translationsEn',
//'uglify:js',
'rev',
'usemin'
]);
/*
* KEHITYS BUILD
*/
grunt.registerTask('kehitys_build', [
'clean:dist',
//'jshint',
'useminPrepare',
'copy:dist',
'ngtemplates',
'concat',
'clean:removetemplate',
'clean:removehtml',
'replace:kehitys',
'replace:translationsFi',
'replace:translationsSv',
'replace:translationsEn',
//'uglify:js',
'rev',
'usemin'
]);
grunt.registerTask('default', ['kehitys_build']);
};