-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile-phar.php
42 lines (33 loc) · 1.25 KB
/
compile-phar.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
#!/usr/bin/env php
<?php
require __DIR__.'/src/Utils.php';
use ExerciseCleaner\Utils;
$pharFileName = 'exercise-cleaner.phar';
@unlink($pharFileName);
$version = trim(shell_exec('git fetch --tags --force --quiet && git describe --tags 2>&-;')) ?? 'dev';
$phar = new Phar($pharFileName);
$phar->addFromString('src/Application.php', preg_replace('@\$version = .+;@', "\$version = '$version';", file_get_contents('src/Application.php')));
$phar->setStub("#!/usr/bin/env php\n".Phar::createDefaultStub('src/Application.php'));
// Remove dev dependencies (like phpunit or php-cs-fixer)
shell_exec('composer install --no-dev --quiet;');
foreach ([
// Exercise Cleaner files except stub
'src/DefaultSingleCommand.php',
'src/ExerciseCleaner.php',
'src/Utils.php',
// Dependencies
'vendor/',
] as $path) {
if (is_dir($path)) {
$fileList = Utils::getFileListFromShellCmd("find $path -type f;");
} elseif (is_file($path)) {
$fileList = [$path];
} else {
trigger_error("$path is not a file nor a directory", E_USER_WARNING);
continue;
}
foreach ($fileList as $file) {
$phar->addFile($file);
}
}
shell_exec("chmod +x $pharFileName");