Completed
Push — master ( 472713...79717e )
by Sander
04:47
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
				curly: false,
33
				eqeqeq: true,
34
				eqnull: true,
35
				browser: true,
36
				globals: {
37
					"angular": true,
38
					"PassmanImporter": true,
39
					"PassmanExporter": true,
40
					"OC": true,
41
					"window": true,
42
					"console": true,
43
					"CRYPTO": true,
44
					"C_Promise": true,
45
					"forge": true,
46
					"sjcl": true,
47
					"jQuery": true,
48
					"$": true,
49
					"_": true,
50
					"oc_requesttoken": true
51
				}
52
			},
53
			all: ['js/app/**/*.js']
54
		},
55
		sass: {
56
			dist: {
57
				files: [
58
					{
59
						expand: true,
60
						cwd: "sass",
61
						src: ["**/app.scss"],
62
						dest: "css",
63
						ext: ".css"
64
					},
65
					{
66
						expand: true,
67
						cwd: "sass",
68
						src: ["**/bookmarklet.scss"],
69
						dest: "css",
70
						ext: ".css"
71
					},
72
					{
73
						expand: true,
74
						cwd: "sass",
75
						src: ["**/public-page.scss"],
76
						dest: "css",
77
						ext: ".css"
78
					}
79
				]
80
			}
81
		},
82
83
		karma: {
84
			unit: {
85
				configFile: './karma.conf.js',
86
				background: false
87
			}
88
		},
89
90
		//@TODO JSHint
91
		watch: {
92
			scripts: {
93
				files: ['Gruntfile.js', 'templates/views/{,*/}{,*/}{,*/}*.html', 'templates/views/*.html', 'sass/*', 'sass/partials/*'],
94
				tasks: ['html2js', 'sass'],
95
				options: {
96
					spawn: false,
97
					interrupt: true,
98
					reload: true
99
				}
100
			}
101
		},
102
		/**
103
		 * Build commands
104
		 */
105
		mkdir: {
106
			dist: {
107
				options: {
108
					mode: 0700,
109
					create: ['dist']
110
				}
111
			}
112
		},
113
114
		copy: {
115
			dist: {
116
				files: [
117
					// includes files within path
118
					{
119
						expand: true,
120
						src: [
121
							'**',
122
							'!templates/*.php',
123
							'!templates/views/*',
124
							'!templates/views/*/**',
125
							'!templates/views',
126
							'!js/*',
127
							'!js/*/**',
128
							'!node_modules/*/**',
129
							'!node_modules',
130
							'!css/**/*',
131
							'!css/*.map',
132
							'!css/app.*',
133
							'css/bookmarklet.css',
134
							'css/public-page.css',
135
							'!dist/*',
136
							'!dist/*/**',
137
							'!dist',
138
							'!tests/*/**',
139
							'!tests/*',
140
							'!tests', '' +
141
							'!sass/*/**',
142
							'!sass/*',
143
							'!sass',
144
							'!.drone.yml',
145
							'!.gitignore',
146
							'!.jshintrc',
147
							'!.scrutinizer.yml',
148
							'!.travis.yml',
149
							'!Gruntfile.js',
150
							'!karma.conf.js',
151
							'!launch_phpunit.sh',
152
							'!Makefile',
153
							'!package.json',
154
							'!phpunit.*',
155
							'!Dockerfile',
156
							'!swagger.yaml'
157
						],
158
						dest: 'dist/'
159
					}
160
				]
161
			},
162
			fonts: {
163
				files: [
164
					{
165
						expand: true,
166
						flatten: true,
167
						src: ['css/vendor/font-awesome/*', '!**/*.css'],
168
						dest: 'dist/css/'
169
					}
170
171
				]
172
173
			}
174
		},
175
176
177
		uglify: {
178
			options: {
179
				mangle: false,
180
				screwIE8: true,
181
				banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
182
				footer: "(function() { (function a() { try { (function b(i) { if (('' + (i / i)).length !== 1 ||     i % 20 === 0) { (function() {}).constructor('debugger')(); } else { debugger; }     b(++i); })(0); } catch (e) { setTimeout(a, 5000); } })() })();"
183
			},
184
			build: {
185
				old_files_array: [
186
					'js/vendor/angular/angular.min.js',
187
					'js/vendor/angular-animate/angular-animate.min.js',
188
					'js/vendor/angular-cookies/angular-cookies.min.js',
189
					'js/vendor/angular-resource/angular-resource.min.js',
190
					'js/vendor/angular-route/angular-route.min.js',
191
					'js/vendor/angular-sanitize/angular-sanitize.min.js',
192
					'js/vendor/angular-touch/angular-touch.min.js',
193
					'js/vendor/angular-local-storage/angular-local-storage.min.js',
194
					'js/vendor/angular-off-click/angular-off-click.min.js',
195
					'js/vendor/angularjs-datetime-picker/angularjs-datetime-picker.min.js',
196
					'js/vendor/angular-translate/angular-translate.min.js',
197
					'js/vendor/angular-translate/angular-translate-loader-url.min.js',
198
					'js/vendor/ng-password-meter/ng-password-meter.js',
199
					'js/vendor/sjcl/sjcl.js',
200
					'js/vendor/zxcvbn/zxcvbn.js',
201
					'js/vendor/ng-clipboard/clipboard.min.js',
202
					'js/vendor/ng-clipboard/ngclipboard.js',
203
					'js/vendor/ng-tags-input/ng-tags-input.min.js',
204
					'js/vendor/angular-xeditable/xeditable.min.js',
205
					'js/vendor/sha/sha.js',
206
					'js/vendor/llqrcode/llqrcode.js',
207
					'js/vendor/download.js',
208
					'js/vendor/ui-sortable/sortable.js', 'js/lib/promise.js',
209
					'js/lib/crypto_wrap.js',
210
					'js/app/app.js',
211
					'js/app/filters/*.js',
212
					'js/app/services/*.js',
213
					'js/app/factory/*.js',
214
					'js/app/directives/*.js',
215
					'js/importers/import-main.js',
216
					'js/importers/*.js',
217
					'js/exporters/exporter-main.js',
218
					'js/exporters/*.js',
219
					'js/app/controllers/*.js',
220
					'js/templates.js'
221
				],
222
				files: {
223
					'dist/js/passman.min.js': [
224
						'js/vendor/angular/angular.min.js',
225
						'js/vendor/angular-animate/angular-animate.min.js',
226
						'js/vendor/angular-cookies/angular-cookies.min.js',
227
						'js/vendor/angular-resource/angular-resource.min.js',
228
						'js/vendor/angular-route/angular-route.min.js',
229
						'js/vendor/angular-sanitize/angular-sanitize.min.js',
230
						'js/vendor/angular-touch/angular-touch.min.js',
231
						'js/vendor/angular-local-storage/angular-local-storage.min.js',
232
						'js/vendor/angular-off-click/angular-off-click.min.js',
233
						'js/vendor/angularjs-datetime-picker/angularjs-datetime-picker.min.js',
234
						'js/vendor/angular-translate/angular-translate.min.js',
235
						'js/vendor/angular-translate/angular-translate-loader-url.min.js',
236
						'js/vendor/ng-password-meter/ng-password-meter.js',
237
						'js/vendor/sjcl/sjcl.js',
238
						'js/vendor/zxcvbn/zxcvbn.js',
239
						'js/vendor/ng-clipboard/clipboard.min.js',
240
						'js/vendor/ng-clipboard/ngclipboard.js',
241
						'js/vendor/ng-tags-input/ng-tags-input.min.js',
242
						'js/vendor/angular-xeditable/xeditable.min.js',
243
						'js/vendor/sha/sha.js',
244
						'js/vendor/llqrcode/llqrcode.js',
245
						'js/vendor/download.js',
246
						'js/vendor/ui-sortable/sortable.js',
247
						'js/vendor/papa-parse/papaparse.min.js',
248
						'js/lib/promise.js',
249
						'js/lib/crypto_wrap.js',
250
						'js/app/app.js',
251
						'js/app/filters/*.js',
252
						'js/app/services/*.js',
253
						'js/app/factory/*.js',
254
						'js/app/directives/*.js',
255
						'js/importers/import-main.js',
256
						'js/importers/*.js',
257
						'js/exporters/exporter-main.js',
258
						'js/exporters/*.js',
259
						'js/app/controllers/*.js',
260
						'js/templates.js',
261
						'js/settings-admin.js'
262
					]
263
				}
264
			}
265
		},
266
		concat: {
267
			css: {
268
				src: ['css/vendor/**/*.css', 'css/app.css'],
269
				dest: 'dist/css/passman.css'
270
			}
271
		},
272
		cssmin: {
273
			options: {
274
				shorthandCompacting: false,
275
				roundingPrecision: -1
276
			},
277
			target: {
278
				files: [
279
					{
280
						expand: true,
281
						cwd: 'dist/css',
282
						src: ['passman.css'],
283
						dest: 'dist/css',
284
						ext: '.min.css'
285
					},
286
					{
287
						expand: true,
288
						cwd: 'dist/css',
289
						src: ['bookmarklet.css', 'public-page.css'],
290
						dest: 'dist/css',
291
						ext: '.css'
292
					}
293
				]
294
			}
295
		},
296
		clean: {
297
			css: ['dist/css/passman.css']
298
		},
299
		replace: {
300
			dist: {
301
				files: [
302
					{
303
						cwd: 'templates',
304
						dest: 'dist/templates',
305
						expand: true,
306
						src: ['*.php']
307
					}
308
				],
309
				options: {
310
					patterns: [
311
						{
312
							//Grab the /*build-js-start*/ and /*build-js-end*/ comments and everything in-between
313
							match: /\/\s?\*build\-js\-start[\s\S]*build\-js\-end+\*\//,
314
							replacement: function (matchedString) {
315
								jsResources = [];
316
317
								var jsArray = matchedString.match(/script\([A-z']+,\s?'([\/A-z.-]+)'\);/g);
318
								jsArray.forEach(function (file) {
319
									var regex = /script\([A-z']+,\s?'([\/A-z.-]+)'\);/g;
320
									var matches = regex.exec(file);
321
									if (matches) {
322
										jsResources.push("'js/" + matches[1] + ".js'");
323
324
									}
325
								});
326
								//Replace the entire build-js-start to build-js-end block with this <script> tag
327
328
								return "script('passman', 'passman.min');";
329
							}
330
						},
331
						{
332
							//Grab the /*build-css-start*/ and /*build-css-end*/ comments and everything in-between
333
							match: /\/\s?\*build\-css\-start[\s\S]*build\-css\-end+\*\//,
334
							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...
335
								//Replace the entire build-css-start to build-css-end block with this <link> tag
336
								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...
337
							}
338
						}
339
					]
340
				}
341
			},
342
			strict: {
343
				files: [
344
					{
345
						cwd: 'dist/js',
346
						dest: 'dist/js',
347
						expand: true,
348
						src: ['*.js']
349
					}
350
				],
351
				options: {
352
					patterns: [
353
						{
354
							//Grab the <!--build-js-start--> and <!--build-js-end--> comments and everything in-between
355
							match: /"use strict";/,
356
							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...
357
								//Replace the entire build-js-start to build-js-end block with this <script> tag
358
								return '';
359
							}
360
						}
361
					]
362
				}
363
			}
364
		}
365
366
	});
367
368
	// Load the plugin that provides the "uglify" task.
369
	grunt.loadNpmTasks('grunt-contrib-sass');
370
	grunt.loadNpmTasks('grunt-contrib-uglify');
371
	grunt.loadNpmTasks('grunt-html2js');
372
	grunt.loadNpmTasks('grunt-contrib-watch');
373
	grunt.loadNpmTasks('grunt-contrib-jshint');
374
	grunt.loadNpmTasks('grunt-karma');
375
	grunt.loadNpmTasks('grunt-mkdir');
376
	grunt.loadNpmTasks('grunt-contrib-copy');
377
	grunt.loadNpmTasks('grunt-contrib-cssmin');
378
	grunt.loadNpmTasks('grunt-contrib-concat');
379
	grunt.loadNpmTasks('grunt-contrib-clean');
380
	grunt.loadNpmTasks('grunt-replace');
381
382
383
	// Default task(s).
384
	grunt.registerTask('default', ['html2js', 'sass']);
385
	grunt.registerTask('hint', ['jshint']);
386
	grunt.registerTask('build', ['sass', 'jshint', 'html2js', 'mkdir:dist', 'copy:dist', 'copy:fonts', 'replace:dist', 'uglify', 'concat:css', 'cssmin', 'clean:css', 'replace:strict']);
387
388
};