-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
executable file
·227 lines (210 loc) · 6.47 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
/*jslint node: true */
//Using exclusion patterns slows down Grunt significantly
//instead of creating a set of patterns like '**/*.js' and '!**/node_modules/**'
//this method is used to create a set of inclusive patterns for all subdirectories
//skipping node_modules, bower_components, dist, and any .dirs
//This enables users to create any directory structure they desire.
var gmapSource = '<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>';
var createFolderGlobs = function(fileTypePatterns) {
fileTypePatterns = Array.isArray(fileTypePatterns) ? fileTypePatterns : [fileTypePatterns];
var ignore = ['node_modules','bower_components','dist','temp','www', 'hooks','merges','pg', 'platforms', 'plugins'];
var fs = require('fs');
return fs.readdirSync(process.cwd())
.map(function(file){
if (ignore.indexOf(file) !== -1 ||
file.indexOf('.') === 0 ||
!fs.lstatSync(file).isDirectory()) {
return null;
} else {
return fileTypePatterns.map(function(pattern) {
return file + '/**/' + pattern;
});
}
})
.filter(function(patterns){
return patterns;
})
.concat(fileTypePatterns);
};
module.exports = function (grunt) {
// load all grunt tasks
require('load-grunt-tasks')(grunt);
// Project configuration.
grunt.initConfig({
connect: {
main: {
options: {
port: 9001
}
}
},
watch: {
main: {
options: {
livereload: true,
spawn: false
},
files: [createFolderGlobs(['*.js','*.less','*.html']),'!_SpecRunner.html','!.grunt'],
tasks: [] //all the tasks are run dynamically during the watch event handler
}
},
jshint: {
main: {
options: {
jshintrc: '.jshintrc'
},
src: createFolderGlobs('*.js')
}
},
clean: {
before:{
src:['www','temp']
},
after: {
src:['temp']
}
},
less: {
production: {
options: {
},
files: {
'temp/app.css': 'app.less'
}
}
},
ngtemplates: {
main: {
options: {
module:'ecoposApp',
htmlmin:'<%= htmlmin.main.options %>'
},
src: [createFolderGlobs('*.html'),'!index.html','!_SpecRunner.html'],
dest: 'temp/templates.js'
}
},
copy: {
main: {
files: [
{src: ['img/**'], dest: 'www/'},
{src: ['config.xml'], dest: 'www/'},
{src: ['bower_components/font-awesome/fonts/**'], dest: 'www/',filter:'isFile',expand:true}
//{src: ['bower_components/angular-ui-utils/ui-utils-ieshiv.min.js'], dest: 'www/'},
//{src: ['bower_components/select2/*.png','bower_components/select2/*.gif'], dest:'www/css/',flatten:true,expand:true},
//{src: ['bower_components/angular-mocks/angular-mocks.js'], dest: 'www/'}
]
}
},
dom_munger:{
read: {
options: {
read:[
{selector:'script[data-build!="exclude"]',attribute:'src',writeto:'appjs'},
{selector:'link[rel="stylesheet"]',attribute:'href',writeto:'appcss'}
]
},
src: 'index.html'
},
update: {
options: {
remove: ['script[data-remove!="exclude"]','link'],
append: [
{selector:'body',html:'<script src="app.full.min.js"></script>'},
{selector:'head',html:'<link rel="stylesheet" href="app.full.min.css">'},
{selector:'head',html:gmapSource}
]
},
src:'index.html',
dest: 'www/index.html'
}
},
cssmin: {
main: {
src:['temp/app.css','<%= dom_munger.data.appcss %>'],
dest:'www/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: 'www/app.full.min.js'
}
},
uglify: {
options: {
mangle: false
},
main: {
src: 'temp/app.full.js',
dest:'www/app.full.min.js'
}
},
htmlmin: {
main: {
options: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
},
files: {
'www/index.html': 'www/index.html'
}
}
},
imagemin: {
main:{
files: [{
expand: true, cwd:'www/',
src:['app/images/{*.png,*.jpg}'],
dest: 'www/assets/images'
}]
}
},
jasmine: {
unit: {
src: ['<%= dom_munger.data.appjs %>','bower_components/angular-mocks/angular-mocks.js'],
options: {
keepRunner: false,
specs: createFolderGlobs('*-spec.js')
}
}
}
});
grunt.registerTask('build',['jshint','clean:before','less','dom_munger','ngtemplates','cssmin','concat','ngmin','copy','htmlmin','imagemin','clean:after']);
grunt.registerTask('server', ['dom_munger:read','jshint','connect', 'watch']);
grunt.registerTask('test',['dom_munger:read','jasmine']);
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) {
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:read');
}
});
};