Skip to content

Commit

Permalink
chore:update
Browse files Browse the repository at this point in the history
  • Loading branch information
tintnaingwinn committed Feb 9, 2024
1 parent 554e36b commit a4571fd
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 19 deletions.
6 changes: 0 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Changelog

All notable changes to `vapor-ignore` will be documented in this file.

## v1.0.0 - 2024-02-09

- Initial release

**Full Changelog**: https://github.com/ageekdev/vapor-ignore/commits/v1.0.0
67 changes: 56 additions & 11 deletions src/Commands/CleanIgnoredFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@
namespace AgeekDev\VaporIgnore\Commands;

use AgeekDev\VaporIgnore\Manifest;
use AgeekDev\VaporIgnore\Path;
use AgeekDev\VaporIgnore\Vendor;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use Laravel\VaporCli\Helpers;
use Laravel\VaporCli\Path;
use Symfony\Component\Finder\Exception\DirectoryNotFoundException;
use Symfony\Component\Finder\Finder;

class CleanIgnoredFilesCommand extends Command
{
protected Filesystem $files;

protected int $totalFiles = 0;

protected int $totalDirectories = 0;

protected int $totalFileSize = 0;

/**
* Configure the command options.
*/
Expand Down Expand Up @@ -46,6 +52,9 @@ public function handle(): void
$this->removeOtherFiles();
$this->removeUserIgnoredFiles();
$this->removeVaporIgnoreYml();

Helpers::step('<comment>Total Removed Files Size:</comment> '.round($this->totalFileSize / 1024, 2).'kb');

}

/**
Expand All @@ -68,6 +77,8 @@ protected function removeReadmeFiles(): void
protected function removeChangeLogFiles(): void
{
if (Manifest::isIgnoredVendor(Vendor::CHANGE_LOG)) {
Helpers::step('<options=bold>Removing CHANGELOG files</>');

$this->removeFiles([
'CHANGELOG.md',
'changelog.htm',
Expand All @@ -81,7 +92,7 @@ protected function removeChangeLogFiles(): void
protected function removeContributingFiles(): void
{
if (Manifest::isIgnoredVendor(Vendor::CONTRIBUTING)) {
Helpers::step('<options=bold>Removing UPGRADE files</>');
Helpers::step('<options=bold>Removing CONTRIBUTING files</>');

$this->removeFiles([
'CONTRIBUTING.md',
Expand All @@ -96,7 +107,7 @@ protected function removeContributingFiles(): void
protected function removeUpgradeFiles(): void
{
if (Manifest::isIgnoredVendor(Vendor::UPGRADE)) {
Helpers::step('<options=bold>Removing Upgrade files</>');
Helpers::step('<options=bold>Removing UPGRADE files</>');

$this->removeFiles([
'UPGRADING.md',
Expand All @@ -111,7 +122,7 @@ protected function removeUpgradeFiles(): void
protected function removeSecurityMdFiles(): void
{
if (Manifest::isIgnoredVendor(Vendor::SECURITY)) {
Helpers::step('<options=bold>Removing security.md files</>');
Helpers::step('<options=bold>Removing SECURITY.md files</>');

$this->removeFiles([
'SECURITY.md',
Expand All @@ -125,7 +136,7 @@ protected function removeSecurityMdFiles(): void
protected function removeTestDirectories(): void
{
if (Manifest::isIgnoredVendor(Vendor::TEST)) {
Helpers::step('<options=bold>Removing Test</>');
Helpers::step('<options=bold>Removing Test Folders</>');

$this->removeFiles([
'phpunit.xml.dist',
Expand All @@ -137,6 +148,9 @@ protected function removeTestDirectories(): void
->in(Path::vendor().'/*/*/');

foreach ($finder as $file) {
Helpers::step('<comment>Removing Ignored Directory:</comment> '.str_replace(Path::current().'/', '', $file->getRealPath()));
$this->totalFileSize += $file->getSize();
$this->totalFiles++;
$this->files->deleteDirectory($file->getRealPath(), true);
}
}
Expand All @@ -148,7 +162,7 @@ protected function removeTestDirectories(): void
protected function removeLicenseFiles(): void
{
if (Manifest::isIgnoredVendor(Vendor::LICENSE)) {
Helpers::step('<options=bold>Removing License Files</>');
Helpers::step('<options=bold>Removing LICENSE Files</>');

$this->removeFiles([
'LICENSE',
Expand All @@ -166,7 +180,7 @@ protected function removeLicenseFiles(): void
protected function removeLaravelIdeaDirectory(): void
{
if (Manifest::isIgnoredVendor(Vendor::LARAVEL_IDEA)) {
Helpers::step('<options=bold>Removing Laravel Idea Folder</>');
Helpers::step('<options=bold>Removing Laravel IDEA Folder</>');

$this->removeDirectory(Path::vendor().'/_laravel_idea');
}
Expand All @@ -178,14 +192,21 @@ protected function removeLaravelIdeaDirectory(): void
protected function removeDotGithubDirectories(): void
{
if (Manifest::isIgnoredVendor(Vendor::DOT_GITHUB)) {
Helpers::step('<options=bold>Removing .github Folders From Vendor</>');
Helpers::step('<options=bold>Removing .github Folders</>');

$finder = (new Finder())
->ignoreDotFiles(false)
->directories()->name('.github')
->in(Path::vendor().'/*/*/');

if ($finder->count() === 0) {
Helpers::step('<comment>Not Found Ignored Directory:</comment> .github/');
}

foreach ($finder as $file) {
Helpers::step('<comment>Removing Ignored Directory:</comment> '.str_replace(Path::current().'/', '', $file->getRealPath()));
$this->totalFileSize += $file->getSize();
$this->totalDirectories++;
$this->files->deleteDirectory($file->getRealPath(), true);
}
}
Expand All @@ -211,7 +232,7 @@ protected function removeOtherFiles(): void
protected function removeDotFiles(): void
{
if (Manifest::isIgnoredVendor(Vendor::DOT_FILES)) {
Helpers::step('<options=bold>Removing Dot Files From Vendor</>');
Helpers::step('<options=bold>Removing Dot Files</>');

$this->removeFiles([
'.editorconfig',
Expand All @@ -227,16 +248,29 @@ protected function removeDotFiles(): void
*/
protected function removeFiles($files, $ignoreDotFiles = true): void
{
$isEmpty = true;

foreach ($files as $item) {
$finder = (new Finder())
->files()->name($item)
->ignoreDotFiles($ignoreDotFiles)
->in(Path::vendor().'/*/*/');

if ($finder->count() > 0) {
$isEmpty = false;
}

foreach ($finder as $file) {
$this->totalFileSize += $file->getSize();
$this->totalFiles++;
Helpers::step('<comment>Removing Ignored File:</comment> '.str_replace(Path::current().'/', '', $file->getRealPath()));
$this->files->delete($file->getRealPath());
}
}

if ($isEmpty) {
Helpers::step('<comment>Not Found Ignored File:</comment> '.implode(', ', $files));
}
}

/**
Expand All @@ -245,6 +279,9 @@ protected function removeFiles($files, $ignoreDotFiles = true): void
protected function removeDirectory($directory): void
{
if ($this->files->isDirectory($directory)) {
Helpers::step('<comment>Removing Ignored Directory: </comment> '.$directory.'/');
$this->totalFileSize += $this->files->size($directory);
$this->totalDirectories++;
$this->files->deleteDirectory($directory, true);
}
}
Expand All @@ -260,15 +297,20 @@ protected function removeUserIgnoredFiles(): void
return;
}

Helpers::step('<options=bold>Removing User Ignored Files</>');

$notFoundDirectories = [];

foreach ($ignoredFiles as $pattern) {
[$directory, $filePattern] = $this->parsePattern($pattern);

if ($this->files->exists($directory.'/'.$filePattern) && $this->files->isDirectory($directory.'/'.$filePattern)) {
Helpers::step('<comment>Removing Ignored Directory:</comment> '.$filePattern.'/');

$fileSize = $this->files->size($directory.'/'.$filePattern);
$this->files->deleteDirectory($directory.'/'.$filePattern);

$this->totalFileSize += $fileSize;
$this->totalDirectories++;
} else {
try {
$files = (new Finder())
Expand All @@ -279,8 +321,11 @@ protected function removeUserIgnoredFiles(): void

foreach ($files as $file) {
Helpers::step('<comment>Removing Ignored File:</comment> '.str_replace(Path::current().'/', '', $file->getRealPath()));

$fileSize = $this->files->size($file->getRealPath());
$this->files->delete($file->getRealPath());

$this->totalFileSize += $fileSize;
$this->totalFiles++;
}
} catch (DirectoryNotFoundException) {
$notFoundDirectories[] = $directory.'/'.$filePattern;
Expand Down
2 changes: 1 addition & 1 deletion src/Manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function addCleanCommandToVaporEnvironments(): void
{
$manifest = static::vapor();

$command = 'php ./vendor/bin/vapor-ignore clean:ignored-file';
$command = 'php ./vendor/bin/vapor-ignore clean:ignored-files';

$environments = $manifest['environments'] ?? [];

Expand Down
2 changes: 1 addition & 1 deletion src/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Path
*/
public static function vendor(): string
{
return static::build().'/vendor';
return static::current().'/vendor';
}

/**
Expand Down

0 comments on commit a4571fd

Please sign in to comment.