Skip to content

Commit

Permalink
Implement export handling in installer.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseleite committed Nov 12, 2024
1 parent 2b25032 commit a2491d6
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/StarterKits/InstallableModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ protected function installableFiles(): Collection
*/
protected function expandExportDirectoriesToFiles(string $to, ?string $from = null): Collection
{
$to = Path::tidy($this->starterKitPath($to));
$from = Path::tidy($from ? $this->starterKitPath($from) : $to);
$to = Path::tidy($this->installableFilesPath($to));
$from = Path::tidy($from ? $this->installableFilesPath($from) : $to);

$paths = collect([$from => $to]);

Expand All @@ -139,13 +139,24 @@ protected function expandExportDirectoriesToFiles(string $to, ?string $from = nu
]);
}

$package = $this->installer->package();

return $paths->mapWithKeys(fn ($to, $from) => [
Path::tidy($from) => Path::tidy(str_replace("/vendor/{$package}", '', $to)),
Path::tidy($from) => Path::tidy($this->convertInstallableToDestinationPath($to)),
]);
}

/**
* Convert installable vendor file path to destination path.
*/
protected function convertInstallableToDestinationPath(string $path): string
{
$package = $this->installer->package();

$path = str_replace("/vendor/{$package}/export", '', $path);
$path = str_replace("/vendor/{$package}", '', $path);

return $path;
}

/**
* Install dependency permanently into app.
*/
Expand Down Expand Up @@ -186,7 +197,7 @@ protected function ensureInstallableFilesExist(): self
$this
->exportPaths()
->merge($this->exportAsPaths())
->reject(fn ($path) => $this->files->exists($this->starterKitPath($path)))
->reject(fn ($path) => $this->files->exists($this->installableFilesPath($path)))
->each(function ($path) {
throw new StarterKitException("Starter kit path [{$path}] does not exist.");
});
Expand Down Expand Up @@ -229,13 +240,17 @@ protected function ensureCanRequireDependencies(array $packages, bool $dev = fal
}

/**
* Get starter kit vendor path.
* Get starter kit installable files path.
*/
protected function starterKitPath(?string $path = null): string
protected function installableFilesPath(?string $path = null): string
{
$package = $this->installer->package();

return collect([base_path("vendor/{$package}"), $path])->filter()->implode('/');
$scope = $this->files->exists(base_path("vendor/{$package}/export"))
? 'export'
: null;

return collect([base_path("vendor/{$package}"), $scope, $path])->filter()->implode('/');
}

/**
Expand Down

0 comments on commit a2491d6

Please sign in to comment.