Security update to Drupal 8.4.6
[yaffs-website] / node_modules / grunt-uncss / tasks / uncss.js
1 /**\r
2  * grunt-uncss\r
3  * https://github.com/addyosmani/grunt-uncss\r
4  *\r
5  * Copyright (c) 2016 Addy Osmani\r
6  * Licensed under the MIT license.\r
7  */\r
8 \r
9 'use strict';\r
10 \r
11 var uncss  = require( 'uncss' ),\r
12     chalk  = require( 'chalk' ),\r
13     maxmin = require( 'maxmin' ),\r
14     async = require( 'async' );\r
15 \r
16 module.exports = function ( grunt ) {\r
17     grunt.registerMultiTask( 'uncss', 'Remove unused CSS', function () {\r
18 \r
19         var done    = this.async(),\r
20             options = this.options({\r
21                 report: 'min'\r
22             });\r
23 \r
24         function processFile ( file, done ) {\r
25 \r
26             var src = file.src.filter(function ( filepath ) {\r
27                 if ( /^https?:\/\//.test(filepath) ) {\r
28                     // This is a remote file: leave it in src array for uncss to handle.\r
29                     return true;\r
30                 } else if ( !grunt.file.exists( filepath ) ) {\r
31                     // Warn on and remove invalid local source files (if nonull was set).\r
32                     grunt.log.warn( 'Source file ' + chalk.cyan( filepath ) + ' not found.' );\r
33                     return false;\r
34                 } else {\r
35                     return true;\r
36                 }\r
37             });\r
38 \r
39             if ( src.length === 0 && file.src.length === 0 ) {\r
40                 grunt.fail.warn( 'Destination (' + file.dest + ') not written because src files were empty.' );\r
41             }\r
42 \r
43             try {\r
44                 uncss( src, options, function ( error, output, report ) {\r
45                     if ( error ) {\r
46                         throw error;\r
47                     }\r
48 \r
49                     grunt.file.write( file.dest, output );\r
50                     grunt.log.writeln('File ' + chalk.cyan( file.dest ) + ' created: ' + maxmin( report.original, output, options.report === 'gzip' ) );\r
51                     if (typeof(options.reportFile) !== 'undefined' && options.reportFile.length > 0) {\r
52                         grunt.file.write(options.reportFile, JSON.stringify(report));\r
53                     }\r
54                     done();\r
55                 });\r
56             } catch ( e ) {\r
57                 var err = new Error( 'Uncss failed.' );\r
58                 if ( e.msg ) {\r
59                     err.message += ', ' + e.msg + '.';\r
60                 }\r
61                 err.origError = e;\r
62                 grunt.log.warn( 'Uncssing source "' + src + '" failed.' );\r
63                 grunt.fail.warn( err );\r
64             }\r
65 \r
66         }\r
67 \r
68         if ( this.files.length === 1 ) {\r
69             processFile( this.files[0], done );\r
70         } else {\r
71             // Processing multiple files must be done sequentially\r
72             // until https://github.com/giakki/uncss/issues/136 is resolved.\r
73             async.eachSeries( this.files, processFile, done );\r
74         }\r
75 \r
76     });\r
77 \r
78 };\r