-
Notifications
You must be signed in to change notification settings - Fork 10
/
Phakefile
93 lines (83 loc) · 2.94 KB
/
Phakefile
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
<?php
require_once 'lib/Proem/Util/Loader/Autoloader.php';
(new \Proem\Util\Loader\Autoloader)
->register();
group('proem', function() {
desc('Get curreent version of proem');
task('version', function() {
echo Proem\Proem::VERSION . "\n";
});
});
group('dev', function() {
desc('Default tasks to execute before commit');
task('pre-commit', 'tests', 'sniff', 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('Sniff code for PSR-1/2');
task('sniff', function ($args) {
chdir(realpath(__DIR__));
system('vendor/bin/phpcs -a --ignore=/Tests/* --standard=PSR2 lib/');
});
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/Util/Autoloader.php';
(new Proem\\Util\\Autoloader(false))
->attachNamespace('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/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/Proem.php', $file);
}
});
});
task('default', 'dev:pre-commit');