-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
286 lines (264 loc) · 7.53 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
'use strict';
module.exports = function(grunt) {
// load grunt tasks based on dependencies in package.json
require('load-grunt-tasks')(grunt);
var help = function(){
grunt.log.writeln('use `grunt build:dev` to build to dist/dev folder');
grunt.log.writeln('use `grunt build:prod` to build to dist folder');
grunt.log.writeln('use `grunt connect:src|prod:keepalive` to launch a local static server');
grunt.log.writeln('use `grunt test:src|prod` to launch tests to src folder or production folder( nightwatch with chrome by default), use `grunt test:src|prod:gecko` to run within Firefox');
grunt.log.writeln('use `grunt spapp_generator:new --name=xxx to generate controller/view skeleton and html/css declaration ');
}
// Configurable paths for the application
var appConfig = {
app: 'src',
dist: 'dist',
distDev: 'dist/dev'
};
var folderToTest = function(){
var f = appConfig.app;
grunt.log.writeln('target:'+grunt.task.current.target);
if (grunt.task.current.args){
var arg = grunt.task.current.args[0];
if (arg==='dev'){
f = appConfig.distDev;
}else if(arg==='prod'){
f = appConfig.dist;
}
}
return f;
}
// Define the configuration for all the tasks
grunt.initConfig({
appConfig : appConfig,
connect: {
src: {
options: {
port: 8000,
base: {
path: '<%= appConfig.app %>',
options: {
index: 'index.html',
maxAge: 300000
}
}
}
},
prod: {
options: {
port: 8000,
base: {
path: '<%= appConfig.dist %>',
options: {
index: 'index.html',
maxAge: 300000
}
}
}
},
},
selenium_standalone: {
options: {
stopOnExit: true
},
default: {
seleniumVersion: '3.7.1',
seleniumDownloadURL: 'http://selenium-release.storage.googleapis.com',
drivers: {
chrome: {
version: '2.33',
arch: process.arch,
baseURL: 'http://chromedriver.storage.googleapis.com'
},
firefox: {
version: '0.19.1',
arch: process.arch,
baseURL: 'https://github.com/mozilla/geckodriver/releases/download',
}
}
}
} ,
nightwatch: {
options: {
"src_folders": [
"test/e2e"// Where you are storing your Nightwatch e2e tests
],
"output_folder": ".tmp/nightwatch/ttb/reports", // reports (test outcome) output by nightwatch
"test_settings": {
"default": {
"launch_url" : "http://localhost",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"screenshots": {
"enabled" : true,// if you want to keep screenshots
"on_failure" : true,
"on_error" : true,
"path" : ".tmp/nightwatch/ttb/screenshots" // save screenshots here //L.D: does not seems to work
},
"globals": {
"waitForConditionTimeout": 4000 // sometimes internet is slow so wait.
},
"desiredCapabilities": { // use Chrome as the default browser for tests
"browserName": "chrome"
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true // turn off to test progressive enhancement
}
},
"gecko": {
"desiredCapabilities": {
"browserName": "firefox",
"javascriptEnabled": true // turn off to test progressive enhancement
}
}
}
}
},
jshint: {
options: {
curly: true,
eqeqeq: true,
eqnull: true,
browser: true
},
all: ['Gruntfile.js', '<%= appConfig.app %>/**.js']
},
spapp_generator: {
src: '<%= appConfig.app %>/index.html',
dest:'<%= appConfig.dist %>/index.html',
options: {
basePath: '<%= appConfig.app %>',
js:'.tmp/spapp/spapp.js',
css:'.tmp/spapp/spapp.css'
}
},
// Reads HTML for usemin blocks to enable smart builds that automatically
// concat, minify and revision files. Creates configurations in memory so
// additional tasks can operate on them
useminPrepare: {
html: '<%= appConfig.app %>/index.html',
options: {
dest: '<%= appConfig.dist %>'
}
},
// Performs rewrites based on rev and the useminPrepare configuration
usemin: {
html: ['<%= appConfig.dist %>/index.html'],
options: {
assetsDirs: ['<%= appConfig.dist %>']
}
},
// Empties folders to start fresh
clean: {
dist: {
files: [{
dot: true,
src: [ '.tmp','<%= appConfig.dist %>/*','!<%= appConfig.dist %>/.git*','!<%= appConfig.dist %>/dev/**']
}]
},
dev:{
files: [{
dot: true,
src: [ '.tmp','<%= appConfig.dist %>/dev/*']
}]
},
tmp: '.tmp'
},
// Copies remaining files to places other tasks can use
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= appConfig.app %>',
dest: '<%= appConfig.dist %>',
src: ['*.{ico,png,txt}','images/{,*/}*.{webp}','fonts/*']
}]
},
dev: {
files: [{
expand: true,
dot: true,
cwd: '<%= appConfig.app %>',
dest: '<%= appConfig.dist %>/dev',
src: ['**/*']
}]
}
},
htmlmin: { // Task
dist: { // Target
options: { // Target options
removeComments: true,
collapseWhitespace: true
},
files: [{
expand: true,
cwd: '<%= appConfig.dist %>',
src: ['index.html'],
dest:'<%= appConfig.dist %>',
}]
}
},
//manifest generator
pkg: grunt.file.readJSON('package.json'),
manifest: {
generate: {
options: {
basePath: '',
cache: ['index.html'],
network: ['*'],
preferOnline: true,
headcomment: " <%= pkg.name %> v<%= pkg.version %>",
verbose: true,
timestamp: true,
hash: true,
process: function(path) {
return path.substring((appConfig.dist + '/').length);
}
},
src: [
'<%= appConfig.dist %>/scripts/*.js',
'<%= appConfig.dist %>/styles/*.css'
],
dest: '<%= appConfig.dist %>/manifest.appcache'
}
}
});
grunt.registerTask('build', ['build:dev']);
grunt.registerTask('build:prod', [
'clean:dist',
'copy:dist',
'spapp_generator:inline',
'useminPrepare',
'concat',
'uglify',
'cssmin',
'usemin',
'htmlmin:dist',
'manifest',
'test:prod',
'clean:tmp'
]);
grunt.registerTask('build:dev', [
'clean:dev',
'copy:dev'
]);
grunt.registerTask('test', function(arg1, arg2) {
if (arg1 == null) {
arg1 = 'src';
}
if(arg2==null){
arg2 = 'chrome';
}
grunt.task.run('selenium_standalone:default:install',
'connect:' + arg1,
'selenium_standalone:default:start',
'nightwatch:' + arg2,
'selenium_standalone:default:stop');
});
grunt.registerTask('help', help);
grunt.registerTask('default', help);
};