-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGruntFile.js
More file actions
328 lines (298 loc) · 10.5 KB
/
GruntFile.js
File metadata and controls
328 lines (298 loc) · 10.5 KB
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
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
module.exports = function (grunt) {
//import modules
grunt.loadNpmTasks('grunt-contrib-watch');
// grunt.loadNpmTasks('grunt-contrib-connect');
// grunt.loadNpmTasks('grunt-open');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-jquery-builder');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-server-mocha');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-html-snapshot');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
timeout: {
app: 'app',
dev: '../web/dev',
dist: '../web/',
tests: 'tests'
},
dist: {
options: {
base: '<%= timeout.dist %>'
}
},
clean: {
options: { force: true },
all: ["<%= timeout.dev %>", "<%= timeout.dist %>/css", "<%= timeout.dist %>/js", "cache"],
dev: ["<%= timeout.dev %>"],
dist: ["<%= timeout.dist %>/css", "<%= timeout.dist %>/js"],
cache: ["cache"]
},
//Setup a server for testing and preview
/* connect: {
server: {
options: {
port: 8080,
base: './',
livereload: 35729
}
}
},*/
jquery: {
dev: {
options: {
prefix: "jquery-"
},
output: "<%= timeout.dev %>/js/core",
versions: {
"1.9.0": [], //works negatively // 'ajax' , 'effects' etc
}
}
},
concat: {
options: {
separator: ';\n',
},
dist: {
src: ['<%= timeout.dev %>/js/core/**/*.js'],
dest: '<%= timeout.dist %>/js/core.js',
}
},
uglify: {
core: {
files: {
'<%= timeout.dist %>/js/core.min.js': ['<%= timeout.dist %>/js/core.js']
}
}
},
//Compile less
less: {
base: {
options: {
paths: ['<%= timeout.app %>/less']
},
files: {
'<%= timeout.dev %>/css/timeout.css' : '<%= timeout.app %>/less/timeout.less'
}
}
},
cssmin: {
minify: {
expand: true,
cwd: '<%= timeout.dev %>/css/',
src: ['*.css', '!*.min.css'],
dest: '<%= timeout.dist %>/css/',
ext: '.min.css'
}
},
//watch files for changes// Watch is a blocking task, no other task is running while this one is running.
watch: {
less: {
options: { livereload: true },
files: ['<%= timeout.app %>/less/**/*.less' ],
tasks: ['less']
},
js : {
options: { livereload: true },
files: ['<%= timeout.app %>/js/**/*.js' ],
tasks: ['copy:js_core', 'uglify']
},
/* jshint : {
files: ['<%= jshint.files %>'],
tasks: ['jshint']
},*/
tests: { // On Javascript Change run tests
options: { livereload: true },
files: '<%= timeout.tests %>/**/*.js',
tasks: ['mocha-server']
},
gruntfile: {
options: { livereload: true },
files: ['GruntFile.js']
},
templates: {
options: { livereload: true },
files: ['<%= timeout.app %>/**/*.html' ],
tasks: ['copy']
}
},
//open browser to this address, probably v4.d/index
/* open: {
dev: {
path: 'http://localhost:8080/dev/'
}
},*/
copy: {
index: {
src: '<%= timeout.app %>/index.html',
dest: '<%= timeout.dev %>/index.html',
filter: 'isFile'
},
templates: {
expand: true,
src: '<%= timeout.app %>/templates/*',
dest: '<%= timeout.dev %>/templates',
filter: 'isFile',
flatten: true
},
snapshots: {
expand: true,
src: '<%= timeout.app %>/snapshots/*',
dest: '<%= timeout.dev %>/snapshots',
filter: 'isFile',
flatten: true
},
js_core: {
expand: true,
src: '<%= timeout.app %>/js/core/**/*.js',
dest: '<%= timeout.dev %>/js/core/',
filter: 'isFile',
flatten: true
}
},
jshint: {
files: ['Gruntfile.js', '<%= timeout.dev %>/js/**/*.js', '<%= timeout.dist %>/js/**/*.js'],
options: {
// options here to override JSHint defaults
globals: {
jQuery: true,
console: true,
module: true,
document: true
}
}
},
//Tests
"mocha-server": {
test: {
src: 'tests/*.js',
options: {
ui: 'tdd',
growl: true,
reporter: 'nyan',
},
},
},
htmlSnapshot: {
all: {
options: {
//that's the path where the snapshots should be placed
//it's empty by default which means they will go into the directory
//where your Gruntfile.js is placed
snapshotPath: '<%= timeout.app %>/snapshots/',
//This should be either the base path to your index.html file
//or your base URL. Currently the task does not use it's own
//webserver. So if your site needs a webserver to be fully
//functional configure it here.
sitePath: 'http://www.timeout.com/london',
//you can choose a prefix for your snapshots
//by default it's 'snapshot_'
fileNamePrefix: 'sp_',
//by default the task waits 500ms before fetching the html.
//this is to give the page enough time to to assemble itself.
//if your page needs more time, tweak here.
msWaitForPages: 1000,
//sanitize function to be used for filenames. Converts '#!/' to '_' as default
//has a filename argument, must have a return that is a sanitized string
sanitize: function (requestUri) {
//returns 'index.html' if the url is '/', otherwise a prefix
if (/\//.test(requestUri)) {
return 'index.html';
} else {
return requestUri.replace(/\//g, 'prefix-');
}
},
//if you would rather not keep the script tags in the html snapshots
//set `removeScripts` to true. It's false by default
removeScripts: false,
//set `removeLinkTags` to true. It's false by default
removeLinkTags: false,
//set `removeMetaTags` to true. It's false by default
removeMetaTags: false,
//Replace arbitrary parts of the html
replaceStrings:[
{'this': 'will get replaced by this'},
{'/old/path/': '/new/path'}
],
// allow to add a custom attribute to the body
bodyAttr: 'data-prerendered',
//here goes the list of all urls that should be fetched
urls: [
'',
'#!/en-gb/showcase'
],
// a list of cookies to be put into the phantomjs cookies jar for the visited page
cookies: [
{"path": "/", "domain": "localhost", "name": "lang", "value": "en-gb"}
]
}
}
}
});
/*
grunt.registerTask('customBuild_jquery', function () {
var done = this.async();
grunt.util.spawn({
grunt: true,
args: [''], //works negatively // 'ajax' , 'effects' etc
opts: {
cwd: 'app/js/core/jquery'
}
}, function (err, result, code) {
grunt.log.warn('A custom jquery version has been built.');
done();
});
});
*/
grunt.registerTask('test', function () {
grunt.task.run(['mocha-server']);
});
grunt.registerTask('build', function () {
grunt.task.run([
'clean',
'mocha-server',
'less',
'cssmin',
'copy',
'jquery',
// 'jshint',
'concat',
'uglify'
]);
});
grunt.registerTask('snapshot', function () {
grunt.task.run(['htmlSnapshot', 'copy:snapshots']);
});
//Register all Tasks you need to run
grunt.registerTask('serve', function () {
grunt.log.warn('Grunt will now open a browser and will watch your TypeScript and Less files for changes.');
grunt.task.run([
'build',
//'connect',
//'open',
'watch' //watch is a blocking action, should run at the end
]);
});
grunt.registerTask('server', function () {
grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
grunt.task.run(['serve']);
});
grunt.registerTask('default', function () {
grunt.task.run(['serve']);
});
}
/// TODO Add Chai and improve the testing framework
/// Sources:
/// https://github.com/pghalliday/grunt-mocha-test
/// http://visionmedia.github.io/mocha/
/// https://www.npmjs.org/package/grunt-server-mocha