forked from nanch/phpfmt_stable
-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.php
60 lines (46 loc) · 1.29 KB
/
build.php
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
<?php
/**
* Variables
*/
$srcRoot = __DIR__ . '/src';
$buildRoot = __DIR__ . '/build';
/**
* Bump version
*/
if ( ! isset( $argv[1] ) ) {
die( 'Provide a version number as argument' . PHP_EOL );
}
$version = $argv[1];
$file = file_get_contents( $srcRoot . '/phpf.php' );
file_put_contents( $srcRoot . '/phpf.php', preg_replace( "/define\( 'VERSION'\, '(.*?)' \)\;/", "define( 'VERSION', '$version' );", $file ) );
/**
* Build PHAR
*/
$phar = new Phar( $buildRoot . '/phpf.phar',
FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, 'myapp.phar' );
$phar['phpf.php'] = file_get_contents( $srcRoot . '/phpf.php' );
$phar->setStub( $phar->createDefaultStub( 'phpf.php' ) );
/**
* Generate READNE
*/
$readme_src = file_get_contents( __DIR__ . '/README.src.md' );
$readme_out = __DIR__ . '/README.md';
$testEnv = true;
require $srcRoot . '/phpf.php';
$usage = '';
foreach ( getOptions( false ) as $k => $v ) {
$usage .= '| ' . $k . ' | ' . $v . " |\n";
}
$cmd = sprintf( 'php %s/phpf.php --list-simple', $srcRoot );
$passes = explode( PHP_EOL, trim( `$cmd` ) );
$passes = implode( PHP_EOL,
array_map( function ( $v ) {
return ' * ' . $v;
}, $passes )
);
file_put_contents( $readme_out,
strtr( $readme_src, [
'%USAGE%' => $usage,
'%PASSES%' => $passes,
] )
);