Skip to content

Commit 36651b7

Browse files
committed
Merge pull request #18 from t32k/develop
Support for short path syntax #17
2 parents 2600db9 + 0274612 commit 36651b7

File tree

6 files changed

+84
-94
lines changed

6 files changed

+84
-94
lines changed

Gruntfile.js

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ module.exports = function (grunt) {
4949
'tmp/idontexist.css': ['test/fixtures/idontexist.css']
5050
}
5151
},
52+
shortcut: {
53+
src: 'test/fixtures/override.css'
54+
},
5255
dynamicMappings: {
5356
files: [{
5457
expand: true,
@@ -76,6 +79,7 @@ module.exports = function (grunt) {
7679

7780
// Whenever the "test" task is run, first clean the "tmp" dir, then run this
7881
// plugin's task(s), then test the result.
82+
grunt.registerTask('default', ['test']);
7983
grunt.registerTask('test', ['clean', 'csso', 'nodeunit']);
8084

8185
};

README.md

+4-31
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
# grunt-csso v0.6.5
1+
# grunt-csso v0.7.0
22

33
[![Build Status](https://secure.travis-ci.org/t32k/grunt-csso.svg?branch=master)](http://travis-ci.org/t32k/grunt-csso)
4-
[![NPM version](https://badge.fury.io/js/grunt-csso.svg)](http://badge.fury.io/js/grunt-csso)
54
[![Dependency Status](https://david-dm.org/t32k/grunt-csso.svg)](https://david-dm.org/t32k/grunt-csso)
65

76
> Minify CSS files with CSSO.
@@ -86,6 +85,9 @@ csso: {
8685
files: {
8786
'banner.css': ['input.css']
8887
}
88+
},
89+
shortcut: {
90+
src: 'override.css'
8991
}
9092
}
9193
```
@@ -104,35 +106,6 @@ csso: {
104106
}
105107
```
106108

107-
## Release History
108-
109-
+ 2014/11/30 - v0.6.5 - Improve CLI output.
110-
+ 2014/11/17 - v0.6.4 - Update dependencies modules.
111-
+ 2014/07/20 - v0.6.3 - Update dependencies modules.
112-
+ 2014/03/18 - v0.6.2 - Update dependencies modules.
113-
+ 2014/03/18 - v0.6.1 - Bug fix several bugs.
114-
+ 2014/03/02 - v0.6.0 - Update dependencies modules.
115-
+ 2013/12/19 - v0.5.3 - Bump v0.5.3
116-
+ 2013/11/25 - v0.5.2 - Bump v0.5.2
117-
+ 2013/11/25 - v0.5.1 - Update CSSO.
118-
+ 2013/03/26 - v0.5.0 - Add 'report' option (false by default).
119-
+ 2013/02/25 - v0.4.1 - Add 'banner' option.
120-
+ 2013/02/17 - v0.4.0 - Support compatibility with Grunt 0.4.
121-
+ 2013/01/17 - v0.3.0 - Improve file handling.
122-
+ 2012/10/20 - v0.2.1 - Fix function to remove unnecessary argument.
123-
+ 2012/10/20 - v0.2.0 - Changed CSSO task from the command line to from the npm module.
124-
+ 2012/10/15 - v0.1.1 - Added keyword "gruntplugin" to package.json.
125-
+ 2012/10/14 - v0.1.0 - Initial release.
126-
127-
## Contributors
128-
129-
Many thanks!
130-
131-
+ [Shogo Sensui](https://github.com/1000ch)
132-
+ [Tyler Kellen](https://github.com/tkellen)
133-
+ [Ayumu Sato](https://github.com/ahomu)
134-
+ [Artem Sapegin](https://github.com/sapegin)
135-
136109
## License
137110

138111
Code is released under [the MIT license](LICENSE).

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "grunt-csso",
33
"description": "Minify CSS files with CSSO.",
4-
"version": "0.6.5",
4+
"version": "0.7.0",
55
"homepage": "https://github.com/t32k/grunt-csso",
66
"author": {
77
"name": "Koji Ishimoto",

tasks/csso.js

+53-52
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,72 @@
22
* grunt-csso
33
* http://github.com/t32k/grunt-csso
44
*
5-
* Copyright (c) 2013 - 2014 Koji Ishimoto
5+
* Copyright (c) 2013 Koji Ishimoto
66
* Licensed under the MIT license.
77
*/
88
'use strict';
99

1010
module.exports = function (grunt) {
1111

12-
var fs = require('fs');
13-
var path = require('path');
12+
var fs = require('fs');
13+
var path = require('path');
1414

15-
var csso = require('csso');
16-
var chalk = require('chalk');
17-
var maxmin = require('maxmin');
15+
var csso = require('csso');
16+
var chalk = require('chalk');
17+
var maxmin = require('maxmin');
1818

19-
grunt.registerMultiTask('csso', 'Minify CSS files with CSSO.', function () {
19+
grunt.registerMultiTask('csso', 'Minify CSS files with CSSO.', function () {
2020

21-
var options = this.options({
22-
restructure: true,
23-
banner: '',
24-
report: false
25-
});
21+
var options = this.options({
22+
restructure: true,
23+
banner: '',
24+
report: false
25+
});
2626

27-
// Process banner.
28-
var banner = grunt.template.process(options.banner);
27+
// Process banner.
28+
var banner = grunt.template.process(options.banner);
2929

30-
this.files.forEach(function (file) {
30+
this.files.forEach(function (file) {
31+
var dest = file.dest || file.src[0];
3132

32-
// 1. check existence
33-
// 2. check file extension
34-
// 3. load and concatenate css files
35-
var original = file.src.filter(function (p) {
36-
if (!fs.existsSync(p)) {
37-
grunt.log.warn('Source file "' + p + '" is not found.');
38-
return false;
39-
} else {
40-
return true;
41-
}
42-
}).filter(function (p) {
43-
if (path.extname(p) !== '.css') {
44-
grunt.log.warn('Source file "' + p + '" is not css.');
45-
return false;
46-
} else {
47-
return true;
48-
}
49-
}).map(function (p) {
50-
return fs.readFileSync(p, {
51-
encoding: 'utf8'
52-
});
53-
}).join(grunt.util.normalizelf(grunt.util.linefeed));
33+
// 1. check existence
34+
// 2. check file extension
35+
// 3. load and concatenate css files
36+
var original = file.src.filter(function (p) {
37+
if (!fs.existsSync(p)) {
38+
grunt.log.warn('Source file "' + p + '" is not found.');
39+
return false;
40+
} else {
41+
return true;
42+
}
43+
}).filter(function (p) {
44+
if (path.extname(p) !== '.css') {
45+
grunt.log.warn('Source file "' + p + '" is not css.');
46+
return false;
47+
} else {
48+
return true;
49+
}
50+
}).map(function (p) {
51+
return fs.readFileSync(p, {
52+
encoding: 'utf8'
53+
});
54+
}).join(grunt.util.normalizelf(grunt.util.linefeed));
5455

55-
// reverse flag
56-
var proceed = csso.justDoIt(original, !options.restructure);
56+
// reverse flag
57+
var proceed = csso.justDoIt(original, !options.restructure);
5758

58-
if (proceed.length === 0) {
59-
grunt.log.warn('Destination is not created because minified CSS was empty.');
60-
} else {
61-
// add banner.
62-
proceed = banner + proceed;
59+
if (proceed.length === 0) {
60+
grunt.log.warn('Destination is not created because minified CSS was empty.');
61+
} else {
62+
// add banner.
63+
proceed = banner + proceed;
6364

64-
grunt.file.write(file.dest, proceed);
65-
if (options.report) {
66-
var report = maxmin(original, proceed, options.report === 'gzip');
67-
}
68-
grunt.log.writeln('File ' + chalk.cyan(file.dest) + ' created' + ((report) ? ': ' + report : '.'));
69-
}
70-
});
65+
grunt.file.write(dest, proceed);
66+
if (options.report) {
67+
var report = maxmin(original, proceed, options.report === 'gzip');
68+
}
69+
grunt.log.writeln('File ' + chalk.cyan(dest) + ' created' + ((report) ? ': ' + report : '.'));
70+
}
7171
});
72-
};
72+
});
73+
};

test/csso-test.js

+21-10
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ exports.csso = {
77
test.expect(1);
88

99
test.equal(
10-
fs.readFileSync('test/expected/output.css', {encoding: 'utf8'}),
11-
fs.readFileSync('tmp/output.css', {encoding: 'utf8'}),
10+
fs.readFileSync('test/expected/output.css', 'utf8'),
11+
fs.readFileSync('tmp/output.css', 'utf8'),
1212
'should minify');
1313

1414
test.done();
@@ -17,8 +17,8 @@ exports.csso = {
1717
test.expect(1);
1818

1919
test.equal(
20-
fs.readFileSync('test/expected/restructure.css', {encoding: 'utf8'}),
21-
fs.readFileSync('tmp/restructure.css', {encoding: 'utf8'}),
20+
fs.readFileSync('test/expected/restructure.css', 'utf8'),
21+
fs.readFileSync('tmp/restructure.css', 'utf8'),
2222
'should minify with restructure'
2323
);
2424

@@ -28,8 +28,8 @@ exports.csso = {
2828
test.expect(1);
2929

3030
test.equal(
31-
fs.readFileSync('test/expected/banner.css', {encoding: 'utf8'}),
32-
fs.readFileSync('tmp/banner.css', {encoding: 'utf8'}),
31+
fs.readFileSync('test/expected/banner.css', 'utf8'),
32+
fs.readFileSync('tmp/banner.css', 'utf8'),
3333
'should minify css and prepend prefix banner'
3434
);
3535

@@ -45,18 +45,29 @@ exports.csso = {
4545

4646
test.done();
4747
},
48+
shortcut: function (test) {
49+
test.expect(1);
50+
51+
test.equal(
52+
fs.readFileSync('test/expected/output.css', 'utf8'),
53+
fs.readFileSync('test/fixtures/override.css', 'utf8'),
54+
'should override minify'
55+
);
56+
57+
test.done();
58+
},
4859
dynamicMappings: function (test) {
4960
test.expect(2);
5061

5162
test.equal(
52-
fs.readFileSync('test/expected/output.css', {encoding: 'utf8'}),
53-
fs.readFileSync('tmp/dest/input.min.css', {encoding: 'utf8'}),
63+
fs.readFileSync('test/expected/output.css', 'utf8'),
64+
fs.readFileSync('tmp/dest/input.min.css', 'utf8'),
5465
'should minify with dynamic mappings'
5566
);
5667

5768
test.equal(
58-
fs.readFileSync('test/expected/output2.css', {encoding: 'utf8'}),
59-
fs.readFileSync('tmp/dest/input2.min.css', {encoding: 'utf8'}),
69+
fs.readFileSync('test/expected/output2.css', 'utf8'),
70+
fs.readFileSync('tmp/dest/input2.min.css', 'utf8'),
6071
'should minify with dynamic mappings'
6172
);
6273

test/fixtures/override.css

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
body{margin:0;font-size:18px}a{color:#fff;background-color:#000}

0 commit comments

Comments
 (0)