Skip to content

Commit

Permalink
Improved bundler further
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammyjo20 committed Aug 31, 2020
1 parent ccf0246 commit 27e94f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 35 deletions.
45 changes: 12 additions & 33 deletions src/Services/BundleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,41 +53,13 @@ public function __construct()
public function create(): void
{
$public_path = config('lasso.public_path');

// Firstly, let's move all the files into a temporary location.
$this->filesystem->copyDirectory($public_path, '.lasso/bundle-unsafe');

// Now we want to process each file, and make sure it's safe.
$this->createSafeDirectory();
}

/**
* @return void
*/
private function createSafeDirectory(): void
{
$filesystem = $this->filesystem;
$path = base_path('.lasso/bundle-unsafe');

// Loop through files and delete any "excluded"
foreach($this->getForbiddenFiles() as $file) {
if ($filesystem->exists($path . '/' . $file)) {
$filesystem->delete($path . '/' . $file);
}
}

// Loop through directories and delete any "excluded"
foreach($this->getForbiddenDirectories() as $directory) {
if ($filesystem->exists($path . '/' . $directory)) {
$filesystem->deleteDirectory($path . '/' . $directory);
}
}

// Now let's create a finder instance from the files remaining.
$files = (new FileLister($path))
// Let's create a finder instance
$files = (new FileLister($public_path))
->getFinder();

$safe_path = base_path('.lasso/bundle-safe');
$path = base_path('.lasso/bundle');

// Now we want to iterate through each of Finder's
// files. We are doing this because Finder will automatically
Expand All @@ -107,16 +79,23 @@ private function createSafeDirectory(): void

// Make sure the destination exists
$filesystem->ensureDirectoryExists(
$safe_path . '/' . $file->getRelativePath()
$path . '/' . $file->getRelativePath()
);

// Copy the file!

$filesystem->copy(
$file->getPathname(),
$safe_path . '/' . $file->getRelativePathname()
$path . '/' . $file->getRelativePathname()
);
}

// Loop through directories and delete any "excluded"
foreach($this->getForbiddenDirectories() as $directory) {
if ($filesystem->exists($path . '/' . $directory)) {
$filesystem->deleteDirectory($path . '/' . $directory);
}
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Services/Bundler.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function deleteLassoDirectory(): void
private function createZipArchiveFromBundle(string $bundle_directory): string
{
$files = (new Finder())
->in(base_path('.lasso/bundle-safe'))
->in(base_path('.lasso/bundle'))
->files();

$relative_path = '.lasso/dist/' . $this->bundle_id . '.zip';
Expand Down Expand Up @@ -124,7 +124,7 @@ public function execute(bool $use_git = true)

$this->console->info('⏳ Zipping assets...');

$zip = $this->createZipArchiveFromBundle('.lasso/bundle-safe');
$zip = $this->createZipArchiveFromBundle('.lasso/bundle');

$this->console->info('✅ Successfully zipped assets.');

Expand Down

0 comments on commit 27e94f4

Please sign in to comment.