-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathpurifycss.js
More file actions
69 lines (55 loc) · 1.77 KB
/
Copy pathpurifycss.js
File metadata and controls
69 lines (55 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* grunt-purifycss
* https://github.com/purifycss/grunt-purify-css
*
* Copyright (c) 2015 Phoebe Li, Matthew Rourke, Kenny Tran
* Licensed under the MIT license.
*/
'use strict';
var glob = require('glob');
var purify = require('purify-css');
var path = require('path');
module.exports = function(grunt) {
grunt.registerMultiTask('purifycss', 'Clean unnecessary CSS', function() {
// Merge task-specific and/or target-specific options with these defaults.
var options = this.options({
separateFiles: false,
prefix: 'pure-'
});
var createOutput = function(srcFiles, css, dest) {
var destFile = '',
styles = css;
if (!Array.isArray(css)) styles = [css];
var pure = purify(srcFiles, styles, {write: false, info: true});
var ext = path.extname(dest);
//if the path has an extension, then use that as the destination file
if (ext) {
destFile = dest;
} else {
destFile = dest + '/' + options.prefix + path.basename(css);
}
grunt.file.write(path.normalize(destFile), pure);
grunt.log.writeln('File "' + path.normalize(destFile) + '" created.');
}
var src = [];
this.data.src.forEach(function(pathPattern) {
var files = glob.sync(pathPattern);
console.log("Source Files: ", files);
src = src.concat(files);
});
var styles = [];
this.data.css.forEach(function(pathPattern) {
var style = glob.sync(pathPattern);
console.log("Style Files: ", style);
styles = styles.concat(style);
});
var dest = this.data.dest;
if (options.separateFiles) {
styles.forEach(function(style) {
createOutput(src, style, dest);
});
} else {
createOutput(src, styles, dest);
}
});
};