Completed
Push — master ( 45d7a1...2503bc )
by Sander
11s
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
			},
183
			build: {
184
				old_files_array: [
185
					'js/vendor/angular/angular.min.js',
186
					'js/vendor/angular-animate/angular-animate.min.js',
187
					'js/vendor/angular-cookies/angular-cookies.min.js',
188
					'js/vendor/angular-resource/angular-resource.min.js',
189
					'js/vendor/angular-route/angular-route.min.js',
190
					'js/vendor/angular-sanitize/angular-sanitize.min.js',
191
					'js/vendor/angular-touch/angular-touch.min.js',
192
					'js/vendor/angular-local-storage/angular-local-storage.min.js',
193
					'js/vendor/angular-off-click/angular-off-click.min.js',
194
					'js/vendor/angularjs-datetime-picker/angularjs-datetime-picker.min.js',
195
					'js/vendor/angular-translate/angular-translate.min.js',
196
					'js/vendor/angular-translate/angular-translate-loader-url.min.js',
197
					'js/vendor/ng-password-meter/ng-password-meter.js',
198
					'js/vendor/sjcl/sjcl.js',
199
					'js/vendor/zxcvbn/zxcvbn.js',
200
					'js/vendor/ng-clipboard/clipboard.min.js',
201
					'js/vendor/ng-clipboard/ngclipboard.js',
202
					'js/vendor/ng-tags-input/ng-tags-input.min.js',
203
					'js/vendor/angular-xeditable/xeditable.min.js',
204
					'js/vendor/sha/sha.js',
205
					'js/vendor/llqrcode/llqrcode.js',
206
					'js/vendor/download.js',
207
					'js/vendor/ui-sortable/sortable.js', 'js/lib/promise.js',
208
					'js/lib/crypto_wrap.js',
209
					'js/app/app.js',
210
					'js/app/filters/*.js',
211
					'js/app/services/*.js',
212
					'js/app/factory/*.js',
213
					'js/app/directives/*.js',
214
					'js/importers/import-main.js',
215
					'js/importers/*.js',
216
					'js/exporters/exporter-main.js',
217
					'js/exporters/*.js',
218
					'js/app/controllers/*.js',
219
					'js/templates.js'
220
				],
221
				files: {
222
					'dist/js/passman.min.js': [
223
						'js/vendor/angular/angular.min.js',
224
						'js/vendor/angular-animate/angular-animate.min.js',
225
						'js/vendor/angular-cookies/angular-cookies.min.js',
226
						'js/vendor/angular-resource/angular-resource.min.js',
227
						'js/vendor/angular-route/angular-route.min.js',
228
						'js/vendor/angular-sanitize/angular-sanitize.min.js',
229
						'js/vendor/angular-touch/angular-touch.min.js',
230
						'js/vendor/angular-local-storage/angular-local-storage.min.js',
231
						'js/vendor/angular-off-click/angular-off-click.min.js',
232
						'js/vendor/angularjs-datetime-picker/angularjs-datetime-picker.min.js',
233
						'js/vendor/angular-translate/angular-translate.min.js',
234
						'js/vendor/angular-translate/angular-translate-loader-url.min.js',
235
						'js/vendor/ng-password-meter/ng-password-meter.js',
236
						'js/vendor/sjcl/sjcl.js',
237
						'js/vendor/zxcvbn/zxcvbn.js',
238
						'js/vendor/ng-clipboard/clipboard.min.js',
239
						'js/vendor/ng-clipboard/ngclipboard.js',
240
						'js/vendor/ng-tags-input/ng-tags-input.min.js',
241
						'js/vendor/angular-xeditable/xeditable.min.js',
242
						'js/vendor/sha/sha.js',
243
						'js/vendor/llqrcode/llqrcode.js',
244
						'js/vendor/download.js',
245
						'js/vendor/ui-sortable/sortable.js',
246
						'js/vendor/papa-parse/papaparse.min.js',
247
						'js/lib/promise.js',
248
						'js/lib/crypto_wrap.js',
249
						'js/app/app.js',
250
						'js/app/filters/*.js',
251
						'js/app/services/*.js',
252
						'js/app/factory/*.js',
253
						'js/app/directives/*.js',
254
						'js/importers/import-main.js',
255
						'js/importers/*.js',
256
						'js/exporters/exporter-main.js',
257
						'js/exporters/*.js',
258
						'js/app/controllers/*.js',
259
						'js/templates.js',
260
						'js/settings-admin.js'
261
					]
262
				}
263
			}
264
		},
265
		concat: {
266
			css: {
267
				src: ['css/vendor/**/*.css', 'css/app.css'],
268
				dest: 'dist/css/passman.css'
269
			}
270
		},
271
		cssmin: {
272
			options: {
273
				shorthandCompacting: false,
274
				roundingPrecision: -1
275
			},
276
			target: {
277
				files: [
278
					{
279
						expand: true,
280
						cwd: 'dist/css',
281
						src: ['passman.css'],
282
						dest: 'dist/css',
283
						ext: '.min.css'
284
					},
285
					{
286
						expand: true,
287
						cwd: 'dist/css',
288
						src: ['bookmarklet.css', 'public-page.css'],
289
						dest: 'dist/css',
290
						ext: '.css'
291
					}
292
				]
293
			}
294
		},
295
		clean: {
296
			css: ['dist/css/passman.css']
297
		},
298
		replace: {
299
			dist: {
300
				files: [
301
					{
302
						cwd: 'templates',
303
						dest: 'dist/templates',
304
						expand: true,
305
						src: ['*.php']
306
					}
307
				],
308
				options: {
309
					patterns: [
310
						{
311
							//Grab the /*build-js-start*/ and /*build-js-end*/ comments and everything in-between
312
							match: /\/\s?\*build\-js\-start[\s\S]*build\-js\-end+\*\//,
313
							replacement: function (matchedString) {
314
								jsResources = [];
315
316
								var jsArray = matchedString.match(/script\([A-z']+,\s?'([\/A-z.-]+)'\);/g);
317
								jsArray.forEach(function (file) {
318
									var regex = /script\([A-z']+,\s?'([\/A-z.-]+)'\);/g;
319
									var matches = regex.exec(file);
320
									if (matches) {
321
										jsResources.push("'js/" + matches[1] + ".js'");
322
323
									}
324
								});
325
								//Replace the entire build-js-start to build-js-end block with this <script> tag
326
327
								return "script('passman', 'passman.min');";
328
							}
329
						},
330
						{
331
							//Grab the /*build-css-start*/ and /*build-css-end*/ comments and everything in-between
332
							match: /\/\s?\*build\-css\-start[\s\S]*build\-css\-end+\*\//,
333
							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...
334
								//Replace the entire build-css-start to build-css-end block with this <link> tag
335
								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...
336
							}
337
						}
338
					]
339
				}
340
			},
341
			strict: {
342
				files: [
343
					{
344
						cwd: 'dist/js',
345
						dest: 'dist/js',
346
						expand: true,
347
						src: ['*.js']
348
					}
349
				],
350
				options: {
351
					patterns: [
352
						{
353
							//Grab the <!--build-js-start--> and <!--build-js-end--> comments and everything in-between
354
							match: /"use strict";/,
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-js-start to build-js-end block with this <script> tag
357
								return '';
358
							}
359
						}
360
					]
361
				}
362
			}
363
		}
364
365
	});
366
367
	// Load the plugin that provides the "uglify" task.
368
	grunt.loadNpmTasks('grunt-contrib-sass');
369
	grunt.loadNpmTasks('grunt-contrib-uglify');
370
	grunt.loadNpmTasks('grunt-html2js');
371
	grunt.loadNpmTasks('grunt-contrib-watch');
372
	grunt.loadNpmTasks('grunt-contrib-jshint');
373
	grunt.loadNpmTasks('grunt-karma');
374
	grunt.loadNpmTasks('grunt-mkdir');
375
	grunt.loadNpmTasks('grunt-contrib-copy');
376
	grunt.loadNpmTasks('grunt-contrib-cssmin');
377
	grunt.loadNpmTasks('grunt-contrib-concat');
378
	grunt.loadNpmTasks('grunt-contrib-clean');
379
	grunt.loadNpmTasks('grunt-replace');
380
381
382
	// Default task(s).
383
	grunt.registerTask('default', ['html2js', 'sass']);
384
	grunt.registerTask('hint', ['jshint']);
385
	grunt.registerTask('build', ['sass', 'jshint', 'html2js', 'mkdir:dist', 'copy:dist', 'copy:fonts', 'replace:dist', 'uglify', 'concat:css', 'cssmin', 'clean:css', 'replace:strict']);
386
387
};