|
1 | 1 | #!/usr/bin/env php
|
2 | 2 | <?php
|
3 | 3 |
|
| 4 | +class NonProjectFilesFilter extends RecursiveFilterIterator { |
| 5 | + public function accept() { |
| 6 | + if ($this->hasChildren()) { |
| 7 | + return true; |
| 8 | + } else { |
| 9 | + /** @var SplFileInfo $current */ |
| 10 | + $current = $this->current(); |
| 11 | + $realpath = substr($current->getRealPath(), strlen(dirname(__FILE__) . DIRECTORY_SEPARATOR)); |
| 12 | + $extension = $current->getExtension(); |
| 13 | + $valid_prefixes = ["src/", "vendor/composer/", "vendor/league/", "vendor/phpseclib/", "vendor/seld/"]; |
| 14 | + |
| 15 | + if ($realpath == "vendor/autoload.php") { |
| 16 | + return true; |
| 17 | + } |
| 18 | + |
| 19 | + foreach ($valid_prefixes as $prefix) { |
| 20 | + if (substr($realpath, 0, strlen($prefix)) == $prefix && $extension == "php") { |
| 21 | + return true; |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + return false; |
| 26 | + } |
| 27 | + } |
| 28 | +} |
| 29 | + |
4 | 30 | if (ini_get("phar.readonly")) {
|
5 |
| - echo "You need to set the 'phar.readonly' option to 'Off' in your php.ini file (" . php_ini_loaded_file() . ")".PHP_EOL; |
| 31 | + echo "You need to set the 'phar.readonly' option to 'Off' in your php.ini file (" . php_ini_loaded_file() . ")" . PHP_EOL; |
6 | 32 | } else {
|
7 | 33 | $phar = new Phar('git-deploy.phar', 0, 'git-deploy');
|
8 |
| - $phar->buildFromDirectory(dirname(__FILE__)); |
| 34 | + $iterator = new NonProjectFilesFilter(new RecursiveDirectoryIterator(dirname(__FILE__), FilesystemIterator::SKIP_DOTS)); |
| 35 | + $d = $phar->buildFromIterator(new RecursiveIteratorIterator($iterator), dirname(__FILE__)); |
9 | 36 | $phar->setStub(file_get_contents(dirname(__FILE__) . "/index.php"));
|
10 | 37 | unset($phar);
|
11 | 38 | @unlink('../git-deploy');
|
12 | 39 | rename('git-deploy.phar', '../git-deploy');
|
13 |
| - echo "Built git-deploy successfully!".PHP_EOL; |
| 40 | + chmod('../git-deploy', 0755); |
| 41 | + echo "Built git-deploy successfully!" . PHP_EOL; |
14 | 42 | }
|
0 commit comments