Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 111 lines (102 sloc) 3.833 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
<?php

require_once 'lib/Proem/Autoloader.php';

(new \Proem\Autoloader)
    ->attachNamespace('Proem', 'lib')
    ->register();

group('proem', function() {
    desc('Get curreent version of proem');
    task('version', function() {
        echo Proem\Proem::VERSION . "\n";
    });
});

group('dev', function() {

    desc('Run the unit tests');
    task('tests', function($args) {
        $report = ' ';
        if (isset($args['coverage'])) {
            if (!is_dir('tests/coverage')) {
                mkdir('tests/coverage');
            }
            $report = ' --coverage-html tests/coverage ';
        }
        if (isset($args['verbose'])) {
            system('vendor/bin/phpunit' . $report . '--colors --debug --verbose --configuration tests/phpunit.xml');
        } else {
            system('vendor/bin/phpunit' . $report . '--colors --configuration tests/phpunit.xml');
        }
    });

    desc('Build the Phar archive');
    task('build', 'tests', function($args) {
        if (!is_dir('build')) {
            mkdir('build');
        }
        chdir('lib');
        $phar = new Phar('proem.phar');
        $phar->buildFromDirectory('.');
        $phar->setStub("<?php
Phar::mapPhar('proem.phar');
require_once 'phar://proem.phar/Proem/Autoloader.php';
(new Proem\Autoloader())->attachNamespaces(['Proem' => 'phar://proem.phar'])->register();
__HALT_COMPILER();
?>");
        rename('proem.phar', '../build/proem.phar');
        chdir('../');
        if (isset($args['runtests'])) {
            system('vendor/bin/phpunit --colors tests/phar-test.php');
        }
    });

    desc('Bump the version number');
    task('bump', function($args) {
        $file = file_get_contents('lib/Proem/Api/Proem.php');
        preg_match('/VERSION = \'([0-9]?)\.([0-9]?)\.([a-z0-9])\';/', $file, $matches);
        list($all, $major, $minor, $incr) = $matches;
        if (isset($args['major'])) {
            $major = (string) ++$major;
            $minor = '0';
            $incr = '0';
        } elseif (isset($args['minor'])) {
            $minor = (string) ++$minor;
            $incr = '0';
        } elseif (isset($args['incr'])) {
            if ($args['incr'] === 'true') {
                $incr = (string) ++$incr;
            } else {
                $incr = $args['incr'];
            }
        }
        $version = "$major.$minor.$incr";
        echo "VERSION = '$version'\n";
        if (isset($args['write'])) {
            $file = preg_replace('/VERSION = \'(.*)\';/', "VERSION = '$version';", $file);
            file_put_contents('lib/Proem/Api/Proem.php', $file);
        }
    });
});

desc('Generate a file of aliased definitions, helpful for IDEs that are having trouble with code completion');
task('gen-ide-help', function() {
    function recurseDir($path = '.')
    {
        $ignore = ['.', '..'];
        $dh = @opendir($path);
        while(false !== ($file = readdir($dh))) {
            if (!in_array($file, $ignore)) {
                if (is_dir("$path/$file")) {
                    recurseDir("$path/$file");
                } else {
                    $filepath = "$path/$file";
                    foreach (file($filepath) as $line) {
                        if (preg_match('/^(class|abstract|trait)/', $line, $matches)) {
                            $type = $matches[1];
                            $class = str_replace(['lib/Proem/Api/', '.php', '/'], ['Proem/', '', '\\'], "$path/$file");
                            $extends = str_replace(['lib/', '.php', '/'], ['', '', '\\'], "$path/$file");
                            echo "$type $class extends $extends {}\n";
                        }
                    }
                }
            }
        }
        closedir( $dh );
    }
    recurseDir('lib');
});

task('default', 'dev:tests');
Something went wrong with that request. Please try again.