Repository navigation
Expand file tree
/
Copy pathuglifycss
More file actions
127 lines (99 loc) · 2.76 KB
/
Copy pathuglifycss
File metadata and controls
127 lines (99 loc) · 2.76 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
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
#! /usr/bin/env node
/**
* UglifyCSS
* Port of YUI CSS Compressor to NodeJS
* Author: Franck Marcia - https://github.com/fmarcia
* MIT licenced
*/
/**
* cssmin.js
* Author: Stoyan Stefanov - http://phpied.com/
* This is a JavaScript port of the CSS minification tool
* distributed with YUICompressor, itself a port
* of the cssmin utility by Isaac Schlueter - http://foohack.com/
* Permission is hereby granted to use the JavaScript version under the same
* conditions as the YUICompressor (original YUICompressor note below).
*/
/**
* YUI Compressor
* http://developer.yahoo.com/yui/compressor/
* Author: Julien Lecomte - http://www.julienlecomte.net/
* Copyright (c) 2011 Yahoo! Inc. All rights reserved.
* The copyrights embodied in the content of this file are licensed
* by Yahoo! Inc. under the BSD (revised) open source license.
*/
var util = require('util'),
uglifycss = require('./'),
uglies = [],
stdin = process.stdin,
filename,
content,
params,
nFiles,
result;
// Print usage
function usage() {
util.error(
'Usage: uglifycss [options] file1.css [file2.css [...]] > output\n' +
'options:\n' +
'--max-line-len x add a newline every x characters; 0 means no newline; default: 5000\n' +
'--expand-vars expand variables\n' +
'--ugly-comments remove newlines within preserved comments\n' +
'--cute-comments preserve newlines within and around preserved comments'
);
}
// Transform strings like "the-parameter" to "theParameter"
function par2var(param) {
return param.replace(/-(.)/g, function (unused, character) {
return character === '-' ? '' : character.toUpperCase();
});
}
// Parse parameters from command line
function parseArguments(argv) {
var index,
len = argv.length,
param,
params = {
options: uglifycss.defaultOptions,
files: []
};
for (index = 2; index < len; index += 1) {
// last argument is always a file
if (index === len - 1) {
params.files.push(argv[index]);
} else {
varia = par2var(argv[index]);
// boolean parameters
if (typeof params.options[varia] === 'boolean') {
params.options[varia] = true;
// integer parameter
} else if (typeof params.options[varia] !== 'undefined') {
params.options[varia] = parseInt(argv[index + 1], 10);
index += 1;
// file
} else {
params.files.push(argv[index]);
}
}
}
return params;
}
// Uglify CSS
params = parseArguments(process.argv);
nFiles = params.files.length;
// . files
if (nFiles) {
util.print(uglifycss.processFiles(params.files, params.options));
// . usage
} else if (stdin.isTTY) {
usage();
// . stdin
} else {
content = '';
stdin.on('data', function (part) {
content += part;
});
stdin.on('end', function () {
util.print(uglifycss.processString(content, params.options));
});
}