Skip to content

Commit 3623b9d

Browse files
authored
Merge pull request #51 from exussum12/optimisePhar
Shrink phar size
2 parents de7f673 + 8384ca4 commit 3623b9d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ composer.lock
44
diff.txt
55
phpmd.xml
66
phpmd-tests.xml
7+
diffFilter.phar

CreatePhar.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<?php
22

3+
chdir(__DIR__);
4+
35
$pharName = 'diffFilter.phar';
6+
7+
cleanUp($pharName);
8+
49
$pharFile = getcwd() . '/diffFilter.phar';
510

611
if (file_exists($pharFile)) {
@@ -47,8 +52,20 @@ function addDir($dir, $phar)
4752
foreach ($iterator as $file) {
4853
$fullPath = $file->getPathname();
4954
$path = $dir . substr($fullPath, $codeLength);
55+
56+
if (strpos($path, '/test/') !== false) {
57+
continue;
58+
}
59+
5060
if (is_file($path)) {
51-
$phar->addFile($path);
61+
$phar->addFromString($path, php_strip_whitespace($path));
5262
}
5363
}
5464
}
65+
66+
function cleanUp($pharName)
67+
{
68+
shell_exec("rm -rf vendor");
69+
shell_exec("rm $pharName");
70+
shell_exec("composer install --no-dev -o");
71+
}

0 commit comments

Comments
 (0)