This repository has been archived by the owner on Feb 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
369 lines (360 loc) · 7.46 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
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
/* Gruntfile.js */
module.exports = function (grunt)
{
// Load all grunt tasks and pluginsautomatically
require('load-grunt-tasks')(grunt);
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
// Project configuration.
grunt.initConfig(
{
pkg: grunt.file.readJSON('package.json'),
express: {
options: {
},
dist: {
options: {
script: 'backend/server.js',
debug: false,
node_env: 'dist'
}
},
dev: {
options: {
script: 'backend/server.js',
debug: true,
node_env: 'dev'
}
}
},
//used to setup jshint for use in IDE's like Sublime and validate with display in terminal command
jshint:
{
files: ['Gruntfile.js', 'frontend/app.js', 'frontend/constants/*.js', 'frontend/controllers/**/*.js',
'frontend/directives/**/*.js', 'frontend/filters/**/*.js', 'frontend/services/**/*.js'
],
options:
{
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
browser: true,
globals:
{
// AMD
module: true,
require: false,
requirejs: false,
define: true,
// Environments
console: true,
// General Purpose Libraries
$: true,
jQuery: true,
// Testing
sinon: true,
describe: true,
it: true,
expect: true,
beforeEach: true,
afterEach: true
}
}
},
//sass will compile scss to css
sass:
{
dist: //run distribution version of sass with compression and copy to dist/css filder
{
options:
{
style: 'compressed',
debugInfo: false
},
expand: true,
cwd: 'frontend/sass/',
src: ['*.scss'],
dest: 'dist/css/',
ext: '.css'
},
dev: //run dev version of sass for expanded, sourcemaps and copy to css folder
{
options:
{
style: 'expanded',
debugInfo: false,
sourcemap: true,
//require: ['./app/styles/sass/helpers/url64.rb']
},
expand: true,
cwd: 'frontend/sass/',
src: ['*.scss'],
dest: 'frontend/css/',
ext: '.css'
}
},
//make js pretty by implementing certain code-standards
jsbeautifier:
{
files: ['frontend/*.js', 'frontend/**/*.js', '!frontend/vendor/*'],
options:
{
js:
{
breakChainedMethods: true,
indentWithTabs: true,
jslintHappy: true,
brace_style: "expand",
wrap_line_length: 0
}
}
},
//make files ugly by compressing and minifying them for speed and optimalisation
uglify:
{
min:
{
options:
{
compress:
{
drop_console: true
},
mangle:
{
except: ['jQuery', 'Angular']
}
},
files: [
{
src: [
"frontend/app.js",
"frontend/constants/*.js",
"frontend/controllers/*.js",
"frontend/directives/*.js",
"frontend/filters/*.js",
"frontend/services/*.js"
],
dest: "dist/js/app.js"
}]
}
},
//remove everything in dist folder to start fresh
clean:
{
build:
{
src: ["build"]
},
dist:
{
src: ["dist"]
}
},
//run copy task to create all needed files in dist folder
//will copy images, locales, partials and vendors and changes index-dist to index.html inside dist folder
copy:
{
build:
{
files: [
{
cwd: 'frontend/',
expand: true,
src: ['img/**'],
dest: 'dist/'
},
{
cwd: 'frontend/',
expand: true,
src: ['partials/**'],
dest: 'dist/'
},
{
cwd: 'frontend/',
expand: true,
src: ['vendor/**'],
dest: 'dist/'
},
{
cwd: 'frontend/',
expand: true,
src: ['font/**'],
dest: 'dist/'
},
{
cwd: 'frontend/',
expand: true,
src: ['taunts/**'],
dest: 'dist/'
},
{
cwd: 'frontend/',
expand: true,
src: ['server.js'],
dest: 'dist/'
},
{
expand: true,
src: ['dist-package.json'],
dest: 'dist/',
rename: function (dest, src)
{
return dest + src.replace('dist-package', 'package');
}
},
{
cwd: 'frontend/',
expand: true,
src: ['index-dist.html'],
dest: 'dist/',
rename: function (dest, src)
{
return dest + src.replace('index-dist', 'index');
}
}]
},
dist:
{
files: [
{
cwd: 'frontend/',
expand: true,
src: ['img/**'],
dest: 'dist/'
},
{
cwd: 'frontend/',
expand: true,
src: ['partials/**'],
dest: 'dist/'
},
{
cwd: 'frontend/',
expand: true,
src: ['vendor/**'],
dest: 'dist/'
},
{
cwd: 'frontend/',
expand: true,
src: ['node_modules/**'],
dest: 'dist/'
},
{
cwd: 'frontend/',
expand: true,
src: ['font/**'],
dest: 'dist/'
},
{
cwd: 'frontend/',
expand: true,
src: ['taunts/**'],
dest: 'dist/'
},
{
cwd: 'frontend/',
expand: true,
src: ['index-dist.html'],
dest: 'dist/',
rename: function (dest, src)
{
return dest + src.replace('index-dist', 'index');
}
}]
}
},
// Run: 'grunt watch' from command line for this section to take effect
watch:
{
options: {
livereload: 8080
},
frontend: {
files: ['frontend/*.js', 'frontend/**/*.js', 'frontend/*/*.json', 'frontend/*.html', 'frontend/**/*.html',
'!frontend/vendor/*', '!frontend/node_modules/*', '!dist/*', '!dist/**/*'
],
tasks: ['jsbeautifier']
},
sass: {
files: ['frontend/sass/**/*.scss'],
tasks: ['sass:dev']
},
express: {
files: ['backend/**/*.js', 'Gruntfile.js'],
tasks: ['express:dev'],
options:{
spawn:false,
atBegin: false
}
}
},
// Run some tasks in parallel to speed up build process
concurrent:
{
dev: {
target: {
options:{
logConcurrentOutput: true
},
tasks: ['watch:express','watch:frontend','watch:sass']
}
}
},
open:
{
all: {
path: 'http://localhost:8000'
}
},
nodewebkit:
{
options:
{
build_dir: './build',
// choose what platforms to compile for here
mac: true,
win: true,
linux32: true,
linux64: true
},
src: ['./dist/**/*']
}
});
// Default task: running development server with livereload, beautifier and watch for sass changes. User is logged in.
grunt.registerTask('default', function ()
{
grunt.task.run([
'express:dev',
'open:all',
'watch'
]);
});
// Distribution task: running cleaning on dist folder, create main.css from sass files, compress and combine js files and copy all needed files to dist folder
grunt.registerTask('dist-prepare', ['clean:dist', 'sass:dist', 'uglify:min',
'copy:dist'
]);
// Distribution task: running cleaning on dist folder, create main.css from sass files, compress and combine js files and copy all needed files to dist folder
grunt.registerTask('dist-serve', ['express:dist', 'open:all', 'watch'
]);
// Test task: allows for testing with debugging off and authentication normal
// TODO: remove debugging and change backend when we have hardware
grunt.registerTask('test', ['clean:dist', 'sass:dist', 'uglify:min',
'copy:dist', 'open:all'
]);
// Build task: allows for building an app out of repository
grunt.registerTask('build-prepare', ['clean:dist', 'sass:dist', 'uglify:min',
'copy:build'
]);
// Build task: allows for building an app out of repository
grunt.registerTask('build', ['clean:build', 'nodewebkit'
]);
};