Skip to content

Commit

Permalink
Task cleanup and added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
somerandomdude committed May 6, 2013
1 parent 6588d7c commit 5b64be6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/*
* grunt-webp
* http://github.com/somerandomdude/grunt-webp
* http://somerandomdude.com
*
* Copyright 2013 P.J. Onori
* Licensed under the MIT license.
* MIT license.
*/

'use strict';
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
grunt-webp
==========

Convert your images to WebP format.
Convert your images to [WebP](https://developers.google.com/speed/webp/) format.

## Getting Started

To install this plugin, open up the terminal, `cd` to your project's root directory and run the following command:

```shell
npm install grunt-webp --save-dev
```

In your `Gruntfile.js` file add the following line:

```js
grunt.loadNpmTasks('grunt-webp');
```

This plugin requires Grunt `~0.4.0`
30 changes: 9 additions & 21 deletions tasks/webp.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* grunt-csso
* http://github.com/t32k/grunt-csso
* http://en.t32k.me
* grunt-webp
* http://github.com/somerandomdude/grunt-webp
* http://somerandomdude.com
*
* Copyright (c) 2013 Koji Ishimoto
* Licensed under the MIT license.
* Copyright (c) 2013 P.J. Onori
* MIT license.
*/


Expand Down Expand Up @@ -76,11 +76,9 @@ module.exports = function(grunt) {
* Retrieves defined options.
*/
var options = this.options();
//var files = grunt.file.expandMapping(this.files);
grunt.verbose.writeflags(options, 'Options');

var done = this.async();
grunt.log.subhead(this.fileDest);

this.files.forEach(function(file) {
var dest = path.normalize(file.dest + '/');
Expand All @@ -89,10 +87,7 @@ module.exports = function(grunt) {

grunt.util.async.forEachSeries(file.src, function(f, next) {



var args = [];
//grunt.log.subhead(String(f));
/**
* Preset setting, one of:
default, photo, picture,
Expand Down Expand Up @@ -280,24 +275,17 @@ module.exports = function(grunt) {
args.push('-v');
}

var fileExtname = path.extname(f);
var outputFilename = path.basename(f, '.png');
outputFilename = path.basename(outputFilename, '.jpg');
outputFilename = path.basename(outputFilename, '.jpeg');
args.push(f);
args.push('-o');
args.push(file.dest + outputFilename+'.webp');
var ext = path.extname(f);
var outputDest = path.join(file.dest, path.basename(f, ext) +'.webp');
args.push(outputDest);

/**
* Outputs the file that is being analysed.
*/
grunt.verbose.writeln('cwebp ' + args.join(' ') + ' ' + f + ' -o ' + file.dest + outputFilename+'.webp');

grunt.log.writeln('cwebp ' + args.join(' ') );


/**
* Executes the csscss command.
*/
var child = grunt.util.spawn({
cmd: 'cwebp',
args: args
Expand Down

0 comments on commit 5b64be6

Please sign in to comment.