-
Notifications
You must be signed in to change notification settings - Fork 18
/
gruntfile.js
113 lines (101 loc) · 3.72 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
module.exports = function (grunt) {
var ENV = process.env.NODE_ENV || 'devel';
var version = grunt.file.readJSON('package.json').version;
console.log('Running grunt for environment: ' + ENV+ ' version: ' + version);
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
all: {
src: [ './public/app/app.js',
'./public/app/services/**/*.js',
'./public/app/controllers/**/*.js',
'./public/app/directives/**/*.js',
'./public/app/filters/**/*.js',
'!./public/app/**/*_test.js'
],
dest: 'public-html/' + ENV + '/app/app-'+ version +'.min.js'
}
},
copy:{
resources: {
expand: true,
cwd: 'public/',
src: [
'app/lib/**',
'css/**',
'fonts/**',
'images/**',
'i18n/**',
'favicon.ico',
'bower_components/**',
'lib/xlsx.full.min.js'
],
dest: 'public-html/' + ENV
},
html:{
expand: true,
cwd: 'public/',
src: ['**/*.html'],
dest: 'public-html/' + ENV,
options: {
process: function (content, srcpath) {
if (process.env.GOOGLE_MAP_APIKEY) {
var mapsRegex = /\/\/maps\.googleapis\.com\/maps\/api\/js/;
if (mapsRegex.test(content)) {
content = content.replace(mapsRegex,
'//maps.googleapis.com/maps/api/js?key=' +
process.env.GOOGLE_MAP_APIKEY);
}
}
if(/\.html$/.test(srcpath)) {
var regex = /<!-- JS-start -->[\s\S.]*<!-- JS-end -->/;
if (regex.test(content)) {
console.log('Replace JS scripts in: ' + srcpath);
}
else {
//console.log('Not found in: ' + srcpath);
return content;
}
return content.replace(regex,
'<script src="/app/app-'+version+'.min.js"></script>');
}
else {
return content;
}
}
}
},
all:{
expand: true,
cwd: 'public/',
src: ['**/*.*'],
dest: 'public-html/' + ENV,
options: {
}
}
},
clean: {
env: ["public-html/" + ENV],
all: ["public-html/"]
},
mochaTest: {
test: {
// Ttest settings
},
coverage: {
options: {
reporter: 'html-cov',
quiet: false
},
src: ['test/*.js']
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.registerTask('release', ['clean:env', 'copy:resources', 'uglify', 'copy:html']);
grunt.registerTask('devel', ['clean:env', 'copy:all']);
};