Skip to content

Commit

Permalink
Merge pull request #18 from t32k/develop
Browse files Browse the repository at this point in the history
Support for short path syntax #17
  • Loading branch information
t32k committed Jan 3, 2015
2 parents 2600db9 + 0274612 commit 36651b7
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 94 deletions.
4 changes: 4 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ module.exports = function (grunt) {
'tmp/idontexist.css': ['test/fixtures/idontexist.css']
}
},
shortcut: {
src: 'test/fixtures/override.css'
},
dynamicMappings: {
files: [{
expand: true,
Expand Down Expand Up @@ -76,6 +79,7 @@ module.exports = function (grunt) {

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

};
35 changes: 4 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# grunt-csso v0.6.5
# grunt-csso v0.7.0

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

> Minify CSS files with CSSO.
Expand Down Expand Up @@ -86,6 +85,9 @@ csso: {
files: {
'banner.css': ['input.css']
}
},
shortcut: {
src: 'override.css'
}
}
```
Expand All @@ -104,35 +106,6 @@ csso: {
}
```

## Release History

+ 2014/11/30 - v0.6.5 - Improve CLI output.
+ 2014/11/17 - v0.6.4 - Update dependencies modules.
+ 2014/07/20 - v0.6.3 - Update dependencies modules.
+ 2014/03/18 - v0.6.2 - Update dependencies modules.
+ 2014/03/18 - v0.6.1 - Bug fix several bugs.
+ 2014/03/02 - v0.6.0 - Update dependencies modules.
+ 2013/12/19 - v0.5.3 - Bump v0.5.3
+ 2013/11/25 - v0.5.2 - Bump v0.5.2
+ 2013/11/25 - v0.5.1 - Update CSSO.
+ 2013/03/26 - v0.5.0 - Add 'report' option (false by default).
+ 2013/02/25 - v0.4.1 - Add 'banner' option.
+ 2013/02/17 - v0.4.0 - Support compatibility with Grunt 0.4.
+ 2013/01/17 - v0.3.0 - Improve file handling.
+ 2012/10/20 - v0.2.1 - Fix function to remove unnecessary argument.
+ 2012/10/20 - v0.2.0 - Changed CSSO task from the command line to from the npm module.
+ 2012/10/15 - v0.1.1 - Added keyword "gruntplugin" to package.json.
+ 2012/10/14 - v0.1.0 - Initial release.

## Contributors

Many thanks!

+ [Shogo Sensui](https://github.com/1000ch)
+ [Tyler Kellen](https://github.com/tkellen)
+ [Ayumu Sato](https://github.com/ahomu)
+ [Artem Sapegin](https://github.com/sapegin)

## License

Code is released under [the MIT license](LICENSE).
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-csso",
"description": "Minify CSS files with CSSO.",
"version": "0.6.5",
"version": "0.7.0",
"homepage": "https://github.com/t32k/grunt-csso",
"author": {
"name": "Koji Ishimoto",
Expand Down
105 changes: 53 additions & 52 deletions tasks/csso.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,72 @@
* grunt-csso
* http://github.com/t32k/grunt-csso
*
* Copyright (c) 2013 - 2014 Koji Ishimoto
* Copyright (c) 2013 Koji Ishimoto
* Licensed under the MIT license.
*/
'use strict';

module.exports = function (grunt) {

var fs = require('fs');
var path = require('path');
var fs = require('fs');
var path = require('path');

var csso = require('csso');
var chalk = require('chalk');
var maxmin = require('maxmin');
var csso = require('csso');
var chalk = require('chalk');
var maxmin = require('maxmin');

grunt.registerMultiTask('csso', 'Minify CSS files with CSSO.', function () {
grunt.registerMultiTask('csso', 'Minify CSS files with CSSO.', function () {

var options = this.options({
restructure: true,
banner: '',
report: false
});
var options = this.options({
restructure: true,
banner: '',
report: false
});

// Process banner.
var banner = grunt.template.process(options.banner);
// Process banner.
var banner = grunt.template.process(options.banner);

this.files.forEach(function (file) {
this.files.forEach(function (file) {
var dest = file.dest || file.src[0];

// 1. check existence
// 2. check file extension
// 3. load and concatenate css files
var original = file.src.filter(function (p) {
if (!fs.existsSync(p)) {
grunt.log.warn('Source file "' + p + '" is not found.');
return false;
} else {
return true;
}
}).filter(function (p) {
if (path.extname(p) !== '.css') {
grunt.log.warn('Source file "' + p + '" is not css.');
return false;
} else {
return true;
}
}).map(function (p) {
return fs.readFileSync(p, {
encoding: 'utf8'
});
}).join(grunt.util.normalizelf(grunt.util.linefeed));
// 1. check existence
// 2. check file extension
// 3. load and concatenate css files
var original = file.src.filter(function (p) {
if (!fs.existsSync(p)) {
grunt.log.warn('Source file "' + p + '" is not found.');
return false;
} else {
return true;
}
}).filter(function (p) {
if (path.extname(p) !== '.css') {
grunt.log.warn('Source file "' + p + '" is not css.');
return false;
} else {
return true;
}
}).map(function (p) {
return fs.readFileSync(p, {
encoding: 'utf8'
});
}).join(grunt.util.normalizelf(grunt.util.linefeed));

// reverse flag
var proceed = csso.justDoIt(original, !options.restructure);
// reverse flag
var proceed = csso.justDoIt(original, !options.restructure);

if (proceed.length === 0) {
grunt.log.warn('Destination is not created because minified CSS was empty.');
} else {
// add banner.
proceed = banner + proceed;
if (proceed.length === 0) {
grunt.log.warn('Destination is not created because minified CSS was empty.');
} else {
// add banner.
proceed = banner + proceed;

grunt.file.write(file.dest, proceed);
if (options.report) {
var report = maxmin(original, proceed, options.report === 'gzip');
}
grunt.log.writeln('File ' + chalk.cyan(file.dest) + ' created' + ((report) ? ': ' + report : '.'));
}
});
grunt.file.write(dest, proceed);
if (options.report) {
var report = maxmin(original, proceed, options.report === 'gzip');
}
grunt.log.writeln('File ' + chalk.cyan(dest) + ' created' + ((report) ? ': ' + report : '.'));
}
});
};
});
};
31 changes: 21 additions & 10 deletions test/csso-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ exports.csso = {
test.expect(1);

test.equal(
fs.readFileSync('test/expected/output.css', {encoding: 'utf8'}),
fs.readFileSync('tmp/output.css', {encoding: 'utf8'}),
fs.readFileSync('test/expected/output.css', 'utf8'),
fs.readFileSync('tmp/output.css', 'utf8'),
'should minify');

test.done();
Expand All @@ -17,8 +17,8 @@ exports.csso = {
test.expect(1);

test.equal(
fs.readFileSync('test/expected/restructure.css', {encoding: 'utf8'}),
fs.readFileSync('tmp/restructure.css', {encoding: 'utf8'}),
fs.readFileSync('test/expected/restructure.css', 'utf8'),
fs.readFileSync('tmp/restructure.css', 'utf8'),
'should minify with restructure'
);

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

test.equal(
fs.readFileSync('test/expected/banner.css', {encoding: 'utf8'}),
fs.readFileSync('tmp/banner.css', {encoding: 'utf8'}),
fs.readFileSync('test/expected/banner.css', 'utf8'),
fs.readFileSync('tmp/banner.css', 'utf8'),
'should minify css and prepend prefix banner'
);

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

test.done();
},
shortcut: function (test) {
test.expect(1);

test.equal(
fs.readFileSync('test/expected/output.css', 'utf8'),
fs.readFileSync('test/fixtures/override.css', 'utf8'),
'should override minify'
);

test.done();
},
dynamicMappings: function (test) {
test.expect(2);

test.equal(
fs.readFileSync('test/expected/output.css', {encoding: 'utf8'}),
fs.readFileSync('tmp/dest/input.min.css', {encoding: 'utf8'}),
fs.readFileSync('test/expected/output.css', 'utf8'),
fs.readFileSync('tmp/dest/input.min.css', 'utf8'),
'should minify with dynamic mappings'
);

test.equal(
fs.readFileSync('test/expected/output2.css', {encoding: 'utf8'}),
fs.readFileSync('tmp/dest/input2.min.css', {encoding: 'utf8'}),
fs.readFileSync('test/expected/output2.css', 'utf8'),
fs.readFileSync('tmp/dest/input2.min.css', 'utf8'),
'should minify with dynamic mappings'
);

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/override.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body{margin:0;font-size:18px}a{color:#fff;background-color:#000}

0 comments on commit 36651b7

Please sign in to comment.