From 2e7883bc628f84000a65e60198bc27f2d04d243b Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Sat, 15 Jul 2017 21:44:48 +0200 Subject: [PATCH] Packaging process bundled as Gulp task Bundling a ready to use plugin ZIP has been automated into a Gulp task. After executing unit tests and code sniffer, only the relevant files are bundled. --- .gitignore | 2 ++ Gulpfile.js | 61 ++++++++++++++++++++++++++++++++++ README.md | 1 + composer.json | 3 +- package.json | 17 ++++++++++ ruleset.xml => phpcs.xml | 3 +- phpunit.xml | 5 ++- statify-blacklist.php | 3 +- test/statifyblacklist-test.php | 4 +-- 9 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 Gulpfile.js create mode 100644 package.json rename ruleset.xml => phpcs.xml (89%) diff --git a/.gitignore b/.gitignore index 155f8d8..a96de97 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ composer.lock /vendor/ +/node_modules/ +/dist/ .idea diff --git a/Gulpfile.js b/Gulpfile.js new file mode 100644 index 0000000..1c87d91 --- /dev/null +++ b/Gulpfile.js @@ -0,0 +1,61 @@ +var gulp = require('gulp'); +var clean = require('gulp-clean'); +var copy = require('gulp-copy'); +var zip = require('gulp-zip'); +var composer = require('gulp-composer'); +var phpunit = require('gulp-phpunit'); +var exec = require('child_process').exec; +var phpcs = require('gulp-phpcs'); +var config = require('./package.json'); + +// Clean the target directory. +gulp.task('clean', function () { + console.log('Cleaning up target directory ...'); + return gulp.src('dist', {read: false}) + .pipe(clean()); +}); + +// Prepare composer. +gulp.task('compose', function () { + console.log('Preparing Composer ...'); + return composer('install'); +}); + +// Execute unit tests. +gulp.task('test', ['compose'], function () { + console.log('Running PHPUnit tests ...'); + return gulp.src('phpunit.xml') + .pipe(phpunit('./vendor/bin/phpunit', {debug: false})); +}); + +// Execute PHP Code Sniffer. +gulp.task('test-cs', function (cb) { + return exec('./vendor/bin/phpcs --config-set installed_paths vendor/wp-coding-standards/wpcs', function (err, stdout, stderr) { + console.log(stdout); + console.log(stderr); + if (null === err) { + console.log('Running PHP Code Sniffer tests ...'); + gulp.src(['statify-blacklist.php', 'inc/**/*.php']) + .pipe(phpcs({bin: './vendor/bin/phpcs', standard: 'phpcs.xml'})) + .pipe(phpcs.reporter('log')); + } + cb(err); + }); +}); + +// Bundle files as required for plugin distribution.. +gulp.task('bundle', ['clean'], function () { + console.log('Collecting files for package dist/' + config.name + config.version + ' ...'); + return gulp.src(['**/*.php', '!test/**', '!vendor/**', 'README.md', 'LICENSE.md'], {base: './'}) + .pipe(copy('./dist/' + config.name + '.' + config.version)); +}); + +// Create a ZIP package of the relevant files for plugin distribution. +gulp.task('package', ['bundle'], function () { + console.log('Building package dist/' + config.name + config.version + '.zip ...'); + return gulp.src('./dist/' + config.name + '.' + config.version + '/**') + .pipe(zip(config.name + '.' + config.version + '.zip')) + .pipe(gulp.dest('./dist')); +}); + +gulp.task('default', ['clean', 'compose', 'test', 'test-cs', 'bundle', 'package']); diff --git a/README.md b/README.md index f6e3655..b1cf7df 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ Because of this, an IP blacklist can only be applied while processing the reques ### Work in Progress ### * Relicensed to GPLv2 or later +* Fix problem with faulty IPv6 netmask in IP blacklist * Minor changes for WP Coding Standard ### 1.4.0 / 10.06.2017 ### diff --git a/composer.json b/composer.json index 6e801ce..8bc4adb 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,6 @@ { "name": "stklcode/statify-blacklist", + "version": "1.4.1-dev", "description": "A blacklist extension for the famous Statify WordPress plugin", "keywords": [ "wordpress", @@ -23,6 +24,6 @@ "require-dev": { "php": ">=5.5", "phpunit/phpunit": "*", - "wp-coding-standards/wpcs": "~0.6.0" + "wp-coding-standards/wpcs": "~0.11.0" } } diff --git a/package.json b/package.json new file mode 100644 index 0000000..823e20e --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "statify-blacklist", + "version": "1.4.1-dev", + "description": "A blacklist extension for the famous Statify WordPress plugin", + "author": "Stefan Kalscheuer", + "license": "GPLv2 or later", + "devDependencies": { + "gulp": "^3.9.1", + "gulp-clean": "^0.3.2", + "gulp-copy": "^1.0.0", + "gulp-zip": "^4.0.0", + "gulp-composer": "^0.4.0", + "gulp-phpunit": "^0.23.0", + "gulp-phpcs": "^2.0.0", + "child_process": "^1.0.2" + } +} diff --git a/ruleset.xml b/phpcs.xml similarity index 89% rename from ruleset.xml rename to phpcs.xml index 0b0c251..797a05d 100644 --- a/ruleset.xml +++ b/phpcs.xml @@ -1,6 +1,7 @@ - Derived from WordPress + Derived from WordPress Coding Standard + diff --git a/phpunit.xml b/phpunit.xml index 8089d7f..c0f5eba 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,8 +2,7 @@ - ./test + ./test/ - - \ No newline at end of file + diff --git a/statify-blacklist.php b/statify-blacklist.php index 41e68e8..3e5c74f 100644 --- a/statify-blacklist.php +++ b/statify-blacklist.php @@ -7,11 +7,10 @@ * @license GPL-2.0+ * * @wordpress-plugin - * * Plugin Name: Statify Blacklist * Plugin URI: https://de.wordpress.org/plugins/statify-blacklist/ * Description: Extension for the Statify plugin to add a customizable blacklists. - * Version: 1.4.0 + * Version: 1.4.1-dev * Author: Stefan Kalscheuer (@stklcode) * Author URI: https://www.stklcode.de * Plugin URI: https://wordpress.org/plugins/statify-blacklist diff --git a/test/statifyblacklist-test.php b/test/statifyblacklist-test.php index 985b131..90a666e 100644 --- a/test/statifyblacklist-test.php +++ b/test/statifyblacklist-test.php @@ -39,12 +39,12 @@ require_once( 'inc/statifyblacklist-admin.class.php' ); * * @since 1.3.0 */ -class StatifyBlacklistTest extends PHPUnit\Framework\TestCase { +class StatifyBlacklist_Test extends PHPUnit_Framework_TestCase { /** * Test simple referer filter. */ - public function testRefererFilter() { + public function test_referer_filter() { // Prepare Options: 2 blacklisted domains, disabled. StatifyBlacklist::$_options = array( 'referer' => array(