Skip to content

Commit

Permalink
Add support for ignorefile when copying project
Browse files Browse the repository at this point in the history
  • Loading branch information
pelmered committed Jun 11, 2024
1 parent cf40900 commit 4c19eb8
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ApplicationFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\VaporCli;

use Illuminate\Support\Str;
use Symfony\Component\Finder\Finder;

class ApplicationFiles
Expand All @@ -22,6 +23,7 @@ public static function get($path)
->notName('rr')
->notPath('/^'.preg_quote('tests', '/').'/')
->ignoreVcs(true)
->ignoreDotFiles(false);
->ignoreDotFiles(false)
->notPath(VaporIgnore::get()->toArray());
}
}
60 changes: 60 additions & 0 deletions src/VaporIgnore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Laravel\VaporCli;

use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\File;
use Illuminate\Support\LazyCollection;
use Illuminate\Support\Str;
use SplFileObject;

class VaporIgnore
{
public static function get(): LazyCollection
{
$path = getcwd().'/.vaporignore';

$baseDir = dirname($path);

return static::getLines($path)->map(function ($line) use ($baseDir) {
return static::parseLine($baseDir, trim($line));
})->flatten()->filter();
}

protected static function getLines($path): LazyCollection
{
return LazyCollection::make(function () use ($path) {
$file = new SplFileObject($path);

$file->setFlags(
SplFileObject::SKIP_EMPTY
| SplFileObject::READ_AHEAD
| SplFileObject::DROP_NEW_LINE
);

while (! $file->eof()) {
yield $file->fgets();
}
});
}

protected static function parseLine($baseDir, $line): false|array|null
{
$line = trim($line);

return Arr::map(match ($line) {
'', '#' => [], # ignore empty lines and comments
default => glob("$baseDir/$line")
}, static function($line) use ($baseDir) {
return Str::of($line)
->after($baseDir)
->trim('/')
->replace('/', '\/')
->prepend('/^')
->append('/')
->toString();
});
}
}

0 comments on commit 4c19eb8

Please sign in to comment.