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