Completed
Push — master ( da2c83...bbbcc3 )
by Sander
17:29 queued 07:34
created

Gruntfile.js (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
module.exports = function (grunt) {
2
	var jsResources = [];
3
	// Project configuration.
4
	grunt.initConfig({
5
		jsResources: [],
6
		cssResources: [],
7
		pkg: grunt.file.readJSON('package.json'),
8
		html2js: {
9
			options: {
10
				// custom options, see below
11
				base: 'templates',
12
				quoteChar: '\'',
13
				useStrict: true,
14
				htmlmin: {
15
					collapseBooleanAttributes: false,
16
					collapseWhitespace: true,
17
					removeAttributeQuotes: false,
18
					removeComments: true,
19
					removeEmptyAttributes: false,
20
					removeRedundantAttributes: false,
21
					removeScriptTypeAttributes: false,
22
					removeStyleLinkTypeAttributes: false
23
				}
24
			},
25
			main: {
26
				src: ['templates/views/**/*.html'],
27
				dest: 'js/templates.js'
28
			}
29
		},
30
		jshint: {
31
			options: {
32
				reporter: require('jshint-stylish'),
33
				curly: false,
34
				eqeqeq: true,
35
				eqnull: true,
36
				browser: true,
37
				globals: {
38
					"angular": true,
39
					"PassmanImporter": true,
40
					"PassmanExporter": true,
41
					"OC": true,
42
					"window": true,
43
					"console": true,
44
					"CRYPTO": true,
45
					"C_Promise": true,
46
					"forge": true,
47
					"sjcl": true,
48
					"jQuery": true,
49
					"$": true,
50
					"_": true,
51
					"oc_requesttoken": true
52
				}
53
			},
54
			all: ['js/app/**/*.js']
55
		},
56
		sass: {
57
			dist: {
58
				files: [
59
					{
60
						expand: true,
61
						cwd: "sass",
62
						src: ["**/app.scss"],
63
						dest: "css",
64
						ext: ".css"
65
					},
66
					{
67
						expand: true,
68
						cwd: "sass",
69
						src: ["**/bookmarklet.scss"],
70
						dest: "css",
71
						ext: ".css"
72
					},
73
					{
74
						expand: true,
75
						cwd: "sass",
76
						src: ["**/public-page.scss"],
77
						dest: "css",
78
						ext: ".css"
79
					},
80
					{
81
						expand: true,
82
						cwd: "sass",
83
						src: ["**/admin.scss"],
84
						dest: "css",
85
						ext: ".css"
86
					}
87
				]
88
			}
89
		},
90
91
		karma: {
92
			unit: {
93
				configFile: './karma.conf.js',
94
				background: false
95
			}
96
		},
97
98
		//@TODO JSHint
99
		watch: {
100
			scripts: {
101
				files: ['Gruntfile.js', 'templates/views/{,*/}{,*/}{,*/}*.html', 'templates/views/*.html', 'sass/*', 'sass/partials/*'],
102
				tasks: ['html2js', 'sass'],
103
				options: {
104
					spawn: false,
105
					interrupt: true,
106
					reload: true
107
				}
108
			}
109
		},
110
		/**
111
		 * Build commands
112
		 */
113
		mkdir: {
114
			dist: {
115
				options: {
116
					mode: 0700,
117
					create: ['dist']
118
				}
119
			}
120
		},
121
122
		copy: {
123
			dist: {
124
				files: [
125
					// includes files within path
126
					{
127
						expand: true,
128
						src: [
129
							'**',
130
							'!templates/*.php',
131
							'!templates/views/*',
132
							'!templates/views/*/**',
133
							'!templates/views',
134
							'!js/*',
135
							'!js/*/**',
136
							'!node_modules/*/**',
137
							'!node_modules',
138
							'!css/**/*',
139
							'!css/*.map',
140
							'!css/app.*',
141
							'css/bookmarklet.css',
142
							'css/public-page.css',
143
							'css/admin.css',
144
							'!dist/*',
145
							'!dist/*/**',
146
							'!dist',
147
							'!tests/*/**',
148
							'!tests/*',
149
							'!tests', '' +
150
							'!sass/*/**',
151
							'!sass/*',
152
							'!sass',
153
							'!.drone.yml',
154
							'!.gitignore',
155
							'!.jshintrc',
156
							'!.scrutinizer.yml',
157
							'!.travis.yml',
158
							'!Gruntfile.js',
159
							'!karma.conf.js',
160
							'!launch_phpunit.sh',
161
							'!Makefile',
162
							'!package.json',
163
							'!phpunit.*',
164
							'!Dockerfile',
165
							'!swagger.yaml'
166
						],
167
						dest: 'dist/'
168
					}
169
				]
170
			},
171
			fonts: {
172
				files: [
173
					{
174
						expand: true,
175
						flatten: false,
176
						src: ['css/vendor/font-awesome/*'],
177
						dest: 'dist/'
178
					}
179
180
				]
181
182
			},
183
			settingsJs: {
184
				files: [
185
					{
186
						expand: true,
187
						flatten: true,
188
						src: ['js/settings-admin.js'],
189
						dest: 'dist/js/'
190
					}
191
192
				]
193
			}
194
		},
195
196
197
		uglify: {
198
			options: {
199
				mangle: false,
200
				screwIE8: true,
201
				banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
202
			},
203
			build: {
204
				old_files_array: [
205
					'js/vendor/angular/angular.min.js',
206
					'js/vendor/angular-animate/angular-animate.min.js',
207
					'js/vendor/angular-cookies/angular-cookies.min.js',
208
					'js/vendor/angular-resource/angular-resource.min.js',
209
					'js/vendor/angular-route/angular-route.min.js',
210
					'js/vendor/angular-sanitize/angular-sanitize.min.js',
211
					'js/vendor/angular-touch/angular-touch.min.js',
212
					'js/vendor/angular-local-storage/angular-local-storage.min.js',
213
					'js/vendor/angular-off-click/angular-off-click.min.js',
214
					'js/vendor/angularjs-datetime-picker/angularjs-datetime-picker.min.js',
215
					'js/vendor/angular-translate/angular-translate.min.js',
216
					'js/vendor/angular-translate/angular-translate-loader-url.min.js',
217
					'js/vendor/ng-password-meter/ng-password-meter.js',
218
					'js/vendor/sjcl/sjcl.js',
219
					'js/vendor/zxcvbn/zxcvbn.js',
220
					'js/vendor/ng-clipboard/clipboard.min.js',
221
					'js/vendor/ng-clipboard/ngclipboard.js',
222
					'js/vendor/ng-tags-input/ng-tags-input.min.js',
223
					'js/vendor/angular-xeditable/xeditable.min.js',
224
					'js/vendor/sha/sha.js',
225
					'js/vendor/llqrcode/llqrcode.js',
226
					'js/vendor/download.js',
227
					'js/vendor/ui-sortable/sortable.js', 'js/lib/promise.js',
228
					'js/lib/crypto_wrap.js',
229
					'js/app/app.js',
230
					'js/app/filters/*.js',
231
					'js/app/services/*.js',
232
					'js/app/factory/*.js',
233
					'js/app/directives/*.js',
234
					'js/importers/import-main.js',
235
					'js/importers/*.js',
236
					'js/exporters/exporter-main.js',
237
					'js/exporters/*.js',
238
					'js/app/controllers/*.js',
239
					'js/templates.js'
240
				],
241
				files: {
242
					'dist/js/passman.min.js': [
243
						'js/vendor/angular/angular.min.js',
244
						'js/vendor/angular-animate/angular-animate.min.js',
245
						'js/vendor/angular-cookies/angular-cookies.min.js',
246
						'js/vendor/angular-resource/angular-resource.min.js',
247
						'js/vendor/angular-route/angular-route.min.js',
248
						'js/vendor/angular-sanitize/angular-sanitize.min.js',
249
						'js/vendor/angular-touch/angular-touch.min.js',
250
						'js/vendor/angular-local-storage/angular-local-storage.min.js',
251
						'js/vendor/angular-off-click/angular-off-click.min.js',
252
						'js/vendor/angularjs-datetime-picker/angularjs-datetime-picker.min.js',
253
						'js/vendor/angular-translate/angular-translate.min.js',
254
						'js/vendor/angular-translate/angular-translate-loader-url.min.js',
255
						'js/vendor/ng-password-meter/ng-password-meter.js',
256
						'js/vendor/sjcl/sjcl.js',
257
						'js/vendor/zxcvbn/zxcvbn.js',
258
						'js/vendor/forge.0.6.9.min.js',
259
						'js/vendor/download.js',
260
						'js/vendor/ng-clipboard/clipboard.min.js',
261
						'js/vendor/ng-clipboard/ngclipboard.js',
262
						'js/vendor/ng-tags-input/ng-tags-input.min.js',
263
						'js/vendor/angular-xeditable/xeditable.min.js',
264
						'js/vendor/sha/sha.js',
265
						'js/vendor/llqrcode/llqrcode.js',
266
						'js/vendor/download.js',
267
						'js/vendor/ui-sortable/sortable.js',
268
						'js/vendor/papa-parse/papaparse.min.js',
269
						'js/lib/promise.js',
270
						'js/lib/crypto_wrap.js',
271
						'js/app/app.js',
272
						'js/app/filters/*.js',
273
						'js/app/services/*.js',
274
						'js/app/factory/*.js',
275
						'js/app/directives/*.js',
276
						'js/importers/import-main.js',
277
						'js/importers/*.js',
278
						'js/exporters/exporter-main.js',
279
						'js/exporters/*.js',
280
						'js/app/controllers/*.js',
281
						'js/templates.js',
282
						'js/settings-admin.js'
283
					]
284
				}
285
			}
286
		},
287
		concat: {
288
			css: {
289
				src: ['css/vendor/**/*.css', 'css/app.css'],
290
				dest: 'dist/css/passman.css'
291
			}
292
		},
293
		cssmin: {
294
			options: {
295
				shorthandCompacting: false,
296
				roundingPrecision: -1
297
			},
298
			target: {
299
				files: [
300
					{
301
						expand: true,
302
						cwd: 'dist/css',
303
						src: ['passman.css'],
304
						dest: 'dist/css',
305
						ext: '.min.css'
306
					},
307
					{
308
						expand: true,
309
						cwd: 'dist/css',
310
						src: ['bookmarklet.css', 'public-page.css'],
311
						dest: 'dist/css',
312
						ext: '.css'
313
					}
314
				]
315
			}
316
		},
317
		clean: {
318
			css: ['dist/css/passman.css']
319
		},
320
		replace: {
321
			dist: {
322
				files: [
323
					{
324
						cwd: 'templates',
325
						dest: 'dist/templates',
326
						expand: true,
327
						src: ['*.php']
328
					}
329
				],
330
				options: {
331
					patterns: [
332
						{
333
							//Grab the /*build-js-start*/ and /*build-js-end*/ comments and everything in-between
334
							match: /\/\s?\*build\-js\-start[\s\S]*build\-js\-end+\*\//,
335
							replacement: function (matchedString) {
336
								jsResources = [];
337
338
								var jsArray = matchedString.match(/script\([A-z']+,\s?'([\/A-z.-]+)'\);/g);
339
								jsArray.forEach(function (file) {
340
									var regex = /script\([A-z']+,\s?'([\/A-z.-]+)'\);/g;
341
									var matches = regex.exec(file);
342
									if (matches) {
343
										jsResources.push("'js/" + matches[1] + ".js'");
344
345
									}
346
								});
347
								//Replace the entire build-js-start to build-js-end block with this <script> tag
348
349
								return "script('passman', 'passman.min');";
350
							}
351
						},
352
						{
353
							//Grab the /*build-css-start*/ and /*build-css-end*/ comments and everything in-between
354
							match: /\/\s?\*build\-css\-start[\s\S]*build\-css\-end+\*\//,
355
							replacement: function (matchedString) {
0 ignored issues
show
The parameter matchedString is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
356
								//Replace the entire build-css-start to build-css-end block with this <link> tag
357
								return "style('passman', 'passman.min');"
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
358
							}
359
						}
360
					]
361
				}
362
			},
363
			strict: {
364
				files: [
365
					{
366
						cwd: 'dist/js',
367
						dest: 'dist/js',
368
						expand: true,
369
						src: ['*.js']
370
					}
371
				],
372
				options: {
373
					patterns: [
374
						{
375
							//Grab the <!--build-js-start--> and <!--build-js-end--> comments and everything in-between
376
							match: /"use strict";/,
377
							replacement: function (matchedString) {
0 ignored issues
show
The parameter matchedString is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
378
								//Replace the entire build-js-start to build-js-end block with this <script> tag
379
								return '';
380
							}
381
						}
382
					]
383
				}
384
			}
385
		}
386
387
	});
388
389
	// Load the plugin that provides the "uglify" task.
390
	grunt.loadNpmTasks('grunt-contrib-sass');
391
	grunt.loadNpmTasks('grunt-contrib-uglify');
392
	grunt.loadNpmTasks('grunt-html2js');
393
	grunt.loadNpmTasks('grunt-contrib-watch');
394
	grunt.loadNpmTasks('grunt-contrib-jshint');
395
	grunt.loadNpmTasks('grunt-karma');
396
	grunt.loadNpmTasks('grunt-mkdir');
397
	grunt.loadNpmTasks('grunt-contrib-copy');
398
	grunt.loadNpmTasks('grunt-contrib-cssmin');
399
	grunt.loadNpmTasks('grunt-contrib-concat');
400
	grunt.loadNpmTasks('grunt-contrib-clean');
401
	grunt.loadNpmTasks('grunt-replace');
402
403
404
	// Default task(s).
405
	grunt.registerTask('default', ['html2js', 'sass']);
406
	grunt.registerTask('hint', ['jshint']);
407
	grunt.registerTask('build', ['sass', 'jshint', 'html2js', 'mkdir:dist', 'copy:dist', 'copy:fonts', 'replace:dist', 'uglify', 'concat:css', 'cssmin', 'clean:css', 'replace:strict', 'copy:settingsJs']);
408
409
};