-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPakefile.php
85 lines (61 loc) · 2.51 KB
/
Pakefile.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
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
<?php
pake_desc('Build phar archive');
pake_task('phar');
function exec_composer($path)
{
$prev_dir = getcwd();
chdir($path);
$composer = 'php composer.phar';
install_composer($path);
echo pake_sh("$composer --version");
pake_echo_action('composer', 'install dependencies');
pake_sh("$composer install --no-dev --classmap-authoritative");
chdir($prev_dir);
}
function install_composer($path)
{
$prev_dir = getcwd();
chdir($path);
pake_echo_action('composer', 'install composer');
// official composer installation guide from https://getcomposer.org/download/
pake_copy('https://getcomposer.org/installer', $path . '/composer-setup.php');
$hash = file_get_contents('https://composer.github.io/installer.sig') ?: NAN;
if (hash_file('SHA384', 'composer-setup.php') === $hash) {
echo 'Installer verified';
} else {
echo 'Installer or signature is corrupt';
}
echo PHP_EOL;
pake_sh('php composer-setup.php --2');
pake_unlink($path . '/composer-setup.php');
chdir($prev_dir);
}
function run_phar()
{
$build_dir = __DIR__ . '/build';
pake_echo_action('phar', 'prepare build dir');
pake_mkdirs($build_dir);
pake_remove(pakeFinder::type('file')->name('*'), $build_dir);
// project files
pake_mirror(pakeFinder::type('file')->name('*.php'), __DIR__ . '/bin', $build_dir . '/bin');
pake_mirror(pakeFinder::type('file')->name('*.php'), __DIR__ . '/src', $build_dir . '/src');
// make clean library installation without dev dependencies
pake_copy(__DIR__ . '/composer.json', $build_dir . '/composer.json');
pake_copy(__DIR__ . '/composer.lock', $build_dir . '/composer.lock');
exec_composer($build_dir);
pake_echo_action('phar', 'set product version');
// App version
$bin_file = file_get_contents($build_dir . '/bin/wp2md.php');
$version = trim(pake_sh('git describe --tags HEAD'));
$bin_file = preg_replace('/@package_version@/', $version, $bin_file);
file_put_contents($build_dir . '/bin/wp2md.php', $bin_file);
pake_echo_action('phar', 'init phar archive');
$phar = new \Secondtruth\Compiler\Compiler($build_dir);
$phar->addDirectory('bin');
$phar->addDirectory('src');
$phar->addDirectory('vendor', array('*Test.php', '*Tester.php', '*/Tests/*'));
$phar->addIndexFile('bin/wp2md.php', 'cli');
$phar->compile($build_dir . '/wp2md.phar');
pake_chmod('wp2md.phar', $build_dir, 0755);
pake_echo_action('phar', 'done. build/wp2md.phar is created');
}