-
Notifications
You must be signed in to change notification settings - Fork 19
/
css-purge.js
147 lines (119 loc) · 3.7 KB
/
css-purge.js
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env node
var through2 = require('through2');
var clc = require('cli-color');
var program = require('commander');
var pkg = require('./package.json');
var cssPurge = require('./lib/css-purge');
var error = clc.red.bold;
var info = clc.xterm(123);
var warn = clc.yellow;
var logoRed = clc.xterm(197);
program
.version(pkg.version)
.option('-c, --cssinput - CSS <the css>', 'The CSS to purge')
.option('-i, --input - CSS file(s) <input filenames, foldernames or url>', 'The CSS file(s) to parse')
.option('-m, --inputhtml - HTML file(s) <input html filenames, foldernames or url>', 'The HTML file(s) to parse for CSS')
.option('-o, --output - CSS file <output filename>', 'The new css filename to output as')
.option('-f, --customconfig - <config filename> - run with custom config filename', 'Global Workflow - All options must be defined in a json file')
.option('-d, --defaultconfig - run with default config file', 'Local Workflow - All options are defined in a config_css.json')
.option('-v, --verbose - displays internal messages', 'Outputs CSS-PURGE activity')
.parse(process.argv);
var options = {};
if (program.cssinput) {
if (program.output) {
options = {
css_output: program.output,
verbose : (program.verbose) ? true : false
};
if (program.customconfig === undefined) {
options.trim = true;
options.shorten = true;
}
cssPurge.purgeCSS(program.cssinput, options, function(error, result){
if (error)
console.log(error)
else
console.log(result);
});
} else {
options = {
verbose : (program.verbose) ? true : false
};
if (program.customconfig === undefined) {
options.trim = true;
options.shorten = true;
}
cssPurge.purgeCSS(program.cssinput, options, function(error, result){
if (error)
console.log(error)
else
console.log(result);
});
}
} else if (program.input && program.inputhtml && program.output) {
options = {
css: program.input,
css_output: program.output,
special_reduce_with_html: true,
html: program.inputhtml,
verbose : (program.verbose) ? true : false
};
if (program.customconfig === undefined) {
options.trim = true;
options.shorten = true;
}
cssPurge.purgeCSSFiles(
options,
(program.customconfig !== undefined) ? program.customconfig : 'cmd_default'
);
} else if (program.input && program.inputhtml) {
options = {
css: program.input,
css_output: program.input.substr(0, program.input.lastIndexOf('.')) + '.min.css',
special_reduce_with_html: true,
html: program.inputhtml,
verbose : (program.verbose) ? true : false
};
if (program.customconfig === undefined) {
options.trim = true;
options.shorten = true;
}
cssPurge.purgeCSSFiles(
options,
(program.customconfig !== undefined) ? program.customconfig : 'cmd_default'
);
} else if (program.input && program.output) {
options = {
css: program.input,
css_output: program.output,
verbose : (program.verbose) ? true : false
};
if (program.customconfig === undefined) {
options.trim = true;
options.shorten = true;
}
cssPurge.purgeCSSFiles(
options,
(program.customconfig !== undefined) ? program.customconfig : 'cmd_default'
);
} else if (program.input) {
options = {
css: program.input,
css_output: program.input.substr(0, program.input.lastIndexOf('.')) + '.min.css',
verbose : (program.verbose) ? true : false
};
if (program.customconfig === undefined) {
options.trim = true;
options.shorten = true;
}
cssPurge.purgeCSSFiles(
options,
(program.customconfig !== undefined) ? program.customconfig : 'cmd_default'
);
} else if (program.customconfig) {
cssPurge.purgeCSSFiles(null, '' + program.customconfig);
} else if (program.defaultconfig) {
cssPurge.purgeCSSFiles();
} else {
program.help();
}