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.
This commit is contained in:
Stefan Kalscheuer 2017-07-15 21:44:48 +02:00
parent 3206da2861
commit 2e7883bc62
9 changed files with 90 additions and 9 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
composer.lock composer.lock
/vendor/ /vendor/
/node_modules/
/dist/
.idea .idea

61
Gulpfile.js Normal file
View File

@ -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']);

View File

@ -83,6 +83,7 @@ Because of this, an IP blacklist can only be applied while processing the reques
### Work in Progress ### ### Work in Progress ###
* Relicensed to GPLv2 or later * Relicensed to GPLv2 or later
* Fix problem with faulty IPv6 netmask in IP blacklist
* Minor changes for WP Coding Standard * Minor changes for WP Coding Standard
### 1.4.0 / 10.06.2017 ### ### 1.4.0 / 10.06.2017 ###

View File

@ -1,5 +1,6 @@
{ {
"name": "stklcode/statify-blacklist", "name": "stklcode/statify-blacklist",
"version": "1.4.1-dev",
"description": "A blacklist extension for the famous Statify WordPress plugin", "description": "A blacklist extension for the famous Statify WordPress plugin",
"keywords": [ "keywords": [
"wordpress", "wordpress",
@ -23,6 +24,6 @@
"require-dev": { "require-dev": {
"php": ">=5.5", "php": ">=5.5",
"phpunit/phpunit": "*", "phpunit/phpunit": "*",
"wp-coding-standards/wpcs": "~0.6.0" "wp-coding-standards/wpcs": "~0.11.0"
} }
} }

17
package.json Normal file
View File

@ -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"
}
}

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<ruleset name="StatifyBlacklist"> <ruleset name="StatifyBlacklist">
<description>Derived from WordPress</description> <description>Derived from WordPress Coding Standard</description>
<rule ref="WordPress"> <rule ref="WordPress">
<!-- Type hint checks mess up PHP 7 checks, while this plugin has compatibility level 5.5 and above. --> <!-- Type hint checks mess up PHP 7 checks, while this plugin has compatibility level 5.5 and above. -->
<exclude name="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing"/> <exclude name="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing"/>

View File

@ -2,8 +2,7 @@
<phpunit bootstrap="./vendor/autoload.php"> <phpunit bootstrap="./vendor/autoload.php">
<testsuites> <testsuites>
<testsuite name="Statify Blacklist TestSuite"> <testsuite name="Statify Blacklist TestSuite">
<directory>./test</directory> <directory suffix="-test.php">./test/</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
</phpunit>
</phpunit>

View File

@ -7,11 +7,10 @@
* @license GPL-2.0+ * @license GPL-2.0+
* *
* @wordpress-plugin * @wordpress-plugin
*
* Plugin Name: Statify Blacklist * Plugin Name: Statify Blacklist
* Plugin URI: https://de.wordpress.org/plugins/statify-blacklist/ * Plugin URI: https://de.wordpress.org/plugins/statify-blacklist/
* Description: Extension for the Statify plugin to add a customizable blacklists. * 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: Stefan Kalscheuer (@stklcode)
* Author URI: https://www.stklcode.de * Author URI: https://www.stklcode.de
* Plugin URI: https://wordpress.org/plugins/statify-blacklist * Plugin URI: https://wordpress.org/plugins/statify-blacklist

View File

@ -39,12 +39,12 @@ require_once( 'inc/statifyblacklist-admin.class.php' );
* *
* @since 1.3.0 * @since 1.3.0
*/ */
class StatifyBlacklistTest extends PHPUnit\Framework\TestCase { class StatifyBlacklist_Test extends PHPUnit_Framework_TestCase {
/** /**
* Test simple referer filter. * Test simple referer filter.
*/ */
public function testRefererFilter() { public function test_referer_filter() {
// Prepare Options: 2 blacklisted domains, disabled. // Prepare Options: 2 blacklisted domains, disabled.
StatifyBlacklist::$_options = array( StatifyBlacklist::$_options = array(
'referer' => array( 'referer' => array(