Version 1
[yaffs-website] / node_modules / grunt-uncss / tasks / uncss.js
diff --git a/node_modules/grunt-uncss/tasks/uncss.js b/node_modules/grunt-uncss/tasks/uncss.js
new file mode 100644 (file)
index 0000000..6a05da8
--- /dev/null
@@ -0,0 +1,78 @@
+/**\r
+ * grunt-uncss\r
+ * https://github.com/addyosmani/grunt-uncss\r
+ *\r
+ * Copyright (c) 2016 Addy Osmani\r
+ * Licensed under the MIT license.\r
+ */\r
+\r
+'use strict';\r
+\r
+var uncss  = require( 'uncss' ),\r
+    chalk  = require( 'chalk' ),\r
+    maxmin = require( 'maxmin' ),\r
+    async = require( 'async' );\r
+\r
+module.exports = function ( grunt ) {\r
+    grunt.registerMultiTask( 'uncss', 'Remove unused CSS', function () {\r
+\r
+        var done    = this.async(),\r
+            options = this.options({\r
+                report: 'min'\r
+            });\r
+\r
+        function processFile ( file, done ) {\r
+\r
+            var src = file.src.filter(function ( filepath ) {\r
+                if ( /^https?:\/\//.test(filepath) ) {\r
+                    // This is a remote file: leave it in src array for uncss to handle.\r
+                    return true;\r
+                } else if ( !grunt.file.exists( filepath ) ) {\r
+                    // Warn on and remove invalid local source files (if nonull was set).\r
+                    grunt.log.warn( 'Source file ' + chalk.cyan( filepath ) + ' not found.' );\r
+                    return false;\r
+                } else {\r
+                    return true;\r
+                }\r
+            });\r
+\r
+            if ( src.length === 0 && file.src.length === 0 ) {\r
+                grunt.fail.warn( 'Destination (' + file.dest + ') not written because src files were empty.' );\r
+            }\r
+\r
+            try {\r
+                uncss( src, options, function ( error, output, report ) {\r
+                    if ( error ) {\r
+                        throw error;\r
+                    }\r
+\r
+                    grunt.file.write( file.dest, output );\r
+                    grunt.log.writeln('File ' + chalk.cyan( file.dest ) + ' created: ' + maxmin( report.original, output, options.report === 'gzip' ) );\r
+                    if (typeof(options.reportFile) !== 'undefined' && options.reportFile.length > 0) {\r
+                        grunt.file.write(options.reportFile, JSON.stringify(report));\r
+                    }\r
+                    done();\r
+                });\r
+            } catch ( e ) {\r
+                var err = new Error( 'Uncss failed.' );\r
+                if ( e.msg ) {\r
+                    err.message += ', ' + e.msg + '.';\r
+                }\r
+                err.origError = e;\r
+                grunt.log.warn( 'Uncssing source "' + src + '" failed.' );\r
+                grunt.fail.warn( err );\r
+            }\r
+\r
+        }\r
+\r
+        if ( this.files.length === 1 ) {\r
+            processFile( this.files[0], done );\r
+        } else {\r
+            // Processing multiple files must be done sequentially\r
+            // until https://github.com/giakki/uncss/issues/136 is resolved.\r
+            async.eachSeries( this.files, processFile, done );\r
+        }\r
+\r
+    });\r
+\r
+};\r