* Version 0.7.0.
+0.7.0 / 2012-10-14
+==================
+
+ * Added stripping special comments to CLI (--s0 and --s1 options).
+ * Added stripping special comments to programatic interface (keepSpecialComments option).
+
0.6.0 / 2012-08-05
==================
- * Full Windows support with tests (./test.bat)
+ * Full Windows support with tests (./test.bat).
0.5.0 / 2012-08-02
==================
if (argv.o) options.target = argv.o;
if (argv._) options.source = argv._[0];
if (argv.e) cleanOptions.removeEmpty = true;
+if (argv.s1) cleanOptions.keepSpecialComments = 1;
+if (argv.s0) cleanOptions.keepSpecialComments = 0;
if (argv.v) {
var packageConfig = fs.readFileSync(path.join(path.dirname(fs.realpathSync(process.argv[1])), '../package.json'));
}
if (argv.h || argv.help || (!fromStdin && argv._.length == 0)) {
- util.print('usage: cleancss [-e] -o <output-file> <input-file>\n');
+ util.puts("usage: cleancss [options] -o <output-file> <input-file>\n");
+ util.puts("options:");
+ util.puts(" -e\tRemove empty declarations (e.g. a{})");
+ util.puts(" --s0\tRemove all special comments (i.e. /*! special comment */)");
+ util.puts(" --s1\tRemove all special comments but the first one");
return 0;
}
options = options || {};
+ // * - leave all important comments
+ // 1 - leave first important comment only
+ // 0 - strip all important comments
+ options.keepSpecialComments = 'keepSpecialComments' in options ?
+ options.keepSpecialComments :
+ '*';
+
// replace function
if (options.debug) {
var originalReplace = replace;
replace(/\} /g, '}') // whitespace after definition
// Get the special comments, content content, and spaces inside calc back
+ var specialCommentsCount = context.specialComments.length;
+
replace(/calc\([^\}]+\}/g, function(match) {
return match.replace(/\+/g, ' + ');
});
- replace(/__CSSCOMMENT__/g, function() { return context.specialComments.shift(); });
- replace(/__CSSCONTENT__/g, function() { return context.contentBlocks.shift(); });
+ replace(/__CSSCOMMENT__/g, function(i) {
+ switch (options.keepSpecialComments) {
+ case '*':
+ return context.specialComments.shift();
+ case 1:
+ return context.specialComments.length == specialCommentsCount ?
+ context.specialComments.shift() :
+ '';
+ case 0:
+ return '';
+ }
+ });
+ replace(/__CSSCONTENT__/g, function() {
+ return context.contentBlocks.shift();
+ });
return data.trim() // trim spaces at beginning and end
},
"type" : "git",
"url" : "http://github.com/GoalSmashers/clean-css.git"
},
- "version": "0.6.0",
+ "version": "0.7.0",
"main": "index.js",
"bin": {
"cleancss": "./bin/cleancss"
assert.equal(stdout, "a{}");
}
}),
+ 'strip all but first comment': pipedContext('/*!1st*//*! 2nd */a{}', '--s1', {
+ 'should keep the 2nd comment': function(error, stdout) {
+ assert.equal(stdout, "/*!1st*/a{}");
+ }
+ }),
+ 'strip all comments': pipedContext('/*!1st*//*! 2nd */a{}', '--s0', {
+ 'should keep the 2nd comment': function(error, stdout) {
+ assert.equal(stdout, "a{}");
+ }
+ }),
'empty': pipedContext('a{}', '-e', {
'should preserve content': function(error, stdout) {
assert.equal(stdout, "");
'/*! \n a > span { } with some content */'
]
}),
+ 'important comments - one': cssContext({
+ 'strip all but first': [
+ '/*! important comment */a{color:red}/* some comment *//*! important comment */',
+ '/*! important comment */a{color:red}'
+ ]
+ }, { keepSpecialComments: 1 }),
+ 'important comments - none': cssContext({
+ 'strip all': [
+ '/*! important comment */a{color:red}/* some comment *//*! important comment */',
+ 'a{color:red}'
+ ]
+ }, { keepSpecialComments: 0 }),
'text content': cssContext({
'normal #1': 'a{content:"."}',
'normal #2': [