Added Robo build script

Created tasks for building and testing using Robo build environment, installed via Composer. This is supposed to replace Gulp as default build tool and makes NPM obsolete.
This commit is contained in:
Stefan Kalscheuer 2017-12-29 11:34:25 +01:00
parent d82de3547b
commit 0b7c9c07e2
3 changed files with 173 additions and 1 deletions

View File

@ -50,7 +50,7 @@ gulp.task('test-cs', function (cb) {
// Bundle files as required for plugin distribution.. // Bundle files as required for plugin distribution..
gulp.task('bundle', ['clean'], function () { gulp.task('bundle', ['clean'], function () {
console.log('Collecting files for package dist/' + config.name + config.version + ' ...'); console.log('Collecting files for package dist/' + config.name + config.version + ' ...');
return gulp.src(['**/*.php', '!test/**', '!vendor/**', 'README.md', 'LICENSE.md'], {base: './'}) return gulp.src(['**/*.php', '!RoboFile.php', '!test/**', '!vendor/**', 'README.md', 'LICENSE.md'], {base: './'})
.pipe(copy('./dist/' + config.name + '.' + config.version + '/' + config.name)); .pipe(copy('./dist/' + config.name + '.' + config.version + '/' + config.name));
}); });

165
RoboFile.php Normal file
View File

@ -0,0 +1,165 @@
<?php
/**
* Statify Blacklist Robo build script.
*
* This file contains the Robo tasks for building a distributable plugin package.
* Should not be included in final package.
*
* @author Stefan Kalscheuer <stefan@stklcode.de>
*
* @package Statify_Blacklist
* @version 1.4.2
*/
use Robo\Tasks;
/**
* Class RoboFile
*/
class RoboFile extends Tasks {
const PROJECT_NAME = 'statify-blacklist';
const OPT_TARGET = 'target';
const OPT_SKIPTEST = 'skipTests';
const OPT_SKIPSTYLE = 'skipStyle';
/**
* Version tag (read from composer.json).
*
* @var string
*/
private $version;
/**
* Target directory path.
*
* @var string
*/
private $target_dir;
/**
* Final package name.
*
* @var string
*/
private $final_name;
/**
* RoboFile constructor
*
* @param array $opts Options.
*
* @return void
*/
public function __construct( $opts = [ self::OPT_TARGET => 'dist' ] ) {
// Read composer configuration and extract version number..
$composer = json_decode( file_get_contents( __DIR__ . '/composer.json' ) );
// Extract parameter from options.
$this->version = $composer->version;
$this->target_dir = $opts[ self::OPT_TARGET ];
$this->final_name = self::PROJECT_NAME . '.' . $this->version;
}
/**
* Clean up target directory
*
* @param array $opts Options.
*
* @return void
*/
public function clean(
$opts = [
self::OPT_TARGET => 'dist'
]
) {
$this->say( 'Cleaning target directory...' );
if ( is_dir( $this->target_dir ) ) {
$this->taskCleanDir( [ $this->target_dir ] )->run();
}
}
/**
* Run PHPUnit tests
*
* @return void
*/
public function test() {
$this->say( 'Executing PHPUnit tests...' );
$this->taskPhpUnit()->configFile( __DIR__ . '/phpunit.xml' )->run();
}
/**
* Run code style tests
*
* @return void
*/
public function testCS() {
$this->say( 'Executing PHPCS tests...' );
$this->_exec( __DIR__ . '/vendor/bin/phpcs --standard=phpcs.xml -s' );
}
/**
* Build a distributable bundle.
*
* @param array $opts Options.
*
* @return void
*/
public function build(
$opts = [
self::OPT_TARGET => 'dist',
self::OPT_SKIPTEST => false,
self::OPT_SKIPSTYLE => false,
]
) {
$this->clean($opts);
if ( isset( $opts[ self::OPT_SKIPTEST ] ) && true === $opts[ self::OPT_SKIPTEST ] ) {
$this->say( 'Tests skipped' );
} else {
$this->test();
}
if ( isset( $opts[ self::OPT_SKIPSTYLE ] ) && true === $opts[ self::OPT_SKIPSTYLE ] ) {
$this->say( 'Style checks skipped' );
} else {
$this->testCS();
}
$this->bundle();
}
/**
* Bundle global resources.
*
* @return void
*/
private function bundle() {
$this->say( 'Bundling resources...' );
$this->taskCopyDir( [
'inc' => $this->target_dir . '/' . $this->final_name . '/inc',
'views' => $this->target_dir . '/' . $this->final_name . '/views',
] )->run();
$this->_copy( 'statify-blacklist.php', $this->target_dir . '/' . $this->final_name . '/statify-blacklist.php' );
$this->_copy( 'README.md', $this->target_dir . '/' . $this->final_name . '/README.md' );
$this->_copy( 'LICENSE.md', $this->target_dir . '/' . $this->final_name . '/LICENSE.md' );
}
/**
* Create ZIP package from distribution bundle.
*
* @param array $opts Options.
*
* @return void
*/
public function package(
$opts = [
self::OPT_TARGET => 'dist',
self::OPT_SKIPTEST => false,
self::OPT_SKIPSTYLE => false,
]
) {
$this->build($opts);
$this->say( 'Packaging...' );
$this->taskPack( $this->target_dir . '/' . $this->final_name . '.zip' )
->addDir( '', $this->target_dir . '/' . $this->final_name )
->run();
}
}

View File

@ -24,6 +24,7 @@
"require-dev": { "require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.4", "dealerdirect/phpcodesniffer-composer-installer": "^0.4",
"php": ">=5.5", "php": ">=5.5",
"consolidation/robo": "^1.0.0",
"phpunit/phpunit": "*", "phpunit/phpunit": "*",
"phpunit/php-code-coverage": "*", "phpunit/php-code-coverage": "*",
"slowprog/composer-copy-file": "~0.2", "slowprog/composer-copy-file": "~0.2",
@ -32,6 +33,12 @@
"wp-coding-standards/wpcs": "~0.14" "wp-coding-standards/wpcs": "~0.14"
}, },
"scripts": { "scripts": {
"build": [
"robo build"
],
"package": [
"robo package"
],
"test-all": [ "test-all": [
"@test", "@test",
"@test-cs" "@test-cs"