Skip to content

Commit

Permalink
update version
Browse files Browse the repository at this point in the history
  • Loading branch information
raulghm committed Feb 1, 2016
1 parent e904ee8 commit 1f1f1ed
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 131 deletions.
11 changes: 5 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# http://editorconfig.org
root = true

[*]
indent_style = tab
indent_size = 4
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
[package.json]
indent_style = space
indent_size = 2

[test/fixtures/*]
insert_final_newline = false
[*.md]
trim_trailing_whitespace = false
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* text=auto
* text=auto
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
node_modules
.DS_Store
node_modules/
temp/
coverage
31 changes: 12 additions & 19 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
{
"node": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 4,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "double",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true,
"white": true
"node": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"immed": true,
"newcap": true,
"noarg": true,
"undef": true,
"unused": "vars",
"strict": true,
"mocha": true
}
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sudo: false
language: node_js
node_js:
- '0.8'
- 'iojs'
- '0.12'
- '0.10'
after_script:
- npm run coveralls
35 changes: 18 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
Copyright 2014 Raúl
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
Copyright (c) raulghm <[email protected]>

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
40 changes: 14 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
<a href="https://github.com/raulghm/gulp-wp-rev/stargazers"><img src="http://img.shields.io/npm/dm/gulp-wp-rev.svg?style=flat-square"></a>
</p>


> gulp-wp-rev plugin for [gulp](https://github.com/wearefractal/gulp)
> Revisioning JS and CSS to scripts.php file on wordpress assets
Revisioning CSS/JS appending a hash in you assets of wordpress theme.

`styles.css?ver=1``styles?ver=bd0622b828f9346876088cd617566fa5`

Alternative gulpjs version for `grunt-wp-version` of https://github.com/roots/roots
<img src="example/demo.gif" alt="demo">

## Usage

Expand All @@ -22,19 +23,18 @@ npm install --save-dev gulp-wp-rev
Then, add it to your `gulpfile.js`:

```javascript
var rev = require("gulp-wp-rev");
var wpRev = require('gulp-wp-rev');

gulp.task('rev', function () {
gulp.src('lib/scripts.php')
.pipe(rev({
css: "assets/css/main.min.css",
cssHandle: "roots_main",
js: "assets/js/scripts.min.js",
jsHandle: "roots_scripts"
}))
.pipe(gulp.dest('lib'));
gulp.src('./wp-content/themes/raulghm-theme/lib/scripts.php')
.pipe(wpRev({
css: 'src/styles/styles.css',
cssHandle: 'my_assets',
js: 'src/scripts/scripts.js',
jsHandle: 'my_assets'
}))
.pipe(gulp.dest('./wp-content/themes/raulghm-theme/lib'));
});

```

## API
Expand Down Expand Up @@ -64,16 +64,4 @@ Name used as a handle for the javascript.

## License

[MIT License](http://en.wikipedia.org/wiki/MIT_License)

[npm-url]: https://npmjs.org/package/gulp-wp-rev
[npm-image]: https://badge.fury.io/js/gulp-wp-rev.png

[travis-url]: http://travis-ci.org/raulghm/gulp-wp-rev
[travis-image]: https://secure.travis-ci.org/raulghm/gulp-wp-rev.png?branch=master

[coveralls-url]: https://coveralls.io/r/raulghm/gulp-wp-rev
[coveralls-image]: https://coveralls.io/repos/raulghm/gulp-wp-rev/badge.png

[depstat-url]: https://david-dm.org/raulghm/gulp-wp-rev
[depstat-image]: https://david-dm.org/raulghm/gulp-wp-rev.png
MIT © [raulghm](https://github.com/raulghm)
Binary file added example/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions example/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

var gulp = require('gulp');
var runSequence = require('run-sequence');
var wpRev = require('gulp-wp-rev');

gulp.task('rev', function () {
gulp.src('./wp-content/themes/raulghm-theme/lib/scripts.php')
.pipe(wpRev({
css: 'src/styles/styles.css',
cssHandle: 'my_assets',
js: 'src/scripts/scripts.js',
jsHandle: 'my_assets'
}))
.pipe(gulp.dest('./wp-content/themes/raulghm-theme/lib'));
});

gulp.task('build', function (callback) {
runSequence(
'rev',
function (error) {
if (error) {
console.log(error.message);
} else {
console.log('Build finished successfully :)');
}
callback(error);
});
});
17 changes: 17 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "example",
"version": "1.0.0",
"description": "example",
"main": "gulpfile.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "gulp build"
},
"author": "raulghm",
"license": "MIT",
"devDependencies": {
"gulp": "^3.9.0",
"gulp-wp-rev": "0.0.1",
"run-sequence": "^1.1.5"
}
}
1 change: 1 addition & 0 deletions example/src/scripts/scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Más vale código en mano que líneas volando');
3 changes: 3 additions & 0 deletions example/src/styles/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background: #bbb;
}
19 changes: 19 additions & 0 deletions example/wp-content/themes/raulghm-theme/lib/scripts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@



<?php
/**
* Enqueue scripts and stylesheets
*
* Simple example
*/

function my_assets_function() {
wp_enqueue_style('my_assets', get_template_directory_uri() . '/assets/styles/styles.css', false, '99751aae501b70d8edb1be6d827adefd');
wp_register_script('my_assets', get_template_directory_uri() . '/assets/scripts/scripts.js', array(), '892354e5fc462fba85da60adb9b87ce7');
wp_enqueue_script('my_assets');
}

add_action('wp_enqueue_scripts', 'my_assets_function', 10);


53 changes: 23 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,48 @@
var through = require("through2"),
gutil = require("gulp-util");
fs = require('fs');
crypto = require('crypto');

'use strict';
var gutil = require('gulp-util');
var through = require('through2');
var fs = require('fs');
var crypto = require('crypto');
var md5 = function(str) {
var hash = crypto.createHash('md5');
hash.update(fs.readFileSync(str));
return hash.digest('hex');
};

module.exports = function(options) {
"use strict";

var o = options || {};

function foo(file, enc, callback) {
module.exports = function (options) {
options = options || {};

// Do nothing if no contents
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
this.push(file);
return callback();
cb(null, file);
return;
}

if (file.isStream()) {
// accepting streams is optional
this.emit("error",
new gutil.PluginError("gulp-foo", "Stream content is not supported"));
return callback();
cb(new gutil.PluginError('gulp-wp-rev', 'Streaming not supported'));
return;
}

// check if file.contents is a `Buffer`
if (file.isBuffer()) {

file.contents = new Buffer(String(file.contents));
if (o.css && o.cssHandle) {
var regexCss = new RegExp("(wp_enqueue_style\\('" + o.cssHandle + "',(\\s*[^,]+,){2})\\s*[^\\)]+\\);");
var hashCss = md5(o.css);
file.contents = new Buffer(String(file.contents));

if (options.css && options.cssHandle) {
var regexCss = new RegExp("(wp_enqueue_style\\('" + options.cssHandle + "',(\\s*[^,]+,){2})\\s*[^\\)]+\\);");
var hashCss = md5(options.css);
file.contents = new Buffer(String(file.contents).replace(regexCss, "$1 '" + hashCss + "');"));
}

if (o.js && o.jsHandle) {
var regexJs = new RegExp("(wp_register_script\\('" + o.jsHandle + "',(\\s*[^,]+,){2})\\s*[^\\)]+\\);");
var hashJs = md5(o.js);
if (options.js && options.jsHandle) {
var regexJs = new RegExp("(wp_register_script\\('" + options.jsHandle + "',(\\s*[^,]+,){2})\\s*[^\\)]+\\);");
var hashJs = md5(options.js);
file.contents = new Buffer(String(file.contents).replace(regexJs, "$1 '" + hashJs + "');"));
}
}

this.push(file);
}
return callback();
}

return through.obj(foo);
cb();
});
};
49 changes: 23 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
{
"name": "gulp-wp-rev",
"version": "0.1.0",
"description": "Revisioning JS and CSS to scripts.php file on wordpress assets",
"version": "0.2.0",
"description": "Revisioning CSS/JS appending a hash in you assets of wordpress theme",
"license": "MIT",
"repository": "raulghm/gulp-wp-rev",
"author": {
"name": "raulghm",
"email": "[email protected]",
"url": "https://github.com/raulghm"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "mocha"
},
"files": [
"index.js"
],
"keywords": [
"gulpplugin",
"wordpress"
Expand All @@ -14,32 +30,13 @@
"cache",
"expire",
"static",
"asset",
"assets"
],
"homepage": "https://github.com/raulghm/gulp-wp-rev",
"bugs": "https://github.com/raulghm/gulp-wp-rev/issues",
"author": {
"name": "Raul Hernandez",
"email": "[email protected]",
"url": "https://github.com/raulghm"
},
"main": "./index.js",
"repository": {
"type": "git",
"url": "git://github.com/raulghm/gulp-wp-rev.git"
},
"dependencies": {
"through2": "*",
"gulp-util": "~2.2.0"
},
"engines": {
"node": ">=0.8.0",
"npm": ">=1.2.10"
"gulp-util": "^3.0.1",
"through2": "^0.6.3"
},
"licenses": [
{
"type": "MIT"
}
]
"devDependencies": {
"mocha": "*"
}
}
Loading

0 comments on commit 1f1f1ed

Please sign in to comment.